src/test/java/com/digitalglobe/util/maven/plugin/TestCloudFormationDeploy.java
/**
     * Validate the log file to make sure that the test was successful.
     *
     * @param assumedRole tells if we are checking for the assumption of a role.
     * @param withSecondary tells if there are secondary stacks.
     * @param withExecution tells if there was a CLI Command Execution.
     * @throws IOException is thrown when we couldn't read from the log file.
     */
Validate the log file to make sure that the test was successful.
@param assumedRole tells if we are checking for the assumption of a role.
@param withSecondary tells if there are secondary stacks.
@param withExecution tells if there was a CLI Command Execution.
@throws IOException is thrown when we couldn't read from the log file.
Validate the log file to make sure that the test was successful . @param assumedRole tells if we are checking for the assumption of a role . @param withSecondary tells if there are secondary stacks . @param withExecution tells if there was a CLI Command Execution . @throws IOException is thrown when we couldn ' t read from the log file .
private void validateLogFile(boolean assumedRole, boolean withSecondary, boolean withExecution) throws IOException {
        int position = 0;
        File touch = new File("target/audit.txt");
        Object[] lines = Files.lines(Paths.get(touch.toURI())).toArray();
        if(withSecondary) Assert.assertTrue(lines[position++].equals("Array counts match."));
        else Assert.assertTrue(lines[position++].equals("Valid because no secondary stack exist and only one stack " +
                "parameter file found."));
        if(!assumedRole) Assert.assertTrue(lines[position++].equals("roleArn: From default provider chain."));
        else {
            Assert.assertTrue(lines[position++].equals("roleArn: aws:iam::1111:role/test"));
            Assert.assertTrue(lines[position++].equals("Role assumed."));
        }
        Matcher matcher = Pattern.compile("^([0-9]) artifact(?:s){0,1} (was|were) found[.]$")
                .matcher(lines[position++].toString());
        Assert.assertTrue(matcher.matches());
        int jarCount = Integer.parseInt(matcher.group(1)) + position;
        for (; position < jarCount; position++)
            Assert.assertTrue(lines[position].toString()
                    .contains("/com/test/application-test/1.0/application-test-1.0.jar"));
        Assert.assertTrue(lines[position++].toString()
                .equals("About to copy application-test-1.0.jar to S3."));
        String test = "^application-test-1.0.jar was copied to the s3 bucket [(]Test[)][.]$";
        Assert.assertTrue(Pattern.matches(test, lines[position++].toString()));
        Assert.assertTrue(lines[position++].equals("Base64 Encoded SHA256 HASH value: " +
                "4S56TNwrXosYz6FIfsGVXbEgwNYCbzrqSVEyQCzppD0="));
        Assert.assertTrue(lines[position].toString().startsWith("Template URL: https://s3.amazonaws.com/bucket/")
                && lines[position++].toString().endsWith("-Test-Test-Template.json"));
        Assert.assertTrue(lines[position].toString().startsWith("Stack Parameter Path: "));
        Assert.assertTrue(lines[position++].toString().endsWith("/target/test-classes/Test-Parameters.json"));
        if(StackScenario.createTest) {
            Assert.assertTrue(lines[position++].toString().equals("Creating the CloudFormation Stack (Test)."));
            test = "^Created Test with id: arn:aws:cloudformation:us-east-1:1111:stack/Test/[-0-9A-Za-z.]+$";
            Assert.assertTrue(Pattern.matches(test, lines[position++].toString()));
        }
        else {
            Assert.assertTrue(lines[position++].toString().equals("Updating the CloudFormation Stack (Test)."));
            test = "^Updated Test with id: arn:aws:cloudformation:us-east-1:1111:stack/Test/[-0-9A-Za-z.]+$";
            Assert.assertTrue(Pattern.matches(test, lines[position++].toString()));
        }
        Assert.assertTrue(lines[position++].equals("Stack Finished."));
        if(withExecution) {
            Assert.assertTrue(lines[position++].equals("Using role from stack credentials."));
            Assert.assertTrue(lines[position++].equals("Using region: us-east-1"));
            Assert.assertTrue(lines[position].toString().startsWith("Executing: java -jar "));
            Assert.assertTrue(lines[position++].toString().endsWith("cloudformation-maven-plugin/test-repository/com/test/" +
                    "application-test/1.0/application-test-1.0.jar"));
        }
        if(withSecondary) {
            if(StackScenario.createTest) {
                Assert.assertTrue(lines[position++].toString()
                        .equals("Creating the CloudFormation Stack (Test)."));
                test = "^Created Test with id: arn:aws:cloudformation:us-east-1:1111:stack/Test/[-0-9A-Za-z.]+$";
                Assert.assertTrue(Pattern.matches(test, lines[position++].toString()));
            } else {
                Assert.assertTrue(lines[position++].equals("Updating the CloudFormation Stack (Test)."));
                test = "^Updated Test with id: arn:aws:cloudformation:us-east-1:1111:stack/Test/[-0-9A-Za-z.]+$";
                Assert.assertTrue(Pattern.matches(test, lines[position++].toString()));
            }
            Assert.assertTrue(lines[position++].equals("Stack Finished."));
            }
        Assert.assertEquals(lines.length, position);
    }
