Search in sources :

Example 11 with Substitutable

use of com.sun.enterprise.admin.servermgmt.stringsubs.Substitutable 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 12 with Substitutable

use of com.sun.enterprise.admin.servermgmt.stringsubs.Substitutable 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)12 Test (org.testng.annotations.Test)8 FileEntry (com.sun.enterprise.admin.servermgmt.xml.stringsubs.FileEntry)7 File (java.io.File)6 FileNotFoundException (java.io.FileNotFoundException)5 BufferedReader (java.io.BufferedReader)4 FileInputStream (java.io.FileInputStream)4 IOException (java.io.IOException)4 InputStreamReader (java.io.InputStreamReader)4 LargeFileSubstitutionHandler (com.sun.enterprise.admin.servermgmt.stringsubs.impl.LargeFileSubstitutionHandler)2 SmallFileSubstitutionHandler (com.sun.enterprise.admin.servermgmt.stringsubs.impl.SmallFileSubstitutionHandler)2 AfterTest (org.testng.annotations.AfterTest)2 StringSubstitutionException (com.sun.enterprise.admin.servermgmt.stringsubs.StringSubstitutionException)1 SubstitutionAlgorithm (com.sun.enterprise.admin.servermgmt.stringsubs.SubstitutionAlgorithm)1 Archive (com.sun.enterprise.admin.servermgmt.xml.stringsubs.Archive)1 ChangePair (com.sun.enterprise.admin.servermgmt.xml.stringsubs.ChangePair)1 ChangePairRef (com.sun.enterprise.admin.servermgmt.xml.stringsubs.ChangePairRef)1 ModeType (com.sun.enterprise.admin.servermgmt.xml.stringsubs.ModeType)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1