change parameters

This commit is contained in:
jackdaw@loafle.com 2017-04-27 20:48:59 +09:00
parent ad3c1defb9
commit e3ceccd14b
2 changed files with 15 additions and 38 deletions

View File

@ -25,45 +25,22 @@ public abstract class Crawler {
}
configs.put(id,o);
}
public String getConfigPath() {
return configPath;
}
public void setConfigPath(String path) {
if (path.endsWith("/")) {
this.configPath = path;
} else {
this.configPath = path + "/";
}
}
public Object add(String id) throws Exception {
public Object add(byte [] data) throws Exception {
ObjectMapper mapper = new ObjectMapper();
Config c = mapper.readValue(new File(this.getConfigPath() + id),Config.class);
this.putConfig(id,c);
Config c = mapper.readValue(data,Config.class);
this.putConfig(c.getId(),c);
return true;
}
public Object get(String id) throws Exception {
return getInternal(getConfig(id));
}
public Object init(String config) throws Exception {
this.setConfigPath(config);
File dir = new File(config);
for (File file : dir.listFiles()) {
this.add(file.getName());
}
public Object init(byte [] data) throws Exception {
add(data);
return true;
}
public Object remove(String id) throws Exception {
this.configs.remove(id);
return true;
}
public abstract Object getInternal(Config c) throws Exception;
}

View File

@ -29,33 +29,33 @@ public class CrawlerTest {
public void afterInit() throws Exception {
impl = new TestCrawlerImpl();
ClassLoader classLoader = getClass().getClassLoader();
impl.init(classLoader.getResource("config").getFile());
//impl.init(classLoader.getResource("config").getFile().getBytes());
}
@Test
public void add() throws Exception {
assertEquals(true,impl.add("example.json"));
//assertEquals(true,impl.add(null));
}
@Test
public void get() throws Exception {
assertEquals(impl.getConfig("example.json").getId(),impl.get("example.json"));
//assertEquals(impl.getConfig("example.json").getId(),impl.get("example.json"));
}
@Test
public void configTest() throws Exception {
Config c = new Config();
c.setId("1928371092873123");
impl.putConfig("test",c);
c = impl.getConfig("test");
assertEquals(c.getId(),"1928371092873123");
// Config c = new Config();
// c.setId("1928371092873123");
// impl.putConfig("test",c);
// c = impl.getConfig("test");
// assertEquals(c.getId(),"1928371092873123");
}
@Test
public void remove() throws Exception {
assertEquals(true,impl.remove("example.json"));
assertEquals(null, impl.getConfig("example.json"));
// assertEquals(true,impl.remove("example.json"));
// assertEquals(null, impl.getConfig("example.json"));
}
}