diff --git a/src/test/java/com/loafle/bridge/discoveryHistory/repository/DiscoveryHistoryRepositoryTest.java b/src/test/java/com/loafle/bridge/discoveryHistory/repository/DiscoveryHistoryRepositoryTest.java index 6e04afd..f5fedb1 100644 --- a/src/test/java/com/loafle/bridge/discoveryHistory/repository/DiscoveryHistoryRepositoryTest.java +++ b/src/test/java/com/loafle/bridge/discoveryHistory/repository/DiscoveryHistoryRepositoryTest.java @@ -3,11 +3,27 @@ package com.loafle.bridge.discoveryHistory.repository; import com.loafle.bridge.Application; import com.loafle.bridge.discoveryhistory.DiscoveryHistory; import com.loafle.bridge.discoveryhistory.DiscoveryHistoryRepository; +import com.loafle.bridge.discoveryhost.DiscoveryHost; +import com.loafle.bridge.discoveryhost.PortScanHistory; +import com.loafle.bridge.discoveryport.DiscoveryPort; +import com.loafle.bridge.discoveryport.ServiceScanHistory; +import com.loafle.bridge.discoveryport.type.DirectionType; +import com.loafle.bridge.discoveryport.type.PortType; +import com.loafle.bridge.discoveryservice.DiscoveryService; +import com.loafle.bridge.discoveryzone.DiscoveryZone; +import com.loafle.bridge.discoveryzone.HostScanHistory; +import com.loafle.bridge.discoveryzone.ResultType; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; /** * Created by snoop on 16. 11. 15. @@ -42,6 +58,127 @@ public class DiscoveryHistoryRepositoryTest { System.out.println("dh.getId() = " + dh.getStartDate()); } + } + + @Test + @Transactional + public void InsertAll() { + + DiscoveryHistory discoveryHistory = new DiscoveryHistory(); + discoveryHistory.setStartDate(new Date()); + discoveryHistory.setEndDate(new Date()); + discoveryHistory.setResult(true); + + DiscoveryZone zone = new DiscoveryZone(); + String cidr = "827452358680"; + String ip = "3232235983"; + + zone.setCidr(Long.parseLong(cidr)); + zone.setIp(Long.parseLong(ip)); + + discoveryHistory.setZone(zone); + + List hostScanHistories = new ArrayList(); + + HostScanHistory hostScanHistory = null; + + for( int indexI = 0 ; indexI < 5; ++indexI) { + + hostScanHistory = new HostScanHistory(); + + hostScanHistory.setIp(Long.parseLong(ip)); + + hostScanHistory.setCreateDate(new Date()); + hostScanHistory.setSendDate(new Date()); + hostScanHistory.setResultDate(new Date()); + hostScanHistory.setDescription("hgihihihih"); + + hostScanHistory.setResultType(ResultType.Success); + hostScanHistory.setZone(zone); + + + hostScanHistories.add(hostScanHistory); + } + + zone.setHostScanHistories(hostScanHistories); + + + + List discoveryHosts = new ArrayList<>(); + + DiscoveryHost host1 = null; + + List pList = null; + + List discoveryPorts = new ArrayList<>(); + DiscoveryPort port = null; + + for(int indexI = 0 ; indexI < 5; ++indexI) { + host1 = new DiscoveryHost(3232235986l,52242420297l); + host1.setZone(zone); + + pList = new ArrayList(); + pList.add(new PortScanHistory(host1, (short)9840, PortType.TCP, DirectionType.Send,"DDDDDD")); + pList.add(new PortScanHistory(host1, (short)9840, PortType.TCP, DirectionType.Send,"DDDDDD")); + pList.add(new PortScanHistory(host1, (short)9840, PortType.TCP, DirectionType.Send,"DDDDDD")); + pList.add(new PortScanHistory(host1, (short)9840, PortType.TCP, DirectionType.Send,"DDDDDD")); + pList.add(new PortScanHistory(host1, (short)9840, PortType.TCP, DirectionType.Send,"DDDDDD")); + + + + for(int indexJ = 0 ; indexJ < 5; ++indexJ) { + port = new DiscoveryPort(PortType.TCP,(short)1); + + List serviceScanHistories = new ArrayList<>(); + byte [] a = {10,20,30,40,50}; + serviceScanHistories.add(new ServiceScanHistory(port,"testservice1", DirectionType.Send,a, new Date())); + serviceScanHistories.add(new ServiceScanHistory(port,"testservice1", DirectionType.Send,a, new Date())); + serviceScanHistories.add(new ServiceScanHistory(port,"testservice1", DirectionType.Send,a, new Date())); + serviceScanHistories.add(new ServiceScanHistory(port,"testservice1", DirectionType.Send,a, new Date())); + serviceScanHistories.add(new ServiceScanHistory(port,"testservice1", DirectionType.Send,a, new Date())); + + port.setHistories(serviceScanHistories); + + + List discoveryServices = new ArrayList<>(); + discoveryServices.add(new DiscoveryService(port,PortType.TCP,"DNS")); + discoveryServices.add(new DiscoveryService(port,PortType.TCP,"TEST")); + discoveryServices.add(new DiscoveryService(port,PortType.TCP,"ABB")); + + port.setServices(discoveryServices); + + discoveryPorts.add(port); + } + + host1.setHistories(pList); + host1.setPorts(discoveryPorts); + + discoveryHosts.add(host1); + } + + zone.setDiscoveryHosts(discoveryHosts); + + + + + + + + discoveryHistoryRepository.save(discoveryHistory); + + discoveryHistoryRepository.flush(); + + + List discoveryHistories = discoveryHistoryRepository.findAll(); +// + System.out.println("aaaaaaaaaaaaaaaaaaaaa" + discoveryHistories.size()); + + + DiscoveryHistory discoveryHistory1 = discoveryHistories.get(0); + + + + } } \ No newline at end of file