OCT
REM: 1. 增加虚拟处置设备,解决jenkins单元测试由于真实设备网络无法访问导致单元测试无法通过的问题
This commit is contained in:
parent
ff02e0c793
commit
a3b766d1c2
|
@ -86,7 +86,9 @@ public class ConstValue {
|
||||||
/**
|
/**
|
||||||
* Haohan platform dispose device type.
|
* Haohan platform dispose device type.
|
||||||
*/
|
*/
|
||||||
HAOHAN_PLATFORM(1, "浩瀚处置设备");
|
HAOHAN_PLATFORM(1, "浩瀚处置设备"),
|
||||||
|
|
||||||
|
VIRTUAL_DISPOSE(999, "虚拟处置设备");
|
||||||
|
|
||||||
private final int code;
|
private final int code;
|
||||||
private final String readme;
|
private final String readme;
|
||||||
|
|
|
@ -15,4 +15,8 @@ public class GlobalVar {
|
||||||
*/
|
*/
|
||||||
public static volatile String THREAT_INFO_TYPE = "1";
|
public static volatile String THREAT_INFO_TYPE = "1";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The constant USED_VIRTUAL_DISPOSE_MODE.
|
||||||
|
*/
|
||||||
|
public static volatile boolean USED_VIRTUAL_DISPOSE_MODE = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package com.dispose.dispose;
|
package com.dispose.dispose;
|
||||||
|
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.ConstValue;
|
||||||
|
import com.dispose.common.GlobalVar;
|
||||||
import com.dispose.dispose.impl.DPTechImpl;
|
import com.dispose.dispose.impl.DPTechImpl;
|
||||||
|
import com.dispose.dispose.impl.VirtualDeviceImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Device router.
|
* The type Device router.
|
||||||
|
@ -17,11 +19,16 @@ public class DeviceRouter {
|
||||||
* @return the dispose entry manager
|
* @return the dispose entry manager
|
||||||
*/
|
*/
|
||||||
public static DisposeEntryManager deviceRouterFactory(int devType, String ipAddr, ConstValue.IPAddrType ipType) {
|
public static DisposeEntryManager deviceRouterFactory(int devType, String ipAddr, ConstValue.IPAddrType ipType) {
|
||||||
|
|
||||||
|
if (GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
|
||||||
|
return new VirtualDeviceImpl(ipAddr);
|
||||||
|
}
|
||||||
|
|
||||||
if (devType == ConstValue.DisposeDeviceType.DPTECH_UMC.getCode()) {
|
if (devType == ConstValue.DisposeDeviceType.DPTECH_UMC.getCode()) {
|
||||||
return new DPTechImpl(ipAddr);
|
return new DPTechImpl(ipAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return new VirtualDeviceImpl(ipAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,142 @@
|
||||||
|
package com.dispose.dispose.impl;
|
||||||
|
|
||||||
|
import com.dispose.common.ConstValue;
|
||||||
|
import com.dispose.dispose.DisposeEntryManager;
|
||||||
|
import com.dispose.dispose.po.DeviceInfo;
|
||||||
|
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Virtual device.
|
||||||
|
*/
|
||||||
|
public class VirtualDeviceImpl implements DisposeEntryManager {
|
||||||
|
/**
|
||||||
|
* Run dispose int.
|
||||||
|
*
|
||||||
|
* @param ip the ip
|
||||||
|
* @return the int
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int runDispose(String ip) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets version.
|
||||||
|
*
|
||||||
|
* @return the version
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getVersion() {
|
||||||
|
return "Virtual_Device_1.0.0";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets device info.
|
||||||
|
*
|
||||||
|
* @return the device info
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public DeviceInfo getDeviceInfo() {
|
||||||
|
return DeviceInfo.builder()
|
||||||
|
.vendor("Virtual")
|
||||||
|
.model("Dispose_1000")
|
||||||
|
.firmware("Unknown")
|
||||||
|
.os("Unknown")
|
||||||
|
.kernel("Linux")
|
||||||
|
.arch("x86_64")
|
||||||
|
.memory(-1)
|
||||||
|
.freeMemory(-1)
|
||||||
|
.cpuUsed(-1)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets device capacity.
|
||||||
|
*
|
||||||
|
* @return the device capacity
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<DisposeDeviceCapacity> getDeviceCapacity() {
|
||||||
|
List<DisposeDeviceCapacity> capList = new ArrayList<>();
|
||||||
|
|
||||||
|
capList.add(DisposeDeviceCapacity.builder()
|
||||||
|
.capacity(ConstValue.DeviceCapacity.CLEANUP.getCode())
|
||||||
|
.tolFlowCapacity(1024)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
capList.add(DisposeDeviceCapacity.builder()
|
||||||
|
.capacity(ConstValue.DeviceCapacity.DETECIVE.getCode())
|
||||||
|
.build());
|
||||||
|
|
||||||
|
return capList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets device link status.
|
||||||
|
*
|
||||||
|
* @return the device link status
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean getDeviceLinkStatus() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all detection object.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @return the all detection object
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public <T> T getAllDetectionObject() {
|
||||||
|
List<String> detectionObjects = new ArrayList<>();
|
||||||
|
|
||||||
|
detectionObjects.add("192.168.10.12-192.168.10.124");
|
||||||
|
return (T) detectionObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all protection object.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @return the all protection object
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public <T> T getAllProtectionObject() {
|
||||||
|
List<String> protectObjects = new ArrayList<>();
|
||||||
|
|
||||||
|
protectObjects.add("10.10.10.1-10.10.10.100");
|
||||||
|
protectObjects.add("172.168.133.12-172.168.133.48");
|
||||||
|
return (T) protectObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets detection devices.
|
||||||
|
*
|
||||||
|
* @return the detection devices
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDetectionDevices() {
|
||||||
|
return "192.168.10.11";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets protect devices.
|
||||||
|
*
|
||||||
|
* @return the protect devices
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getProtectDevices() {
|
||||||
|
return "192.168.10.10";
|
||||||
|
}
|
||||||
|
|
||||||
|
public VirtualDeviceImpl(String ipAddr) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public VirtualDeviceImpl(String ipAddr, ConstValue.IPAddrType type) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.dispose.Global;
|
||||||
|
|
||||||
|
import com.dispose.common.GlobalVar;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class InitTestEnvironment {
|
||||||
|
@BeforeClass
|
||||||
|
public static void initVirtualDevice(){
|
||||||
|
GlobalVar.USED_VIRTUAL_DISPOSE_MODE = true;
|
||||||
|
log.warn("Current Used Virtual Dispose Device");
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package com.dispose.controller;
|
package com.dispose.controller;
|
||||||
|
|
||||||
|
import com.dispose.Global.InitTestEnvironment;
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.ConstValue;
|
||||||
import com.dispose.pojo.dto.ProtocolReqDTO;
|
import com.dispose.pojo.dto.ProtocolReqDTO;
|
||||||
import com.dispose.pojo.dto.ProtocolRespDTO;
|
import com.dispose.pojo.dto.ProtocolRespDTO;
|
||||||
|
@ -34,7 +35,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AuthControllerTest {
|
public class AuthControllerTest extends InitTestEnvironment {
|
||||||
@Resource
|
@Resource
|
||||||
private MockMvc mockMvc;
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.dispose.controller;
|
package com.dispose.controller;
|
||||||
|
|
||||||
|
import com.dispose.Global.InitTestEnvironment;
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.ConstValue;
|
||||||
import com.dispose.mapper.DisposeDeviceMapper;
|
import com.dispose.mapper.DisposeDeviceMapper;
|
||||||
import com.dispose.pojo.dto.ProtocolReqDTO;
|
import com.dispose.pojo.dto.ProtocolReqDTO;
|
||||||
|
@ -33,7 +34,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
public class DeviceNodeInfoControllerTest {
|
public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
|
||||||
@Resource
|
@Resource
|
||||||
private MockMvc mockMvc;
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.dispose.controller;
|
package com.dispose.controller;
|
||||||
|
|
||||||
|
import com.dispose.Global.InitTestEnvironment;
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.ConstValue;
|
||||||
import com.dispose.pojo.dto.ProtocolReqDTO;
|
import com.dispose.pojo.dto.ProtocolReqDTO;
|
||||||
import com.dispose.pojo.po.NewNodeInfo;
|
import com.dispose.pojo.po.NewNodeInfo;
|
||||||
|
@ -33,7 +34,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DeviceNodeManagerControllerTest {
|
public class DeviceNodeManagerControllerTest extends InitTestEnvironment {
|
||||||
@Resource
|
@Resource
|
||||||
private MockMvc mockMvc;
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.dispose.dptech;
|
package com.dispose.dptech;
|
||||||
|
|
||||||
|
import com.dispose.Global.InitTestEnvironment;
|
||||||
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;
|
||||||
|
@ -40,7 +41,7 @@ import java.util.List;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
public class DPTechInterfaceTestCase {
|
public class DPTechInterfaceTestCase extends InitTestEnvironment {
|
||||||
// @Before
|
// @Before
|
||||||
// public void initVirtualDevice() {
|
// public void initVirtualDevice() {
|
||||||
// List<ProtectionObjectDataForService> protectList = new ArrayList<>();
|
// List<ProtectionObjectDataForService> protectList = new ArrayList<>();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.dispose.mapper;
|
package com.dispose.mapper;
|
||||||
|
|
||||||
|
import com.dispose.Global.InitTestEnvironment;
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.ConstValue;
|
||||||
import com.dispose.pojo.entity.DisposeDevice;
|
import com.dispose.pojo.entity.DisposeDevice;
|
||||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||||
|
@ -26,7 +27,7 @@ import java.util.List;
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
public class DisposeDeviceMapperTest {
|
public class DisposeDeviceMapperTest extends InitTestEnvironment {
|
||||||
@Resource
|
@Resource
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.dispose.mapper;
|
package com.dispose.mapper;
|
||||||
|
|
||||||
|
import com.dispose.Global.InitTestEnvironment;
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.ConstValue;
|
||||||
import com.dispose.pojo.entity.UserAccount;
|
import com.dispose.pojo.entity.UserAccount;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
@ -23,7 +24,7 @@ import javax.annotation.Resource;
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
public class UserAccountMapperTest {
|
public class UserAccountMapperTest extends InitTestEnvironment {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ObjectMapper objMapper;
|
private ObjectMapper objMapper;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.dispose.service;
|
package com.dispose.service;
|
||||||
|
|
||||||
|
import com.dispose.Global.InitTestEnvironment;
|
||||||
import com.dispose.common.ErrorCode;
|
import com.dispose.common.ErrorCode;
|
||||||
import com.dispose.pojo.entity.UserAccount;
|
import com.dispose.pojo.entity.UserAccount;
|
||||||
import com.dispose.pojo.po.MReturnType;
|
import com.dispose.pojo.po.MReturnType;
|
||||||
|
@ -19,7 +20,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
public class UserAccountServiceTest {
|
public class UserAccountServiceTest extends InitTestEnvironment {
|
||||||
@Resource
|
@Resource
|
||||||
private UserAccountService userAccountService;
|
private UserAccountService userAccountService;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue