From 8c44bb712c7e576053f8bc9356e07d6187ddeb0c Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Tue, 11 Aug 2020 11:25:05 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0service?= =?UTF-8?q?=E5=B1=82=E5=A4=84=E7=BD=AE=E8=AE=BE=E5=A4=87=E5=AF=B9=E6=8E=A5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/DisposeDeviceManagerTest.java | 2 +- .../DisposeAbilityRouterServiceTest.java | 126 ++++++++++++++++++ 2 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java diff --git a/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java b/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java index d90d9274..1a816c73 100644 --- a/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java +++ b/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java @@ -170,7 +170,7 @@ public class DisposeDeviceManagerTest { * A 3 change dispose device status. */ @Test - public void a3_changeDisposeDeviceStatus() { + public void a3_changeDisposeDeviceStatus() { disposeDeviceMapper.selectAll().forEach(v -> { for (ObjectStatus obj : ObjectStatus.values() diff --git a/src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java b/src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java new file mode 100644 index 00000000..8c74ca63 --- /dev/null +++ b/src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java @@ -0,0 +1,126 @@ +package com.dispose.test.service; + +import com.dispose.common.DisposeDeviceType; +import com.dispose.common.ErrorCode; +import com.dispose.common.HttpType; +import com.dispose.common.ObjectStatus; +import com.dispose.pojo.entity.DisposeDevice; +import com.dispose.pojo.po.AbilityInfo; +import com.dispose.pojo.po.MulReturnType; +import com.dispose.service.DisposeAbilityRouterService; +import com.dispose.service.UserAccountService; +import com.dispose.test.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.Before; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +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.security.NoSuchAlgorithmException; +import java.util.List; + +/** + * The type User account service test. + * + * @author + */ +@RunWith(SpringRunner.class) +@SpringBootTest +@Slf4j +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Transactional +@Rollback +public class DisposeAbilityRouterServiceTest extends InitTestEnvironment { + /** + * The constant token. + */ + private static String token = ""; + /** + * The User account service. + */ + @Resource + private UserAccountService userAccountService; + /** + * The dispose device ability router service. + */ + @Resource + private DisposeAbilityRouterService disposeAbilityRouterService; + /** + * The Object mapper. + */ + @Resource + private ObjectMapper objectMapper; + + + public static Integer VIRTUAL_DISPOSE = 999; + + /** + * User login test. + * + * @throws NoSuchAlgorithmException the no such algorithm exception + */ + @Before + public void userLoginTest() throws NoSuchAlgorithmException { + MulReturnType ret = userAccountService.loginService(getUSER_NAME(), + getPASSWORD()); + + if (ret.getFirstParam() == ErrorCode.ERR_OK) { + DisposeAbilityRouterServiceTest.token = ret.getSecondParam(); + } + } + + /** + * A 1 Add dispose device list. + */ + @Test + public void a1_addDisposeAbilityDeviceTest() throws JsonProcessingException { + DisposeDevice dev = DisposeDevice.builder() + .ipAddr("192.168.10.1") + .ipPort("") + .deviceType(DisposeDeviceType.VIRTUAL_DISPOSE) + .areaCode(0) + .deviceName("虚拟设备") + .manufacturer("Virtual") + .model("Unknown") + .version("Unknown") + .userName("") + .password("") + .urlPath("") + .urlType(HttpType.HTTP) + .readme("实验室测试设备") + .status(ObjectStatus.NORMAL) + .build(); + + disposeAbilityRouterService.addDisposeAbilityDevice(dev); + + Assert.assertEquals(dev.getDeviceType().getValue(), VIRTUAL_DISPOSE); + + AbilityInfo abilityInfo = disposeAbilityRouterService.getAbilityDevice(dev.getIpAddr(), dev.getIpPort()); + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(abilityInfo)); + } + + + /** + * A 2 Gets all ability devices. + */ + @Test + public void a2_getAllAbilityDevicesTest() throws JsonProcessingException { + List abilityInfoList = disposeAbilityRouterService.getAllAbilityDevices(); + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(abilityInfoList)); + + abilityInfoList.forEach(v->{ + Assert.assertNotNull(v.getDb()); + Assert.assertNotNull(v.getDev()); + Assert.assertFalse(v.isLinkStatus()); + }); + } +}