diff --git a/src/main/java/com/loafle/overflow/central/module/noauthprobe/dao/NoAuthProbeDAO.java b/src/main/java/com/loafle/overflow/central/module/noauthprobe/dao/NoAuthProbeDAO.java index 655d55d..b3ac142 100644 --- a/src/main/java/com/loafle/overflow/central/module/noauthprobe/dao/NoAuthProbeDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/noauthprobe/dao/NoAuthProbeDAO.java @@ -12,20 +12,7 @@ import java.util.List; */ @Repository public interface NoAuthProbeDAO extends JpaRepository { - NoAuthProbe findByTempProbeKey(String tempProbeKey); List findAllByDomainIdAndMetaNoAuthProbeStatusId(Long domainID, Short metaNoAuthProbeStatusId); - - // NoAuthProbeDeprecate findByTempKey(NoAuthProbeDeprecate noAuthAgent); - // List findAllByNoAuth(NoAuthProbeDeprecate noAuthAgent); - // @Query("SELECT n FROM NoAuthProbe n WHERE n.tempProbeKey = :tempProbeKey") - // @Query("select m from Member m WHERE m.email = :#{#m2.email}") - - // @Modifying(clearAutomatically = true) - // @Query("UPDATE NoAuthProbe n set n.connectDate = :connectDate, - // n.connectAddress = :connectAddress where n.tempProbeKey = :tempProbeKey") - // int saveConnect(@Param("tempProbeKey") String tempProbeKey, - // @Param("connectDate") Date connectDate, @Param("connectAddress") String - // connectAddress); } diff --git a/src/test/java/com/loafle/overflow/central/module/noauthprobe/dao/NoAuthProbeDAOTest.java b/src/test/java/com/loafle/overflow/central/module/noauthprobe/dao/NoAuthProbeDAOTest.java new file mode 100644 index 0000000..adf71fc --- /dev/null +++ b/src/test/java/com/loafle/overflow/central/module/noauthprobe/dao/NoAuthProbeDAOTest.java @@ -0,0 +1,42 @@ +package com.loafle.overflow.central.module.noauthprobe.dao; + +import static org.junit.Assert.assertNotNull; + +import java.util.List; + +import com.loafle.overflow.central.spring.AppConfigTest; +import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus; +import com.loafle.overflow.model.noauthprobe.NoAuthProbe; + +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; + +/** + * Created by snoop on 17. 9. 14. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {AppConfigTest.class}) +public class NoAuthProbeDAOTest { + + @Autowired + private NoAuthProbeDAO noAuthProbeDAO; + + @Test + public void findByTempProbeKey() throws Exception { + + NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findByTempProbeKey("1cf2555c57d511e79714080027658d13"); + + assertNotNull(noAuthProbe); + } + + @Test + public void findAllMemberByDomainId() throws Exception { + + List noAuthProbes = this.noAuthProbeDAO.findAllByDomainIdAndMetaNoAuthProbeStatusId((long) 1, MetaNoAuthProbeStatus.Enum.PROCESSING.getValue()); + + assertNotNull(noAuthProbes); + } +} diff --git a/src/test/java/com/loafle/overflow/central/module/noauthprobe/service/NoAuthProbeServiceTest.java b/src/test/java/com/loafle/overflow/central/module/noauthprobe/service/NoAuthProbeServiceTest.java index 7abf50f..1d157e4 100644 --- a/src/test/java/com/loafle/overflow/central/module/noauthprobe/service/NoAuthProbeServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/noauthprobe/service/NoAuthProbeServiceTest.java @@ -1,21 +1,15 @@ package com.loafle.overflow.central.module.noauthprobe.service; -import com.loafle.overflow.central.commons.service.MessagePublisher; import com.loafle.overflow.central.spring.AppConfigTest; -import com.loafle.overflow.core.exception.OverflowException; -import com.loafle.overflow.model.domain.Domain; -import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus; import com.loafle.overflow.model.noauthprobe.NoAuthProbe; 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.ArrayList; import java.util.List; /** @@ -28,125 +22,56 @@ public class NoAuthProbeServiceTest { @Autowired private CentralNoAuthProbeService noAuthProbeService; - @Autowired - private MessagePublisher messagePublisher; - - @Ignore @Test public void regist() throws Exception { NoAuthProbe noAuthProbe = new NoAuthProbe(); - // noAuthProbe.setHostName("snoop"); - // noAuthProbe.setIpAddress(3232235980L); - // noAuthProbe.setMacAddress(8796753988883L); + noAuthProbe.setApiKey("52abd6fd57e511e7ac52080027658d13"); noAuthProbe.setInfraHostMeta( "{\"host\":{\"name\":\"snoop-ubuntu\",\"os\":\"linux\",\"paltform\":\"ubuntu\",\"platformFamily\":\"debian\",\"platformVersion\":\"\",\"kernelVersion\":\"4.4.0-93-generic\",\"hostID\":\"DE60E4C3-347A-4D38-AEAB-1760471665EA\"},\"network\":{\"name\":\"enp3s0\",\"address\":\"192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64\",\"gateway\":\"192.168.1.254\",\"macAddress\":\"44:8a:5b:f1:f1:f3\"}}"); - noAuthProbe.setApiKey("52abd6fd57e511e7ac52080027658d13"); + noAuthProbe = this.noAuthProbeService.regist(noAuthProbe); - MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus(); - metaNoAuthProbeStatus.setId((short) 3); - - noAuthProbe.setMetaNoAuthProbeStatus(metaNoAuthProbeStatus); - noAuthProbe.setTempProbeKey("ac7f252b5bc811e784ad080027658d13"); - - Domain d = new Domain(); - d.setId(Long.valueOf(1)); - noAuthProbe.setDomain(d); - - this.noAuthProbeService.regist(noAuthProbe); - - Assert.assertNotEquals(noAuthProbe.getId().longValue(), 0); - - } - - @Ignore - @Test - public void registForNoAuthProbes() throws Exception { - - NoAuthProbe noAuthProbe = new NoAuthProbe(); - - // noAuthProbe.setHostName("geek"); - // noAuthProbe.setIpAddress(3232235980L); - // noAuthProbe.setMacAddress(8796753988883L); - noAuthProbe.setInfraHostMeta( - "{\"host\":{\"name\":\"geek-ubuntu\",\"os\":\"linux\",\"paltform\":\"ubuntu\",\"platformFamily\":\"debian\",\"platformVersion\":\"\",\"kernelVersion\":\"4.4.0-93-generic\",\"hostID\":\"03000200-0400-0500-0006-000700080009\"},\"network\":{\"name\":\"enp3s0\",\"address\":\"192.168.1.103/24|fe80::36c0:6c3e:6006:dd23/64\",\"gateway\":\"192.168.1.254\",\"macAddress\":\"44:8a:5b:f1:f1:f3\"}}"); - noAuthProbe.setApiKey("521abd6fd57e511e7ac52080027658d13"); - - MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus(); - metaNoAuthProbeStatus.setId((short) 3); - - noAuthProbe.setMetaNoAuthProbeStatus(metaNoAuthProbeStatus); - noAuthProbe.setTempProbeKey("a1c7f252b5bc811e784ad080027658d13"); - - Domain d = new Domain(); - d.setId(Long.valueOf(1)); - noAuthProbe.setDomain(d); - - List noAuthProbes = new ArrayList(); - - noAuthProbes.add(noAuthProbe); - // List dd = - // this.noAuthProbeService.registForNoAuthProbes(noAuthProbes); - - // System.out.println(dd.get(0).getId()); - - Assert.assertNotEquals(noAuthProbes.size(), 2); - - } - - @Ignore - @Test - public void readAllByDomainID() throws Exception { - List probes = this.noAuthProbeService.readAllByDomainID(Long.valueOf(1)); - - Assert.assertNotEquals(probes.size(), 0); - - } - - @Ignore - @Test - public void read() throws Exception { - NoAuthProbe noAuthProbe = this.noAuthProbeService.read(Long.valueOf(1)); - - Assert.assertNotEquals(noAuthProbe, null); - } - - @Ignore - @Test - public void acceptProbe() throws Exception { - - this.noAuthProbeService.acceptNoAuthProbe(Long.valueOf(1), "192.168.1.0/24"); - - } - - @Ignore - @Test - public void ssss() { - String ss = "192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64"; - - String[] sss = ss.split("\\|"); - - System.out.println(sss[0]); + Assert.assertNotNull(noAuthProbe.getId()); } @Test - public void readByTempKey() throws Exception { - + public void readByTempProbeKey() throws Exception { NoAuthProbe noAuthProbe = this.noAuthProbeService.readByTempProbeKey("1cf2555c57d511e79714080027658d15"); - Assert.assertNotEquals(noAuthProbe, null); - + Assert.assertNotNull(noAuthProbe); } @Test - @Ignore - public void sendWeb() throws OverflowException { - List probes = this.noAuthProbeService.readAllByDomainID(Long.valueOf(1)); - - messagePublisher.publishToDomainMembers(Long.valueOf(1), "NoAuthProbeService.regist", probes); + public void readAllByDomainID() throws Exception { + List noAuthProbes = this.noAuthProbeService.readAllByDomainID((long) 1); + Assert.assertNotEquals(noAuthProbes.size(), 0); } -} \ No newline at end of file + @Test + public void acceptNoAuthProbe() throws Exception { + List noAuthProbes = this.noAuthProbeService.acceptNoAuthProbe((long) 1, "192.168.1.0/24"); + + Assert.assertNotEquals(noAuthProbes.size(), 0); + } + + @Test + public void denyNoauthProbe() throws Exception { + List noAuthProbes = this.noAuthProbeService.denyNoauthProbe((long) 1); + + Assert.assertNotEquals(noAuthProbes.size(), 0); + } + + @Test + public void onConnect() throws Exception { + this.noAuthProbeService.onConnect("1cf2555c57d511e79714080027658d15", "192.168.1.101"); + } + + @Test + public void onDisconnect() throws Exception { + this.noAuthProbeService.onDisconnect("1cf2555c57d511e79714080027658d15"); + } + +}