PathConditionTest.java from Kneobase at Krugle
Show PathConditionTest.java syntax highlighted
/*
* Created on 20/05/2004
*
*/
package com.kneobase.driver.condition;
import junit.framework.TestCase;
import com.kneobase.KneobaseException;
import com.kneobase.driver.TreeCompositeContentAux;
import com.kneobase.driver.TreeContentSourceAux;
import com.kneobase.driver.TreeContentUnitAux;
/**
* @author Ernesto De Santis
*
*/
public class PathConditionTest extends TestCase {
TreeContentSourceAux contentSource;
PathCondition sexCondition;
PathCondition infoCondition;
PathCondition wcCondition;
PathCondition doubleAsterixCondition;
public void setUp() {
try {
contentSource = new TreeContentSourceAux("testfolder\\source\\");
contentSource.setSeparatorChar('\\');
} catch (KneobaseException e) {
fail();
}
sexCondition = new PathCondition("sexo/*");
sexCondition.setAbsolutePath(false);
infoCondition = new PathCondition("informatica/*");
infoCondition.setAbsolutePath(false);
wcCondition = new PathCondition("sexo/a?ex.*");
wcCondition.setAbsolutePath(false);
doubleAsterixCondition = new PathCondition("sexo/*/*");
doubleAsterixCondition.setAbsolutePath(false);
}
public void testIncludesLinuxSeparator() {
TreeCompositeContentAux folder = new TreeCompositeContentAux();
folder.setAbsolutePath("testfolder/source/sexo/");
folder.setContentSource(contentSource);
TreeContentUnitAux cu = new TreeContentUnitAux(folder);
cu.setAbsolutePath("testfolder/source/sexo/alex.txt");
try {
assertTrue(sexCondition.isSatisfied(cu));
} catch (Exception e) {
fail();
}
}
public void testIncludesWindowsSeparator() {
TreeCompositeContentAux folder = new TreeCompositeContentAux();
folder.setAbsolutePath("testfolder\\sexo\\");
folder.setContentSource(contentSource);
TreeContentUnitAux cu = new TreeContentUnitAux(folder);
cu.setAbsolutePath("testfolder\\source\\sexo\\alex.txt");
try {
assertTrue(sexCondition.isSatisfied(cu));
} catch (Exception e) {
fail();
}
}
public void testNotIncludes() {
TreeCompositeContentAux folder = new TreeCompositeContentAux();
folder.setAbsolutePath("testfolder\\source\\sexo\\");
folder.setContentSource(contentSource);
TreeContentUnitAux cu = new TreeContentUnitAux(folder);
cu.setAbsolutePath("testfolder\\source\\sexo\\alex.txt");
try {
assertFalse(infoCondition.isSatisfied(cu));
} catch (Exception e) {
fail();
}
}
public void testDoubleAsterix() {
TreeCompositeContentAux folder = new TreeCompositeContentAux();
folder.setAbsolutePath("testfolder\\source\\sexo\\");
folder.setContentSource(contentSource);
TreeContentUnitAux cu = new TreeContentUnitAux(folder);
cu.setAbsolutePath("testfolder\\source\\sexo\\other\\alex.txt");
try {
assertTrue(doubleAsterixCondition.isSatisfied(cu));
} catch (Exception e) {
fail();
}
}
public void testFileNotExist() {
TreeCompositeContentAux folder = new TreeCompositeContentAux();
folder.setAbsolutePath("testfolder\\source\\sexo\\");
folder.setContentSource(contentSource);
TreeContentUnitAux cu = new TreeContentUnitAux(folder);
cu.setAbsolutePath("testfolder\\source\\sexo\\alexa.txt");
try {
assertFalse(infoCondition.isSatisfied(cu));
} catch (Exception e) {
fail();
}
}
public void testAbspath() {
try {
TreeContentSourceAux contentSourceAbsPath =
new TreeContentSourceAux("C:\\Eclipse\\workspace\\OpenKDB-Robot-FileSystem\\testfolder\\source\\");
TreeCompositeContentAux folder = new TreeCompositeContentAux();
folder.setAbsolutePath(
"C:\\Eclipse\\workspace\\OpenKDB-Robot-FileSystem\\testfolder\\source\\sexo\\");
folder.setContentSource(contentSourceAbsPath);
TreeContentUnitAux cu = new TreeContentUnitAux(folder);
cu.setAbsolutePath(
"C:\\Eclipse\\workspace\\OpenKDB-Robot-FileSystem\\testfolder\\source\\sexo\\alex.txt");
assertTrue(sexCondition.isSatisfied(cu));
} catch (KneobaseException e) {
fail();
}
}
public void testWC() {
TreeCompositeContentAux folder = new TreeCompositeContentAux();
folder.setAbsolutePath("testfolder\\source\\sexo\\");
folder.setContentSource(contentSource);
TreeContentUnitAux cu = new TreeContentUnitAux(folder);
cu.setAbsolutePath("testfolder\\source\\sexo\\alex.txt");
try {
assertTrue(wcCondition.isSatisfied(cu));
} catch (Exception e) {
fail();
}
}
/*
public void testWildcards() {
String file = "/unpath/subpath/unfile.txt";
String newcriteria = sexCategory.wildCardTransformation("/unpath/*");
assertTrue(file.matches(newcriteria));
newcriteria = sexCategory.wildCardTransformation("* /unpath/*");
assertTrue(file.matches(newcriteria));
newcriteria = sexCategory.wildCardTransformation("* /unpath/* /unfile.*");
assertTrue(file.matches(newcriteria));
newcriteria = sexCategory.wildCardTransformation("/unpath/???path/*");
assertTrue(file.matches(newcriteria));
newcriteria =
sexCategory.wildCardTransformation("/unpath/subpath/unfile.???");
assertTrue(file.matches(newcriteria));
newcriteria =
sexCategory.wildCardTransformation("* /subpath/unfile.???");
assertTrue("c:/xxx/subpath/unfile.txt".matches(newcriteria));
newcriteria =
sexCategory.wildCardTransformation("*\\\\subpath\\\\unfile.???");
assertTrue("\\xxx\\subpath\\unfile.txt".matches(newcriteria));
}
*/
}
See more files for this project here