From 6a3cb4af63aa97d72ab98c889d3d11c6953e8d50 Mon Sep 17 00:00:00 2001 From: insanity Date: Thu, 28 Jun 2018 19:59:50 +0900 Subject: [PATCH 1/2] SensorServiceTest --- .../sensor/service/SensorServiceTest.java | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/loafle/overflow/central/module/sensor/service/SensorServiceTest.java b/src/test/java/com/loafle/overflow/central/module/sensor/service/SensorServiceTest.java index b9c161b..ef16cdb 100644 --- a/src/test/java/com/loafle/overflow/central/module/sensor/service/SensorServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/sensor/service/SensorServiceTest.java @@ -1,8 +1,13 @@ package com.loafle.overflow.central.module.sensor.service; +import com.loafle.overflow.central.module.meta.dao.MetaCrawlerMappingDAO; import com.loafle.overflow.central.module.meta.dao.MetaDisplayItemMappingDAO; import com.loafle.overflow.central.spring.AppConfigTest; -import com.fasterxml.jackson.databind.ObjectMapper; + +import java.util.ArrayList; +import java.util.List; + +import com.loafle.overflow.model.meta.MetaCrawlerMapping; import com.loafle.overflow.model.sensor.Sensor; import com.loafle.overflow.model.target.Target; import com.loafle.overflow.service.central.sensor.SensorService; @@ -30,9 +35,8 @@ public class SensorServiceTest { @Autowired MetaDisplayItemMappingDAO metaDisplayItemMappingService; - @Autowired - ObjectMapper objectMapper; + MetaCrawlerMappingDAO metaCrawlerMappingDAO; @Test @Ignore @@ -42,7 +46,40 @@ public class SensorServiceTest { Sensor sensor = new Sensor(); sensor.setTarget(target); + List metaCrawlerMappings = this.metaCrawlerMappingDAO.findAll(); + sensor.setMetaCrawlerMapping(metaCrawlerMappings.get(0)); + Sensor result = this.sensorService.regist(sensor, this.metaDisplayItemMappingService.findAll()); Assert.assertNotNull(result); } + + @Test + @Ignore + public void readAllByTargetID() throws Exception { + this.regist(); + Assert.assertNotNull(this.sensorService.readAllByTargetID(Long.valueOf(1))); + } + + @Test + @Ignore + public void readAllByTargetIn() throws Exception { + this.regist(); + List targets = new ArrayList(); + Target t1 = new Target(); + t1.setId(Long.valueOf(1)); + Target t2 = new Target(); + t2.setId(Long.valueOf(2)); + targets.add(t1); + targets.add(t2); + List sensors = this.sensorService.readAllByTargetIn(targets); + Assert.assertNotNull(sensors); + } + + @Test + @Ignore + public void readAllByTargetInfraProbeID() throws Exception { + this.regist(); + List sensors = this.sensorService.readAllByTargetInfraProbeID(Long.valueOf(1)); + Assert.assertNotNull(sensors); + } } From ed72bf084b3e6c184fca2018fe13571b37704ae0 Mon Sep 17 00:00:00 2001 From: insanity Date: Thu, 28 Jun 2018 20:05:40 +0900 Subject: [PATCH 2/2] Sensor modify --- .../sensor/service/CentralSensorItemService.java | 4 ++++ .../module/sensor/service/CentralSensorService.java | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java index 374aacd..471e6bd 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java @@ -58,4 +58,8 @@ public class CentralSensorItemService implements SensorItemService { this.sensorItemDAO.deleteById(sensorItemID); } + public void removeAllBySensorID(Long sensorID) throws OverflowException { + this.sensorItemDAO.deleteAll(this.readAllBySensorID(sensorID)); + } + } diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java index d213b59..1624ae9 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java @@ -57,8 +57,15 @@ public class CentralSensorService implements SensorService { @Transactional @Override public Sensor modify(Long sensorID, List metaDisplayItemMappings) throws OverflowException { - // FIXME : not impl - return null; + Sensor sensor = this.read(sensorID); + if (null == sensor) { + throw new OverflowException(String.format("ID[%d] of Sensor is not valid", sensorID)); + } + this.sensorItemService.readAllBySensorID(sensorID); + for (MetaDisplayItemMapping metaDisplayItemMapping : metaDisplayItemMappings) { + this.sensorItemService.regist(sensor, metaDisplayItemMapping); + } + return sensor; } @Override