Example usage for java.lang System clearProperty

List of usage examples for java.lang System clearProperty

Introduction

In this page you can find the example usage for java.lang System clearProperty.

Prototype

public static String clearProperty(String key) 

Source Link

Document

Removes the system property indicated by the specified key.

Usage

From source file:com.cisco.dvbu.ps.deploytool.CisDeployTool.java

/***************************************************************************************************************
 * Execute the CisDeployTool and orchestrate over the passed in property file to execute actions.
 * //from  w ww  . jav a 2 s.  c om
 * @param file - the name of the property file to orchestrate through
 * @param vcsUser - the VCS user passed in from the command-line invocation
 * @param vcsPassword - the VCS password passed in from the command-line invocation
 ***************************************************************************************************************/
public static void execCisDeployTool(String file, String vcsUser, String vcsPassword)
        throws CompositeException {

    try {
        /*****************************************
         * INITIALIZE VARIABLES
         *****************************************/
        // Trim input variables to remove spaces
        file = file.trim();
        if (vcsUser == null) {
            vcsUser = "";
        }
        if (vcsPassword == null) {
            vcsUser = "";
        }
        vcsUser = vcsUser.trim();
        vcsPassword = vcsPassword.trim();

        String prefix = "CisDeployTool";
        boolean exitOrchestrationOnError = false;
        String expectedStatus = null;
        String exitOnError = null;
        String actionType = null;
        String moduleAction = null;
        String serverId = null;
        String arguments = null;
        String message = null;
        String padCounter = null;
        String overallExecutionStatus = "PASS";
        String regressionStatus = "";
        String actualStatus = "";
        // Set pad amount
        int exitOnErrorPadAmt = 13;
        int actionTypePadAmt = 23;
        int moduleActionPadAmt = 37;
        int serverIdHostPortPadAmt = 50;
        int moduleActionObjectivePadAmt = 70;
        int messagePadAmt = 50;
        int headerLinePadAmt = 10 + exitOnErrorPadAmt + actionTypePadAmt + moduleActionPadAmt
                + serverIdHostPortPadAmt + moduleActionObjectivePadAmt + messagePadAmt;
        // Initialize Pad variables
        String exitOnErrorPad = "";
        String actionTypePad = "";
        String moduleActionPad = "";
        String serverIdHostPortPad = "";
        String moduleActionObjectivePad = "";
        String messagePad = "";
        String compositeServerHostnamePort = "";
        String serverIdHostPort = "";
        String moduleActionObjective = "";
        String moduleActionMessage = "";
        String headerLinePad = "";

        logger.info("--------------------------------------------------------");
        logger.info("--------------- COMMAND-LINE DEPLOYMENT ----------------");
        logger.info("--------------------------------------------------------");

        /*  Determine the property file name for this environment
         *    1. Start with default file "deploy.properties"
         *    2. Get Java Environment variables
         *    3. Get OS System Environment variables
         */
        propertyFile = CommonUtils.getFileOrSystemPropertyValue(null, "CONFIG_PROPERTY_FILE");
        String propertyOrderPrecedence = CommonUtils.getFileOrSystemPropertyValue(propertyFile,
                "propertyOrderPrecedence");
        if (propertyOrderPrecedence == null || propertyOrderPrecedence.trim().length() == 0)
            propertyOrderPrecedence = CommonConstants.propertyOrderPrecedenceDefault;

        logger.info("");
        logger.info("----------------------------------------------");
        logger.info("CONFIG_PROPERTY_FILE=" + propertyFile);
        logger.info("propertyOrderPrecedence=" + propertyOrderPrecedence);
        logger.info("----------------------------------------------");

        if (!PropertyManager.getInstance().doesPropertyFileExist(propertyFile)) {
            throw new ApplicationException(
                    "The property file does not exist for CONFIG_PROPERTY_FILE=" + propertyFile);
        }

        // Set the global suppress and debug flags for this class based on properties found in the property file
        setGlobalProperties();

        /*****************************************
         * INITIALIZE DEBUG LOG EXECUTION
         *****************************************/
        CommonUtils.writeOutput("---------------------------------------------------------------------------",
                prefix, "-info", logger, debug1, debug2, debug3);
        CommonUtils.writeOutput("***** BEGIN DEPLOYMENT ORCHESTRATION *****", prefix, "-info", logger, debug1,
                debug2, debug3);
        CommonUtils.writeOutput("---------------------------------------------------------------------------",
                prefix, "-info", logger, debug1, debug2, debug3);

        /*****************************************
         * DISPLAY/VALIDATE PROPERTY VARIABLES
         *****************************************/
        validateDeployProperties(prefix);

        /*****************************************
         * INITIALIZE THE SUMMARY LOG
         *****************************************/
        /* Overview of SUMMARY.log
           ========================================================================================================================================================================================================================================================================
           Summary Status Log
           ========================================================================================================================================================================================================================================================================
           Regression Status=Did the execution meet expectations.
           Expected Status=Did the user expect this action to PASS or FAIL.
           Actual Status=What really happened during execution of this action.
           ========================================================================================================================================================================================================================================================================
           Line #     Regression  Expected  Actual  ExitOnError    ActionType               ModuleAction                    Server                                              ModuleObjective                                          Message                                               
           ---------  ----------  --------  ------  -------------  -----------------------  ------------------------------  --------------------------------------------------  -------------------------------------------------------  --------------------------------------------------  
           Line   85  FAIL        PASS      FAIL    FALSE          ExecuteAction            vcsCheckouts                    DEV1_9420http=localhost:9420                        CHECKOUT : Rev=HEAD : /services/databases/TEST00         Review Stack Trace for details.
           Line   95  PASS        PASS      PASS    TRUE           ExecuteAction            updateDataSources               DEV1_9420http=localhost:9420                        UPDATE : ds3=/shared/test00/DataSources/testWebService   none
           Line   97  PASS        PASS      PASS    FALSE          ExecuteAction            updateServerAttributes          DEV1_9420http=localhost:9420                        UPDATE : studio6=/studio/lock/enabled                    none
           Line   99  PASS        PASS      PASS    FALSE          ExecuteAction            executeConfiguredProcedures     DEV1_9420http=localhost:9420                        EXECUTE : testproc=testproc                              none
           Line  112  PASS        FAIL      FAIL    FALSE          ExecuteAction            updateDataSources               unknown                                             unknown                                                  Passed in method  updateDataSources does not exist or does not match the number of required arguments.
           Line  118  PASS        FAIL      FAIL    FALSE          ExecuteActionXXX         updateDataSources               unknown                                             unknown                                                  Action Type [ExecuteActionXXX] is not valid.
           ========================================================================================================================================================================================================================================================================
           Overall Regression Execution Status=FAIL
           Script ran to completion.                                                             
           ========================================================================================================================================================================================================================================================================
        */

        // Get the summary log location
        String summaryLogLocation = CommonUtils.extractVariable(prefix,
                CommonUtils.getFileOrSystemPropertyValue(propertyFile, "SUMMARY_LOG"), propertyFile, true);
        CommonUtils.createFileWithContent(summaryLogLocation, "");

        headerLinePad = CommonUtils.rpad("=", headerLinePadAmt, "=");

        writeSummaryLog("=========================================" + headerLinePad, null, null,
                summaryLogLocation);
        writeSummaryLog("Summary Status Log", null, null, summaryLogLocation);
        writeSummaryLog("=========================================" + headerLinePad, null, null,
                summaryLogLocation);
        writeSummaryLog("Regression Status=Did the execution meet expectations.", null, null,
                summaryLogLocation);
        writeSummaryLog("Expected Status=Did the user expect this action to PASS or FAIL.", null, null,
                summaryLogLocation);
        writeSummaryLog("Actual Status=What really happened during execution of this action.", null, null,
                summaryLogLocation);
        writeSummaryLog("=========================================" + headerLinePad, null, null,
                summaryLogLocation);
        //writeSummaryLog("Line #     Regression  Expected  Actual  ExitOnError  ActionType             ModuleAction                  Server                                            ModuleObjective                                  Message"                                 ,null,null, summaryLogLocation);
        //writeSummaryLog("---------  ----------  --------  ------  -----------  ---------------------  ----------------------------  ------------------------------------------------  -----------------------------------------------  -----------------------------------------------"   ,null,null, summaryLogLocation);
        exitOnErrorPad = CommonUtils.rpad("ExitOnError", exitOnErrorPadAmt, " ") + "  ";
        actionTypePad = CommonUtils.rpad("ActionType", actionTypePadAmt, " ") + "  ";
        moduleActionPad = CommonUtils.rpad("ModuleAction", moduleActionPadAmt, " ") + "  ";
        serverIdHostPortPad = CommonUtils.rpad("Server", serverIdHostPortPadAmt, " ") + "  ";
        moduleActionObjectivePad = CommonUtils.rpad("ModuleObjective", moduleActionObjectivePadAmt, " ") + "  ";
        messagePad = CommonUtils.rpad("Message", messagePadAmt, " ") + "  ";
        writeSummaryLog(
                "Line #     Regression  Expected  Actual  " + exitOnErrorPad + actionTypePad + moduleActionPad
                        + serverIdHostPortPad + moduleActionObjectivePad + messagePad,
                null, null, summaryLogLocation);

        exitOnErrorPad = CommonUtils.rpad("-", exitOnErrorPadAmt, "-") + "  ";
        actionTypePad = CommonUtils.rpad("-", actionTypePadAmt, "-") + "  ";
        moduleActionPad = CommonUtils.rpad("-", moduleActionPadAmt, "-") + "  ";
        serverIdHostPortPad = CommonUtils.rpad("-", serverIdHostPortPadAmt, "-") + "  ";
        moduleActionObjectivePad = CommonUtils.rpad("-", moduleActionObjectivePadAmt, "-") + "  ";
        messagePad = CommonUtils.rpad("-", messagePadAmt, "-") + "  ";
        writeSummaryLog(
                "---------  ----------  --------  ------  " + exitOnErrorPad + actionTypePad + moduleActionPad
                        + serverIdHostPortPad + moduleActionObjectivePad + messagePad,
                null, null, summaryLogLocation);

        /*****************************************
         * READ THE ORCHESTRATION PROPERTY FILE
         *****************************************/
        BufferedReader reader = new BufferedReader(new FileReader(file));
        String line = null;
        int lnCount = 0;
        // Iterate through the orchestration property file
        while (!exitOrchestrationOnError && ((line = reader.readLine()) != null)) {
            lnCount++;
            padCounter = CommonUtils.padCount(lnCount, 4, " ");

            /*****************************************
             * TEST LINE FOR BLANK
             *****************************************/
            if (line.trim().isEmpty() || line.trim().length() == 0) {

                CommonUtils.writeOutput(
                        "---------------------------------------------------------------------------", prefix,
                        "-info" + suppress, logger, debug1, debug2, debug3);
                CommonUtils.writeOutput("Line" + padCounter + " [SKIP BLANK]::" + line.trim(), prefix,
                        "-info" + suppress, logger, debug1, debug2, debug3);

                /*****************************************
                 * TEST LINE FOR COMMENT (#)
                 *****************************************/
            } else if (line.trim().startsWith("#")) {

                CommonUtils.writeOutput(
                        "---------------------------------------------------------------------------", prefix,
                        "-info" + suppress, logger, debug1, debug2, debug3);
                CommonUtils.writeOutput("Line" + padCounter + " [SKIP COMMENT]::" + line.trim(), prefix,
                        "-info" + suppress, logger, debug1, debug2, debug3);

                // Otherwise this is a line to be processed
            } else {

                CommonUtils.writeOutput(
                        "---------------------------------------------------------------------------", prefix,
                        "-info", logger, debug1, debug2, debug3);
                CommonUtils.writeOutput("Line" + padCounter + " " + line.trim(), prefix, "-info", logger,
                        debug1, debug2, debug3);

                /*****************************************
                 * PARSE THE LINE
                 *****************************************/
                // [mtinius: 2015-09-03] These property values will be set in WsApiHelperObjects.java once the module is invoked
                System.clearProperty("CIS_SERVER_HOST_PORT");
                // [mtinius: 2015-09-03] This property gets set by each module based on the method being executed.  It identifies the objective for the method execution.
                System.clearProperty("MODULE_ACTION_OBJECTIVE");
                // [mtinius: 2015-09-03] This property gets set by each module based on the method being executed.  It identifies the return message which can be info or error.
                System.clearProperty("MODULE_ACTION_MESSAGE");

                // Convert tabs to spaces
                line = line.replaceAll("\u0009", " ");
                // Convert ' "" ' (space quote quote space) into (space quote quote quote quote space) so that the intention of this is not lost during the next conversion
                while (line.contains(" \"\" "))
                    line = line.replaceAll(" \"\" ", " \"\"\"\" ");
                // Convert double sets of quotes "" to a single double quote "
                line = line.replaceAll("\"\"", "\"");
                // Trim the line of spaces
                line = line.trim();
                // Tokenize a space separated line
                StringTokenizer st = new StringTokenizer(line, " ");
                int arg = 0;
                arguments = "";
                while (st.hasMoreTokens()) {
                    arg++;
                    String val = st.nextToken();
                    // PASS or FAIL
                    if (arg == 1) {
                        expectedStatus = CommonUtils.extractVariable(prefix, val, propertyFile, false)
                                .toUpperCase();
                        if (expectedStatus.equalsIgnoreCase("PASS")
                                || expectedStatus.equalsIgnoreCase("FAIL")) {
                            CommonUtils.writeOutput("  expectedStatus=" + expectedStatus, prefix, "-info",
                                    logger, debug1, debug2, debug3);
                        } else {
                            throw new CompositeException(
                                    "Failure parsing property file.  PARAM1::expectedStatus=[" + exitOnError
                                            + "] is invalid.  Must be PASS or FAIL.  File=[" + file + "]");
                        }
                    }
                    // TRUE or FALSE
                    if (arg == 2) {
                        exitOnError = CommonUtils.extractVariable(prefix, val, propertyFile, false)
                                .toUpperCase();
                        if (exitOnError.equalsIgnoreCase("TRUE") || exitOnError.equalsIgnoreCase("FALSE")) {
                            CommonUtils.writeOutput("  exitOnError=   " + exitOnError, prefix, "-info", logger,
                                    debug1, debug2, debug3);
                        } else {
                            throw new CompositeException(
                                    "Failure parsing property file.  PARAM2::exitOnError=[" + exitOnError
                                            + "] is invalid.  Must be TRUE or FALSE.  File=[" + file + "]");
                        }
                    }
                    if (arg == 3) {
                        // Validate the actionType action against a valid list in the deploy.properties file [ExecuteAction]
                        actionType = val;
                        CommonUtils.writeOutput("  actionType=    " + actionType, prefix, "-info", logger,
                                debug1, debug2, debug3);
                    }
                    if (arg == 4) {
                        // Validate the moduleAction action against a valid list in the deploy.properties file.
                        moduleAction = val;
                        CommonUtils.writeOutput("  moduleAction=  " + moduleAction, prefix, "-info", logger,
                                debug1, debug2, debug3);
                    }
                    if (arg == 5) {
                        // Get the serverId.
                        String serverIdVar = val;
                        if (moduleAction.equalsIgnoreCase("vcsInitWorkspace")
                                || moduleAction.equalsIgnoreCase("vcsInitWorkspace2")
                                || moduleAction.equalsIgnoreCase("vcsInitializeBaseFolderCheckin")
                                || moduleAction.equalsIgnoreCase("vcsInitializeBaseFolderCheckin2")) {
                            serverId = "unknown";
                        } else {
                            serverId = CommonUtils.extractVariable(prefix, serverIdVar, propertyFile, true);
                            if (serverIdVar.equalsIgnoreCase(serverId))
                                CommonUtils.writeOutput("  serverId=      " + serverIdVar, prefix, "-info",
                                        logger, debug1, debug2, debug3);
                            else
                                CommonUtils.writeOutput(
                                        "  serverId=      " + serverIdVar + "  /  resolved=" + serverId, prefix,
                                        "-info", logger, debug1, debug2, debug3);
                        }
                    }
                    if (arg >= 5) {
                        arguments = arguments.trim() + " " + val;
                    }
                }
                CommonUtils.writeOutput("  arguments=     " + arguments, prefix, "-info", logger, debug1,
                        debug2, debug3);
                CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);

                // Determine the padding for summary variables
                exitOnErrorPad = CommonUtils.rpad(exitOnError, exitOnErrorPadAmt, " ") + "  ";
                actionTypePad = CommonUtils.rpad(actionType, actionTypePadAmt, " ") + "  ";
                moduleActionPad = CommonUtils.rpad(moduleAction, moduleActionPadAmt, " ") + "  ";
                serverIdHostPortPad = CommonUtils.rpad(serverIdHostPort, serverIdHostPortPadAmt, " ") + "  ";
                moduleActionObjectivePad = CommonUtils.rpad(moduleActionObjective, moduleActionObjectivePadAmt,
                        " ") + "  ";

                /*****************************************
                * VALIDATE MODULE ACTION EXISTS
                *    ExecuteAction - executeAction()
                *****************************************/
                if (actionType.equalsIgnoreCase("ExecuteAction")) {

                    CompositeException exception = null;
                    message = NONE;
                    /*****************************************
                    * INVOKE THE MODULE ACTION: 
                    *****************************************/
                    try {
                        if (actionType.contains("ExecuteAction")) {
                            executeAction(prefix, moduleAction, arguments, vcsUser, vcsPassword);
                        }

                    } catch (CompositeException e) {
                        exception = e;
                        message = "Review Stack Trace for details.";
                        if (e.getMessage() != null) {
                            message = e.getMessage().toString();
                        }
                    }

                    // [mtinius: 2015-09-03] Get the system property values post-execution
                    //       These property values were set in WsApiHelperObjects.java when "executeAction" was invoked
                    compositeServerHostnamePort = System.getProperty("CIS_SERVER_HOST_PORT");
                    if (compositeServerHostnamePort == null)
                        compositeServerHostnamePort = "unknown";
                    serverIdHostPort = serverId + "=" + compositeServerHostnamePort;
                    //       This property gets set by each module based on the method being executed.  It identifies the objective for the method execution.
                    moduleActionObjective = System.getProperty("MODULE_ACTION_OBJECTIVE");
                    if (moduleActionObjective == null)
                        moduleActionObjective = "unknown";
                    //       Determine the padding for summary variables
                    serverIdHostPortPad = CommonUtils.rpad(serverIdHostPort, serverIdHostPortPadAmt, " ")
                            + "  ";
                    moduleActionObjectivePad = CommonUtils.rpad(moduleActionObjective,
                            moduleActionObjectivePadAmt, " ") + "  ";
                    //       This property gets set by each module based on the method being executed.  It identifies the return message which can be info or error.
                    moduleActionMessage = System.getProperty("MODULE_ACTION_MESSAGE");
                    if (message.equalsIgnoreCase(NONE)) {
                        if (moduleActionMessage != null && moduleActionMessage.length() > 0)
                            message = moduleActionMessage;
                    } else {
                        message = message + "  " + moduleActionMessage;
                    }

                    /*****************************************
                     * PROCESS SUMMARY LOG and HANDLE ERRORS
                     *****************************************/
                    if (exception != null) {
                        // Script executed with error

                        // ###########################################
                        // # Begin::Write out the summary status
                        // ###########################################
                        if (expectedStatus.equalsIgnoreCase("PASS")) {
                            regressionStatus = "FAIL";
                            overallExecutionStatus = "FAIL";
                        }
                        if (expectedStatus.equalsIgnoreCase("FAIL")) {
                            regressionStatus = "PASS";
                        }
                        actualStatus = "FAIL";

                        // Write out the SUMMARY.log entry
                        //writeSummaryLog("Line "+padCounter+"  "+regressionStatus+"        "+expectedStatus+"      "+actualStatus+"    "+exitOnErrorPad+actionTypePad+moduleAction,   null,null, summaryLogLocation);
                        writeSummaryLog("Line " + padCounter + "  " + regressionStatus + "        "
                                + expectedStatus + "      " + actualStatus + "    " + exitOnErrorPad
                                + actionTypePad + moduleActionPad + serverIdHostPortPad
                                + moduleActionObjectivePad + message, null, null, summaryLogLocation);

                        // ###########################################
                        // # End::Write out the summary status
                        // ###########################################

                        if (exitOnError.equalsIgnoreCase("TRUE")) {

                            // Script was set to exit orchestration on error
                            if (expectedStatus.equalsIgnoreCase("FAIL")) {
                                exitOrchestrationOnError = false;
                                CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);
                                //CommonUtils.writeOutput("Line "+padCounter+"   SCRIPT_RESULTS::"+actualStatus,                        prefix,"-info",logger,debug1,debug2,debug3);
                                CommonUtils.writeOutput(
                                        "Line " + padCounter + "   SCRIPT_RESULTS=" + regressionStatus
                                                + "  EXPECTED=" + expectedStatus + "  ACTUAL=" + actualStatus
                                                + "  EXIT_ON_ERROR=" + exitOnError + "  ACTION=" + moduleAction,
                                        prefix, "-info", logger, debug1, debug2, debug3);
                                CommonUtils.writeOutput("Line " + padCounter
                                        + "   MESSAGE=Expected Script Error. Script will continue processing.  ERROR="
                                        + message, prefix, "-info", logger, debug1, debug2, debug3);
                                CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);

                            } else { // expectedStatus=PASS

                                exitOrchestrationOnError = true;
                                CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);
                                //CommonUtils.writeOutput("Line "+padCounter+"   SCRIPT_RESULTS::"+actualStatus,                        prefix,"-info",logger,debug1,debug2,debug3);
                                CommonUtils.writeOutput(
                                        "Line " + padCounter + "   SCRIPT_RESULTS=" + regressionStatus
                                                + "  EXPECTED=" + expectedStatus + "  ACTUAL=" + actualStatus
                                                + "  EXIT_ON_ERROR=" + exitOnError + "  ACTION=" + moduleAction,
                                        prefix, "-info", logger, debug1, debug2, debug3);
                                CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);
                            }

                        } else { // exitOnError=FALSE

                            if (expectedStatus.equalsIgnoreCase("FAIL")) {
                                exitOrchestrationOnError = false;
                                CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);
                                //CommonUtils.writeOutput("Line "+padCounter+"   SCRIPT_RESULTS::"+actualStatus,                        prefix,"-info",logger,debug1,debug2,debug3);
                                CommonUtils.writeOutput(
                                        "Line " + padCounter + "   SCRIPT_RESULTS=" + regressionStatus
                                                + "  EXPECTED=" + expectedStatus + "  ACTUAL=" + actualStatus
                                                + "  EXIT_ON_ERROR=" + exitOnError + "  ACTION=" + moduleAction,
                                        prefix, "-info", logger, debug1, debug2, debug3);
                                CommonUtils.writeOutput("Line " + padCounter
                                        + "   MESSAGE=Expected Script Error. Script is set to continue processing.  ERROR="
                                        + message, prefix, "-info", logger, debug1, debug2, debug3);
                                CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);

                            } else { // expectedStatus=PASS

                                exitOrchestrationOnError = false;
                                CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);
                                //CommonUtils.writeOutput("Line "+padCounter+"   SCRIPT_RESULTS::"+actualStatus,                        prefix,"-info",logger,debug1,debug2,debug3);
                                CommonUtils.writeOutput(
                                        "Line " + padCounter + "   SCRIPT_RESULTS=" + regressionStatus
                                                + "  EXPECTED=" + expectedStatus + "  ACTUAL=" + actualStatus
                                                + "  EXIT_ON_ERROR=" + exitOnError + "  ACTION=" + moduleAction,
                                        prefix, "-info", logger, debug1, debug2, debug3);
                                CommonUtils.writeOutput("Line " + padCounter
                                        + "   MESSAGE=Abnormal Script Termination. Script is set to continue processing.  ERROR="
                                        + message, prefix, "-info", logger, debug1, debug2, debug3);
                                CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);
                            }
                        }

                    } else {
                        // Script executed successfully

                        // ###########################################
                        // # Begin::Write out the summary status
                        // ###########################################
                        if (expectedStatus.equalsIgnoreCase("PASS")) {
                            regressionStatus = "PASS";
                        }
                        if (expectedStatus.equalsIgnoreCase("FAIL")) {
                            regressionStatus = "FAIL";
                            overallExecutionStatus = "FAIL";
                        }
                        actualStatus = "PASS";

                        // Write out the SUMMARY.log entry
                        //writeSummaryLog("Line "+padCounter+"  "+regressionStatus+"        "+expectedStatus+"      "+actualStatus+"    "+exitOnErrorPad+actionTypePad+moduleAction,null,null, summaryLogLocation); 
                        writeSummaryLog("Line " + padCounter + "  " + regressionStatus + "        "
                                + expectedStatus + "      " + actualStatus + "    " + exitOnErrorPad
                                + actionTypePad + moduleActionPad + serverIdHostPortPad
                                + moduleActionObjectivePad + message, null, null, summaryLogLocation);

                        // ###########################################
                        // # End::Write out the summary status
                        // ###########################################

                        if (exitOnError.equalsIgnoreCase("TRUE")) {
                            // Script is expected to FAIL and Script was set to exit orchestration on error
                            if (expectedStatus.equalsIgnoreCase("FAIL")) {
                                exitOrchestrationOnError = true;
                                message = "Expected error but execution was successful.";

                                CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);
                                CommonUtils.writeOutput(
                                        "Line " + padCounter + "   SCRIPT_RESULTS=" + regressionStatus
                                                + "  EXPECTED=" + expectedStatus + "  ACTUAL=" + actualStatus
                                                + "  EXIT_ON_ERROR=" + exitOnError + "  ACTION=" + moduleAction,
                                        prefix, "-info", logger, debug1, debug2, debug3);
                                CommonUtils.writeOutput("Line " + padCounter
                                        + "   MESSAGE=Abnormal Script Termination.  ERROR=" + message, prefix,
                                        "-info", logger, debug1, debug2, debug3);
                                CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);

                            } else { // expectedStatus=PASS

                                exitOrchestrationOnError = false;
                                CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);
                                //CommonUtils.writeOutput("Line "+padCounter+"   SCRIPT_RESULTS::"+actualStatus,                              prefix,"-info",logger,debug1,debug2,debug3); 
                                CommonUtils.writeOutput(
                                        "Line " + padCounter + "   SCRIPT_RESULTS=" + regressionStatus
                                                + "  EXPECTED=" + expectedStatus + "  ACTUAL=" + actualStatus
                                                + "  EXIT_ON_ERROR=" + exitOnError + "  ACTION=" + moduleAction,
                                        prefix, "-info", logger, debug1, debug2, debug3);
                                CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);
                            }
                        } else { // exitOnError=FALSE

                            // Script is expected to FAIL and Script was NOT set to exit orchestration on error
                            if (expectedStatus.equalsIgnoreCase("FAIL")) {
                                exitOrchestrationOnError = false;
                                message = "Expected error but execution was successful.";
                                CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);
                                CommonUtils.writeOutput(
                                        "Line " + padCounter + "   SCRIPT_RESULTS=" + regressionStatus
                                                + "  EXPECTED=" + expectedStatus + "  ACTUAL=" + actualStatus
                                                + "  EXIT_ON_ERROR=" + exitOnError + "  ACTION=" + moduleAction,
                                        prefix, "-info", logger, debug1, debug2, debug3);
                                CommonUtils.writeOutput("Line " + padCounter
                                        + "   MESSAGE=Abnormal Script Termination. Script is set to continue processing.  ERROR="
                                        + message, prefix, "-info", logger, debug1, debug2, debug3);

                            } else { // expectedStatus=PASS

                                exitOrchestrationOnError = false;
                                CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);
                                //CommonUtils.writeOutput("Line "+padCounter+"   SCRIPT_RESULTS::"+actualStatus,                              prefix,"-info",logger,debug1,debug2,debug3); 
                                CommonUtils.writeOutput(
                                        "Line " + padCounter + "   SCRIPT_RESULTS=" + regressionStatus
                                                + "  EXPECTED=" + expectedStatus + "  ACTUAL=" + actualStatus
                                                + "  EXIT_ON_ERROR=" + exitOnError + "  ACTION=" + moduleAction,
                                        prefix, "-info", logger, debug1, debug2, debug3);
                                CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);
                            }
                        }
                    }

                } else { // else if (actionType.equalsIgnoreCase("ExecuteAction") ) {

                    message = "Action Type [" + actionType + "] is not valid.";

                    // ###########################################
                    // # Begin::Write out the summary status
                    // ###########################################
                    if (expectedStatus.equalsIgnoreCase("PASS")) {
                        regressionStatus = "FAIL";
                        overallExecutionStatus = "FAIL";
                    }
                    if (expectedStatus.equalsIgnoreCase("FAIL")) {
                        regressionStatus = "PASS";
                    }
                    actualStatus = "FAIL";

                    // Write out the SUMMARY.log entry
                    //writeSummaryLog("Line "+padCounter+"  "+regressionStatus+"        "+expectedStatus+"      "+actualStatus+"    "+exitOnErrorPad+actionTypePad+moduleAction,null,null, summaryLogLocation); 
                    writeSummaryLog("Line " + padCounter + "  " + regressionStatus + "        " + expectedStatus
                            + "      " + actualStatus + "    " + exitOnErrorPad + actionTypePad
                            + moduleActionPad + serverIdHostPortPad + moduleActionObjectivePad + message, null,
                            null, summaryLogLocation);

                    // ###########################################
                    // # End::Write out the summary status
                    // ###########################################

                    if (exitOnError.equalsIgnoreCase("TRUE")) {
                        CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);
                        CommonUtils.writeOutput("Line " + padCounter + "   SCRIPT_RESULTS::" + actualStatus,
                                prefix, "-info", logger, debug1, debug2, debug3);
                        CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);

                        CommonUtils.writeOutput(
                                "---------------------------------------------------------------------------",
                                prefix, "-info", logger, debug1, debug2, debug3);
                        CommonUtils.writeOutput("Line " + padCounter + " EXIT_ON_ERROR::" + exitOnError, prefix,
                                "-info", logger, debug1, debug2, debug3);
                        CommonUtils
                                .writeOutput(
                                        "Line " + padCounter + "   ERROR_FOUND::" + actionType + " "
                                                + moduleAction + " " + arguments,
                                        prefix, "-info", logger, debug1, debug2, debug3);
                        CommonUtils.writeOutput(
                                "Abnormal Script Termination. Action Type " + actionType
                                        + " does not exist. ERROR=" + message,
                                prefix, "-info", logger, debug1, debug2, debug3);
                        CommonUtils.writeOutput("End of $CONTROLSCRIPT orchestration script.", prefix, "-info",
                                logger, debug1, debug2, debug3);
                        CommonUtils.writeOutput(
                                "---------------------------------------------------------------------------",
                                prefix, "-info", logger, debug1, debug2, debug3);

                        // Script was set to exit orchestration on error
                        exitOrchestrationOnError = true;

                    } else {
                        CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);
                        CommonUtils.writeOutput("Line " + padCounter + "   SCRIPT_RESULTS::" + actualStatus,
                                prefix, "-info", logger, debug1, debug2, debug3);
                        CommonUtils.writeOutput("", prefix, "-info", logger, debug1, debug2, debug3);

                        CommonUtils.writeOutput("Line " + padCounter + " EXIT_ON_ERROR::" + exitOnError, prefix,
                                "-info", logger, debug1, debug2, debug3);
                        CommonUtils
                                .writeOutput(
                                        "Line " + padCounter + "   ERROR_FOUND::" + actionType + " "
                                                + moduleAction + " " + arguments,
                                        prefix, "-info", logger, debug1, debug2, debug3);
                        CommonUtils.writeOutput(
                                "Action Type [" + actionType
                                        + "] does not exist.  Script is set to continue processing.",
                                prefix, "-info", logger, debug1, debug2, debug3);
                    }

                } // end inner if-then-else 

            } // end outer if-then-else

        } // end while loop

        if (!exitOrchestrationOnError) { // Do Not Exit On Error
            /*****************************************
             * CLOSE OUT THE SUMMRY LOG
             *****************************************/
            writeSummaryLog("=========================================" + headerLinePad, null, null,
                    summaryLogLocation);
            writeSummaryLog("Overall Regression Execution Status=" + overallExecutionStatus, null, null,
                    summaryLogLocation);
            writeSummaryLog("                                                                               ",
                    null, null, summaryLogLocation);
            writeSummaryLog(
                    "Script ran to completion.                                                             ",
                    null, null, summaryLogLocation);
            writeSummaryLog("=========================================" + headerLinePad, null, null,
                    summaryLogLocation);

            /*****************************************
             * CLOSE OUT DEBUG LOG
             *****************************************/
            CommonUtils.writeOutput(
                    "---------------------------------------------------------------------------", prefix,
                    "-info", logger, debug1, debug2, debug3);
            CommonUtils.writeOutput("***** COMPLETED DEPLOYMENT ORCHESTRATION SUCCESSFULLY *****", prefix,
                    "-info", logger, debug1, debug2, debug3);
            CommonUtils.writeOutput("End of CisDeployTool orchestration script.", prefix, "-info", logger,
                    debug1, debug2, debug3);
            CommonUtils.writeOutput(
                    "---------------------------------------------------------------------------", prefix,
                    "-info", logger, debug1, debug2, debug3);
        } else { // Exit On Error
            /*****************************************
             * CLOSE OUT THE SUMMRY LOG
             *****************************************/
            writeSummaryLog("=========================================" + headerLinePad, null, null,
                    summaryLogLocation);
            writeSummaryLog("Overall Regression Execution Status=" + overallExecutionStatus, null, null,
                    summaryLogLocation);
            writeSummaryLog(
                    "                                                                                                        ",
                    null, null, summaryLogLocation);
            writeSummaryLog(
                    "Script was set to exit on error.                                                                        ",
                    null, null, summaryLogLocation);
            writeSummaryLog("=========================================" + headerLinePad, null, null,
                    summaryLogLocation);

            /*****************************************
             * CLOSE OUT DEBUG LOG
             *****************************************/
            CommonUtils.writeOutput(
                    "---------------------------------------------------------------------------", prefix,
                    "-info", logger, debug1, debug2, debug3);
            CommonUtils.writeOutput("Abnormal Script Termination. Script will exit.  ERROR=" + message, prefix,
                    "-info", logger, debug1, debug2, debug3);
            CommonUtils.writeOutput("End of CisDeployTool orchestration script.", prefix, "-info", logger,
                    debug1, debug2, debug3);
            CommonUtils.writeOutput(
                    "---------------------------------------------------------------------------", prefix,
                    "-info", logger, debug1, debug2, debug3);

            throw new ApplicationException("Exiting Script with error.  ERROR=" + message);
        }

    } catch (ValidationException e) {
        throw new CompositeException(e.getMessage(), e);
    } catch (ApplicationException e) {
        throw new CompositeException(e.getMessage(), e);
    } catch (CompositeException e) {
        throw new CompositeException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        throw new CompositeException(e.getMessage(), e);
    } catch (IOException e) {
        throw new CompositeException(e.getMessage(), e);
    }
}

