crawler model dao add
crawler test code add
This commit is contained in:
parent
82c35d8c8f
commit
ea3935251b
|
@ -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<Crawler> {
|
||||
}
|
|
@ -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<CrawlerInputItem> {
|
||||
}
|
|
@ -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<CrawlerInputItemMapping> {
|
||||
}
|
|
@ -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<Crawler> implements CrawlerDAO {
|
||||
}
|
|
@ -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<CrawlerInputItem> implements CrawlerInputItemDAO {
|
||||
}
|
|
@ -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<CrawlerInputItemMapping> implements CrawlerInputItemMappingDAO {
|
||||
}
|
76
src/main/java/com/loafle/overflow/crawler/model/Crawler.java
Normal file
76
src/main/java/com/loafle/overflow/crawler/model/Crawler.java
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -12,4 +12,6 @@ public interface EmailAuthDAO extends BaseDAO<EmailAuth> {
|
|||
public EmailAuth findByAuthToken(EmailAuth emailAuth);
|
||||
|
||||
public List<EmailAuth> findByMemberId(EmailAuth emailAuth);
|
||||
|
||||
// public EmailAuth updateEmailAuth(EmailAuth emailAuth);
|
||||
}
|
||||
|
|
|
@ -41,4 +41,23 @@ public class JPAEmailAuthDAO extends JPABaseDAO<EmailAuth> 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;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -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<Crawler> crawlers = new ArrayList<Crawler>();
|
||||
|
||||
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
|
||||
}
|
|
@ -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<CrawlerInputItem> cris = new ArrayList<CrawlerInputItem>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -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<CrawlerInputItemMapping> crs = new ArrayList<CrawlerInputItemMapping>();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
<class>com.loafle.overflow.agent.model.Agent</class>
|
||||
<class>com.loafle.overflow.email.model.EmailAuth</class>
|
||||
<class>com.loafle.overflow.target.model.Target</class>
|
||||
<class>com.loafle.overflow.crawler.model.Crawler</class>
|
||||
<class>com.loafle.overflow.crawler.model.CrawlerInputItem</class>
|
||||
<class>com.loafle.overflow.crawler.model.CrawlerInputItemMapping</class>
|
||||
<properties>
|
||||
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://192.168.1.106:5432/postgres" />
|
||||
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
|
||||
|
|
Loading…
Reference in New Issue
Block a user