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 StringBLK1Template block 1 name constant.private static StringBLK1_BLKTemplate block 1 block name constant.private static StringFILE1Template file 1 name constant.private static StringFILE2Template file 2 name constant.private static StringFILE3Template file 3 name constant.private static StringFILE4Template file 4 name constant.private static org.apache.logging.log4j.LoggerLOGGERLogger.private static StringMAX_VARNAMEMaximum allowed varname.private static StringNO_TEMPLATE_FOUNDNo template found message.private static StringOUTPUTTemplate output variable name constant.private static StringTEMPLATETemplate constant.private static StringTEMPLATE1_TMPLTemplate file 1 path constant.private static StringTEMPLATE10_TMPLTemplate 10 path (file to large).private static StringTEMPLATE2_TMPLTemplate file 2 path constant.private static StringTEMPLATE4_TMPLTemplate 4 path.private static StringTEMPLATE8_TMPLTemplate 8 path.private static StringTEMPLATE9_TMPLTemplate 9 path (maximum file size).private static StringTESTTemplate variable value constant.private static StringTO_LONG_VARNAMETo long varname.private static StringVALUE1Value 1.private static StringVALUE2Value 2.private static StringVALUE3Value 3.private static StringVARIABLE_VALUE_NOT_AS_EXPECTEDVariable value not as expected message.private static StringVARIABLE1Template variable 1 name constant.private static StringVARIABLE2Template variable 2 name constant.private static StringVARIABLE3Template variable 3 name constant.private static StringVARIABLE4Template variable 4 name constant with illegal character.
-
Constructor Summary
Constructors Constructor Description TemplateEngineTests()Default constructor.
-
Method Summary
Modifier and Type Method Description voidcopyConstructor()Test copy constructor.voiddefaultConstructor()Test default constructor.voiddoubleOpenCurlyBrace()Test two { after each other within template.voidfinishEmpty()Test empty finish.voidfinishMaxSize()Test finish with maximum template size.voidfinishToLarge()Test finish with to large template.voidgetComment()Test get replace with comment variable parsing.voidgetKeep()Test get keep variable parsing.voidgetRemoved()Test get removed variable parsing.voidgetUndefined()Get undefined variables from template.voidgetUndefinedEmpty()Get empty undefined variables.voidgetUndefinedFromEmptyFile()Get undefined variables from empty template.voidgetUndefinedMaxLength()Get undefined variables with maximum varname length.voidgetUndefinedToLong()Get undefined variables with to long varname.voidgetUndefinedWrongName()Get undefined variables with wrong varname.voidgetVarEmpty()Test get empty variable with value.voidgetVarMaxLong()Test get variable with maximum long name.voidgetVars()Test variable list.voidgetVarsEmpty()Test empty variable list.voidgetVarToLong()Test get variable with to long name.voidgetVarWrongName()Test get variable with wrong name.voidnewInstanceCopy()Test newInstance from TemplateEngine copy.voidnewInstanceFile1()Test newInstance from file.voidnewInstanceFileFromDirectory()Test newInstance from directory.voidnewInstanceFileMaxSize()Test newInstance with maximum size file.voidnewInstanceFileNonExisting()Test newInstance from non existing file.voidnewInstanceFileNull()Test newInstance from File with null.voidnewInstanceFileToLarge()Test newInstance with a to large file.voidnewInstanceInputStream()Test newInstance from InputStream.voidnewInstanceInputStreamEmpty()Test newInstance from empty InputStream.voidnewInstanceInputStreamNull()Test newInstance from InputStream with null.voidnewInstanceString()Test newInstance from String.voidnewInstanceStringEmpty()Test newInstance from String with empty string.voidnewInstanceStringMaxSize()Test newInstance from String with max size string.voidnewInstanceStringNull()Test newInstance from String with null.voidnewInstanceStringToLarge()Test newInstance from String with to large string.voidparseAppend()Test parsing with append.voidparseEmpty()Test empty parsing.voidparseNonAppend()Test parsing without append.voidparseProblem()Test a specific parsing problem.voidparseTargetMaxLength()Test parsing with maximum target name length.voidparseTargetToLong()Test parsing with to long target name.voidparseTargetWrong()Test parsing with wrong target name.voidparseVarnameMaxLength()Test parsing with maximum varname length.voidparseVarnameToLong()Test parsing with to long varname.voidparseVarnameWrong()Test parsing with wrong varname.voidreadFromClasspath()Test read template file from classpath.voidreadNonExisting()Test read template file from classpath.private static StringreadStringFromFile(File file)Read String from File.voidsetBlock()Test set existing block.voidsetBlockEmpty()Test set empty block name.voidsetBlockEmptyFile()Test set existing block.voidsetBlockFailure()Test set non existing block.voidsetBlockNameMaxLength()Test set block with max length name.voidsetBlockNameToLong()Test set block with to long name.voidsetBlockNameWrong()Test set block with wrong name.voidsetBlockParentMaxLength()Test set block with to max length parent name.voidsetBlockParentMaxLength2()Test set block with to max length parent name.voidsetBlockParentToLong()Test set block with to long parent name.voidsetBlockParentWrong()Test set block with to wrong parent name.voidsetBlockVarnameMaxLength()Test set block with max length varname.voidsetBlockVarnameToLong()Test set block with to long varname.voidsetBlockVarnameWrong()Test set block with wrong varname.voidsetEmptyVar()Test set empty variable with value.voidsetFile()Test set template file.voidsetFileEmpty()Test set template file.voidsetFileMaxLength()Test set template file with max length.voidsetFileToLarge()Test set template file with to large file.voidsetFileToLong()Test set template file with to long filename.voidsetFileWrongname()Test set template file with wrong filename.voidsetUnknowns()Test get keep variable parsing.voidsetVar()Test set variable with value.voidsetVarEmpty()Test set variable as empty.voidsetVarMaxLarge()Test set variable with maximum value size.voidsetVarMaxLong()Test set variable with maximum long name.voidsetVarToLarge()Test set variable with to large value.voidsetVarToLong()Test set variable with to long name.voidsetVarWrongName()Test set variable with wrong name.voidsubst()Test read template file.voidsubstEmpty()Test read empty template file.voidsubstEmptyFile()Test subst empty file.voidsubstMaxLength()Test subst with max varname length varname.voidsubstToLong()Test subst with to long varname.voidsubstWrongName()Test subst with wrong varname.voidtestEquals()Test equals.voidtestHashCode()Test hash code.voidtestToString()Test toString.voidundefined()Test HandleUndefined.voidunsetVar()Test unset variable.voidunsetVarEmpty()Test unset empty variable.voidunsetVarMaxLength()Test unset variable with maximum name length.voidunsetVarToLong()Test unset variable with to long name.voidunsetVarWrongName()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 IOExceptionTest 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 IOExceptionTest subst with max varname length varname.- Throws:
IOException- IO exception
-
getUndefined
@Test public void getUndefined() throws IOExceptionGet undefined variables from template.- Throws:
IOException- IO exception
-
getUndefinedFromEmptyFile
@Test public void getUndefinedFromEmptyFile() throws IOExceptionGet 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 IOExceptionGet undefined variables with maximum varname length.- Throws:
IOException- IO exception
-
setVarEmpty
@Test public void setVarEmpty() throws IOExceptionTest set variable as empty.- Throws:
IOException- IO exception
-
setVar
@Test public void setVar() throws IOExceptionTest 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 IOExceptionTest set variable with maximum value size.- Throws:
IOException- IO exception
-
getRemoved
@Test public void getRemoved() throws IOExceptionTest get removed variable parsing.- Throws:
IOException- IO exception
-
getKeep
@Test public void getKeep() throws IOExceptionTest get keep variable parsing.- Throws:
IOException- IO exception
-
getComment
@Test public void getComment() throws IOExceptionTest 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 IOExceptionTest 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 IOExceptionTest set block with to max length parent name.- Throws:
IOException- IO exception
-
setBlockParentMaxLength2
@Test public void setBlockParentMaxLength2() throws IOExceptionTest set block with to max length parent name.- Throws:
IOException- IO exception
-
setBlockVarnameMaxLength
@Test public void setBlockVarnameMaxLength() throws IOExceptionTest set block with max length varname.- Throws:
IOException- IO exception
-
setBlockNameMaxLength
@Test public void setBlockNameMaxLength() throws IOExceptionTest set block with max length name.- Throws:
IOException- IO exception
-
parseNonAppend
@Test public void parseNonAppend() throws IOExceptionTest parsing without append.- Throws:
IOException- IO exception
-
parseEmpty
@Test public void parseEmpty()
Test empty parsing.
-
parseAppend
@Test public void parseAppend() throws IOExceptionTest parsing with append.- Throws:
IOException- IO exception
-
parseProblem
@Test public void parseProblem() throws IOExceptionTest 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 IOExceptionTest parsing with maximum target name length.- Throws:
IOException- IO exception
-
parseVarnameMaxLength
@Test public void parseVarnameMaxLength() throws IOExceptionTest 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 IOExceptionTest subst empty file.- Throws:
IOException- IO exception
-
setBlockEmptyFile
@Test public void setBlockEmptyFile() throws IOExceptionTest set existing block.- Throws:
IOException- IO exception
-
setUnknowns
@Test public void setUnknowns() throws IOExceptionTest get keep variable parsing.- Throws:
IOException- IO exception
-
readFromClasspath
@Test public void readFromClasspath() throws IOExceptionTest read template file from classpath.- Throws:
IOException- IO exception
-
readNonExisting
@Test public void readNonExisting() throws IOExceptionTest read template file from classpath.- Throws:
IOException- IO exception
-
unsetVar
@Test public void unsetVar() throws IOExceptionTest unset variable.- Throws:
IOException- IO exception
-
unsetVarEmpty
@Test public void unsetVarEmpty()
Test unset empty variable.
-
unsetVarMaxLength
@Test public void unsetVarMaxLength() throws IOExceptionTest 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 IOExceptionTest 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 IOExceptionTest 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 IOExceptionTest 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 IOExceptionTest newInstance from String with max size string.- Throws:
IOException- IO exception
-
newInstanceCopy
@Test public void newInstanceCopy() throws IOExceptionTest 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 IOExceptionTest finish with maximum template size.- Throws:
IOException- IO exception
-
doubleOpenCurlyBrace
@Test public void doubleOpenCurlyBrace() throws IOExceptionTest 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.
-
-