added probeHost service

This commit is contained in:
snoop 2017-08-21 18:04:53 +09:00
parent 4b2b87024f
commit fe6ecc58df
4 changed files with 98 additions and 1 deletions

View File

@ -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, Long> {
ProbeHost findByProbe(Probe probe);
}

View File

@ -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);
}
}

View File

@ -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 ( INSERT INTO public.infra_os_daemon ("name",id,os_id) VALUES (
'Apache',6,2); 'Apache',6,2);
insert into public.PROBE_INFRAHOST (HOST_ID, PROBE_ID) values (3, 1);

View File

@ -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);
}
}