use of com.sun.enterprise.admin.servermgmt.stringsubs.impl.SmallFileSubstitutionHandler in project Payara by payara.
the class AbstractSubstitutionAlgo method testSmallTextFileSubstitution.
/**
* Test substitution for small text file.
*/
@Test
public void testSmallTextFileSubstitution() {
createTextFile();
Substitutable resolver = null;
try {
resolver = new SmallFileSubstitutionHandler(_testFile);
_algorithm.substitute(resolver);
resolver.finish();
} catch (Exception e) {
Assert.fail("Test case execution failed", e);
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(_testFile)));
String afterSubstitutionLine = null;
int i = 0;
while ((afterSubstitutionLine = reader.readLine()) != null) {
switch(i++) {
case 0:
Assert.assertEquals(afterSubstitutionLine, "First replacedLine in testFile repeat First replacedLine in testFile");
break;
case 1:
Assert.assertEquals(afterSubstitutionLine, "Second replacedLine in testFile");
break;
default:
break;
}
}
reader.close();
} catch (IOException e) {
Assert.fail("Not able to read test file");
} finally {
_testFile.delete();
}
}
use of com.sun.enterprise.admin.servermgmt.stringsubs.impl.SmallFileSubstitutionHandler in project Payara by payara.
the class AbstractSubstitutionAlgo method testSmallXMLFileSubstitution.
/**
* Test substitution for small XML file.
*/
@Test
public void testSmallXMLFileSubstitution() {
String fileName = _testFileName.replace(".txt", ".xml");
createXMLFile(fileName);
Substitutable resolver = null;
try {
resolver = new SmallFileSubstitutionHandler(new File(fileName));
_algorithm.substitute(resolver);
resolver.finish();
} catch (Exception e) {
Assert.fail("Test case failed", e);
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(_testFile)));
String afterSubstitutionLine = null;
int i = 0;
while ((afterSubstitutionLine = reader.readLine()) != null) {
switch(i++) {
case 1:
Assert.assertEquals(afterSubstitutionLine, "<port name=\"http\" value=\"8080\"></port>");
break;
case 2:
Assert.assertEquals(afterSubstitutionLine, "<port name=\"https\" value=\"8443\"></port>");
break;
default:
break;
}
}
reader.close();
} catch (IOException e) {
Assert.fail("Not able to read test file.", e);
} finally {
_testFile.delete();
}
}
Aggregations