* Tests the creation of the necessary directories
*
*/
public void testDirectories() {
// absolute path
I_Info prop = new PropertiesInfo(new Properties());
prop.put("mom.topicName", "dummy");
prop.put("filewatcher.directoryName", this.pollerDirName);
prop.put("filewatcher.sent", this.pollerDirNameSent);
prop.put("filewatcher.discarded", this.pollerDirNameDiscarded);
try {
new Publisher(this.global, "test", prop);
}
catch (XmlBlasterException ex) {
ex.printStackTrace();
assertTrue("An exception should not occur here " + ex.getMessage(), false);
}
checkDirs();
// repeat that with already existing directories
prop = new PropertiesInfo(new Properties());
prop.put("mom.topicName", "dummy");
prop.put("filewatcher.directoryName", this.pollerDirName);
prop.put("filewatcher.sent", this.pollerDirNameSent);
prop.put("filewatcher.discarded", this.pollerDirNameDiscarded);
try {
new Publisher(this.global, "test", prop);
}
catch (XmlBlasterException ex) {
ex.printStackTrace();
assertTrue("An exception should not occur here " + ex.getMessage(), false);
}
checkDirs();
cleanUpDirs();
// relative path are added to the 'directoryName'
prop = new PropertiesInfo(new Properties());
prop.put("mom.topicName", "dummy");
prop.put("filewatcher.directoryName", this.pollerDirName);
prop.put("filewatcher.sent", "Sent");
prop.put("filewatcher.discarded", "Discarded");
try {
new Publisher(this.global, "test", prop);
}
catch (XmlBlasterException ex) {
ex.printStackTrace();
assertTrue("An exception should not occur here " + ex.getMessage(), false);
}
checkDirs();
// relative path are added to the 'directoryName' repeat with existing directories
prop = new PropertiesInfo(new Properties());
prop.put("mom.topicName", "dummy");
prop.put("filewatcher.directoryName", this.pollerDirName);
prop.put("filewatcher.filewatcher.sent", "Sent");
prop.put("filewatcher.discarded", "Discarded");
try {
new Publisher(this.global, "test", prop);
}
catch (XmlBlasterException ex) {
ex.printStackTrace();
assertTrue("An exception should not occur here " + ex.getMessage(), false);
}
checkDirs();
cleanUpDirs();
// now some which should fail:
// existing file but not a directory
File file = new File(this.pollerDirName);
try {
file.createNewFile();
}
catch (IOException ex) {
assertTrue("could not create the file '" + this.pollerDirName + "'", false);
}
prop = new PropertiesInfo(new Properties());
prop.put("mom.topicName", "dummy");
prop.put("filewatcher.directoryName", this.pollerDirName);
prop.put("filewatcher.sent", "Sent");
prop.put("filewatcher.discarded", "Discarded");
try {
new Publisher(this.global, "test", prop);
assertTrue("an exception should occur since '" + this.pollerDirName + "' is a file and should be a directory", false);
}
catch (XmlBlasterException ex) {
log.info("Exception is OK here");
}
cleanUpDirs();
try {
file = new File(this.pollerDirName);
boolean ret = file.mkdir();
assertTrue("could not create directory '" + this.pollerDirName + "'", ret);
file = new File(this.pollerDirNameSent);
file.createNewFile();
}
catch (IOException ex) {
assertTrue("could not create the file '" + this.pollerDirNameSent + "'", false);
}
prop = new PropertiesInfo(new Properties());
prop.put("mom.topicName", "dummy");
prop.put("filewatcher.directoryName", this.pollerDirName);
prop.put("filewatcher.sent", "Sent");
prop.put("filewatcher.discarded", "Discarded");
try {
new Publisher(this.global, "test", prop);
assertTrue("an exception should occur since '" + this.pollerDirName + "' is a file and should be a directory", false);
}
catch (XmlBlasterException ex) {