diff --git a/src/main/resources/mappers/ServiceGroup.xml b/src/main/resources/mappers/ServiceGroup.xml index 1de535f3..e2eb2675 100644 --- a/src/main/resources/mappers/ServiceGroup.xml +++ b/src/main/resources/mappers/ServiceGroup.xml @@ -19,7 +19,7 @@ INSERT IGNORE INTO service_group(serviceId, serviceType, serviceBandwidth, serviceIp) VALUES - (#{svg.deviceId}, #{svg.serviceType}, #{svg.serviceBandwidth}, #{svg.serviceIp}) + (#{svg.serviceId}, #{svg.serviceType}, #{svg.serviceBandwidth}, #{svg.serviceIp}) diff --git a/src/test/java/com/dispose/test/dev/mapper/ServiceGroupMapperTest.java b/src/test/java/com/dispose/test/dev/mapper/ServiceGroupMapperTest.java new file mode 100644 index 00000000..f65ecdc7 --- /dev/null +++ b/src/test/java/com/dispose/test/dev/mapper/ServiceGroupMapperTest.java @@ -0,0 +1,74 @@ +package com.dispose.test.dev.mapper; + +import com.dispose.mapper.ServiceGroupMapper; +import com.dispose.pojo.entity.ServiceInfo; +import com.dispose.test.dev.Global.InitTestEnvironment; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.Rollback; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +@RunWith(SpringRunner.class) +@SpringBootTest +@Slf4j +//@FixMethodOrder(MethodSorters.NAME_ASCENDING) +//@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +@Transactional +@Rollback +public class ServiceGroupMapperTest extends InitTestEnvironment { + /** + * The service group mapper. + */ + @Resource + private ServiceGroupMapper serviceGroupMapper; + /** + * The Object mapper. + */ + @Resource + private ObjectMapper objectMapper; + + /** + * A 1 add new service group. + * + * @throws JsonProcessingException the json processing exception + */ + @Test + public void a1_addServiceGroup() throws JsonProcessingException{ + List service = new ArrayList<>(); + service.add(ServiceInfo.builder() + .serviceId("100") + .serviceType("GAME") + .serviceBandwidth(1000L) + .serviceIp("192.168.100.1-192.168.100.10,192.168.100.20-192.168.100.21") + .build()); + service.add(ServiceInfo.builder() + .serviceId("101") + .serviceType("DNS") + .serviceBandwidth(2000L) + .serviceIp("192.168.101.1-192.168.101.10") + .build()); + + int num = serviceGroupMapper.addServiceGroup(service); + Assert.assertEquals(num, service.size()); + log.info("add num {}: {}", num, objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(service)); + + List serviceList = serviceGroupMapper.selectAll(); + Assert.assertNotNull(serviceList); + Assert.assertNotEquals(serviceList.size(), 0); + + log.info("Database: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(serviceList)); + + } + + +}