parent
3964061010
commit
1b14dbca41
|
@ -114,7 +114,4 @@ buildNumber.properties
|
||||||
/logs/
|
/logs/
|
||||||
!/src/main/resources/git.properties
|
!/src/main/resources/git.properties
|
||||||
basedir/
|
basedir/
|
||||||
src/test/java/com/dispose/manager/
|
|
||||||
src/test/java/com/dispose/redis/
|
|
||||||
src/test/java/com/dispose/service/
|
|
||||||
/.idea/
|
/.idea/
|
||||||
|
|
|
@ -19,17 +19,20 @@ public class DisposeCapacity {
|
||||||
/**
|
/**
|
||||||
* The interface Base view.
|
* The interface Base view.
|
||||||
*/
|
*/
|
||||||
public interface BaseView {}
|
public interface BaseView {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Capacity view.
|
* The interface Capacity view.
|
||||||
*/
|
*/
|
||||||
public interface CapacityView extends BaseView {}
|
public interface CapacityView extends BaseView {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Depend ip view.
|
* The interface Depend ip view.
|
||||||
*/
|
*/
|
||||||
public interface DependIpView extends BaseView {}
|
public interface DependIpView extends BaseView {
|
||||||
|
}
|
||||||
|
|
||||||
@JsonView(BaseView.class)
|
@JsonView(BaseView.class)
|
||||||
private int type;
|
private int type;
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.dispose.controller.DeviceNodeManagerControllerTest;
|
||||||
import com.dispose.dptech.DPTechInterfaceTestCase;
|
import com.dispose.dptech.DPTechInterfaceTestCase;
|
||||||
import com.dispose.mapper.DisposeDeviceMapperTest;
|
import com.dispose.mapper.DisposeDeviceMapperTest;
|
||||||
import com.dispose.mapper.UserAccountMapperTest;
|
import com.dispose.mapper.UserAccountMapperTest;
|
||||||
|
import com.dispose.service.UserAccountServiceTest;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Suite;
|
import org.junit.runners.Suite;
|
||||||
|
|
||||||
|
@ -20,7 +21,8 @@ import org.junit.runners.Suite;
|
||||||
DisposeDeviceMapperTest.class,
|
DisposeDeviceMapperTest.class,
|
||||||
AuthControllerTest.class,
|
AuthControllerTest.class,
|
||||||
DeviceNodeManagerControllerTest.class,
|
DeviceNodeManagerControllerTest.class,
|
||||||
DeviceNodeInfoControllerTest.class
|
DeviceNodeInfoControllerTest.class,
|
||||||
|
UserAccountServiceTest.class
|
||||||
})
|
})
|
||||||
public class AllDisposePlatformTest {
|
public class AllDisposePlatformTest {
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,11 @@ import com.dispose.pojo.dto.ProtocolReqDTO;
|
||||||
import com.dispose.pojo.dto.ProtocolRespDTO;
|
import com.dispose.pojo.dto.ProtocolRespDTO;
|
||||||
import com.dispose.pojo.vo.auth.LoginReq;
|
import com.dispose.pojo.vo.auth.LoginReq;
|
||||||
import com.dispose.pojo.vo.auth.LoginRsp;
|
import com.dispose.pojo.vo.auth.LoginRsp;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
|
@ -38,7 +41,36 @@ public class AuthControllerTest {
|
||||||
@Resource
|
@Resource
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
static private String logToken = "";
|
private static String logToken = "";
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void userLogin() throws Exception {
|
||||||
|
LoginReq logReq = LoginReq.builder()
|
||||||
|
.userName("admin")
|
||||||
|
.password("c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||||
|
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
||||||
|
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||||
|
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||||
|
reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq));
|
||||||
|
|
||||||
|
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||||
|
.post("/auth/login")
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||||
|
.andDo(print()).andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.code").value(200))
|
||||||
|
.andReturn()
|
||||||
|
.getResponse()
|
||||||
|
.getContentAsString();
|
||||||
|
|
||||||
|
ProtocolRespDTO rspInfo = objectMapper.readValue(ret, ProtocolRespDTO.class);
|
||||||
|
LoginRsp logRsp = objectMapper.readValue(rspInfo.getMsgContent(), LoginRsp.class);
|
||||||
|
|
||||||
|
logToken = logRsp.getToken();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Login 1.
|
* Login 1.
|
||||||
|
@ -71,8 +103,7 @@ public class AuthControllerTest {
|
||||||
ProtocolRespDTO rspInfo = objectMapper.readValue(ret, ProtocolRespDTO.class);
|
ProtocolRespDTO rspInfo = objectMapper.readValue(ret, ProtocolRespDTO.class);
|
||||||
LoginRsp logRsp = objectMapper.readValue(rspInfo.getMsgContent(), LoginRsp.class);
|
LoginRsp logRsp = objectMapper.readValue(rspInfo.getMsgContent(), LoginRsp.class);
|
||||||
|
|
||||||
logToken = logRsp.getToken();
|
Assert.assertEquals(logToken, logRsp.getToken());
|
||||||
log.info("Login Token:" + logToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,8 +123,6 @@ public class AuthControllerTest {
|
||||||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||||
reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq));
|
reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq));
|
||||||
|
|
||||||
login1();
|
|
||||||
|
|
||||||
mockMvc.perform(MockMvcRequestBuilders
|
mockMvc.perform(MockMvcRequestBuilders
|
||||||
.post("/auth/logout")
|
.post("/auth/logout")
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
|
|
@ -3,112 +3,143 @@ package com.dispose.dptech;
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.ConstValue;
|
||||||
import com.dispose.dispose.DeviceRouter;
|
import com.dispose.dispose.DeviceRouter;
|
||||||
import com.dispose.dispose.DisposeEntryManager;
|
import com.dispose.dispose.DisposeEntryManager;
|
||||||
|
import com.dispose.dispose.po.DeviceInfo;
|
||||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||||
import com.dptech.dispose.DetectionObjectDataForService;
|
import com.dptech.dispose.DetectionObjectDataForService;
|
||||||
import com.dptech.dispose.ProtectionObjectDataForService;
|
import com.dptech.dispose.ProtectionObjectDataForService;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import java.util.ArrayList;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.cxf.databinding.AbstractDataBinding;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.FixMethodOrder;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.MethodSorters;
|
||||||
|
import org.mockito.BDDMockito;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
|
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Dp tech interface test case.
|
|
||||||
*/
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@SpringBootTest
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
public class DPTechInterfaceTestCase {
|
public class DPTechInterfaceTestCase {
|
||||||
// @Resource
|
// @Before
|
||||||
// private ObjectMapper objMapper;
|
// public void initVirtualDevice() {
|
||||||
|
// List<ProtectionObjectDataForService> protectList = new ArrayList<>();
|
||||||
/**
|
// List<DetectionObjectDataForService> detectionList = new ArrayList<>();
|
||||||
* Get all detection object from umc.
|
// detectionList.add(new DetectionObjectDataForService());
|
||||||
*/
|
// detectionList.add(new DetectionObjectDataForService());
|
||||||
// @Test
|
// detectionList.add(new DetectionObjectDataForService());
|
||||||
// public void getAllDetectionObjectFromUMC(){
|
|
||||||
//
|
//
|
||||||
// try {
|
// protectList.add(new ProtectionObjectDataForService());
|
||||||
// DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15");
|
// protectList.add(new ProtectionObjectDataForService());
|
||||||
|
// protectList.add(new ProtectionObjectDataForService());
|
||||||
//
|
//
|
||||||
// List<DetectionObjectDataForService> detDevs = dp.getAllDetectionObject();
|
// List<DisposeDeviceCapacity> capList = new ArrayList<>();
|
||||||
|
// capList.add(DisposeDeviceCapacity.builder()
|
||||||
|
// .capacity(0)
|
||||||
|
// .tolFlowCapacity(1024)
|
||||||
|
// .build());
|
||||||
|
// capList.add(DisposeDeviceCapacity.builder()
|
||||||
|
// .capacity(1)
|
||||||
|
// .build());
|
||||||
//
|
//
|
||||||
// Assert.assertNotEquals(detDevs.size(), 0);
|
// DisposeEntryManager disposeEntryManager = PowerMockito.mock(DisposeEntryManager.class);
|
||||||
//
|
//
|
||||||
// } catch (Exception ex){
|
// PowerMockito.when(disposeEntryManager.getAllDetectionObject()).thenReturn(detectionList);
|
||||||
// Assert.fail();
|
// PowerMockito.when(disposeEntryManager.getAllProtectionObject()).thenReturn(protectList);
|
||||||
// }
|
// PowerMockito.when(disposeEntryManager.getProtectDevices()).thenReturn("10.88.76.41");
|
||||||
|
// PowerMockito.when(disposeEntryManager.getDeviceLinkStatus()).thenReturn(true);
|
||||||
|
// PowerMockito.when(disposeEntryManager.getDeviceCapacity()).thenReturn(capList);
|
||||||
|
// PowerMockito.when(disposeEntryManager.getVersion()).thenReturn("1.0.0");
|
||||||
|
// PowerMockito.when(disposeEntryManager.getDeviceInfo()).thenReturn(new DeviceInfo());
|
||||||
|
//
|
||||||
|
// PowerMockito.mockStatic(DeviceRouter.class);
|
||||||
|
// PowerMockito.when(DeviceRouter.deviceRouterFactory(BDDMockito.anyInt(), BDDMockito.anyString())).thenReturn(disposeEntryManager);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/**
|
@Test
|
||||||
* Get all protect devices.
|
public void t1_getAllDetectionObjectFromUMC(){
|
||||||
*/
|
|
||||||
// @Test
|
|
||||||
// public void getAllProtectDevices(){
|
|
||||||
//
|
|
||||||
// try {
|
|
||||||
// DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15");
|
|
||||||
//
|
|
||||||
// String proDevs = dp.getProtectDevices();
|
|
||||||
//
|
|
||||||
// Assert.assertNotEquals(proDevs.length(), 0);
|
|
||||||
//
|
|
||||||
// } catch (Exception ex){
|
|
||||||
// Assert.fail();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
try {
|
||||||
* Get all protect objects.
|
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15");
|
||||||
*/
|
|
||||||
// @Test
|
|
||||||
// public void getAllProtectObjects(){
|
|
||||||
//
|
|
||||||
// try {
|
|
||||||
// DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15");
|
|
||||||
//
|
|
||||||
// List<ProtectionObjectDataForService> proObjs = dp.getAllProtectionObject();
|
|
||||||
//
|
|
||||||
// Assert.assertNotEquals(proObjs.size(), 0);
|
|
||||||
//
|
|
||||||
// } catch (Exception ex){
|
|
||||||
// Assert.fail();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
List<DetectionObjectDataForService> detDevs = dp.getAllDetectionObject();
|
||||||
* Get link status.
|
|
||||||
*/
|
|
||||||
// @Test
|
|
||||||
// public void getLinkStatus(){
|
|
||||||
//
|
|
||||||
// DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(),
|
|
||||||
// "10.88.77.15");
|
|
||||||
//
|
|
||||||
// Assert.assertTrue(dp.getDeviceLinkStatus());
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
Assert.assertNotEquals(detDevs.size(), 0);
|
||||||
* Gets device capacity.
|
|
||||||
*
|
} catch (Exception ex){
|
||||||
* @throws JsonProcessingException the json processing exception
|
Assert.fail();
|
||||||
*/
|
}
|
||||||
// @Test
|
}
|
||||||
// public void getDeviceCapacity() throws JsonProcessingException {
|
|
||||||
//
|
@Test
|
||||||
// DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(),
|
public void t2_getAllProtectDevices(){
|
||||||
// "10.88.77.15");
|
|
||||||
//
|
try {
|
||||||
// List<DisposeDeviceCapacity> capList = dp.getDeviceCapacity();
|
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15");
|
||||||
//
|
|
||||||
// Assert.assertNotEquals(capList.size(), 0);
|
String proDevs = dp.getProtectDevices();
|
||||||
//
|
|
||||||
// log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList));
|
Assert.assertNotEquals(proDevs.length(), 0);
|
||||||
// }
|
|
||||||
|
} catch (Exception ex){
|
||||||
|
Assert.fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void t3_getAllProtectObjects(){
|
||||||
|
|
||||||
|
try {
|
||||||
|
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15");
|
||||||
|
|
||||||
|
List<ProtectionObjectDataForService> proObjs = dp.getAllProtectionObject();
|
||||||
|
|
||||||
|
Assert.assertNotEquals(proObjs.size(), 0);
|
||||||
|
|
||||||
|
} catch (Exception ex){
|
||||||
|
Assert.fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void t4_getLinkStatus(){
|
||||||
|
|
||||||
|
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(),
|
||||||
|
"10.88.77.15");
|
||||||
|
|
||||||
|
Assert.assertTrue(dp.getDeviceLinkStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void t5_getDeviceCapacity() throws JsonProcessingException {
|
||||||
|
|
||||||
|
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(),
|
||||||
|
"10.88.77.15");
|
||||||
|
|
||||||
|
List<DisposeDeviceCapacity> capList = dp.getDeviceCapacity();
|
||||||
|
|
||||||
|
Assert.assertNotEquals(capList.size(), 0);
|
||||||
|
|
||||||
|
log.info(new ObjectMapper().writeValueAsString(capList));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
package com.dispose.service;
|
||||||
|
|
||||||
|
import com.dispose.common.ErrorCode;
|
||||||
|
import com.dispose.pojo.entity.UserAccount;
|
||||||
|
import com.dispose.pojo.po.MReturnType;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
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.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
@Slf4j
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
public class UserAccountServiceTest {
|
||||||
|
@Resource
|
||||||
|
private UserAccountService userAccountService;
|
||||||
|
|
||||||
|
private static String token = "";
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void userLogin() throws NoSuchAlgorithmException {
|
||||||
|
MReturnType<ErrorCode, String> ret = userAccountService.loginService("admin",
|
||||||
|
"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58");
|
||||||
|
|
||||||
|
if(ret.getFirstParam() == ErrorCode.ERR_OK) {
|
||||||
|
UserAccountServiceTest.token = ret.getSecondParam();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void t1_logService() throws NoSuchAlgorithmException {
|
||||||
|
MReturnType<ErrorCode, String> ret = userAccountService.loginService("admin",
|
||||||
|
"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58");
|
||||||
|
|
||||||
|
Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK);
|
||||||
|
Assert.assertNotNull(ret.getSecondParam());
|
||||||
|
Assert.assertEquals(ret.getSecondParam(), UserAccountServiceTest.token);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void t2_logoutService() {
|
||||||
|
ErrorCode err = userAccountService.logoutService("admin", token);
|
||||||
|
Assert.assertEquals(err, ErrorCode.ERR_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void t3_getUserByToken() {
|
||||||
|
UserAccount username = userAccountService.getUserByToken(UserAccountServiceTest.token);
|
||||||
|
|
||||||
|
Assert.assertEquals(username.getUsername(), "admin");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue