Merge remote-tracking branch 'origin/master'
This commit is contained in:
		
						commit
						dcea99dc21
					
				| @ -1,6 +1,7 @@ | |||||||
| package com.loafle.bridge.discoveryport.entity; | package com.loafle.bridge.discoveryport; | ||||||
| 
 | 
 | ||||||
| import com.loafle.bridge.discoveryport.constant.PortType; | import com.loafle.bridge.discoveryport.type.PortType; | ||||||
|  | import com.loafle.bridge.discoveryservice.entity.DiscoveryService; | ||||||
| 
 | 
 | ||||||
| import javax.persistence.*; | import javax.persistence.*; | ||||||
| import java.util.Date; | import java.util.Date; | ||||||
| @ -28,26 +29,26 @@ public class DiscoveryPort { | |||||||
|     private PortType portType; |     private PortType portType; | ||||||
| 
 | 
 | ||||||
|     @Column(nullable = false) |     @Column(nullable = false) | ||||||
|     private short portNumber; |     private int portNumber; | ||||||
| 
 | 
 | ||||||
|     @OneToMany(mappedBy = "port") |     @OneToMany(mappedBy = "port") | ||||||
|     private List<ServiceScanHistory> histories; |     private List<ServiceScanHistory> histories; | ||||||
| 
 | 
 | ||||||
| //    @OneToMany(mappedBy = "port") |     @OneToMany(mappedBy = "port" ,cascade = CascadeType.ALL) | ||||||
| //    private List<DiscoveryService> services; |     private List<DiscoveryService> services; | ||||||
| // | 
 | ||||||
| //    public List<DiscoveryService> getServices() { |     public List<DiscoveryService> getServices() { | ||||||
| //        return services; |         return services; | ||||||
| //    } |     } | ||||||
| // | 
 | ||||||
| //    public void setServices(List<DiscoveryService> services) { |     public void setServices(List<DiscoveryService> services) { | ||||||
| //        this.services = services; |         this.services = services; | ||||||
| //    } |     } | ||||||
| 
 | 
 | ||||||
|     @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false) |     @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false) | ||||||
|     private Date createDate; |     private Date createDate; | ||||||
| 
 | 
 | ||||||
