public void testSetTemplateNameFromFile() throws Exception {
BasicTemplatePath btp = new BasicTemplatePath( "src/org/jostraca/test/file.txt" );
try {
btp.setTemplateNameFromFile( null, null );
fail();
} catch( IllegalArgumentException e ) {}
try {
btp.setTemplateNameFromFile( "", null );
fail();
} catch( IllegalArgumentException e ) {}
try {
btp.setTemplateNameFromFile( null, "" );
fail();
} catch( IllegalArgumentException e ) {}
try {
btp.setTemplateNameFromFile( "nonexistent-file.txt", "nonexistant-folder/filelist.txt" );
btp.resolve( new String[] {} );
fail();
} catch( TemplateException tpe ) {
assertEquals( StandardException.Code.CAT_user, tpe.getCat() );
}
// REVIEW: file.txt is found because it exists - is this good?
try {
btp.setTemplateNameFromFile( "src/org/jostraca/test/file.txt", "nonexistent-folder/filelist.txt" );
btp.resolve( new String[] {} );
} catch( TemplateException tpe ) {
fail();
}
try {
btp.setTemplateNameFromFile( "some-file.txt", "nonexistent-folder/filelist.txt" );
btp.resolve( new String[] {} );
fail();
} catch( TemplateException tpe ) {
assertEquals( StandardException.Code.CAT_user, tpe.getCat() );
}
try {
btp.setTemplateNameFromFile( "nonexistent-file.txt", "src/org/jostraca/test/folder/filelist.txt" );
btp.resolve( new String[] {} );
fail();
} catch( TemplateException tpe ) {
assertEquals( StandardException.Code.CAT_user, tpe.getCat() );
}
try {
btp.setTemplateNameFromFile( "src/org/jostraca/test/file.txt", "src/org/jostraca/test/folder/filelist.txt" );
btp.resolve( new String[] {} );
//assertTrue( ("folder"+File.separator+"file.txt").equals( btp.getTemplatePath() ) );
}
catch( TemplateException tpe ) {
fail();
}
try {
File tmpFile = File.createTempFile( "jostraca", "test" );
btp.setTemplateNameFromFile( tmpFile.getAbsolutePath(), "src/org/jostraca/test/folder/filelist.txt" );
btp.resolve( new String[] {} );
assertTrue( tmpFile.getAbsolutePath().equals( btp.getTemplatePath() ) );
}
catch( TemplateException tpe ) {
fail();
}
try {
btp.setTemplateNameFromFile( "src/org/jostraca/test/file.txt", "src/org/jostraca/test/filelist.txt" );
assertTrue( "src/org/jostraca/test/file.txt".equals( btp.getTemplateName() ) );
} catch( TemplateException tpe ) {
fail();
}
}