From d4861a8c95f85e9f5e69ff48f4efacfcb3bbe71c Mon Sep 17 00:00:00 2001 From: insanity Date: Wed, 16 Nov 2016 12:33:23 +0900 Subject: [PATCH] Collector --- .../collector/{entity => }/Collector.java | 62 ++++++++--------- .../{controller => }/CollectorController.java | 2 +- .../{repository => }/CollectorRepository.java | 4 +- .../loafle/bridge/collector/LicenseType.java | 21 ++++++ .../collector/CollectorRepositoryTest.java | 66 +++++++++++++++++++ 5 files changed, 117 insertions(+), 38 deletions(-) rename src/main/java/com/loafle/bridge/collector/{entity => }/Collector.java (60%) rename src/main/java/com/loafle/bridge/collector/{controller => }/CollectorController.java (62%) rename src/main/java/com/loafle/bridge/collector/{repository => }/CollectorRepository.java (77%) create mode 100644 src/main/java/com/loafle/bridge/collector/LicenseType.java create mode 100644 src/test/java/com/loafle/bridge/collector/CollectorRepositoryTest.java diff --git a/src/main/java/com/loafle/bridge/collector/entity/Collector.java b/src/main/java/com/loafle/bridge/collector/Collector.java similarity index 60% rename from src/main/java/com/loafle/bridge/collector/entity/Collector.java rename to src/main/java/com/loafle/bridge/collector/Collector.java index 57a8af1..fb37cfb 100644 --- a/src/main/java/com/loafle/bridge/collector/entity/Collector.java +++ b/src/main/java/com/loafle/bridge/collector/Collector.java @@ -1,4 +1,4 @@ -package com.loafle.bridge.collector.entity; +package com.loafle.bridge.collector; import javax.persistence.*; import java.util.Date; @@ -7,14 +7,6 @@ import java.util.Date; * Created by root on 16. 11. 15. */ -enum License { - LICENSE1, - LICENSE2, - LICENSE3, - LICENSE4, - LICENSE5; -} - @Entity public class Collector { @@ -25,14 +17,11 @@ public class Collector { @Column(nullable = false) private String productId; - @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false) - private Date installedDate; - - @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") - private Date updatedDate; + @Column(nullable = false) + private String version; @Enumerated(EnumType.STRING) - private License licenseType; + private LicenseType licenseType; @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") private Date licenseDueDate; @@ -40,8 +29,11 @@ public class Collector { @Column(nullable = false) private String configPath; - @Column(nullable = false) - private String collectorVersion; + @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false) + private Date installDate; + + @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") + private Date updateDate; public Collector() { } @@ -62,19 +54,27 @@ public class Collector { this.productId = productId; } - public Date getInstalledDate() { - return installedDate; + public Date getInstallDate() { + return installDate; } - public void setInstalledDate(Date installedDate) { - this.installedDate = installedDate; + public void setInstallDate(Date installDate) { + this.installDate = installDate; } - public License getLicenseType() { + public Date getUpdateDate() { + return updateDate; + } + + public void setUpdateDate(Date updateDate) { + this.updateDate = updateDate; + } + + public LicenseType getLicenseType() { return licenseType; } - public void setLicenseType(License licenseType) { + public void setLicenseType(LicenseType licenseType) { this.licenseType = licenseType; } @@ -94,19 +94,11 @@ public class Collector { this.configPath = configPath; } - public String getCollectorVersion() { - return collectorVersion; + public String getVersion() { + return version; } - public void setCollectorVersion(String collectorVersion) { - this.collectorVersion = collectorVersion; - } - - public Date getUpdatedDate() { - return updatedDate; - } - - public void setUpdatedDate(Date updatedDate) { - this.updatedDate = updatedDate; + public void setVersion(String version) { + this.version = version; } } diff --git a/src/main/java/com/loafle/bridge/collector/controller/CollectorController.java b/src/main/java/com/loafle/bridge/collector/CollectorController.java similarity index 62% rename from src/main/java/com/loafle/bridge/collector/controller/CollectorController.java rename to src/main/java/com/loafle/bridge/collector/CollectorController.java index 325556a..1b4cd6f 100644 --- a/src/main/java/com/loafle/bridge/collector/controller/CollectorController.java +++ b/src/main/java/com/loafle/bridge/collector/CollectorController.java @@ -1,4 +1,4 @@ -package com.loafle.bridge.collector.controller; +package com.loafle.bridge.collector; /** * Created by root on 16. 11. 15. diff --git a/src/main/java/com/loafle/bridge/collector/repository/CollectorRepository.java b/src/main/java/com/loafle/bridge/collector/CollectorRepository.java similarity index 77% rename from src/main/java/com/loafle/bridge/collector/repository/CollectorRepository.java rename to src/main/java/com/loafle/bridge/collector/CollectorRepository.java index ca1d43a..b10c8e5 100644 --- a/src/main/java/com/loafle/bridge/collector/repository/CollectorRepository.java +++ b/src/main/java/com/loafle/bridge/collector/CollectorRepository.java @@ -1,6 +1,6 @@ -package com.loafle.bridge.collector.repository; +package com.loafle.bridge.collector; -import com.loafle.bridge.collector.entity.Collector; +import com.loafle.bridge.collector.Collector; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; diff --git a/src/main/java/com/loafle/bridge/collector/LicenseType.java b/src/main/java/com/loafle/bridge/collector/LicenseType.java new file mode 100644 index 0000000..5ee98af --- /dev/null +++ b/src/main/java/com/loafle/bridge/collector/LicenseType.java @@ -0,0 +1,21 @@ +package com.loafle.bridge.collector; + +/** + * Created by root on 16. 11. 16. + */ +public enum LicenseType { + + LICENSE1("License 1"), + LICENSE2("License 2"), + LICENSE3("License 3"), + LICENSE4("License 4"), + LICENSE5("License 5"); + + private String stringValue; + LicenseType(String string) {stringValue = string;} + + @Override + public String toString() { + return stringValue; + } +} \ No newline at end of file diff --git a/src/test/java/com/loafle/bridge/collector/CollectorRepositoryTest.java b/src/test/java/com/loafle/bridge/collector/CollectorRepositoryTest.java new file mode 100644 index 0000000..99f51a7 --- /dev/null +++ b/src/test/java/com/loafle/bridge/collector/CollectorRepositoryTest.java @@ -0,0 +1,66 @@ +package com.loafle.bridge.collector; + +import com.loafle.bridge.Application; +import org.apache.log4j.Logger; +import org.junit.After; +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.Date; + +import static org.junit.Assert.assertEquals; + +/** + * Created by root on 16. 11. 15. + */ + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = Application.class) +public class CollectorRepositoryTest { + + + + @Autowired + private CollectorRepository repo; + + Logger l = Logger.getLogger(this.getClass()); + + +// @Before +// public void Before() { +// Collector c = new Collector(); +// c.setCollectorVersion("1.0.0"); +// c.setConfigPath("/root"); +// c.setInstalledDate(new Date()); +// c.setLicenseDueDate(new Date()); +// c.setProductId("1111111"); +// repo.save(c); +// } + + @After + public void After() { + repo.deleteAll(); + } + + @Test + public void TestInsertPort() { + + Collector c = new Collector(); + c.setVersion("1.0.0"); + c.setConfigPath("/root"); + c.setInstallDate(new Date()); + c.setUpdateDate(new Date()); + c.setLicenseDueDate(new Date()); + c.setProductId("1111111"); + repo.save(c); + + Collector res = repo.findOne(c.getId()); + + assertEquals(c.getId(),res.getId()); + + } + +} \ No newline at end of file