|     @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false) |     @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false) | ||||||
|     private Date updateDate; |     private Date updateDate; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -74,11 +75,11 @@ public class DiscoveryPort { | |||||||
|         this.portType = portType; |         this.portType = portType; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public short getPortNumber() { |     public int getPortNumber() { | ||||||
|         return portNumber; |         return portNumber; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public void setPortNumber(short portNumber) { |     public void setPortNumber(int portNumber) { | ||||||
|         this.portNumber = portNumber; |         this.portNumber = portNumber; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -99,9 +100,6 @@ public class DiscoveryPort { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Date getUpdateDate() { |     public Date getUpdateDate() { | ||||||
|         if (this.updateDate == null) { |  | ||||||
|             this.updateDate = new Date(); |  | ||||||
|         } |  | ||||||
|         return updateDate; |         return updateDate; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -0,0 +1,47 @@ | |||||||
|  | package com.loafle.bridge.discoveryport; | ||||||
|  | 
 | ||||||
|  | import com.loafle.bridge.discoveryport.type.PortType; | ||||||
|  | import com.loafle.bridge.discoveryservice.entity.DiscoveryService; | ||||||
|  | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  | import org.springframework.web.bind.annotation.PathVariable; | ||||||
|  | import org.springframework.web.bind.annotation.RequestMapping; | ||||||
|  | import org.springframework.web.bind.annotation.RequestMethod; | ||||||
|  | import org.springframework.web.bind.annotation.RestController; | ||||||
|  | 
 | ||||||
|  | import javax.transaction.Transactional; | ||||||
|  | import java.util.ArrayList; | ||||||
|  | import java.util.List; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Created by root on 16. 11. 15. | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | @RestController | ||||||
|  | public class DiscoveryPortController { | ||||||
|  | 
 | ||||||
|  |     @Autowired | ||||||
|  |     DiscoveryPortRepository repository; | ||||||
|  | 
 | ||||||
|  |     @RequestMapping(value = "/discoveryPort/{id}", method = RequestMethod.GET) | ||||||
|  |     public DiscoveryPort get(@PathVariable(value = "id") long id) { | ||||||
|  |         return repository.findOne(id); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @RequestMapping(value ="/index") | ||||||
|  |     @Transactional | ||||||
|  |     public void index() { | ||||||
|  |         DiscoveryPort p = new DiscoveryPort(PortType.TCP,(short)12786); | ||||||
|  | 
 | ||||||
|  |         List<DiscoveryService> ss = new ArrayList<>(); | ||||||
|  | 
 | ||||||
|  |         repository.save(p); | ||||||
|  | 
 | ||||||
|  |         ss.add(new DiscoveryService(p,PortType.TCP,"DNS")); | ||||||
|  |         ss.add(new DiscoveryService(p,PortType.TCP,"TEST")); | ||||||
|  |         ss.add(new DiscoveryService(p,PortType.TCP,"ABB")); | ||||||
|  | 
 | ||||||
|  |         p.setServices(ss); | ||||||
|  | 
 | ||||||
|  |         repository.save(p); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -1,6 +1,5 @@ | |||||||
| package com.loafle.bridge.discoveryport.repository; | package com.loafle.bridge.discoveryport; | ||||||
| 
 | 
 | ||||||
| import com.loafle.bridge.discoveryport.entity.DiscoveryPort; |  | ||||||
| import org.springframework.data.jpa.repository.JpaRepository; | import org.springframework.data.jpa.repository.JpaRepository; | ||||||
| import org.springframework.data.rest.core.annotation.RepositoryRestResource; | import org.springframework.data.rest.core.annotation.RepositoryRestResource; | ||||||
| 
 | 
 | ||||||
| @ -1,6 +1,6 @@ | |||||||
| package com.loafle.bridge.discoveryport.entity; | package com.loafle.bridge.discoveryport; | ||||||
| 
 | 
 | ||||||
| import com.loafle.bridge.discoveryport.constant.DirectionType; | import com.loafle.bridge.discoveryport.type.DirectionType; | ||||||
| 
 | 
 | ||||||
| import javax.persistence.*; | import javax.persistence.*; | ||||||
| import java.util.Date; | import java.util.Date; | ||||||
| @ -16,10 +16,14 @@ public class ServiceScanHistory { | |||||||
|     @GeneratedValue(strategy = GenerationType.AUTO) |     @GeneratedValue(strategy = GenerationType.AUTO) | ||||||
|     private long id; |     private long id; | ||||||
| 
 | 
 | ||||||
|  |     @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false) | ||||||
|  |     private Date createDate; | ||||||
|  | 
 | ||||||
|     @ManyToOne(fetch = FetchType.LAZY) |     @ManyToOne(fetch = FetchType.LAZY) | ||||||
|     @JoinColumn |     @JoinColumn | ||||||
|     private DiscoveryPort port; |     private DiscoveryPort port; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|     @Column(nullable = false) |     @Column(nullable = false) | ||||||
|     private String serviceName; |     private String serviceName; | ||||||
| 
 | 
 | ||||||
| @ -27,8 +31,7 @@ public class ServiceScanHistory { | |||||||
|     @Enumerated(EnumType.STRING) |     @Enumerated(EnumType.STRING) | ||||||
|     private DirectionType direction; |     private DirectionType direction; | ||||||
| 
 | 
 | ||||||
|     @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false) | 
 | ||||||
|     private Date createDate; |  | ||||||
| 
 | 
 | ||||||
|     @Lob |     @Lob | ||||||
|     @Column(nullable = false) |     @Column(nullable = false) | ||||||
| @ -1,25 +0,0 @@ | |||||||
| package com.loafle.bridge.discoveryport.controller; |  | ||||||
| 
 |  | ||||||
| import com.loafle.bridge.discoveryport.entity.DiscoveryPort; |  | ||||||
| import com.loafle.bridge.discoveryport.repository.DiscoveryPortRepository; |  | ||||||
| import org.springframework.beans.factory.annotation.Autowired; |  | ||||||
| import org.springframework.web.bind.annotation.PathVariable; |  | ||||||
| import org.springframework.web.bind.annotation.RequestMapping; |  | ||||||
| import org.springframework.web.bind.annotation.RequestMethod; |  | ||||||
| import org.springframework.web.bind.annotation.RestController; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * Created by root on 16. 11. 15. |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| @RestController |  | ||||||
| public class DiscoveryPortController { |  | ||||||
| 
 |  | ||||||
|     @Autowired |  | ||||||
|     DiscoveryPortRepository repository; |  | ||||||
| 
 |  | ||||||
|     @RequestMapping(value = "/discoveryPort/{id}", method = RequestMethod.GET) |  | ||||||
|     public DiscoveryPort get(@PathVariable(value = "id") long id) { |  | ||||||
|         return repository.findOne(id); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,4 +1,4 @@ | |||||||
| package com.loafle.bridge.discoveryport.constant; | package com.loafle.bridge.discoveryport.type; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Created by root on 16. 11. 15. |  * Created by root on 16. 11. 15. | ||||||
| @ -1,4 +1,4 @@ | |||||||
| package com.loafle.bridge.discoveryport.constant; | package com.loafle.bridge.discoveryport.type; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Created by root on 16. 11. 15. |  * Created by root on 16. 11. 15. | ||||||
| @ -1,6 +1,7 @@ | |||||||
| package com.loafle.bridge.discoveryservice.entity; | package com.loafle.bridge.discoveryservice.entity; | ||||||
| 
 | 
 | ||||||
| import com.loafle.bridge.discoveryport.constant.PortType; | import com.loafle.bridge.discoveryport.DiscoveryPort; | ||||||
|  | import com.loafle.bridge.discoveryport.type.PortType; | ||||||
| 
 | 
 | ||||||
| import javax.persistence.*; | import javax.persistence.*; | ||||||
| import java.util.Date; | import java.util.Date; | ||||||
| @ -14,16 +15,16 @@ public class DiscoveryService { | |||||||
|     @GeneratedValue(strategy = GenerationType.AUTO) |     @GeneratedValue(strategy = GenerationType.AUTO) | ||||||
|     private long id; |     private long id; | ||||||
| 
 | 
 | ||||||
| //    @ManyToOne |     @ManyToOne | ||||||
| //    @JoinColumn(nullable = false) |     @JoinColumn(nullable = false) | ||||||
| //    private DiscoveryPort port; |     private DiscoveryPort port; | ||||||
| //    public DiscoveryPort getPort() { |     public DiscoveryPort getPort() { | ||||||
| //        return port; |         return port; | ||||||
| //    } |     } | ||||||
| // | 
 | ||||||
| //    public void setPort(DiscoveryPort port) { |     public void setPort(DiscoveryPort port) { | ||||||
| //        this.port = port; |         this.port = port; | ||||||
| //    } |     } | ||||||
| 
 | 
 | ||||||
|     @Column(nullable = false) |     @Column(nullable = false) | ||||||
|     @Enumerated(EnumType.STRING) |     @Enumerated(EnumType.STRING) | ||||||
| @ -35,12 +36,13 @@ public class DiscoveryService { | |||||||
|     @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false) |     @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false) | ||||||
|     private Date createDate; |     private Date createDate; | ||||||
| 
 | 
 | ||||||
|     @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false) |     @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false ,insertable = false) | ||||||
|     private Date updateDate; |     private Date updateDate; | ||||||
| 
 | 
 | ||||||
|     public DiscoveryService() {} |     public DiscoveryService() {} | ||||||
| 
 | 
 | ||||||
|     public DiscoveryService(PortType t, String serviceName) { |     public DiscoveryService(DiscoveryPort port,PortType t, String serviceName) { | ||||||
|  |         this.port = port; | ||||||
|         this.portType = t; |         this.portType = t; | ||||||
|         this.serviceName = serviceName; |         this.serviceName = serviceName; | ||||||
|     } |     } | ||||||
| @ -63,9 +65,6 @@ public class DiscoveryService { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Date getUpdateDate() { |     public Date getUpdateDate() { | ||||||
|         if (this.updateDate == null) { |  | ||||||
|             this.updateDate = new Date(); |  | ||||||
|         } |  | ||||||
|         return updateDate; |         return updateDate; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| ## DataSource configuration | ## DataSource configuration | ||||||
| spring.datasource.url=jdbc:h2:file:~/data/test | spring.datasource.url=jdbc:h2:file:~/data/test;DB_CLOSE_ON_EXIT=FALSE | ||||||
| spring.datasource.username=sa | spring.datasource.username=sa | ||||||
| spring.datasource.password=qwe123 | spring.datasource.password=qwe123 | ||||||
| spring.datasource.driver-class-name=org.h2.Driver | spring.datasource.driver-class-name=org.h2.Driver | ||||||
|  | |||||||
| @ -1,10 +1,11 @@ | |||||||
| package com.loafle.bridge.discoveryport.repository; | package com.loafle.bridge.discoveryport.repository; | ||||||
| 
 | 
 | ||||||
| import com.loafle.bridge.Application; | import com.loafle.bridge.Application; | ||||||
| import com.loafle.bridge.discoveryport.constant.DirectionType; | import com.loafle.bridge.discoveryport.DiscoveryPort; | ||||||
| import com.loafle.bridge.discoveryport.constant.PortType; | import com.loafle.bridge.discoveryport.DiscoveryPortRepository; | ||||||
| import com.loafle.bridge.discoveryport.entity.DiscoveryPort; | import com.loafle.bridge.discoveryport.ServiceScanHistory; | ||||||
| import com.loafle.bridge.discoveryport.entity.ServiceScanHistory; | import com.loafle.bridge.discoveryport.type.DirectionType; | ||||||
|  | import com.loafle.bridge.discoveryport.type.PortType; | ||||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||||
| import org.junit.After; | import org.junit.After; | ||||||
| import org.junit.Before; | import org.junit.Before; | ||||||
|  | |||||||
| @ -1,7 +1,9 @@ | |||||||
| package com.loafle.bridge.discoveryservice.repository; | package com.loafle.bridge.discoveryservice.repository; | ||||||
| 
 | 
 | ||||||
| import com.loafle.bridge.Application; | import com.loafle.bridge.Application; | ||||||
| import com.loafle.bridge.discoveryport.constant.PortType; | import com.loafle.bridge.discoveryport.DiscoveryPort; | ||||||
|  | import com.loafle.bridge.discoveryport.DiscoveryPortRepository; | ||||||
|  | import com.loafle.bridge.discoveryport.type.PortType; | ||||||
| import com.loafle.bridge.discoveryservice.entity.DiscoveryService; | import com.loafle.bridge.discoveryservice.entity.DiscoveryService; | ||||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||||
| import org.junit.After; | import org.junit.After; | ||||||
| @ -12,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired; | |||||||
| import org.springframework.test.context.ContextConfiguration; | import org.springframework.test.context.ContextConfiguration; | ||||||
| import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||||||
| 
 | 
 | ||||||
|  | import javax.transaction.Transactional; | ||||||
|  | import java.util.ArrayList; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| 
 | 
 | ||||||
| import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||||
| @ -25,14 +29,28 @@ import static org.junit.Assert.assertEquals; | |||||||
| public class DiscoveryServiceRepositoryTest { | public class DiscoveryServiceRepositoryTest { | ||||||
| 
 | 
 | ||||||
|     @Autowired |     @Autowired | ||||||
|     private DiscoveryServiceRepository repo; |     private DiscoveryPortRepository repo; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|     private Logger log = Logger.getLogger(this.getClass()); |     private Logger log = Logger.getLogger(this.getClass()); | ||||||
| 
 | 
 | ||||||
|     @Before |     @Before | ||||||
|  |     @Transactional | ||||||
|     public void Before() { |     public void Before() { | ||||||
|        repo.save(new DiscoveryService(PortType.TLS,"HTTP")); | 
 | ||||||
|         repo.save(new DiscoveryService(PortType.TCP,"WMI")); |         DiscoveryPort p = new DiscoveryPort(PortType.TCP,(short)12786); | ||||||
|         repo.save(new DiscoveryService(PortType.UDP,"DNS")); | 
 | ||||||
|  |         List<DiscoveryService> ss = new ArrayList<>(); | ||||||
|  | 
 | ||||||
|  |         ss.add(new DiscoveryService(p,PortType.TCP,"DNS")); | ||||||
|  |         ss.add(new DiscoveryService(p,PortType.TCP,"TEST")); | ||||||
|  |         ss.add(new DiscoveryService(p,PortType.TCP,"ABB")); | ||||||
|  | 
 | ||||||
|  |         p.setServices(ss); | ||||||
|  | 
 | ||||||
|  |         repo.save(p); | ||||||
|  | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @After |     @After | ||||||
| @ -41,8 +59,10 @@ public class DiscoveryServiceRepositoryTest { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|  |     @Transactional | ||||||
|     public void TestBefore() { |     public void TestBefore() { | ||||||
|         List<DiscoveryService> l = repo.findAll(); |         List<DiscoveryPort> ll  = repo.findAll(); | ||||||
|         assertEquals(3, l.size()); |         assertEquals(1,ll.size()); | ||||||
|  |         assertEquals(3,ll.get(0).getServices().size()); | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user