diff --git a/src/main/java/com/loafle/overflow/central/module/target/dao/TargetDAO.java b/src/main/java/com/loafle/overflow/central/module/target/dao/TargetDAO.java index bc98493..08bb2f6 100644 --- a/src/main/java/com/loafle/overflow/central/module/target/dao/TargetDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/target/dao/TargetDAO.java @@ -1,13 +1,24 @@ package com.loafle.overflow.central.module.target.dao; import com.loafle.overflow.model.target.Target; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.util.List; + /** * Created by root on 17. 6. 5. */ @Repository public interface TargetDAO extends JpaRepository { Target findByInfraId(Long infraId); + +// @Query("select t.infra from target t where t.infra.probe.id = :probeId") +// Page findForProbeId(@Param("probeId") Long probeId, Pageable pageRequest); + + Page findAllByInfraProbeId(Long probeId, Pageable pageRequest); } diff --git a/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java b/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java index 7385d90..05d752e 100644 --- a/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java +++ b/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java @@ -3,6 +3,7 @@ package com.loafle.overflow.central.module.target.service; import java.util.ArrayList; import java.util.List; +import com.loafle.overflow.central.commons.utils.PageUtil; import com.loafle.overflow.central.module.infra.service.CentralInfraHostService; import com.loafle.overflow.central.module.infra.service.CentralInfraServiceService; import com.loafle.overflow.central.module.probe.service.CentralProbeService; @@ -100,7 +101,8 @@ public class CentralTargetService implements TargetService { } public Page readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException { - return null; + return this.targetDAO.findAllByInfraProbeId(probeID, PageUtil.getPageRequest(pageParams)); +// return null; } @Transactional public List registDiscoveredTargets(Long probeId, List hosts, List services) diff --git a/src/test/java/com/loafle/overflow/central/module/target/service/TargetServiceTest.java b/src/test/java/com/loafle/overflow/central/module/target/service/TargetServiceTest.java index a29ca5b..6215518 100644 --- a/src/test/java/com/loafle/overflow/central/module/target/service/TargetServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/target/service/TargetServiceTest.java @@ -1,48 +1,67 @@ -// package com.loafle.overflow.central.module.target.service; + package com.loafle.overflow.central.module.target.service; -// import com.loafle.overflow.central.module.target.model.Target; -// import com.loafle.overflow.central.spring.AppConfigTest; -// import org.junit.Assert; -// import org.junit.Ignore; -// import org.junit.Test; -// import org.junit.runner.RunWith; -// import org.springframework.beans.factory.annotation.Autowired; -// import org.springframework.test.context.ContextConfiguration; -// import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -// import java.util.Date; + import com.loafle.overflow.central.spring.AppConfigTest; + import com.loafle.overflow.core.model.PageParams; + import com.loafle.overflow.model.target.Target; + import com.loafle.overflow.service.central.target.TargetService; + import org.junit.Assert; + import org.junit.Ignore; + import org.junit.Test; + import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; + import org.springframework.data.domain.Page; + import org.springframework.test.context.ActiveProfiles; + import org.springframework.test.context.ContextConfiguration; + import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -// /** -// * Created by insanity on 17. 6. 28. -// */ + import java.util.Date; -// @RunWith(SpringJUnit4ClassRunner.class) -// @ContextConfiguration(classes = {AppConfigTest.class}) -// public class TargetServiceTest { + /** + * Created by insanity on 17. 6. 28. + */ + + @RunWith(SpringJUnit4ClassRunner.class) + @ActiveProfiles("test") + @ContextConfiguration(classes = {AppConfigTest.class}) + public class TargetServiceTest { // @Autowired // TargetService targetService; - +// // @Ignore // @Test // public void regist() throws Exception { -// Target t = new Target(); -// t.setCreateDate(new Date()); -// // Infra infra = new Infra(); -// // infra.setId(1); -// // Probe probe = new Probe(); -// // probe.setId(1); -// // t.setProbe(probe); -// // t.setInfra(infra); -// t.setDescription("i am target"); -// t.setDisplayName("ghost target"); - -// Target res = this.targetService.regist(t); -// Assert.assertNotNull(res); +//// Target t = new Target(); +//// t.setCreateDate(new Date()); +//// // Infra infra = new Infra(); +//// // infra.setId(1); +//// // Probe probe = new Probe(); +//// // probe.setId(1); +//// // t.setProbe(probe); +//// // t.setInfra(infra); +//// t.setDescription("i am target"); +//// t.setDisplayName("ghost target"); +//// +//// Target res = this.targetService.regist(t); +//// Assert.assertNotNull(res); // } - +// // @Test +// @Ignore // public void read() throws Exception { -// Target res = this.targetService.read("1"); -// Assert.assertNotNull(res); +//// Target res = this.targetService.read("1"); +//// Assert.assertNotNull(res); // } -// } +// +// @Test +// public void testReadAllByProbeId() throws Exception { +// PageParams pageParams = new PageParams(); +// pageParams.setPageNo(1); +// pageParams.setCountPerPage(10); +// +// Page targets = this.targetService.readAllByProbeID((long)1, pageParams); +// +// System.out.println(targets.getSize()); +// } +// + }