test
This commit is contained in:
snoop 2016-11-17 15:17:33 +09:00
parent 84bb955d2e
commit 2b2ec9ebd5

View File

@ -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<HostScanHistory> hostScanHistories = new ArrayList<HostScanHistory>();
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<DiscoveryHost> discoveryHosts = new ArrayList<>();
DiscoveryHost host1 = null;
List<PortScanHistory> pList = null;
List<DiscoveryPort> discoveryPorts = new ArrayList<>();
DiscoveryPort port = null;
for(int indexI = 0 ; indexI < 5; ++indexI) {
host1 = new DiscoveryHost(3232235986l,52242420297l);
host1.setZone(zone);
pList = new ArrayList<PortScanHistory>();
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<ServiceScanHistory> 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<DiscoveryService> 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<DiscoveryHistory> discoveryHistories = discoveryHistoryRepository.findAll();
//
System.out.println("aaaaaaaaaaaaaaaaaaaaa" + discoveryHistories.size());
DiscoveryHistory discoveryHistory1 = discoveryHistories.get(0);
}
}