Search in sources :

Example 1 with SmallFileSubstitutionHandler

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();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Substitutable(com.sun.enterprise.admin.servermgmt.stringsubs.Substitutable) SmallFileSubstitutionHandler(com.sun.enterprise.admin.servermgmt.stringsubs.impl.SmallFileSubstitutionHandler) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 2 with SmallFileSubstitutionHandler

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();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Substitutable(com.sun.enterprise.admin.servermgmt.stringsubs.Substitutable) SmallFileSubstitutionHandler(com.sun.enterprise.admin.servermgmt.stringsubs.impl.SmallFileSubstitutionHandler) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Aggregations

Substitutable (com.sun.enterprise.admin.servermgmt.stringsubs.Substitutable)2 SmallFileSubstitutionHandler (com.sun.enterprise.admin.servermgmt.stringsubs.impl.SmallFileSubstitutionHandler)2 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 AfterTest (org.testng.annotations.AfterTest)2 Test (org.testng.annotations.Test)2 File (java.io.File)1