From source file:org.alfresco.repo.activities.AbstractSiteActivityTest.java

@AfterClass
// remove system "user.name.caseSensitive" property
public static void afterClass() {
    System.clearProperty("user.name.caseSensitive");
}

From source file:org.apache.geronimo.mavenplugins.car.AbstractCarMojo.java

protected void unsetSystemProperties(Map<String, String> previousSystemProperties) {
    if (previousSystemProperties != null) {
        for (Map.Entry<String, String> entry : previousSystemProperties.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            if (value == null) {
                System.clearProperty(key);
            } else {
                System.setProperty(key, value);
            }/*from  w w w.ja  v a2s .  c om*/
        }
    }
}

From source file:org.apache.taverna.security.credentialmanager.impl.CredentialManagerImpl.java

/**
 * Load Taverna's Keystore from a file on the disk.
 *//*  w w w .j a v a 2  s. c o  m*/
private void loadKeystore() throws CMException {
    if (keystore == null) {
        try {
            // Try to create Taverna's Keystore as Bouncy Castle UBER-type
            // keystore.
            keystore = KeyStore.getInstance("UBER", "BC");
        } catch (Exception ex) {
            // The requested keystore type is not available from security
            // providers.
            throw new CMException("Failed to instantiate Taverna's Keystore.", ex);
        }

        if (keystoreFile.exists()) { // If the file exists, open it
            // Try to load the Keystore
            try (FileInputStream fis = new FileInputStream(keystoreFile)) {
                // Load the Keystore from the file
                keystore.load(fis, masterPassword.toCharArray());
            } catch (Exception ex) {
                keystore = null; // make it null as it was just created but
                                 // failed to load so it is not null
                masterPassword = null; // it is probably the wrong password
                // so do not remember it just in
                // case
                String exMessage = "Failed to load Taverna's Keystore from " + keystoreFile.getAbsolutePath()
                        + ". Possible reason: incorrect password or corrupted file.";
                logger.error(exMessage, ex);
                throw new CMException(exMessage, ex);
            }
        } else {
            // Otherwise create a new empty Keystore
            try (FileOutputStream fos = new FileOutputStream(keystoreFile)) {
                keystore.load(null, null);
                // Immediately save the new (empty) Keystore to the file
                keystore.store(fos, masterPassword.toCharArray());
            } catch (Exception ex) {
                String exMessage = "Failed to generate a new empty Keystore.";
                // logger.error(exMessage, ex);
                throw new CMException(exMessage, ex);
            }
        }

        /*
         * Taverna distro for MAC contains info.plist file with some Java
         * system properties set to use the Keychain which clashes with what
         * we are setting here so we need to clear them
         */
        System.clearProperty(PROPERTY_KEYSTORE_TYPE);
        System.clearProperty(PROPERTY_KEYSTORE_PROVIDER);

        /*
         * Not quite sure why we still need to set these two properties
         * since we are creating our own SSLSocketFactory with our own
         * KeyManager that uses Taverna's Keystore, but seem like after
         * Taverna starts up and the first time it needs SSLSocketFactory
         * for HTTPS connection it is still using the default Java's
         * keystore unless these properties are set. Set the system property
         * "javax.net.ssl.keystore" to use Taverna's keystore.
         *
         * Axis 1 likes reading from these properties but seems to work as
         * well with Taverna's SSLSocetFactory as well. We do not want to
         * expose these as they can be read from Beanshells.
         */
        // System.setProperty(PROPERTY_KEYSTORE, keystoreFile.getAbsolutePath());
        // System.setProperty(PROPERTY_KEYSTORE_PASSWORD, masterPassword);
        System.clearProperty(PROPERTY_KEYSTORE);
        System.clearProperty(PROPERTY_KEYSTORE_PASSWORD);
    }
}

