From 1867f54c56f05a61a1123a93262e1f5b6d9fdd5c Mon Sep 17 00:00:00 2001 From: snoop Date: Mon, 21 Aug 2017 16:09:45 +0900 Subject: [PATCH] fixed infra list for domain --- .../overflow/module/infra/dao/InfraDAO.java | 7 +- .../module/infra/service/InfraService.java | 9 +- .../service/InfraMachineServiceTest.java | 2 +- .../infra/service/InfraServiceTest.java | 110 +++++------------- 4 files changed, 39 insertions(+), 89 deletions(-) diff --git a/src/main/java/com/loafle/overflow/module/infra/dao/InfraDAO.java b/src/main/java/com/loafle/overflow/module/infra/dao/InfraDAO.java index 256ce49..b8ad594 100644 --- a/src/main/java/com/loafle/overflow/module/infra/dao/InfraDAO.java +++ b/src/main/java/com/loafle/overflow/module/infra/dao/InfraDAO.java @@ -18,11 +18,12 @@ import java.util.List; public interface InfraDAO extends JpaRepository { public List findAllByProbe(Probe probe); - List findAllByProbe(List probeList); + @Query("SELECT i FROM INFRA i WHERE i.probe IN (:probeList)") + List findAllByProbeList(@Param("probeList") List probeList); -// @Query("SELECT DISTINCT i.target FROM Infra i WHERE i.probe IN (:probeList)") -// List findAllTargetByProbeList(@Param("probeList") List probeList); + @Query("SELECT DISTINCT i.target FROM INFRA i WHERE i.probe IN (:probeList)") + List findAllTargetByProbeList(@Param("probeList") List probeList); // List findAllByProbe(List probeList); } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/module/infra/service/InfraService.java b/src/main/java/com/loafle/overflow/module/infra/service/InfraService.java index 4a0eb2c..a3ffe08 100644 --- a/src/main/java/com/loafle/overflow/module/infra/service/InfraService.java +++ b/src/main/java/com/loafle/overflow/module/infra/service/InfraService.java @@ -40,15 +40,16 @@ public class InfraService { List probeList = this.probeService.readAllByDomain(domain); - return this.infraDAO.findAllByProbe(probeList); + return this.infraDAO.findAllByProbeList(probeList); } public List readAllByProbeList(List probeList) { - return this.infraDAO.findAllByProbe(probeList); + return this.infraDAO.findAllByProbeList(probeList); } public List readAllTargetByProbeList(List probeList) { -// return this.infraDAO.findAllTargetByProbeList(probeList); - return null; + return this.infraDAO.findAllTargetByProbeList(probeList); +// return null; } + } diff --git a/src/test/java/com/loafle/overflow/module/infra/service/InfraMachineServiceTest.java b/src/test/java/com/loafle/overflow/module/infra/service/InfraMachineServiceTest.java index e3a22c9..48154cb 100644 --- a/src/test/java/com/loafle/overflow/module/infra/service/InfraMachineServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/infra/service/InfraMachineServiceTest.java @@ -47,7 +47,7 @@ public class InfraMachineServiceTest { @Test public void read() throws Exception { - regist(); +// regist(); InfraMachine infraMachine = this.infraMachineService.read(1); diff --git a/src/test/java/com/loafle/overflow/module/infra/service/InfraServiceTest.java b/src/test/java/com/loafle/overflow/module/infra/service/InfraServiceTest.java index f52ec4e..bc2b365 100644 --- a/src/test/java/com/loafle/overflow/module/infra/service/InfraServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/infra/service/InfraServiceTest.java @@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import java.io.IOException; import java.util.List; /** @@ -36,91 +37,12 @@ public class InfraServiceTest { private InfraMachineService infraMachineService; -// public void regist() throws Exception { -// -// long id =registInfra(7,1); -// Assert.assertNotEquals(id, 0); -// -//// id =registInfra(3,1); -//// Assert.assertNotEquals(id, 0); -//// -//// id =registInfra(2,1); -//// Assert.assertNotEquals(id, 0); -// -// -// -// } @Test public void tttt() { } - @Test - public void registInfraMachine() { - - InfraMachine infraMachine = new InfraMachine(); - infraMachine.setMeta("i am a inframachine"); - - - -// Assert.assertNotEquals(infraMachine.getId(), 0); - -// Probe probe = new Probe(); -// probe.setId(1); -// -// Target target = new Target(); -// target.setId(1); - -// Infra infra = new Infra(); -// infra.setTarget(target); - - MetaInfraType metaInfraType = new MetaInfraType(); - metaInfraType.setId(1); - -// infraMachine.setInfraType(metaInfraType); - -// infra.setProbe(probe); - -// infra.setInfraChild(infraMachine); - - this.infraMachineService.regist(infraMachine); - -// this.infraService.regist(infra); - -// Assert.assertNotEquals(infra.getId(), 0); - - } - - @Test - public void registInfraOS() { - registInfraMachine(); - } - -//// @Ignore -// public long registInfra(int type, int childId) { -// MetaInfraType metaInfraType = new MetaInfraType(); -// metaInfraType.setId(type); -// -// Infra infra = new Infra(); -// infra.setInfraType(metaInfraType); -//// infra.setChildId(childId); -// -// -// -// Probe probe = new Probe(); -// probe.setId(1); -// -// Target target = new Target(); -// target.setId(1); -// -// infra.setProbe(probe); -// infra.setTarget(target); -// -// this.infraService.regist(infra); -// -// return infra.getId(); -// } @Test public void read() throws Exception { @@ -136,7 +58,30 @@ public class InfraServiceTest { } @Test - public void readAllByProbeList() { + public void readAllProbe() throws IOException { + + Probe probe = new Probe(); + probe.setId(1); + + List infraList = this.infraService.readAllByProbe(probe); + + ObjectMapper objectMapper = new ObjectMapper(); + String json = objectMapper.writeValueAsString(infraList); + + System.out.println(json); + + } + + @Test + public void readAllTarget() { + Domain domain = new Domain(); + domain.setId(1); + +// this.infraService.readAllTargetByProbeList() + } + + @Test + public void readAllByProbeList() throws IOException { Domain domain = new Domain(); domain.setId(1); @@ -144,7 +89,10 @@ public class InfraServiceTest { List fl = this.infraService.readAllByDomain(domain); - System.out.println(fl.size()); + ObjectMapper objectMapper = new ObjectMapper(); + String json = objectMapper.writeValueAsString(fl); + + System.out.println(json); }