Merge branch 'master' of git.komect.net:DDOSAQ/phoenix_ddos_handle
This commit is contained in:
commit
08ea6568c4
|
@ -11,7 +11,7 @@
|
|||
<directory>${project.build.directory}</directory>
|
||||
<outputDirectory>${file.separator}</outputDirectory>
|
||||
<includes>
|
||||
<include>phoenix-boot.jar</include>
|
||||
<include>phoenix_ddos_handle.jar</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
|
|
|
@ -1 +1 @@
|
|||
spring.profiles.active=local
|
||||
spring.profiles.active=test
|
6
pom.xml
6
pom.xml
|
@ -10,9 +10,9 @@
|
|||
<relativePath />
|
||||
</parent>
|
||||
<groupId>com.dispose</groupId>
|
||||
<artifactId>phoenix-boot</artifactId>
|
||||
<artifactId>phoenix_ddos_handle</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<name>phoenix-boot</name>
|
||||
<name>phoenix_ddos_handle</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -212,7 +212,7 @@
|
|||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>phoenix-boot</finalName>
|
||||
<finalName>phoenix_ddos_handle</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package com.dispose.manager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年4月27日
|
||||
*/
|
||||
public interface DisposeDeviceManager {
|
||||
|
||||
/**
|
||||
*
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* @param dd
|
||||
* @return
|
||||
*/
|
||||
int saveDisposeDevice(DisposeDevice dd);
|
||||
|
||||
/**
|
||||
*
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* @param ip
|
||||
* @return
|
||||
*/
|
||||
DisposeDevice findDisposeDeviceByIp(String ip);
|
||||
|
||||
/**
|
||||
*
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
DisposeDevice findDisposeDeviceById(Long id);
|
||||
|
||||
/**
|
||||
*
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* @return
|
||||
*/
|
||||
List<DisposeDevice> findAllDisposeDevice();
|
||||
|
||||
/**
|
||||
*
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* @param ip
|
||||
* @return
|
||||
*/
|
||||
int delDisposeDeviceByIp(String ip);
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package com.dispose.manager.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.dispose.manager.DisposeDeviceManager;
|
||||
import com.dispose.mapper.DisposeDeviceMapper;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
import tk.mybatis.mapper.entity.Example.Criteria;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年4月27日
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||
|
||||
@Resource
|
||||
private DisposeDeviceMapper disposeDeviceMapper;
|
||||
|
||||
@Override
|
||||
public int saveDisposeDevice(DisposeDevice dd) {
|
||||
// TODO Auto-generated method stub
|
||||
return disposeDeviceMapper.insert(dd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DisposeDevice findDisposeDeviceByIp(String ip) {
|
||||
// TODO Auto-generated method stub
|
||||
log.info("根据IP {} 查询处置设备信息", ip);
|
||||
Example example = new Example(DisposeDevice.class);
|
||||
Criteria c = example.createCriteria();
|
||||
c.andEqualTo("ipAddr", ip);
|
||||
List<DisposeDevice> list = disposeDeviceMapper.selectByExample(example);
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
return list.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DisposeDevice findDisposeDeviceById(Long id) {
|
||||
// TODO Auto-generated method stub
|
||||
return disposeDeviceMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delDisposeDeviceByIp(String ip) {
|
||||
// TODO Auto-generated method stub
|
||||
log.info("根据IP {} 删除处置设备信息", ip);
|
||||
Example example = new Example(DisposeDevice.class);
|
||||
Criteria c = example.createCriteria();
|
||||
c.andEqualTo("ipAddr", ip);
|
||||
return disposeDeviceMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DisposeDevice> findAllDisposeDevice() {
|
||||
// TODO Auto-generated method stub
|
||||
return disposeDeviceMapper.selectAll();
|
||||
}
|
||||
|
||||
}
|
|
@ -8,49 +8,5 @@ import tk.mybatis.mapper.common.MySqlMapper;
|
|||
* The interface Dispose device mapper.
|
||||
*/
|
||||
public interface DisposeDeviceMapper extends Mapper<DisposeDevice>, MySqlMapper<DisposeDevice> {
|
||||
/**
|
||||
* Add new dispose device.
|
||||
*
|
||||
* @param dev the dev
|
||||
*/
|
||||
void addNewDisposeDevice(DisposeDevice dev);
|
||||
|
||||
/**
|
||||
* Is device exists by ip int.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @return the int
|
||||
*/
|
||||
int isDeviceExistsByIp(String ipAddr);
|
||||
|
||||
/**
|
||||
* Is device exists by id int.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the int
|
||||
*/
|
||||
int isDeviceExistsById(Long id);
|
||||
|
||||
/**
|
||||
* Gets device by ip.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @return the device by ip
|
||||
*/
|
||||
DisposeDevice getDeviceByIp(String ipAddr);
|
||||
|
||||
/**
|
||||
* Gets device by id.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the device by id
|
||||
*/
|
||||
DisposeDevice getDeviceById(Long id);
|
||||
|
||||
/**
|
||||
* Del dispose device by ip.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
*/
|
||||
void delDisposeDeviceByIp(String ipAddr);
|
||||
}
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
package com.dispose.pojo.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import com.dispose.dispose.po.DeviceInfo;
|
||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import tk.mybatis.mapper.annotation.KeySql;
|
||||
import tk.mybatis.mapper.annotation.NameStyle;
|
||||
import tk.mybatis.mapper.code.Style;
|
||||
|
||||
|
@ -39,7 +43,7 @@ public class DisposeDevice implements Serializable {
|
|||
* The Id.
|
||||
*/
|
||||
@Id
|
||||
//@KeySql(useGeneratedKeys = true)
|
||||
@KeySql(useGeneratedKeys = true)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
|
|
|
@ -70,4 +70,12 @@ public interface DisposeNodeManager {
|
|||
* @return the dispose device
|
||||
*/
|
||||
DisposeDevice getDisposeDevice(String ipAddr, DeviceCapacity capacity);
|
||||
|
||||
/**
|
||||
*
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* @param ip
|
||||
* @return
|
||||
*/
|
||||
boolean isExistsDisposeDeviceByIp(String ip);
|
||||
}
|
||||
|
|
|
@ -5,13 +5,15 @@ import com.dispose.common.ErrorCode;
|
|||
import com.dispose.common.IPAddrType;
|
||||
import com.dispose.dispose.DeviceRouter;
|
||||
import com.dispose.dispose.DisposeEntryManager;
|
||||
import com.dispose.mapper.DisposeDeviceMapper;
|
||||
import com.dispose.manager.DisposeDeviceManager;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||
import com.dispose.pojo.po.MReturnType;
|
||||
import com.dispose.service.DisposeNodeManager;
|
||||
import com.dispose.service.UserAccountService;
|
||||
import inet.ipaddr.AddressStringException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
@ -24,28 +26,35 @@ import org.springframework.stereotype.Service;
|
|||
* The type Dispose node manager.
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
||||
|
||||
@Resource
|
||||
private DisposeDeviceManager disposeDeviceManager;
|
||||
/**
|
||||
* The Dispose dev map.
|
||||
*/
|
||||
private final ConcurrentHashMap<String, DisposeDevice> disposeDevMap = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* The Dispose device mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeDeviceMapper disposeDeviceMapper;
|
||||
|
||||
/**
|
||||
* The User account service.
|
||||
*/
|
||||
@Resource
|
||||
private UserAccountService userAccountService;
|
||||
|
||||
@Override
|
||||
public boolean isExistsDisposeDeviceByIp(String ip) {
|
||||
// TODO Auto-generated method stub
|
||||
log.info("查询该处置设备是否存在 {}", ip);
|
||||
return disposeDeviceManager.findDisposeDeviceByIp(ip) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load dispose node from db.
|
||||
*/
|
||||
@Override
|
||||
public void loadDisposeNodeFromDB() {
|
||||
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
|
||||
List<DisposeDevice> devList = disposeDeviceManager.findAllDisposeDevice();
|
||||
|
||||
if (devList == null) {
|
||||
return;
|
||||
|
@ -73,8 +82,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
*/
|
||||
@Override
|
||||
public ErrorCode delDisposeDeviceById(Long id) {
|
||||
DisposeEntryManager dp;
|
||||
DisposeDevice dev = disposeDeviceMapper.getDeviceById(id);
|
||||
DisposeDevice dev = disposeDeviceManager.findDisposeDeviceById(id);
|
||||
|
||||
if (dev == null) {
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
|
@ -91,9 +99,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
*/
|
||||
@Override
|
||||
public ErrorCode delDisposeDeviceByIp(String ipAddr) {
|
||||
DisposeEntryManager dp;
|
||||
|
||||
if (disposeDeviceMapper.isDeviceExistsByIp(ipAddr) == 0
|
||||
if (!isExistsDisposeDeviceByIp(ipAddr)
|
||||
|| !disposeDevMap.containsKey(ipAddr)) {
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
@ -104,7 +110,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
disposeDeviceMapper.delDisposeDeviceByIp(ipAddr);
|
||||
disposeDeviceManager.delDisposeDeviceByIp(ipAddr);
|
||||
disposeDevMap.remove(ipAddr);
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
|
@ -127,7 +133,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
return new MReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, String.valueOf(-1));
|
||||
}
|
||||
|
||||
DisposeDevice dbDev = disposeDeviceMapper.getDeviceByIp(dev.getIpAddr());
|
||||
DisposeDevice dbDev = disposeDeviceManager.findDisposeDeviceByIp(dev.getIpAddr());
|
||||
|
||||
if (dbDev != null) {
|
||||
return new MReturnType<>(ErrorCode.ERR_DEVICEEXISTS, String.valueOf(dbDev.getId()));
|
||||
|
@ -145,7 +151,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
|
||||
dev.setDevInfo(dp.getDeviceInfo());
|
||||
|
||||
disposeDeviceMapper.addNewDisposeDevice(dev);
|
||||
disposeDeviceManager.saveDisposeDevice(dev);
|
||||
|
||||
disposeDevMap.put(dev.getIpAddr(), dev);
|
||||
return new MReturnType<>(ErrorCode.ERR_OK, dev.getId().toString());
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.dispose.mapper.DisposeDeviceMapper">
|
||||
<insert id="addNewDisposeDevice" useGeneratedKeys="true" keyProperty="id" parameterType="com.dispose.pojo.entity.DisposeDevice">
|
||||
INSERT IGNORE INTO
|
||||
dispose_device(ipAddr, type,
|
||||
areaCode, name, manufacturer,
|
||||
model, version, readme, status)
|
||||
VALUES
|
||||
(#{ipAddr}, #{type},
|
||||
#{areaCode}, #{name}, #{manufacturer},
|
||||
#{model}, #{version}, #{readme}, 0)
|
||||
</insert>
|
||||
|
||||
<select id="getDeviceByIp" resultType="com.dispose.pojo.entity.DisposeDevice" parameterType="java.lang.String">
|
||||
SELECT * FROM dispose_device
|
||||
WHERE
|
||||
ipAddr = #{ipAddr}
|
||||
</select>
|
||||
|
||||
<select id="getDeviceById" resultType="com.dispose.pojo.entity.DisposeDevice" parameterType="java.lang.Long">
|
||||
SELECT * FROM dispose_device
|
||||
WHERE
|
||||
id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="isDeviceExistsByIp" resultType="java.lang.Integer">
|
||||
SELECT COUNT(*) FROM dispose_device
|
||||
WHERE
|
||||
ipAddr = #{ipAddr}
|
||||
</select>
|
||||
<select id="isDeviceExistsById" resultType="java.lang.Integer">
|
||||
SELECT COUNT(*) FROM dispose_device
|
||||
WHERE
|
||||
id = #{id}
|
||||
</select>
|
||||
<delete id="delDisposeDeviceByIp" parameterType="java.lang.String">
|
||||
DELETE
|
||||
dispose_device
|
||||
FROM
|
||||
dispose_device
|
||||
WHERE
|
||||
dispose_device.ipAddr = #{ipAddr}
|
||||
</delete>
|
||||
<delete id="delDisposeDeviceById" parameterType="java.lang.Long">
|
||||
DELETE
|
||||
dispose_device
|
||||
FROM
|
||||
dispose_device
|
||||
WHERE
|
||||
dispose_device.id = #{id}
|
||||
</delete>
|
||||
</mapper>
|
|
@ -9,7 +9,6 @@ import com.dispose.controller.DeviceNodeManagerControllerTest;
|
|||
import com.dispose.controller.TaskControllerTest;
|
||||
import com.dispose.dptech.DPTechInterfaceTestCase;
|
||||
import com.dispose.manager.UserAccountManagerTest;
|
||||
import com.dispose.mapper.DisposeDeviceMapperTest;
|
||||
import com.dispose.mapper.DisposeTaskMapperTest;
|
||||
import com.dispose.mapper.UserAccountMapperTest;
|
||||
import com.dispose.service.DisposeNodeManagerTest;
|
||||
|
@ -29,7 +28,6 @@ import org.junit.runners.Suite;
|
|||
DPTechInterfaceTestCase.class,
|
||||
UserAccountMapperTest.class,
|
||||
UserAccountManagerTest.class,
|
||||
DisposeDeviceMapperTest.class,
|
||||
AuthControllerTest.class,
|
||||
DeviceNodeManagerControllerTest.class,
|
||||
DeviceNodeInfoControllerTest.class,
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package com.dispose.manager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.dispose.mapper.DisposeDeviceMapper;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年4月27日
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
public class DisposeDeviceManagerTest {
|
||||
|
||||
@Resource
|
||||
private DisposeDeviceMapper disposeDeviceMapper;
|
||||
|
||||
@Resource
|
||||
private DisposeDeviceManager disposeDeviceManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ReflectionTestUtils.setField(disposeDeviceManager, "disposeDeviceMapper", disposeDeviceMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisposeDeviceManager() {
|
||||
log.info("DisposeDeviceManager 单元测试");
|
||||
String ip = "ip18867101080";
|
||||
DisposeDevice dd = DisposeDevice.builder().areaCode(1).ipAddr(ip).linkStatus(1).manufacturer("厂商")
|
||||
.model("model").name("name").readme("readme").status(1).type(1).version("v1").build();
|
||||
int res = disposeDeviceManager.saveDisposeDevice(dd);
|
||||
TestCase.assertEquals(res, 1);
|
||||
DisposeDevice deviceIp = disposeDeviceManager.findDisposeDeviceByIp(ip);
|
||||
TestCase.assertNotNull(deviceIp);
|
||||
DisposeDevice deviceId = disposeDeviceManager.findDisposeDeviceById(dd.getId());
|
||||
TestCase.assertNotNull(deviceId);
|
||||
List<DisposeDevice> deviceList = disposeDeviceManager.findAllDisposeDevice();
|
||||
TestCase.assertTrue(deviceList.size() > 0);
|
||||
int delRes = disposeDeviceManager.delDisposeDeviceByIp(ip);
|
||||
TestCase.assertEquals(delRes, 1);
|
||||
deviceId = disposeDeviceManager.findDisposeDeviceById(dd.getId());
|
||||
TestCase.assertNull(deviceId);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,154 +0,0 @@
|
|||
package com.dispose.mapper;
|
||||
|
||||
import com.dispose.Global.InitTestEnvironment;
|
||||
import com.dispose.common.DisposeDeviceType;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
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;
|
||||
|
||||
/**
|
||||
* The type Dispose device mapper test.
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@Transactional
|
||||
@Rollback
|
||||
public class DisposeDeviceMapperTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* The Dispose device mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeDeviceMapper disposeDeviceMapper;
|
||||
|
||||
/**
|
||||
* T 1 add new dispose device.
|
||||
*
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@Test
|
||||
public void t1_addNewDisposeDevice() throws JsonProcessingException {
|
||||
Long devId = -1L;
|
||||
DisposeDevice dev = new DisposeDevice();
|
||||
List<DisposeDeviceCapacity> devCaps = new ArrayList<>();
|
||||
dev.setId(devId);
|
||||
dev.setIpAddr("10.88.77.15");
|
||||
dev.setType(DisposeDeviceType.DPTECH_UMC.getCode());
|
||||
dev.setName("中移杭研实验室清洗设备");
|
||||
dev.setManufacturer("DPTech");
|
||||
dev.setModel("UMC");
|
||||
dev.setVersion("5.7.13");
|
||||
dev.setReadme("实验室测试设备");
|
||||
dev.setAreaCode(0);
|
||||
dev.setDevCaps(devCaps);
|
||||
|
||||
disposeDeviceMapper.addNewDisposeDevice(dev);
|
||||
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev));
|
||||
|
||||
Assert.assertNotEquals(disposeDeviceMapper.isDeviceExistsByIp(dev.getIpAddr()), 0);
|
||||
|
||||
List<DisposeDevice> dp = disposeDeviceMapper.selectAll();
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp));
|
||||
}
|
||||
|
||||
/**
|
||||
* T 2 is device exists by ip.
|
||||
*
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@Test
|
||||
public void t2_isDeviceExistsByIp() throws JsonProcessingException {
|
||||
List<DisposeDevice> dp = disposeDeviceMapper.selectAll();
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp));
|
||||
|
||||
dp.forEach(v -> Assert.assertNotEquals(disposeDeviceMapper.isDeviceExistsByIp(v.getIpAddr()), 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* T 3 is device exists by id.
|
||||
*
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@Test
|
||||
public void t3_isDeviceExistsById() throws JsonProcessingException {
|
||||
List<DisposeDevice> dp = disposeDeviceMapper.selectAll();
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp));
|
||||
|
||||
dp.forEach(v -> Assert.assertNotEquals(disposeDeviceMapper.isDeviceExistsById(v.getId()), 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* T 4 get device exists by ip.
|
||||
*
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@Test
|
||||
public void t4_getDeviceExistsByIp() throws JsonProcessingException {
|
||||
List<DisposeDevice> dp = disposeDeviceMapper.selectAll();
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp));
|
||||
|
||||
dp.forEach(v -> {
|
||||
DisposeDevice dev = disposeDeviceMapper.getDeviceByIp(v.getIpAddr());
|
||||
Assert.assertNotNull(dp);
|
||||
Assert.assertEquals(dev.getIpAddr(), v.getIpAddr());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* T 5 get device exists by id.
|
||||
*
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@Test
|
||||
public void t5_getDeviceExistsById() throws JsonProcessingException {
|
||||
List<DisposeDevice> dp = disposeDeviceMapper.selectAll();
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp));
|
||||
|
||||
dp.forEach(v -> {
|
||||
DisposeDevice dev = disposeDeviceMapper.getDeviceById(v.getId());
|
||||
Assert.assertNotNull(dp);
|
||||
Assert.assertEquals(dev.getId(), v.getId());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* T 0 del dispose device by ip.
|
||||
*
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@Test
|
||||
public void t0_delDisposeDeviceByIp() throws JsonProcessingException {
|
||||
String ipAddr = "10.88.77.15";
|
||||
disposeDeviceMapper.delDisposeDeviceByIp(ipAddr);
|
||||
|
||||
List<DisposeDevice> dp = disposeDeviceMapper.selectAll();
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp));
|
||||
dp.forEach(v -> {
|
||||
if (v.getIpAddr().equals(ipAddr)) {
|
||||
Assert.fail();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue