Merge remote-tracking branch 'origin/v2.0.0_dev' into v2.0.0_dev

This commit is contained in:
HuangXin 2020-09-12 10:59:14 +08:00
commit 7b90ef9005
6 changed files with 65 additions and 65 deletions

View File

@ -19,6 +19,7 @@ import com.dispose.pojo.dto.protocol.device.manager.AddDeviceReq;
import com.dispose.pojo.dto.protocol.device.manager.AddDeviceRet; import com.dispose.pojo.dto.protocol.device.manager.AddDeviceRet;
import com.dispose.pojo.dto.protocol.device.manager.AddDeviceRsp; import com.dispose.pojo.dto.protocol.device.manager.AddDeviceRsp;
import com.dispose.pojo.dto.protocol.device.manager.BasePagesGetReq; import com.dispose.pojo.dto.protocol.device.manager.BasePagesGetReq;
import com.dispose.pojo.dto.protocol.device.manager.CommDeviceListRsp;
import com.dispose.pojo.dto.protocol.device.manager.DeviceInfoRsp; import com.dispose.pojo.dto.protocol.device.manager.DeviceInfoRsp;
import com.dispose.pojo.dto.protocol.device.manager.GetDeviceRsp; import com.dispose.pojo.dto.protocol.device.manager.GetDeviceRsp;
import com.dispose.pojo.entity.DisposeDevice; import com.dispose.pojo.entity.DisposeDevice;
@ -219,8 +220,8 @@ public class DisposeDeviceManagerControllerTest extends InitTestEnvironment {
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
ProtocolRespDTO<List<DeviceInfoRsp>> rspInfo = objectMapper.readValue(ret, ProtocolRespDTO<CommDeviceListRsp> rspInfo = objectMapper.readValue(ret,
new TypeReference<ProtocolRespDTO<List<DeviceInfoRsp>>>() { new TypeReference<ProtocolRespDTO<CommDeviceListRsp>>() {
}); });
verifyRespProtocol(rspInfo); verifyRespProtocol(rspInfo);
@ -229,7 +230,7 @@ public class DisposeDeviceManagerControllerTest extends InitTestEnvironment {
List<DisposeDevice> decsAfter = disposeDeviceMapper.selectAll(); List<DisposeDevice> decsAfter = disposeDeviceMapper.selectAll();
for (DeviceInfoRsp d : rspInfo.getMsgContent() for (DeviceInfoRsp d : rspInfo.getMsgContent().getItems()
) { ) {
//before: device information exists after: no device information //before: device information exists after: no device information
boolean before = false; boolean before = false;
@ -258,10 +259,10 @@ public class DisposeDeviceManagerControllerTest extends InitTestEnvironment {
if (before && after) { if (before && after) {
Assert.assertEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); Assert.assertEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(d.getDevStatus(), ObjectStatus.DELETED); Assert.assertEquals(d.getDevStatus(), ObjectStatus.DELETED.getValue());
} else { } else {
Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertNotEquals(d.getDevStatus(), ObjectStatus.DELETED); Assert.assertNotEquals(d.getDevStatus(), ObjectStatus.DELETED.getValue());
} }
} }
} }
@ -335,15 +336,15 @@ public class DisposeDeviceManagerControllerTest extends InitTestEnvironment {
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
ProtocolRespDTO<List<DeviceInfoRsp>> rspInfo = objectMapper.readValue(ret, ProtocolRespDTO<CommDeviceListRsp> rspInfo = objectMapper.readValue(ret,
new TypeReference<ProtocolRespDTO<List<DeviceInfoRsp>>>() { new TypeReference<ProtocolRespDTO<CommDeviceListRsp>>() {
}); });
verifyRespProtocol(rspInfo); verifyRespProtocol(rspInfo);
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo)); log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo));
for (DeviceInfoRsp deviceInfoRsp : rspInfo.getMsgContent() for (DeviceInfoRsp deviceInfoRsp : rspInfo.getMsgContent().getItems()
) { ) {
List<MulReturnType<Long, String>> beforeDev = beforeRed.stream() List<MulReturnType<Long, String>> beforeDev = beforeRed.stream()
@ -409,8 +410,6 @@ public class DisposeDeviceManagerControllerTest extends InitTestEnvironment {
Assert.assertEquals(rspInfo.getMsgContent().getCurPageNumber(), getReq.getStartPage()); Assert.assertEquals(rspInfo.getMsgContent().getCurPageNumber(), getReq.getStartPage());
Assert.assertEquals(String.valueOf(rspInfo.getMsgContent().getPageSize()), String.valueOf(getReq.getPageSize())); Assert.assertEquals(String.valueOf(rspInfo.getMsgContent().getPageSize()), String.valueOf(getReq.getPageSize()));
Assert.assertEquals(String.valueOf(rspInfo.getMsgContent().getTotalItems()), String.valueOf(deviceList.size()));
Assert.assertEquals(Double.valueOf(rspInfo.getMsgContent().getTotalPages()), Double.valueOf(totalPages));
if(totalPages >= (double)(getReq.getStartPage())){ if(totalPages >= (double)(getReq.getStartPage())){
Assert.assertNotEquals(rspInfo.getMsgContent().getItems().size(), 0); Assert.assertNotEquals(rspInfo.getMsgContent().getItems().size(), 0);

View File

@ -23,7 +23,6 @@ import org.junit.runners.MethodSorters;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
@ -44,7 +43,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@AutoConfigureMockMvc @AutoConfigureMockMvc
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Slf4j @Slf4j
public class DisposeInfoControllerTest extends InitTestEnvironment { public class DisposeInfoControllerTest extends InitTestEnvironment {
@ -71,34 +69,34 @@ public class DisposeInfoControllerTest extends InitTestEnvironment {
*/ */
@Test @Test
public void a1_getAllDisposeDeviceAreaInfo() throws Exception { public void a1_getAllDisposeDeviceAreaInfo() throws Exception {
String ret = mockMvc.perform(MockMvcRequestBuilders // String ret = mockMvc.perform(MockMvcRequestBuilders
.get("/info/areaInfo") // .get("/info/areaInfo")
.contentType(MediaType.APPLICATION_JSON) // .contentType(MediaType.APPLICATION_JSON)
.header("Authorization", ConstValue.STRING_HTTP_AUTH_HEAD + getLoginToken()) // .header("Authorization", ConstValue.STRING_HTTP_AUTH_HEAD + getLoginToken())
.content(objectMapper.writeValueAsString(null))) // .content(objectMapper.writeValueAsString(null)))
.andDo(print()).andExpect(status().isOk()) // .andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(HttpStatus.ok().status())) // .andExpect(jsonPath("$.code").value(HttpStatus.ok().status()))
.andReturn() // .andReturn()
.getResponse() // .getResponse()
.getContentAsString(); // .getContentAsString();
//
ProtocolRespDTO<GetAreaInfoRsp> rspInfo = objectMapper.readValue(ret, // ProtocolRespDTO<GetAreaInfoRsp> rspInfo = objectMapper.readValue(ret,
new TypeReference<ProtocolRespDTO<GetAreaInfoRsp>>() { // new TypeReference<ProtocolRespDTO<GetAreaInfoRsp>>() {
}); // });
//
verifyRespProtocol(rspInfo); // verifyRespProtocol(rspInfo);
//
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo)); // log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo));
//
Assert.assertEquals(String.valueOf(rspInfo.getMsgContent().getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); // Assert.assertEquals(String.valueOf(rspInfo.getMsgContent().getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(rspInfo.getMsgContent().getMessage()[0], ErrorCode.ERR_OK.getMsg()); // Assert.assertEquals(rspInfo.getMsgContent().getMessage()[0], ErrorCode.ERR_OK.getMsg());
//
rspInfo.getMsgContent().getItems().forEach(v -> { // rspInfo.getMsgContent().getItems().forEach(v -> {
Assert.assertNotNull(v.getNodeId()); // Assert.assertNotNull(v.getNodeId());
Assert.assertNotNull(v.getTotalNetflow()); // Assert.assertNotNull(v.getTotalNetflow());
Assert.assertNotNull(v.getOnlineDevices()); // Assert.assertNotNull(v.getOnlineDevices());
Assert.assertNotNull(v.getCapacityType()); // Assert.assertNotNull(v.getCapacityType());
}); // });
} }
/** /**

View File

@ -7,9 +7,9 @@ import com.dispose.common.DisposeConfigValue;
import com.dispose.common.DisposeTaskStatus; import com.dispose.common.DisposeTaskStatus;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.NetflowDirection; import com.dispose.common.NetflowDirection;
import com.dispose.common.ObjectStatus;
import com.dispose.common.ProtoCryptoType; import com.dispose.common.ProtoCryptoType;
import com.dispose.mapper.DisposeTaskMapper; import com.dispose.mapper.DisposeTaskMapper;
import com.dispose.pojo.dto.protocol.base.BaseIdResp;
import com.dispose.pojo.dto.protocol.base.IdArraysReq; import com.dispose.pojo.dto.protocol.base.IdArraysReq;
import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO; import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
@ -17,7 +17,9 @@ import com.dispose.pojo.dto.protocol.device.manager.BasePagesGetReq;
import com.dispose.pojo.dto.protocol.task.GetTaskRsp; import com.dispose.pojo.dto.protocol.task.GetTaskRsp;
import com.dispose.pojo.dto.protocol.task.TaskStartMulRsp; import com.dispose.pojo.dto.protocol.task.TaskStartMulRsp;
import com.dispose.pojo.dto.protocol.task.TaskStartReq; import com.dispose.pojo.dto.protocol.task.TaskStartReq;
import com.dispose.pojo.dto.protocol.task.TaskStartRsp;
import com.dispose.pojo.dto.protocol.task.TaskStopItem; import com.dispose.pojo.dto.protocol.task.TaskStopItem;
import com.dispose.pojo.dto.protocol.task.TaskStopRsp;
import com.dispose.pojo.entity.DisposeTask; import com.dispose.pojo.entity.DisposeTask;
import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.po.MulReturnType;
import com.dispose.service.DisposeDeviceManagerService; import com.dispose.service.DisposeDeviceManagerService;
@ -46,6 +48,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
@ -126,8 +129,8 @@ public class DisposeTaskControllerTest extends InitTestEnvironment {
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
ProtocolRespDTO<BaseIdResp> rspInfo = objectMapper.readValue(ret, ProtocolRespDTO<TaskStartRsp> rspInfo = objectMapper.readValue(ret,
new TypeReference<ProtocolRespDTO<BaseIdResp>>() { new TypeReference<ProtocolRespDTO<TaskStartRsp>>() {
}); });
verifyRespProtocol(rspInfo); verifyRespProtocol(rspInfo);
@ -187,14 +190,14 @@ public class DisposeTaskControllerTest extends InitTestEnvironment {
.getContentAsString(); .getContentAsString();
ProtocolRespDTO<BaseIdResp> rspInfo = objectMapper.readValue(ret, ProtocolRespDTO<TaskStartRsp> rspInfo = objectMapper.readValue(ret,
new TypeReference<ProtocolRespDTO<BaseIdResp>>() { new TypeReference<ProtocolRespDTO<TaskStartRsp>>() {
}); });
verifyRespProtocol(rspInfo); verifyRespProtocol(rspInfo);
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo)); log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo));
Assert.assertNotNull(rspInfo.getMsgContent().getStatus()); Assert.assertNotNull(rspInfo.getMsgContent());
if (disposeTask.getCurrentStatus() == DisposeTaskStatus.TASK_FINISHED || if (disposeTask.getCurrentStatus() == DisposeTaskStatus.TASK_FINISHED ||
disposeTask.getCurrentStatus() == DisposeTaskStatus.TASK_CANCELED || disposeTask.getCurrentStatus() == DisposeTaskStatus.TASK_CANCELED ||
@ -217,7 +220,10 @@ public class DisposeTaskControllerTest extends InitTestEnvironment {
List<String> taskIds = new ArrayList<>(); List<String> taskIds = new ArrayList<>();
List<String> runTaskIds = new ArrayList<>(); List<String> runTaskIds = new ArrayList<>();
disposeTaskMapper.selectAll().forEach(v -> taskIds.add(String.valueOf(v.getId()))); List<DisposeTask> devices = disposeTaskMapper.selectAll().stream().limit(20)
.collect(Collectors.toList());
devices.forEach(v -> taskIds.add(String.valueOf(v.getId())));
disposeTaskMapper.selectAll().forEach(v -> { disposeTaskMapper.selectAll().forEach(v -> {
if (v.getCurrentStatus() == DisposeTaskStatus.TASK_NEW || if (v.getCurrentStatus() == DisposeTaskStatus.TASK_NEW ||
@ -251,14 +257,13 @@ public class DisposeTaskControllerTest extends InitTestEnvironment {
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
ProtocolRespDTO<List<TaskStopItem>> rspInfo = objectMapper.readValue(ret, ProtocolRespDTO<TaskStopRsp> rspInfo = objectMapper.readValue(ret, new TypeReference<ProtocolRespDTO<TaskStopRsp>>() {
new TypeReference<ProtocolRespDTO<List<TaskStopItem>>>() {
}); });
verifyRespProtocol(rspInfo); verifyRespProtocol(rspInfo);
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo)); log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo));
for (TaskStopItem t : rspInfo.getMsgContent() for (TaskStopItem t : rspInfo.getMsgContent().getItems()
) { ) {
Assert.assertNotNull(t.getTaskId()); Assert.assertNotNull(t.getTaskId());
Assert.assertNotNull(t.getStatus()); Assert.assertNotNull(t.getStatus());

View File

@ -84,8 +84,8 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment {
// 初始化设备 // 初始化设备
db.initDeviceEnv(url, dev.getUserName(), dev.getPassword()); db.initDeviceEnv(url, dev.getUserName(), dev.getPassword());
MulReturnType<ErrorCode, Long> ret = db.runDispose("192.168.3.5", DisposeCapacityType.CLEANUP, MulReturnType<ErrorCode, Long> ret = db.runDispose("192.168.3.2", DisposeCapacityType.CLEANUP,
NetflowDirection.DIRECTION_BI, DDoSAttackType.ALL_ATTACKS.getValue(), -1L); NetflowDirection.DIRECTION_BI, DDoSAttackType.CLDAP_AMPLIFICATION.getValue(), -1L);
Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK); Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK);
} }
@ -126,8 +126,9 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment {
db.initDeviceEnv(url, dev.getUserName(), dev.getPassword()); db.initDeviceEnv(url, dev.getUserName(), dev.getPassword());
Assert.assertTrue(db.getDeviceLinkStatus()); Assert.assertTrue(db.getDeviceLinkStatus());
MulReturnType<ErrorCode, Long> ret = db.stopDispose("192.168.3.5", DisposeCapacityType.CLEANUP,
NetflowDirection.DIRECTION_BI, DDoSAttackType.ALL_ATTACKS.getValue(), -1L); MulReturnType<ErrorCode, Long> ret = db.stopDispose("192.168.3.2", DisposeCapacityType.CLEANUP,
NetflowDirection.DIRECTION_BI, DDoSAttackType.CLDAP_AMPLIFICATION.getValue(), -1L);
Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK); Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK);
} }

View File

@ -158,8 +158,6 @@ public class DisposeCapacityMapperTest {
Assert.assertEquals(disposeCapacityMapper.addNewDisposeCapacity(newCapList), newCapList.size()); Assert.assertEquals(disposeCapacityMapper.addNewDisposeCapacity(newCapList), newCapList.size());
Assert.assertNotEquals(disposeCapacityMapper.delDeviceDisposeCapacity(newCapList.get(0).getDeviceId()), 0); Assert.assertNotEquals(disposeCapacityMapper.delDeviceDisposeCapacity(newCapList.get(0).getDeviceId()), 0);
Assert.assertEquals(0, disposeCapacityMapper.selectAll().size());
} }
/** /**
@ -195,8 +193,6 @@ public class DisposeCapacityMapperTest {
List<DisposeCapacity> capList = disposeCapacityMapper.getDeviceDisposeCapacity(newCapList.get(0).getDeviceId()); List<DisposeCapacity> capList = disposeCapacityMapper.getDeviceDisposeCapacity(newCapList.get(0).getDeviceId());
Assert.assertEquals(capList.size(), caps.size() + newCapList.size());
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList)); log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList));
} }
} }

View File

@ -112,21 +112,22 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
Assert.assertNotNull(ret.getSecondParam()); Assert.assertNotNull(ret.getSecondParam());
Assert.assertEquals(String.valueOf(ret.getSecondParam().getDisposeCapacity()), String.valueOf(DisposeCapacityType.CLEANUP));
} else { } else {
Assert.assertNotEquals(ret.getFirstParam().getCode(), ErrorCode.ERR_OK.getCode()); Assert.assertNotEquals(ret.getFirstParam().getCode(), ErrorCode.ERR_OK.getCode());
} }
Assert.assertEquals(ret.getSecondParam().getId(), disposeTaskManager.getDisposeTask(newTask.getDeviceId(), disposeTaskManager.getExpiredTasks().forEach(v->{
newTask.getDisposeIp(), newTask.getDisposeCapacity()).getId()); disposeTaskManager.changeDisposeTaskStatus(v.getId(), DisposeTaskStatus.TASK_NEW);
ret = disposeTaskService.createTask(newTask); MulReturnType<ErrorCode, DisposeTask> result = disposeTaskService.createTask(v);
Assert.assertEquals(ret.getFirstParam().getCode(), ErrorCode.ERR_TASKRUNNING.getCode()); Assert.assertEquals(result.getFirstParam().getCode(), ErrorCode.ERR_TASKRUNNING.getCode());
Assert.assertEquals(ret.getSecondParam().getId(), disposeTaskManager.getDisposeTask(newTask.getDeviceId(), Assert.assertEquals(result.getSecondParam().getId(), disposeTaskManager.getDisposeTask(newTask.getDeviceId(),
newTask.getDisposeIp(), newTask.getDisposeCapacity()).getId()); newTask.getDisposeIp(), newTask.getDisposeCapacity()).getId());
});
} }
/** /**
* creat task mul return type. * creat task mul return type.
*/ */