From source file:com.seleniumtests.it.core.TestSeleniumRobotTestListener.java

@Test(groups = { "it" })
public void testContextDriverNotBlockingInAfterMethod(ITestContext testContext) throws Exception {

    try {//from   w ww .  ja  v a 2 s . c o m
        System.setProperty(SeleniumTestsContext.BROWSER, "htmlunit");
        System.setProperty("startLocation", "afterMethod");
        executeSubTest(1,
                new String[] { "com.seleniumtests.it.stubclasses.StubTestClassForListener5.test1Listener5",
                        "com.seleniumtests.it.stubclasses.StubTestClassForListener5.test2Listener5" },
                "", "stub1");
    } finally {
        System.clearProperty(SeleniumTestsContext.BROWSER);
    }

    String detailedReportContent1 = readTestMethodResultFile("test1Listener5");
    Assert.assertFalse(detailedReportContent1.contains(DRIVER_BLOCKED_MSG));

    String logs = readSeleniumRobotLogFile();
    Assert.assertTrue(logs.contains("Finished creating *htmlunit driver"));
    Assert.assertTrue(logs.contains("start suite"));
    Assert.assertTrue(logs.contains("start test"));
    Assert.assertTrue(logs.contains("start class"));
    Assert.assertTrue(logs.contains("start method"));
    Assert.assertTrue(logs.contains("test 1"));
    Assert.assertTrue(logs.contains("end method"));

    String outDir = new File(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory())
            .getAbsolutePath();
    JSONObject jsonResult = new JSONObject(
            FileUtils.readFileToString(Paths.get(outDir, "results.json").toFile()));

    // All tests should be skipped because configuration method is skipped
    Assert.assertEquals(jsonResult.getInt("pass"), 2);
}

