Class TemplateEngineTests
- java.lang.Object
-
- de.powerstat.phplib.templateengine.test.TemplateEngineTests
-
public final class TemplateEngineTests extends Object
TemplateEngine tests.
-
-
Field Summary
Fields Modifier and Type Field Description private static String
BLK1
Template block 1 name constant.private static String
BLK1_BLK
Template block 1 block name constant.private static String
FILE1
Template file 1 name constant.private static String
FILE2
Template file 2 name constant.private static String
FILE3
Template file 3 name constant.private static String
FILE4
Template file 4 name constant.private static org.apache.logging.log4j.Logger
LOGGER
Logger.private static String
MAX_VARNAME
Maximum allowed varname.private static String
NO_TEMPLATE_FOUND
No template found message.private static String
OUTPUT
Template output variable name constant.private static String
TEMPLATE
Template constant.private static String
TEMPLATE1_TMPL
Template file 1 path constant.private static String
TEMPLATE10_TMPL
Template 10 path (file to large).private static String
TEMPLATE2_TMPL
Template file 2 path constant.private static String
TEMPLATE4_TMPL
Template 4 path.private static String
TEMPLATE8_TMPL
Template 8 path.private static String
TEMPLATE9_TMPL
Template 9 path (maximum file size).private static String
TEST
Template variable value constant.private static String
TO_LONG_VARNAME
To long varname.private static String
VALUE1
Value 1.private static String
VALUE2
Value 2.private static String
VALUE3
Value 3.private static String
VARIABLE_VALUE_NOT_AS_EXPECTED
Variable value not as expected message.private static String
VARIABLE1
Template variable 1 name constant.private static String
VARIABLE2
Template variable 2 name constant.private static String
VARIABLE3
Template variable 3 name constant.private static String
VARIABLE4
Template variable 4 name constant with illegal character.
-
Constructor Summary
Constructors Constructor Description TemplateEngineTests()
Default constructor.
-
Method Summary
Modifier and Type Method Description void
copyConstructor()
Test copy constructor.void
defaultConstructor()
Test default constructor.void
doubleOpenCurlyBrace()
Test two { after each other within template.void
finishEmpty()
Test empty finish.void
finishMaxSize()
Test finish with maximum template size.void
finishToLarge()
Test finish with to large template.void
getComment()
Test get replace with comment variable parsing.void
getKeep()
Test get keep variable parsing.void
getRemoved()
Test get removed variable parsing.void
getUndefined()
Get undefined variables from template.void
getUndefinedEmpty()
Get empty undefined variables.void
getUndefinedFromEmptyFile()
Get undefined variables from empty template.void
getUndefinedMaxLength()
Get undefined variables with maximum varname length.void
getUndefinedToLong()
Get undefined variables with to long varname.void
getUndefinedWrongName()
Get undefined variables with wrong varname.void
getVarEmpty()
Test get empty variable with value.void
getVarMaxLong()
Test get variable with maximum long name.void
getVars()
Test variable list.void
getVarsEmpty()
Test empty variable list.void
getVarToLong()
Test get variable with to long name.void
getVarWrongName()
Test get variable with wrong name.void
newInstanceCopy()
Test newInstance from TemplateEngine copy.void
newInstanceFile1()
Test newInstance from file.void
newInstanceFileFromDirectory()
Test newInstance from directory.void
newInstanceFileMaxSize()
Test newInstance with maximum size file.void
newInstanceFileNonExisting()
Test newInstance from non existing file.void
newInstanceFileNull()
Test newInstance from File with null.void
newInstanceFileToLarge()
Test newInstance with a to large file.void
newInstanceInputStream()
Test newInstance from InputStream.void
newInstanceInputStreamEmpty()
Test newInstance from empty InputStream.void
newInstanceInputStreamNull()
Test newInstance from InputStream with null.void
newInstanceString()
Test newInstance from String.void
newInstanceStringEmpty()
Test newInstance from String with empty string.void
newInstanceStringMaxSize()
Test newInstance from String with max size string.void
newInstanceStringNull()
Test newInstance from String with null.void
newInstanceStringToLarge()
Test newInstance from String with to large string.void
parseAppend()
Test parsing with append.void
parseEmpty()
Test empty parsing.void
parseNonAppend()
Test parsing without append.void
parseProblem()
Test a specific parsing problem.void
parseTargetMaxLength()
Test parsing with maximum target name length.void
parseTargetToLong()
Test parsing with to long target name.void
parseTargetWrong()
Test parsing with wrong target name.void
parseVarnameMaxLength()
Test parsing with maximum varname length.void
parseVarnameToLong()
Test parsing with to long varname.void
parseVarnameWrong()
Test parsing with wrong varname.void
readFromClasspath()
Test read template file from classpath.void
readNonExisting()
Test read template file from classpath.private static String
readStringFromFile(File file)
Read String from File.void
setBlock()
Test set existing block.void
setBlockEmpty()
Test set empty block name.void
setBlockEmptyFile()
Test set existing block.void
setBlockFailure()
Test set non existing block.void
setBlockNameMaxLength()
Test set block with max length name.void
setBlockNameToLong()
Test set block with to long name.void
setBlockNameWrong()
Test set block with wrong name.void
setBlockParentMaxLength()
Test set block with to max length parent name.void
setBlockParentMaxLength2()
Test set block with to max length parent name.void
setBlockParentToLong()
Test set block with to long parent name.void
setBlockParentWrong()
Test set block with to wrong parent name.void
setBlockVarnameMaxLength()
Test set block with max length varname.void
setBlockVarnameToLong()
Test set block with to long varname.void
setBlockVarnameWrong()
Test set block with wrong varname.void
setEmptyVar()
Test set empty variable with value.void
setFile()
Test set template file.void
setFileEmpty()
Test set template file.void
setFileMaxLength()
Test set template file with max length.void
setFileToLarge()
Test set template file with to large file.void
setFileToLong()
Test set template file with to long filename.void
setFileWrongname()
Test set template file with wrong filename.void
setUnknowns()
Test get keep variable parsing.void
setVar()
Test set variable with value.void
setVarEmpty()
Test set variable as empty.void
setVarMaxLarge()
Test set variable with maximum value size.void
setVarMaxLong()
Test set variable with maximum long name.void
setVarToLarge()
Test set variable with to large value.void
setVarToLong()
Test set variable with to long name.void
setVarWrongName()
Test set variable with wrong name.void
subst()
Test read template file.void
substEmpty()
Test read empty template file.void
substEmptyFile()
Test subst empty file.void
substMaxLength()
Test subst with max varname length varname.void
substToLong()
Test subst with to long varname.void
substWrongName()
Test subst with wrong varname.void
testEquals()
Test equals.void
testHashCode()
Test hash code.void
testToString()
Test toString.void
undefined()
Test HandleUndefined.void
unsetVar()
Test unset variable.void
unsetVarEmpty()
Test unset empty variable.void
unsetVarMaxLength()
Test unset variable with maximum name length.void
unsetVarToLong()
Test unset variable with to long name.void
unsetVarWrongName()
Test unset variable with wrong name.
-
-
-
Field Detail
-
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER
Logger.
-
TEMPLATE1_TMPL
private static final String TEMPLATE1_TMPL
Template file 1 path constant.- See Also:
- Constant Field Values
-
TEMPLATE2_TMPL
private static final String TEMPLATE2_TMPL
Template file 2 path constant.- See Also:
- Constant Field Values
-
TEMPLATE4_TMPL
private static final String TEMPLATE4_TMPL
Template 4 path.- See Also:
- Constant Field Values
-
TEMPLATE8_TMPL
private static final String TEMPLATE8_TMPL
Template 8 path.- See Also:
- Constant Field Values
-
TEMPLATE9_TMPL
private static final String TEMPLATE9_TMPL
Template 9 path (maximum file size).- See Also:
- Constant Field Values
-
TEMPLATE10_TMPL
private static final String TEMPLATE10_TMPL
Template 10 path (file to large).- See Also:
- Constant Field Values
-
FILE1
private static final String FILE1
Template file 1 name constant.- See Also:
- Constant Field Values
-
FILE2
private static final String FILE2
Template file 2 name constant.- See Also:
- Constant Field Values
-
FILE3
private static final String FILE3
Template file 3 name constant.- See Also:
- Constant Field Values
-
FILE4
private static final String FILE4
Template file 4 name constant.- See Also:
- Constant Field Values
-
VARIABLE1
private static final String VARIABLE1
Template variable 1 name constant.- See Also:
- Constant Field Values
-
VARIABLE2
private static final String VARIABLE2
Template variable 2 name constant.- See Also:
- Constant Field Values
-
VARIABLE3
private static final String VARIABLE3
Template variable 3 name constant.- See Also:
- Constant Field Values
-
VARIABLE4
private static final String VARIABLE4
Template variable 4 name constant with illegal character.- See Also:
- Constant Field Values
-
VALUE1
private static final String VALUE1
Value 1.- See Also:
- Constant Field Values
-
VALUE2
private static final String VALUE2
Value 2.- See Also:
- Constant Field Values
-
VALUE3
private static final String VALUE3
Value 3.- See Also:
- Constant Field Values
-
MAX_VARNAME
private static final String MAX_VARNAME
Maximum allowed varname.- See Also:
- Constant Field Values
-
TO_LONG_VARNAME
private static final String TO_LONG_VARNAME
To long varname.- See Also:
- Constant Field Values
-
TEST
private static final String TEST
Template variable value constant.- See Also:
- Constant Field Values
-
BLK1_BLK
private static final String BLK1_BLK
Template block 1 block name constant.- See Also:
- Constant Field Values
-
BLK1
private static final String BLK1
Template block 1 name constant.- See Also:
- Constant Field Values
-
OUTPUT
private static final String OUTPUT
Template output variable name constant.- See Also:
- Constant Field Values
-
TEMPLATE
private static final String TEMPLATE
Template constant.- See Also:
- Constant Field Values
-
NO_TEMPLATE_FOUND
private static final String NO_TEMPLATE_FOUND
No template found message.- See Also:
- Constant Field Values
-
VARIABLE_VALUE_NOT_AS_EXPECTED
private static final String VARIABLE_VALUE_NOT_AS_EXPECTED
Variable value not as expected message.- See Also:
- Constant Field Values
-
-
Method Detail
-
defaultConstructor
@Test public void defaultConstructor()
Test default constructor.
-
setFile
@Test public void setFile()
Test set template file.
-
setFileMaxLength
@Test public void setFileMaxLength()
Test set template file with max length.
-
setFileEmpty
@Test public void setFileEmpty()
Test set template file.
-
setFileToLong
@Test public void setFileToLong()
Test set template file with to long filename.
-
setFileWrongname
@Test public void setFileWrongname()
Test set template file with wrong filename.
-
setFileToLarge
@Test public void setFileToLarge()
Test set template file with to large file.
-
subst
@Test public void subst() throws IOException
Test read template file.- Throws:
IOException
- IO exception
-
substEmpty
@Test public void substEmpty()
Test read empty template file.
-
substToLong
@Test public void substToLong()
Test subst with to long varname.
-
substWrongName
@Test public void substWrongName()
Test subst with wrong varname.
-
substMaxLength
@Test public void substMaxLength() throws IOException
Test subst with max varname length varname.- Throws:
IOException
- IO exception
-
getUndefined
@Test public void getUndefined() throws IOException
Get undefined variables from template.- Throws:
IOException
- IO exception
-
getUndefinedFromEmptyFile
@Test public void getUndefinedFromEmptyFile() throws IOException
Get undefined variables from empty template.- Throws:
IOException
- IO exception
-
getUndefinedEmpty
@Test public void getUndefinedEmpty()
Get empty undefined variables.
-
getUndefinedToLong
@Test public void getUndefinedToLong()
Get undefined variables with to long varname.
-
getUndefinedWrongName
@Test public void getUndefinedWrongName()
Get undefined variables with wrong varname.
-
getUndefinedMaxLength
@Test public void getUndefinedMaxLength() throws IOException
Get undefined variables with maximum varname length.- Throws:
IOException
- IO exception
-
setVarEmpty
@Test public void setVarEmpty() throws IOException
Test set variable as empty.- Throws:
IOException
- IO exception
-
setVar
@Test public void setVar() throws IOException
Test set variable with value.- Throws:
IOException
- IO exception
-
setEmptyVar
@Test public void setEmptyVar()
Test set empty variable with value.
-
setVarMaxLong
@Test public void setVarMaxLong()
Test set variable with maximum long name.
-
setVarToLong
@Test public void setVarToLong()
Test set variable with to long name.
-
setVarWrongName
@Test public void setVarWrongName()
Test set variable with wrong name.
-
setVarToLarge
@Test public void setVarToLarge()
Test set variable with to large value.
-
setVarMaxLarge
@Test public void setVarMaxLarge() throws IOException
Test set variable with maximum value size.- Throws:
IOException
- IO exception
-
getRemoved
@Test public void getRemoved() throws IOException
Test get removed variable parsing.- Throws:
IOException
- IO exception
-
getKeep
@Test public void getKeep() throws IOException
Test get keep variable parsing.- Throws:
IOException
- IO exception
-
getComment
@Test public void getComment() throws IOException
Test get replace with comment variable parsing.- Throws:
IOException
- IO exception
-
setBlockFailure
@Test public void setBlockFailure()
Test set non existing block.
-
setBlockEmpty
@Test public void setBlockEmpty()
Test set empty block name.
-
setBlock
@Test public void setBlock() throws IOException
Test set existing block.- Throws:
IOException
- IO exception
-
setBlockParentToLong
@Test public void setBlockParentToLong()
Test set block with to long parent name.
-
setBlockVarnameToLong
@Test public void setBlockVarnameToLong()
Test set block with to long varname.
-
setBlockNameToLong
@Test public void setBlockNameToLong()
Test set block with to long name.
-
setBlockParentWrong
@Test public void setBlockParentWrong()
Test set block with to wrong parent name.
-
setBlockVarnameWrong
@Test public void setBlockVarnameWrong()
Test set block with wrong varname.
-
setBlockNameWrong
@Test public void setBlockNameWrong()
Test set block with wrong name.
-
setBlockParentMaxLength
@Test public void setBlockParentMaxLength() throws IOException
Test set block with to max length parent name.- Throws:
IOException
- IO exception
-
setBlockParentMaxLength2
@Test public void setBlockParentMaxLength2() throws IOException
Test set block with to max length parent name.- Throws:
IOException
- IO exception
-
setBlockVarnameMaxLength
@Test public void setBlockVarnameMaxLength() throws IOException
Test set block with max length varname.- Throws:
IOException
- IO exception
-
setBlockNameMaxLength
@Test public void setBlockNameMaxLength() throws IOException
Test set block with max length name.- Throws:
IOException
- IO exception
-
parseNonAppend
@Test public void parseNonAppend() throws IOException
Test parsing without append.- Throws:
IOException
- IO exception
-
parseEmpty
@Test public void parseEmpty()
Test empty parsing.
-
parseAppend
@Test public void parseAppend() throws IOException
Test parsing with append.- Throws:
IOException
- IO exception
-
parseProblem
@Test public void parseProblem() throws IOException
Test a specific parsing problem. Problem description for original phplib template engine: When using the same template-variable within a page and a block thats contained by the page, then the behavior during parsing the page might be different. Thats because inside the subst() method a loop runs over the list of known template variables. When a variable has been replaced before a block (that contains the same variable) will be replaced, then the variable will not be replaced within the block. When the block will be parsed first, then the variable will also be replaced within the block.- Throws:
IOException
- IO exception
-
parseTargetToLong
@Test public void parseTargetToLong()
Test parsing with to long target name.
-
parseVarnameToLong
@Test public void parseVarnameToLong()
Test parsing with to long varname.
-
parseTargetWrong
@Test public void parseTargetWrong()
Test parsing with wrong target name.
-
parseVarnameWrong
@Test public void parseVarnameWrong()
Test parsing with wrong varname.
-
parseTargetMaxLength
@Test public void parseTargetMaxLength() throws IOException
Test parsing with maximum target name length.- Throws:
IOException
- IO exception
-
parseVarnameMaxLength
@Test public void parseVarnameMaxLength() throws IOException
Test parsing with maximum varname length.- Throws:
IOException
- IO exception
-
getVarsEmpty
@Test public void getVarsEmpty()
Test empty variable list.
-
getVars
@Test public void getVars()
Test variable list.
-
getVarMaxLong
@Test public void getVarMaxLong()
Test get variable with maximum long name.
-
getVarToLong
@Test public void getVarToLong()
Test get variable with to long name.
-
getVarWrongName
@Test public void getVarWrongName()
Test get variable with wrong name.
-
substEmptyFile
@Test public void substEmptyFile() throws IOException
Test subst empty file.- Throws:
IOException
- IO exception
-
setBlockEmptyFile
@Test public void setBlockEmptyFile() throws IOException
Test set existing block.- Throws:
IOException
- IO exception
-
setUnknowns
@Test public void setUnknowns() throws IOException
Test get keep variable parsing.- Throws:
IOException
- IO exception
-
readFromClasspath
@Test public void readFromClasspath() throws IOException
Test read template file from classpath.- Throws:
IOException
- IO exception
-
readNonExisting
@Test public void readNonExisting() throws IOException
Test read template file from classpath.- Throws:
IOException
- IO exception
-
unsetVar
@Test public void unsetVar() throws IOException
Test unset variable.- Throws:
IOException
- IO exception
-
unsetVarEmpty
@Test public void unsetVarEmpty()
Test unset empty variable.
-
unsetVarMaxLength
@Test public void unsetVarMaxLength() throws IOException
Test unset variable with maximum name length.- Throws:
IOException
- IO exception
-
unsetVarToLong
@Test public void unsetVarToLong()
Test unset variable with to long name.
-
unsetVarWrongName
@Test public void unsetVarWrongName()
Test unset variable with wrong name.
-
testToString
@Test public void testToString()
Test toString.
-
newInstanceFile1
@Test public void newInstanceFile1() throws IOException
Test newInstance from file.- Throws:
IOException
- IO exception
-
newInstanceFileNonExisting
@Test public void newInstanceFileNonExisting()
Test newInstance from non existing file.
-
newInstanceFileFromDirectory
@Test public void newInstanceFileFromDirectory()
Test newInstance from directory.
-
newInstanceFileNull
@Test public void newInstanceFileNull()
Test newInstance from File with null.
-
newInstanceFileToLarge
@Test public void newInstanceFileToLarge()
Test newInstance with a to large file.
-
newInstanceFileMaxSize
@Test public void newInstanceFileMaxSize() throws IOException
Test newInstance with maximum size file.- Throws:
IOException
- IO exception
-
newInstanceInputStreamNull
@Test public void newInstanceInputStreamNull()
Test newInstance from InputStream with null.
-
newInstanceInputStream
@Test public void newInstanceInputStream() throws IOException
Test newInstance from InputStream.- Throws:
IOException
- IO exception
-
newInstanceInputStreamEmpty
@Test public void newInstanceInputStreamEmpty()
Test newInstance from empty InputStream.
-
newInstanceStringNull
@Test public void newInstanceStringNull()
Test newInstance from String with null.
-
newInstanceStringEmpty
@Test public void newInstanceStringEmpty()
Test newInstance from String with empty string.
-
newInstanceString
@Test public void newInstanceString()
Test newInstance from String.
-
readStringFromFile
private static String readStringFromFile(File file) throws IOException
Read String from File.- Parameters:
file
- File to read from- Returns:
- File content as String
- Throws:
IOException
- IO exception
-
newInstanceStringToLarge
@Test public void newInstanceStringToLarge()
Test newInstance from String with to large string.
-
newInstanceStringMaxSize
@Test public void newInstanceStringMaxSize() throws IOException
Test newInstance from String with max size string.- Throws:
IOException
- IO exception
-
newInstanceCopy
@Test public void newInstanceCopy() throws IOException
Test newInstance from TemplateEngine copy.- Throws:
IOException
- IO exception
-
copyConstructor
@Test public void copyConstructor()
Test copy constructor.
-
getVarEmpty
@Test public void getVarEmpty()
Test get empty variable with value.
-
finishEmpty
@Test public void finishEmpty()
Test empty finish.
-
finishToLarge
@Test public void finishToLarge()
Test finish with to large template.
-
finishMaxSize
@Test public void finishMaxSize() throws IOException
Test finish with maximum template size.- Throws:
IOException
- IO exception
-
doubleOpenCurlyBrace
@Test public void doubleOpenCurlyBrace() throws IOException
Test two { after each other within template.- Throws:
IOException
- IO exception
-
testHashCode
@Test public void testHashCode()
Test hash code.
-
testEquals
@Test public void testEquals()
Test equals.
-
undefined
@Test public void undefined()
Test HandleUndefined.
-
-