diff --git a/src/test/java/com/dispose/test/dev/mapper/ServiceGroupMapperTest.java b/src/test/java/com/dispose/test/dev/mapper/ServiceGroupMapperTest.java index f65ecdc7..a004c249 100644 --- a/src/test/java/com/dispose/test/dev/mapper/ServiceGroupMapperTest.java +++ b/src/test/java/com/dispose/test/dev/mapper/ServiceGroupMapperTest.java @@ -23,8 +23,8 @@ import java.util.List; @Slf4j //@FixMethodOrder(MethodSorters.NAME_ASCENDING) //@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) -@Transactional -@Rollback +//@Transactional +//@Rollback public class ServiceGroupMapperTest extends InitTestEnvironment { /** * The service group mapper. @@ -38,12 +38,25 @@ public class ServiceGroupMapperTest extends InitTestEnvironment { private ObjectMapper objectMapper; /** - * A 1 add new service group. + * A 1 select all. * * @throws JsonProcessingException the json processing exception */ @Test - public void a1_addServiceGroup() throws JsonProcessingException{ + public void a1_selectAllTest() throws JsonProcessingException{ + List serviceList = serviceGroupMapper.selectAll(); + //Assert.assertNotNull(serviceList); + //Assert.assertNotEquals(serviceList.size(), 0); + log.info("Database: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(serviceList)); + } + + /** + * A 2 add new service group. + * + * @throws JsonProcessingException the json processing exception + */ + @Test + public void a2_addServiceGroup() throws JsonProcessingException{ List service = new ArrayList<>(); service.add(ServiceInfo.builder() .serviceId("100") @@ -70,5 +83,75 @@ public class ServiceGroupMapperTest extends InitTestEnvironment { } + /** + * A 3 delete service group by id. + */ + @Test + public void a3_delServiceGroupByIdTest(){ + 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()); + serviceGroupMapper.addServiceGroup(service); + + log.info("service number: {}", serviceGroupMapper.selectAll().size()); + serviceGroupMapper.selectAll().forEach(v -> { + int ret = serviceGroupMapper.delServiceGroupById(v.getId()); + + try { + log.info("service info: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v)); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + Assert.assertEquals(1,ret); + }); + log.info("service after delete operate: {}", serviceGroupMapper.selectAll()); + Assert.assertEquals(0,serviceGroupMapper.selectAll().size()); + } + + /** + * A 4 delete service group by service id. + */ + @Test + public void a4_delServiceGroupByServiceIdTest(){ + 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()); + serviceGroupMapper.addServiceGroup(service); + + log.info("service number: {}", serviceGroupMapper.selectAll().size()); + serviceGroupMapper.selectAll().forEach(v -> { + int ret = serviceGroupMapper.delServiceGroupByServiceId(v.getServiceId()); + + try { + log.info("service info: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v)); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + + Assert.assertEquals(1,ret); + }); + log.info("service after delete operate: {}", serviceGroupMapper.selectAll()); + Assert.assertEquals(0,serviceGroupMapper.selectAll().size()); + } }