private void validateLogFile ( boolean assumedRole , boolean withSecondary , boolean withExecution ) throws IOException { int position = 0 ; File touch = new File ( "target/audit.txt" ) ; Object [ ] lines = Files . lines ( Paths . get ( touch . toURI ( ) ) ) . toArray ( ) ; if ( withSecondary ) Assert . assertTrue ( lines [ position ++ ] . equals ( "Array counts match." ) ) ; else Assert . assertTrue ( lines [ position ++ ] . equals ( "Valid because no secondary stack exist and only one stack " + "parameter file found." ) ) ; if ( ! assumedRole ) Assert . assertTrue ( lines [ position ++ ] . equals ( "roleArn: From default provider chain." ) ) ; else { Assert . assertTrue ( lines [ position ++ ] . equals ( "roleArn: aws:iam::1111:role/test" ) ) ; Assert . assertTrue ( lines [ position ++ ] . equals ( "Role assumed." ) ) ; } Matcher matcher = Pattern . compile ( "^([0-9]) artifact(?:s){0,1} (was|were) found[.]$" ) . matcher ( lines [ position ++ ] . toString ( ) ) ; Assert . assertTrue ( matcher . matches ( ) ) ; int jarCount = Integer . parseInt ( matcher . group ( 1 ) ) + position ; for ( ; position < jarCount ; position ++ ) Assert . assertTrue ( lines [ position ] . toString ( ) . contains ( "/com/test/application-test/1.0/application-test-1.0.jar" ) ) ; Assert . assertTrue ( lines [ position ++ ] . toString ( ) . equals ( "About to copy application-test-1.0.jar to S3." ) ) ; String test = "^application-test-1.0.jar was copied to the s3 bucket [(]Test[)][.]$" ; Assert . assertTrue ( Pattern . matches ( test , lines [ position ++ ] . toString ( ) ) ) ; Assert . assertTrue ( lines [ position ++ ] . equals ( "Base64 Encoded SHA256 HASH value: " + "4S56TNwrXosYz6FIfsGVXbEgwNYCbzrqSVEyQCzppD0=" ) ) ; Assert . assertTrue ( lines [ position ] . toString ( ) . startsWith ( "Template URL: https://s3.amazonaws.com/bucket/" ) && lines [ position ++ ] . toString ( ) . endsWith ( "-Test-Test-Template.json" ) ) ; Assert . assertTrue ( lines [ position ] . toString ( ) . startsWith ( "Stack Parameter Path: " ) ) ; Assert . assertTrue ( lines [ position ++ ] . toString ( ) . endsWith ( "/target/test-classes/Test-Parameters.json" ) ) ; if ( StackScenario . createTest ) { Assert . assertTrue ( lines [ position ++ ] . toString ( ) . equals ( "Creating the CloudFormation Stack (Test)." ) ) ; test = "^Created Test with id: arn:aws:cloudformation:us-east-1:1111:stack/Test/[-0-9A-Za-z.]+$" ; Assert . assertTrue ( Pattern . matches ( test , lines [ position ++ ] . toString ( ) ) ) ; } else { Assert . assertTrue ( lines [ position ++ ] . toString ( ) . equals ( "Updating the CloudFormation Stack (Test)." ) ) ; test = "^Updated Test with id: arn:aws:cloudformation:us-east-1:1111:stack/Test/[-0-9A-Za-z.]+$" ; Assert . assertTrue ( Pattern . matches ( test , lines [ position ++ ] . toString ( ) ) ) ; } Assert . assertTrue ( lines [ position ++ ] . equals ( "Stack Finished." ) ) ; if ( withExecution ) { Assert . assertTrue ( lines [ position ++ ] . equals ( "Using role from stack credentials." ) ) ; Assert . assertTrue ( lines [ position ++ ] . equals ( "Using region: us-east-1" ) ) ; Assert . assertTrue ( lines [ position ] . toString ( ) . startsWith ( "Executing: java -jar " ) ) ; Assert . assertTrue ( lines [ position ++ ] . toString ( ) . endsWith ( "cloudformation-maven-plugin/test-repository/com/test/" + "application-test/1.0/application-test-1.0.jar" ) ) ; } if ( withSecondary ) { if ( StackScenario . createTest ) { Assert . assertTrue ( lines [ position ++ ] . toString ( ) . equals ( "Creating the CloudFormation Stack (Test)." ) ) ; test = "^Created Test with id: arn:aws:cloudformation:us-east-1:1111:stack/Test/[-0-9A-Za-z.]+$" ; Assert . assertTrue ( Pattern . matches ( test , lines [ position ++ ] . toString ( ) ) ) ; } else { Assert . assertTrue ( lines [ position ++ ] . equals ( "Updating the CloudFormation Stack (Test)." ) ) ; test = "^Updated Test with id: arn:aws:cloudformation:us-east-1:1111:stack/Test/[-0-9A-Za-z.]+$" ; Assert . assertTrue ( Pattern . matches ( test , lines [ position ++ ] . toString ( ) ) ) ; } Assert . assertTrue ( lines [ position ++ ] . equals ( "Stack Finished." ) ) ; } Assert . assertEquals ( lines . length , position ) ; }
Validate the log file to make sure that the test was successful.
Validate the log file to make sure that the test was successful .
// Validate Array Sizes // Validate role // Validate the number of jars found in the repository directory and file names. // Validate the name of the file copied to s3. // Validate the stack is creating or updating // Validate that we finished the routine without errors.