Part of fix for [HER-1725] on engine page, 'create new job' form gives NPE

* Engine.java
  made protected getProfileCxmlResource() for clear testability
* EngineTest.java
  added testGetProfileCxmlResource()
This commit is contained in:
szznax
2009-12-11 00:47:06 +00:00
parent 56d6e2ee26
commit bf2eaef6e2
2 changed files with 24 additions and 4 deletions
@@ -55,7 +55,10 @@ public class Engine {
protected File jobsDir;
/** map of job short names -> CrawlJob instances */
protected HashMap<String,CrawlJob> jobConfigs = new HashMap<String,CrawlJob>();
protected String profileCxmlPath =
"/org/archive/crawler/restlet/profile-crawler-beans.cxml";
public Engine(File jobsDir) {
this.jobsDir = jobsDir;
this.jobsDir.mkdirs();
@@ -319,6 +322,13 @@ public class Engine {
return false;
}
/**
* @return InputStream resource from defined profile CXML path
*/
protected InputStream getProfileCxmlResource() {
return getClass().getResourceAsStream(profileCxmlPath);
}
public boolean createNewJobWithDefaults(String path) throws IOException {
File newJobDir = new File(jobsDir,"/"+path);
@@ -327,9 +337,8 @@ public class Engine {
}
newJobDir.mkdirs();
// get crawler-beans template from this package into string
InputStream inStream = getClass().getResourceAsStream(
"/org/archive/crawler/restlet/profile-crawler-beans.cxml");
// get crawler-beans template from this package into string
InputStream inStream = getProfileCxmlResource();
String defaultCxmlStr = IOUtils.toString(inStream);
inStream.close();
@@ -0,0 +1,11 @@
package org.archive.crawler.framework;
import org.archive.util.TmpDirTestCase;
public class EngineTest extends TmpDirTestCase {
public void testGetProfileCxmlResource() {
assertNotNull(new Engine(getTmpDir()).getProfileCxmlResource());
}
}