diff --git a/src/main/java/com/loafle/overflow/module/probe/dao/ProbeHostDAO.java b/src/main/java/com/loafle/overflow/module/probe/dao/ProbeHostDAO.java new file mode 100644 index 0000000..5f47a1f --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/probe/dao/ProbeHostDAO.java @@ -0,0 +1,15 @@ +package com.loafle.overflow.module.probe.dao; + +import com.loafle.overflow.module.probe.model.Probe; +import com.loafle.overflow.module.probe.model.ProbeHost; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * Created by snoop on 17. 8. 21. + */ +@Repository +public interface ProbeHostDAO extends JpaRepository { + + ProbeHost findByProbe(Probe probe); +} diff --git a/src/main/java/com/loafle/overflow/module/probe/service/ProbeHostService.java b/src/main/java/com/loafle/overflow/module/probe/service/ProbeHostService.java new file mode 100644 index 0000000..c7fb9a5 --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/probe/service/ProbeHostService.java @@ -0,0 +1,25 @@ +package com.loafle.overflow.module.probe.service; + +import com.loafle.overflow.module.probe.dao.ProbeHostDAO; +import com.loafle.overflow.module.probe.model.Probe; +import com.loafle.overflow.module.probe.model.ProbeHost; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * Created by snoop on 17. 8. 21. + */ +@Service("ProbeHostService") +public class ProbeHostService { + + @Autowired + private ProbeHostDAO probeHostDAO; + + public ProbeHost readByProbe(Probe probe) { + return this.probeHostDAO.findByProbe(probe); + } + + public ProbeHost regist(ProbeHost probeHost) { + return this.probeHostDAO.save(probeHost); + } +} diff --git a/src/main/resources/init.sql b/src/main/resources/init.sql index 5893987..04f78eb 100644 --- a/src/main/resources/init.sql +++ b/src/main/resources/init.sql @@ -438,7 +438,7 @@ INSERT INTO public.infra_os_application ("name",id,os_id) VALUES ( INSERT INTO public.infra_os_daemon ("name",id,os_id) VALUES ( 'Apache',6,2); - +insert into public.PROBE_INFRAHOST (HOST_ID, PROBE_ID) values (3, 1); diff --git a/src/test/java/com/loafle/overflow/module/probe/service/ProbeHostServiceTest.java b/src/test/java/com/loafle/overflow/module/probe/service/ProbeHostServiceTest.java new file mode 100644 index 0000000..bc7f14a --- /dev/null +++ b/src/test/java/com/loafle/overflow/module/probe/service/ProbeHostServiceTest.java @@ -0,0 +1,57 @@ +package com.loafle.overflow.module.probe.service; + +import com.loafle.overflow.module.infra.model.InfraHost; +import com.loafle.overflow.module.probe.model.Probe; +import com.loafle.overflow.module.probe.model.ProbeHost; +import com.loafle.overflow.spring.AppConfigTest; +import org.junit.Assert; +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 static org.junit.Assert.*; + +/** + * Created by snoop on 17. 8. 21. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {AppConfigTest.class}) +public class ProbeHostServiceTest { + + @Autowired + private ProbeHostService probeHostService; + + @Test + public void regist() { + ProbeHost probeHost = new ProbeHost(); + + Probe probe = new Probe(); + probe.setId(1); + + InfraHost infraHost = new InfraHost(); + infraHost.setId(3); + + probeHost.setProbe(probe); + + probeHost.setHost(infraHost); + + this.probeHostService.regist(probeHost); + + Assert.assertNotEquals(probeHost.getId(), 0); + } + + @Test + public void readByProbe() throws Exception { + + Probe probe = new Probe(); + probe.setId(1); + + ProbeHost probeHost = this.probeHostService.readByProbe(probe); + + Assert.assertNotEquals(probeHost, null); + + } + +} \ No newline at end of file