From ea3935251b8b730e9dc2e9b751ec1670b164de2f Mon Sep 17 00:00:00 2001 From: geek Date: Thu, 8 Jun 2017 18:43:32 +0900 Subject: [PATCH] crawler model dao add crawler test code add --- .../overflow/crawler/dao/CrawlerDAO.java | 10 +++ .../crawler/dao/CrawlerInputItemDAO.java | 10 +++ .../dao/CrawlerInputItemMappingDAO.java | 10 +++ .../overflow/crawler/dao/JPACrawlerDAO.java | 10 +++ .../crawler/dao/JPACrawlerInputItemDAO.java | 10 +++ .../dao/JPACrawlerInputItemMappingDAO.java | 10 +++ .../overflow/crawler/model/Crawler.java | 76 ++++++++++++++++ .../crawler/model/CrawlerInputItem.java | 75 ++++++++++++++++ .../model/CrawlerInputItemMapping.java | 86 +++++++++++++++++++ .../overflow/email/dao/EmailAuthDAO.java | 2 + .../overflow/email/dao/JPAEmailAuthDAO.java | 19 ++++ .../crawler/dao/JPACrawlerDAOTest.java | 72 ++++++++++++++++ .../dao/JPACrawlerInputItemDAOTest.java | 61 +++++++++++++ .../JPACrawlerInputItemMappingDAOTest.java | 82 ++++++++++++++++++ .../email/dao/JPAEmailAuthDAOTest.java | 2 +- src/test/resources/META-INF/persistence.xml | 3 + 16 files changed, 537 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/loafle/overflow/crawler/dao/CrawlerDAO.java create mode 100644 src/main/java/com/loafle/overflow/crawler/dao/CrawlerInputItemDAO.java create mode 100644 src/main/java/com/loafle/overflow/crawler/dao/CrawlerInputItemMappingDAO.java create mode 100644 src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerDAO.java create mode 100644 src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemDAO.java create mode 100644 src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAO.java create mode 100644 src/main/java/com/loafle/overflow/crawler/model/Crawler.java create mode 100644 src/main/java/com/loafle/overflow/crawler/model/CrawlerInputItem.java create mode 100644 src/main/java/com/loafle/overflow/crawler/model/CrawlerInputItemMapping.java create mode 100644 src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerDAOTest.java create mode 100644 src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemDAOTest.java create mode 100644 src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAOTest.java diff --git a/src/main/java/com/loafle/overflow/crawler/dao/CrawlerDAO.java b/src/main/java/com/loafle/overflow/crawler/dao/CrawlerDAO.java new file mode 100644 index 0000000..aeccb0b --- /dev/null +++ b/src/main/java/com/loafle/overflow/crawler/dao/CrawlerDAO.java @@ -0,0 +1,10 @@ +package com.loafle.overflow.crawler.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.crawler.model.Crawler; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +public interface CrawlerDAO extends BaseDAO { +} diff --git a/src/main/java/com/loafle/overflow/crawler/dao/CrawlerInputItemDAO.java b/src/main/java/com/loafle/overflow/crawler/dao/CrawlerInputItemDAO.java new file mode 100644 index 0000000..058c399 --- /dev/null +++ b/src/main/java/com/loafle/overflow/crawler/dao/CrawlerInputItemDAO.java @@ -0,0 +1,10 @@ +package com.loafle.overflow.crawler.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.crawler.model.CrawlerInputItem; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +public interface CrawlerInputItemDAO extends BaseDAO { +} diff --git a/src/main/java/com/loafle/overflow/crawler/dao/CrawlerInputItemMappingDAO.java b/src/main/java/com/loafle/overflow/crawler/dao/CrawlerInputItemMappingDAO.java new file mode 100644 index 0000000..6d1f37a --- /dev/null +++ b/src/main/java/com/loafle/overflow/crawler/dao/CrawlerInputItemMappingDAO.java @@ -0,0 +1,10 @@ +package com.loafle.overflow.crawler.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.crawler.model.CrawlerInputItemMapping; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +public interface CrawlerInputItemMappingDAO extends BaseDAO { +} diff --git a/src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerDAO.java b/src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerDAO.java new file mode 100644 index 0000000..def8dc4 --- /dev/null +++ b/src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerDAO.java @@ -0,0 +1,10 @@ +package com.loafle.overflow.crawler.dao; + +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.crawler.model.Crawler; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +public class JPACrawlerDAO extends JPABaseDAO implements CrawlerDAO { +} diff --git a/src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemDAO.java b/src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemDAO.java new file mode 100644 index 0000000..d35779c --- /dev/null +++ b/src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemDAO.java @@ -0,0 +1,10 @@ +package com.loafle.overflow.crawler.dao; + +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.crawler.model.CrawlerInputItem; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +public class JPACrawlerInputItemDAO extends JPABaseDAO implements CrawlerInputItemDAO { +} diff --git a/src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAO.java b/src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAO.java new file mode 100644 index 0000000..47bc258 --- /dev/null +++ b/src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAO.java @@ -0,0 +1,10 @@ +package com.loafle.overflow.crawler.dao; + +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.crawler.model.CrawlerInputItemMapping; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +public class JPACrawlerInputItemMappingDAO extends JPABaseDAO implements CrawlerInputItemMappingDAO { +} diff --git a/src/main/java/com/loafle/overflow/crawler/model/Crawler.java b/src/main/java/com/loafle/overflow/crawler/model/Crawler.java new file mode 100644 index 0000000..84e6920 --- /dev/null +++ b/src/main/java/com/loafle/overflow/crawler/model/Crawler.java @@ -0,0 +1,76 @@ +package com.loafle.overflow.crawler.model; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +@SuppressWarnings("serial") +@Entity(name="CRAWLER") +public class Crawler implements Serializable { + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @Column(name="NAME", nullable=false) + private String name; + + @Column(name="DESCRIPTION") + private String description; + + @Column(name="CRAWLER_TYPE") + private String crawlerType; + + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) + private Date createDate; + + public Crawler() { + } + + public Crawler(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getCrawlerType() { + return crawlerType; + } + + public void setCrawlerType(String crawlerType) { + this.crawlerType = crawlerType; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } +} diff --git a/src/main/java/com/loafle/overflow/crawler/model/CrawlerInputItem.java b/src/main/java/com/loafle/overflow/crawler/model/CrawlerInputItem.java new file mode 100644 index 0000000..fdc1123 --- /dev/null +++ b/src/main/java/com/loafle/overflow/crawler/model/CrawlerInputItem.java @@ -0,0 +1,75 @@ +package com.loafle.overflow.crawler.model; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +@SuppressWarnings("serial") +@Entity(name="CRAWLER_INPUT_ITEM") +public class CrawlerInputItem implements Serializable { + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @Column(name = "NAME") + private String name; + + @Column(name = "DESCRIPTION") + private String description; + + @Column(name = "DATA_TYPE") + private String dataType; + + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) + private Date createDate; + + + public CrawlerInputItem(){} + + public CrawlerInputItem(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } +} diff --git a/src/main/java/com/loafle/overflow/crawler/model/CrawlerInputItemMapping.java b/src/main/java/com/loafle/overflow/crawler/model/CrawlerInputItemMapping.java new file mode 100644 index 0000000..c5ba20c --- /dev/null +++ b/src/main/java/com/loafle/overflow/crawler/model/CrawlerInputItemMapping.java @@ -0,0 +1,86 @@ +package com.loafle.overflow.crawler.model; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +@SuppressWarnings("serial") +@Entity(name="CRAWLER_INPUT_ITEM_MAPPING") +public class CrawlerInputItemMapping implements Serializable { + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @ManyToOne + @JoinColumn(name = "CRAWLER_ID", nullable=false) + private Crawler crawler; + + @ManyToOne + @JoinColumn(name = "CRAWLER_INPUT_ITEM_ID", nullable=false) + private CrawlerInputItem crawlerInputItem; + + @Column(name = "PRIORITY") + private short priority; + + @Column(name = "REQUIRED_TYPE") + private boolean requiredType; + + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) + private Date createDate; + + public CrawlerInputItemMapping(){} + public CrawlerInputItemMapping(Long id){ + this.id = id; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Crawler getCrawler() { + return crawler; + } + + public void setCrawler(Crawler crawler) { + this.crawler = crawler; + } + + public CrawlerInputItem getCrawlerInputItem() { + return crawlerInputItem; + } + + public void setCrawlerInputItem(CrawlerInputItem crawlerInputItem) { + this.crawlerInputItem = crawlerInputItem; + } + + public short getPriority() { + return priority; + } + + public void setPriority(short priority) { + this.priority = priority; + } + + public boolean isRequiredType() { + return requiredType; + } + + public void setRequiredType(boolean requiredType) { + this.requiredType = requiredType; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } +} diff --git a/src/main/java/com/loafle/overflow/email/dao/EmailAuthDAO.java b/src/main/java/com/loafle/overflow/email/dao/EmailAuthDAO.java index 292f15e..804812b 100644 --- a/src/main/java/com/loafle/overflow/email/dao/EmailAuthDAO.java +++ b/src/main/java/com/loafle/overflow/email/dao/EmailAuthDAO.java @@ -12,4 +12,6 @@ public interface EmailAuthDAO extends BaseDAO { public EmailAuth findByAuthToken(EmailAuth emailAuth); public List findByMemberId(EmailAuth emailAuth); + +// public EmailAuth updateEmailAuth(EmailAuth emailAuth); } diff --git a/src/main/java/com/loafle/overflow/email/dao/JPAEmailAuthDAO.java b/src/main/java/com/loafle/overflow/email/dao/JPAEmailAuthDAO.java index 30f06e5..3f4c0b5 100644 --- a/src/main/java/com/loafle/overflow/email/dao/JPAEmailAuthDAO.java +++ b/src/main/java/com/loafle/overflow/email/dao/JPAEmailAuthDAO.java @@ -41,4 +41,23 @@ public class JPAEmailAuthDAO extends JPABaseDAO implements EmailAuthD return auths; } } + +// @Override +// public EmailAuth updateEmailAuth(EmailAuth emailAuth) { +// EntityTransaction tx = this.getEntityManager().getTransaction(); +// if (!tx.isActive()) { +// tx.begin(); +// } +// +// try { +// emailAuth.setUpdateDate(new Date()); +// +// EmailAuth result = this.getEntityManager().merge(emailAuth); +// tx.commit(); +// return result; +// }catch (Exception e) { +// tx.rollback(); +// return null; +// } +// } } diff --git a/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerDAOTest.java b/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerDAOTest.java new file mode 100644 index 0000000..ee496df --- /dev/null +++ b/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerDAOTest.java @@ -0,0 +1,72 @@ +package com.loafle.overflow.crawler.dao; + + +import com.loafle.overflow.crawler.model.Crawler; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +public class JPACrawlerDAOTest { + + private JPACrawlerDAO jpaCrawlerDAO = null; + + @Before + public void before() { + this.jpaCrawlerDAO = new JPACrawlerDAO(); + + } + + // TODO Crawler Meta Data Insert + @Test + public void TestInsertList() { + List crawlers = new ArrayList(); + + Crawler crawler1 = new Crawler(); + crawler1.setName("SNMP Crawler"); + crawler1.setDescription("SNMP Crawler"); + crawler1.setCrawlerType("SNMP"); + + Crawler crawler2 = new Crawler(); + crawler2.setName("WMI Crawler"); + crawler2.setDescription("WMI Crawler"); + crawler2.setCrawlerType("WMI"); + + Crawler crawler3 = new Crawler(); + crawler3.setName("HTTP Crawler"); + crawler3.setDescription("HTTP Crawler"); + crawler3.setCrawlerType("Network"); + + Crawler crawler4 = new Crawler(); + crawler4.setName("FTP Crawler"); + crawler4.setDescription("FTP Crawler"); + crawler4.setCrawlerType("Network"); + + crawlers.add(crawler1); + crawlers.add(crawler2); + crawlers.add(crawler3); + crawlers.add(crawler4); + + this.jpaCrawlerDAO.createAll(crawlers); + } + + @Test + public void TestInsert() { + Crawler crawler = new Crawler(); + crawler.setName("SQL Crawler"); + crawler.setDescription("SQL Crawler"); + crawler.setCrawlerType("Java"); + this.jpaCrawlerDAO.create(crawler); + } + // TODO Crawler Select Test + + // TODO Crawler Update Test + + // TODO Crawler Delete Test +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemDAOTest.java b/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemDAOTest.java new file mode 100644 index 0000000..b5d4d0c --- /dev/null +++ b/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemDAOTest.java @@ -0,0 +1,61 @@ +package com.loafle.overflow.crawler.dao; + +import com.loafle.overflow.crawler.model.CrawlerInputItem; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +public class JPACrawlerInputItemDAOTest { + + private JPACrawlerInputItemDAO inputItemDAO = null; + + @Before + public void before() { + this.inputItemDAO = new JPACrawlerInputItemDAO(); + } + + @Test + public void TestInsertList() { + List cris = new ArrayList(); + + CrawlerInputItem item1 = new CrawlerInputItem(); + item1.setName("ID"); + item1.setDataType("String"); + item1.setDescription("Auth ID"); + + CrawlerInputItem item2 = new CrawlerInputItem(); + item2.setName("PW"); + item2.setDataType("String"); + item2.setDescription("Auth PW"); + + CrawlerInputItem item3 = new CrawlerInputItem(); + item3.setName("AuthType"); + item3.setDataType("Select"); + item3.setDescription("MD5||SHA"); + + CrawlerInputItem item4 = new CrawlerInputItem(); + item4.setName("community"); + item4.setDataType("String"); + item4.setDescription("community"); + + CrawlerInputItem item5 = new CrawlerInputItem(); + item5.setName("textfield"); + item5.setDataType("String"); + item5.setDescription("User ID"); + + cris.add(item1); + cris.add(item2); + cris.add(item3); + cris.add(item4); + cris.add(item5); + + this.inputItemDAO.createAll(cris); + } +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAOTest.java b/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAOTest.java new file mode 100644 index 0000000..f92eec9 --- /dev/null +++ b/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAOTest.java @@ -0,0 +1,82 @@ +package com.loafle.overflow.crawler.dao; + +import com.loafle.overflow.crawler.model.Crawler; +import com.loafle.overflow.crawler.model.CrawlerInputItem; +import com.loafle.overflow.crawler.model.CrawlerInputItemMapping; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Created by geek@loafle.com on 17. 6. 8. + */ +public class JPACrawlerInputItemMappingDAOTest { + + private JPACrawlerInputItemMappingDAO mappingDAO = null; + + @Before + public void before() { + this.mappingDAO = new JPACrawlerInputItemMappingDAO(); + } + + @Test + public void TestInsert() { + CrawlerInputItemMapping itemMapping = new CrawlerInputItemMapping(); + itemMapping.setCrawler(new Crawler((long)5)); + itemMapping.setCrawlerInputItem(new CrawlerInputItem((long)1)); + itemMapping.setPriority((short) 1); + itemMapping.setRequiredType(true); + + CrawlerInputItemMapping itemMapping1 = new CrawlerInputItemMapping(); + itemMapping1.setCrawler(new Crawler((long)5)); + itemMapping1.setCrawlerInputItem(new CrawlerInputItem((long)2)); + itemMapping1.setPriority((short) 2); + itemMapping1.setRequiredType(true); + + CrawlerInputItemMapping itemMapping2 = new CrawlerInputItemMapping(); + itemMapping2.setCrawler(new Crawler((long)1)); + itemMapping2.setCrawlerInputItem(new CrawlerInputItem((long)1)); + itemMapping2.setPriority((short) 1); + itemMapping2.setRequiredType(true); + + CrawlerInputItemMapping itemMapping3 = new CrawlerInputItemMapping(); + itemMapping3.setCrawler(new Crawler((long)1)); + itemMapping3.setCrawlerInputItem(new CrawlerInputItem((long)2)); + itemMapping3.setPriority((short) 2); + itemMapping3.setRequiredType(true); + + CrawlerInputItemMapping itemMapping4 = new CrawlerInputItemMapping(); + itemMapping4.setCrawler(new Crawler((long)1)); + itemMapping4.setCrawlerInputItem(new CrawlerInputItem((long)3)); + itemMapping4.setPriority((short) 3); + itemMapping4.setRequiredType(true); + + CrawlerInputItemMapping itemMapping5 = new CrawlerInputItemMapping(); + itemMapping5.setCrawler(new Crawler((long)2)); + itemMapping5.setCrawlerInputItem(new CrawlerInputItem((long)1)); + itemMapping5.setPriority((short) 1); + itemMapping5.setRequiredType(true); + + CrawlerInputItemMapping itemMapping6 = new CrawlerInputItemMapping(); + itemMapping6.setCrawler(new Crawler((long)2)); + itemMapping6.setCrawlerInputItem(new CrawlerInputItem((long)2)); + itemMapping6.setPriority((short) 2); + itemMapping6.setRequiredType(true); + + List crs = new ArrayList(); + crs.add(itemMapping); + crs.add(itemMapping1); + crs.add(itemMapping2); + crs.add(itemMapping3); + crs.add(itemMapping4); + crs.add(itemMapping5); + crs.add(itemMapping6); + + this.mappingDAO.createAll(crs); + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/email/dao/JPAEmailAuthDAOTest.java b/src/test/java/com/loafle/overflow/email/dao/JPAEmailAuthDAOTest.java index 36605a0..b0eb132 100644 --- a/src/test/java/com/loafle/overflow/email/dao/JPAEmailAuthDAOTest.java +++ b/src/test/java/com/loafle/overflow/email/dao/JPAEmailAuthDAOTest.java @@ -11,7 +11,7 @@ import java.util.Date; import java.util.List; /** - * Created by root on 17. 6. 6. + * Created by geek@loafle.com on 17. 6. 6. */ @Ignore public class JPAEmailAuthDAOTest { diff --git a/src/test/resources/META-INF/persistence.xml b/src/test/resources/META-INF/persistence.xml index ce661fd..07e69dd 100644 --- a/src/test/resources/META-INF/persistence.xml +++ b/src/test/resources/META-INF/persistence.xml @@ -9,6 +9,9 @@ com.loafle.overflow.agent.model.Agent com.loafle.overflow.email.model.EmailAuth com.loafle.overflow.target.model.Target + com.loafle.overflow.crawler.model.Crawler + com.loafle.overflow.crawler.model.CrawlerInputItem + com.loafle.overflow.crawler.model.CrawlerInputItemMapping