From source file:net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl.java

/**
 * Load Taverna's Keystore from a file on the disk.
 *//*from  w ww. j a  va2s .  c  om*/
private void loadKeystore() throws CMException {
    if (keystore == null) {
        try {
            // Try to create Taverna's Keystore as Bouncy Castle UBER-type
            // keystore.
            keystore = KeyStore.getInstance("UBER", "BC");
        } catch (Exception ex) {
            // The requested keystore type is not available from security
            // providers.
            throw new CMException("Failed to instantiate Taverna's Keystore.", ex);
        }

        if (keystoreFile.exists()) { // If the file exists, open it
            // Try to load the Keystore
            try (FileInputStream fis = new FileInputStream(keystoreFile)) {
                // Load the Keystore from the file
                keystore.load(fis, masterPassword.toCharArray());
            } catch (Exception ex) {
                keystore = null;
                /*
                 * make it null as it was just created but failed to load so
                 * it is not null
                 */
                masterPassword = null;
                /*
                 * it is probably the wrong password so do not remember it
                 * just in case
                 */
                String exMessage = "Failed to load Taverna's Keystore from " + keystoreFile.getAbsolutePath()
                        + ". Possible reason: incorrect password or corrupted file.";
                logger.error(exMessage, ex);
                throw new CMException(exMessage, ex);
            }
        } else {
            // Otherwise create a new empty Keystore
            try (FileOutputStream fos = new FileOutputStream(keystoreFile)) {
                keystore.load(null, null);
                // Immediately save the new (empty) Keystore to the file
                keystore.store(fos, masterPassword.toCharArray());
            } catch (Exception ex) {
                String exMessage = "Failed to generate a new empty Keystore.";
                // logger.error(exMessage, ex);
                throw new CMException(exMessage, ex);
            }
        }

        /*
         * Taverna distro for MAC contains info.plist file with some Java
         * system properties set to use the Keychain which clashes with what
         * we are setting here so we need to clear them
         */
        System.clearProperty(PROPERTY_KEYSTORE_TYPE);
        System.clearProperty(PROPERTY_KEYSTORE_PROVIDER);

        /*
         * Not quite sure why we still need to set these two properties
         * since we are creating our own SSLSocketFactory with our own
         * KeyManager that uses Taverna's Keystore, but seem like after
         * Taverna starts up and the first time it needs SSLSocketFactory
         * for HTTPS connection it is still using the default Java's
         * keystore unless these properties are set. Set the system property
         * "javax.net.ssl.keystore" to use Taverna's keystore.
         *
         * Axis 1 likes reading from these properties but seems to work as
         * well with Taverna's SSLSocetFactory as well. We do not want to
         * expose these as they can be read from Beanshells.
         */
        // System.setProperty(PROPERTY_KEYSTORE, keystoreFile.getAbsolutePath());
        // System.setProperty(PROPERTY_KEYSTORE_PASSWORD, masterPassword);
        System.clearProperty(PROPERTY_KEYSTORE);
        System.clearProperty(PROPERTY_KEYSTORE_PASSWORD);
    }
}

