From afc316945bc7f7dbf84f8daded510316a6d6fbce Mon Sep 17 00:00:00 2001 From: wangyiyun Date: Fri, 15 Jan 2021 14:35:58 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=E6=B7=BB=E5=8A=A0=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E4=BF=A1=E6=81=AF=E6=9F=A5=E7=9C=8B=E3=80=81=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E7=9A=84mapper=E5=B1=82=E6=B5=8B=E8=AF=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/mapper/ServiceGroupMapperTest.java | 91 ++++++++++++++++++- 1 file changed, 87 insertions(+), 4 deletions(-) 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()); + } }