From source file:org.jahia.bin.listeners.JahiaContextLoaderListener.java

private static void removeAddedSystemProperties() {
    try {/*from  w  ww  .j av a 2s . com*/
        for (String key : addedSystemProperties) {
            System.clearProperty(key);
        }
    } finally {
        addedSystemProperties.clear();
    }
}

From source file:org.apache.hadoop.registry.client.impl.zk.RegistrySecurity.java

/**
 * Reset any system properties related to JAAS
 *///from   w  w  w .j ava  2  s  . co  m
public static void clearJaasSystemProperties() {
    System.clearProperty(Environment.JAAS_CONF_KEY);
}

From source file:org.nuxeo.launcher.config.ConfigurationGeneratorTest.java

protected void runJVMCheck(boolean fail, Runnable runnable) {
    String old = System.getProperty(JVMCHECK_PROP);
    try {/*  w  w  w  .  ja  v  a 2s.  co m*/
        System.setProperty(JVMCHECK_PROP, fail ? JVMCHECK_FAIL : JVMCHECK_NOFAIL);
        runnable.run();
    } finally {
        if (old == null) {
            System.clearProperty(JVMCHECK_PROP);
        } else {
            System.setProperty(JVMCHECK_PROP, old);
        }
    }
}

From source file:com.seleniumtests.it.reporter.TestSeleniumTestsReporter2.java

@Test(groups = { "it" })
public void testAttachmentRenamingWithOptimizeReports() throws Exception {
    try {//  w ww.ja  v  a 2 s .  co m
        System.setProperty("optimizeReports", "true");
        executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClass" },
                ParallelMode.METHODS, new String[] { "testAndSubActions", "testInError", "testWithException" });
    } finally {
        System.clearProperty("optimizeReports");
    }

    // check that with error, remaining steps are skipped
    String detailedReportContent1 = readTestMethodResultFile("testAndSubActions");
    Assert.assertTrue(detailedReportContent1
            .contains(" | <a href='screenshot/testAndSubActions_1-1_step_1-img_with_very_very_ve.png'"));
    Assert.assertTrue(detailedReportContent1.contains(
            " | <a href='htmls/testAndSubActions_1-1_step_1-html_with_very_very_v.html.zip' target=html>"));

    // check file has been moved
    Assert.assertTrue(
            Paths.get(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory(), "testAndSubActions",
                    "htmls", "testAndSubActions_1-1_step_1-html_with_very_very_v.html.zip").toFile().exists());
    Assert.assertFalse(
            Paths.get(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory(), "testAndSubActions",
                    "htmls", "testAndSubActions_1-1_step_1-html_with_very_very_v.html").toFile().exists());
}