Example usage for java.lang Exception Exception

List of usage examples for java.lang Exception Exception

Introduction

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

Prototype

public Exception(Throwable cause) 

Source Link

Document

Constructs a new exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:com.hpe.nv.samples.advanced.AdvMultipleTestsSequential.java

public static void main(String[] args) throws Exception {
    try {/* w w  w  .  j  ava  2  s  .c o  m*/
        // program arguments
        Options options = new Options();
        options.addOption("i", "server-ip", true, "[mandatory] NV Test Manager IP");
        options.addOption("o", "server-port", true, "[mandatory] NV Test Manager port");
        options.addOption("u", "username", true, "[mandatory] NV username");
        options.addOption("w", "password", true, "[mandatory] NV password");
        options.addOption("e", "ssl", true, "[optional] Pass true to use SSL. Default: false");
        options.addOption("y", "proxy", true, "[optional] Proxy server host:port");
        options.addOption("t", "site-url", true,
                "[optional] Site under test URL. Default: HPE Network Virtualization site URL. If you change this value, make sure to change the --xpath argument too");
        options.addOption("x", "xpath", true,
                "[optional] Parameter for ExpectedConditions.visibilityOfElementLocated(By.xpath(...)) method. Use an xpath expression of some element in the site. Default: //div[@id='content']");
        options.addOption("a", "active-adapter-ip", true,
                "[optional] Active adapter IP. Default: --server-ip argument");
        options.addOption("f", "first-zip-result-file-path", true,
                "[optional] File path to store the first test analysis results as a .zip file");
        options.addOption("s", "second-zip-result-file-path", true,
                "[optional] File path to store the second test analysis results as a .zip file");
        options.addOption("k", "analysis-ports", true,
                "[optional] A comma-separated list of ports for test analysis");
        options.addOption("b", "browser", true,
                "[optional] The browser for which the Selenium WebDriver is built. Possible values: Chrome and Firefox. Default: Firefox");
        options.addOption("d", "debug", true,
                "[optional] Pass true to view console debug messages during execution. Default: false");
        options.addOption("h", "help", false, "[optional] Generates and prints help information");

        // parse and validate the command line arguments
        CommandLineParser parser = new DefaultParser();
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("help")) {
            // print help if help argument is passed
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("AdvMultipleTestsSequential.java", options);
            return;
        }

        if (line.hasOption("server-ip")) {
            serverIp = line.getOptionValue("server-ip");
            if (serverIp.equals("0.0.0.0")) {
                throw new Exception(
                        "Please replace the server IP argument value (0.0.0.0) with your NV Test Manager IP");
            }
        } else {
            throw new Exception("Missing argument -i/--server-ip <serverIp>");
        }

        if (line.hasOption("server-port")) {
            serverPort = Integer.parseInt(line.getOptionValue("server-port"));
        } else {
            throw new Exception("Missing argument -o/--server-port <serverPort>");
        }

        if (line.hasOption("username")) {
            username = line.getOptionValue("username");
        } else {
            throw new Exception("Missing argument -u/--username <username>");
        }

        if (line.hasOption("password")) {
            password = line.getOptionValue("password");
        } else {
            throw new Exception("Missing argument -w/--password <password>");
        }

        if (line.hasOption("ssl")) {
            ssl = Boolean.parseBoolean(line.getOptionValue("ssl"));
        }

        if (line.hasOption("site-url")) {
            siteUrl = line.getOptionValue("site-url");
        } else {
            siteUrl = "http://www8.hp.com/us/en/software-solutions/network-virtualization/index.html";
        }

        if (line.hasOption("xpath")) {
            xpath = line.getOptionValue("xpath");
        } else {
            xpath = "//div[@id='content']";
        }

        if (line.hasOption("first-zip-result-file-path")) {
            firstZipResultFilePath = line.getOptionValue("first-zip-result-file-path");
        }

        if (line.hasOption("second-zip-result-file-path")) {
            secondZipResultFilePath = line.getOptionValue("second-zip-result-file-path");
        }

        if (line.hasOption("proxy")) {
            proxySetting = line.getOptionValue("proxy");
        }

        if (line.hasOption("active-adapter-ip")) {
            activeAdapterIp = line.getOptionValue("active-adapter-ip");
        } else {
            activeAdapterIp = serverIp;
        }

        if (line.hasOption("analysis-ports")) {
            String analysisPortsStr = line.getOptionValue("analysis-ports");
            analysisPorts = analysisPortsStr.split(",");
        } else {
            analysisPorts = new String[] { "80", "8080" };
        }

        if (line.hasOption("browser")) {
            browser = line.getOptionValue("browser");
        } else {
            browser = "Firefox";
        }

        if (line.hasOption("debug")) {
            debug = Boolean.parseBoolean(line.getOptionValue("debug"));
        }

        String newLine = System.getProperty("line.separator");
        String testDescription = "***   This sample shows how to run several tests sequentially with different network scenarios.       ***"
                + newLine
                + "***                                                                                                   ***"
                + newLine
                + "***   You can view the actual steps of this sample in the AdvMultipleTestsSequential.java file.       ***"
                + newLine;

        // print the sample's description
        System.out.println(testDescription);

        // start console spinner
        if (!debug) {
            spinner = new Thread(new Spinner());
            spinner.start();
        }

        // sample execution steps
        /*****    Part 1 - Initialize the TestManager object and set the active adapter                                                 *****/
        printPartDescription(
                "\b------    Part 1 - Initialize the TestManager object and set the active adapter");
        initTestManager();
        setActiveAdapter();
        printPartSeparator();
        /*****    Part 2 - Start the first NV test with the "3G Busy" network scenario and run the "Home Page" transaction              *****/
        printPartDescription(
                "------    Part 2 - Start the first NV test with the \"3G Busy\" network scenario and run the \"Home Page\" transaction");
        startTest("3G Busy");
        testRunning = true;
        connectToTransactionManager();
        startTransaction();
        transactionInProgress = true;
        buildSeleniumWebDriver();
        seleniumNavigateToPage();
        stopTransaction();
        transactionInProgress = false;
        driverCloseAndQuit();
        printPartSeparator();
        /*****    Part 3 - Stop the first NV test, analyze it and print the results to the console                                      *****/
        printPartDescription(
                "------    Part 3 - Stop the first NV test, analyze it and print the results to the console");
        stopTest();
        testRunning = false;
        analyzeTest();
        printPartSeparator();
        /*****    Part 4 - Start the second NV test with the "3G Good" network scenario and run the "Home Page" transaction                                                                                                                 *****/
        printPartDescription(
                "------    Part 4 - Start the second NV test with the \"3G Good\" network scenario and run the \"Home Page\" transaction");
        startTest("3G Good");
        testRunning = true;
        connectToTransactionManager();
        startTransaction();
        transactionInProgress = true;
        buildSeleniumWebDriver();
        seleniumNavigateToPage();
        stopTransaction();
        transactionInProgress = false;
        driverCloseAndQuit();
        printPartSeparator();
        /*****    Part 5 - Stop the second NV test, analyze it and print the results to the console                                      *****/
        printPartDescription(
                "------    Part 3 - Stop the second NV test, analyze it and print the results to the console");
        stopTest();
        testRunning = false;
        analyzeTest();
        printPartSeparator();
        doneCallback();

    } catch (Exception e) {
        try {
            handleError(e.getMessage());
        } catch (Exception e2) {
            System.out.println("Error occurred: " + e2.getMessage());
        }
    }
}

From source file:com.hpe.nv.samples.advanced.AdvRealtimeUpdate.java

public static void main(String[] args) throws Exception {
    try {//from   w  ww  . jav  a 2 s  .co  m
        // program arguments
        Options options = new Options();
        options.addOption("i", "server-ip", true, "[mandatory] NV Test Manager IP");
        options.addOption("o", "server-port", true, "[mandatory] NV Test Manager port");
        options.addOption("u", "username", true, "[mandatory] NV username");
        options.addOption("w", "password", true, "[mandatory] NV password");
        options.addOption("e", "ssl", true, "[optional] Pass true to use SSL. Default: false");
        options.addOption("y", "proxy", true, "[optional] Proxy server host:port");
        options.addOption("t", "site-url", true,
                "[optional] Site under test URL. Default: HPE Network Virtualization site URL. If you change this value, make sure to change the --xpath argument too");
        options.addOption("x", "xpath", true,
                "[optional] Parameter for ExpectedConditions.visibilityOfElementLocated(By.xpath(...)) method. Use an xpath expression of some element in the site. Default: //div[@id='content']");
        options.addOption("a", "active-adapter-ip", true,
                "[optional] Active adapter IP. Default: --server-ip argument");
        options.addOption("n", "ntx-file-path", true,
                "[optional] File path (of an .ntx or .ntxx file) to update the test in ntx mode");
        options.addOption("z", "zip-result-file-path", true,
                "[optional] File path to store the analysis results as a .zip file");
        options.addOption("k", "analysis-ports", true,
                "[optional] A comma-separated list of ports for test analysis");
        options.addOption("b", "browser", true,
                "[optional] The browser for which the Selenium WebDriver is built. Possible values: Chrome and Firefox. Default: Firefox");
        options.addOption("d", "debug", true,
                "[optional] Pass true to view console debug messages during execution. Default: false");
        options.addOption("h", "help", false, "[optional] Generates and prints help information");

        // parse and validate the command line arguments
        CommandLineParser parser = new DefaultParser();
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("help")) {
            // print help if help argument is passed
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("AdvRealtimeUpdate.java", options);
            return;
        }

        if (line.hasOption("server-ip")) {
            serverIp = line.getOptionValue("server-ip");
            if (serverIp.equals("0.0.0.0")) {
                throw new Exception(
                        "Please replace the server IP argument value (0.0.0.0) with your NV Test Manager IP");
            }
        } else {
            throw new Exception("Missing argument -i/--server-ip <serverIp>");
        }

        if (line.hasOption("server-port")) {
            serverPort = Integer.parseInt(line.getOptionValue("server-port"));
        } else {
            throw new Exception("Missing argument -o/--server-port <serverPort>");
        }

        if (line.hasOption("username")) {
            username = line.getOptionValue("username");
        } else {
            throw new Exception("Missing argument -u/--username <username>");
        }

        if (line.hasOption("password")) {
            password = line.getOptionValue("password");
        } else {
            throw new Exception("Missing argument -w/--password <password>");
        }

        if (line.hasOption("ssl")) {
            ssl = Boolean.parseBoolean(line.getOptionValue("ssl"));
        }

        if (line.hasOption("zip-result-file-path")) {
            zipResultFilePath = line.getOptionValue("zip-result-file-path");
        }

        if (line.hasOption("site-url")) {
            siteUrl = line.getOptionValue("site-url");
        } else {
            siteUrl = "http://www8.hp.com/us/en/software-solutions/network-virtualization/index.html";
        }

        if (line.hasOption("xpath")) {
            xpath = line.getOptionValue("xpath");
        } else {
            xpath = "//div[@id='content']";
        }

        if (line.hasOption("proxy")) {
            proxySetting = line.getOptionValue("proxy");
        }

        if (line.hasOption("active-adapter-ip")) {
            activeAdapterIp = line.getOptionValue("active-adapter-ip");
        } else {
            activeAdapterIp = serverIp;
        }

        if (line.hasOption("analysis-ports")) {
            String analysisPortsStr = line.getOptionValue("analysis-ports");
            analysisPorts = analysisPortsStr.split(",");
        } else {
            analysisPorts = new String[] { "80", "8080" };
        }

        if (line.hasOption("ntx-file-path")) {
            ntxFilePath = line.getOptionValue("ntx-file-path");
        }

        if (line.hasOption("browser")) {
            browser = line.getOptionValue("browser");
        } else {
            browser = "Firefox";
        }

        if (line.hasOption("debug")) {
            debug = Boolean.parseBoolean(line.getOptionValue("debug"));
        }

        String newLine = System.getProperty("line.separator");
        String testDescription = "***   This sample demonstrates the real-time update API. You can use this API to update the test during runtime.                ***"
                + newLine
                + "***   For example, you can update the network scenario to run several \"mini tests\" in a single test.                            ***"
                + newLine
                + "***                                                                                                                             ***"
                + newLine
                + "***   This sample starts by running an NV test with a single transaction that uses the \"3G Busy\" network scenario. Then the     ***"
                + newLine
                + "***   sample updates the network scenario to \"3G Good\" and reruns the transaction. You can update the test in real time         ***"
                + newLine
                + "***   using either the NTX or Custom real-time update modes.                                                                    ***"
                + newLine
                + "***                                                                                                                             ***"
                + newLine
                + "***   You can view the actual steps of this sample in the AdvRealtimeUpdate.java file.                                          ***"
                + newLine;

        // print the sample's description
        System.out.println(testDescription);

        // start console spinner
        if (!debug) {
            spinner = new Thread(new Spinner());
            spinner.start();
        }

        // sample execution steps
        /*****    Part 1 - Navigate to the site with the NV "3G Busy" network scenario                                                                      *****/
        printPartDescription(
                "\b------    Part 1 - Navigate to the site with the NV \"3G Busy\" network scenario");
        initTestManager();
        setActiveAdapter();
        startBusyTest();
        testRunning = true;
        connectToTransactionManager();
        startTransaction();
        transactionInProgress = true;
        buildSeleniumWebDriver();
        seleniumNavigateToPage();
        stopTransaction();
        transactionInProgress = false;
        driverCloseAndQuit();
        printPartSeparator();
        /*****    Part 2 - Update the NV test in real-time---update the network scenario to "3G Good"                                                       *****/
        printPartDescription(
                "------    Part 2 - Update the NV test in real time to the \"3G Good\" network scenario");
        realTimeUpdateTest();
        printPartSeparator();
        /*****    Part 3 - Navigate to the site with the NV \"3G Good\" network scenario                                                                    *****/
        printPartDescription(
                "------    Part 3 - Navigate to the site with the NV \"3G Good\" network scenario");
        startTransactionAfterRTU();
        transactionInProgress = true;
        buildSeleniumWebDriver();
        seleniumNavigateToPage();
        stopTransaction();
        transactionInProgress = false;
        driverCloseAndQuit();
        printPartSeparator();
        /*****    Part 4 - Stop the NV test, analyze it and print the results to the console                                                                *****/
        printPartDescription(
                "------    Part 4 - Stop the NV test, analyze it and print the results to the console");
        stopTest();
        testRunning = false;
        analyzeTest();
        printPartSeparator();
        doneCallback();

    } catch (Exception e) {
        try {
            handleError(e.getMessage());
        } catch (Exception e2) {
            System.out.println("Error occurred: " + e2.getMessage());
        }
    }
}

From source file:edu.msu.cme.rdp.readseq.utils.ResampleSeqFile.java

public static void main(String[] args) throws IOException {
    int numOfSelection = 0;
    int subregion_length = 0;

    try {//ww  w .ja  v a  2  s  . co m
        CommandLine line = new PosixParser().parse(options, args);
        if (line.hasOption("num-selection")) {
            numOfSelection = Integer.parseInt(line.getOptionValue("num-selection"));
            if (numOfSelection < 1) {
                throw new Exception("num-selection should be at least 1");
            }
        }
        if (line.hasOption("subregion_length")) {
            subregion_length = Integer.parseInt(line.getOptionValue("subregion_length"));
            if (subregion_length < 1) {
                throw new Exception("subregion_length should be at least 1");
            }
        }

        args = line.getArgs();
        if (args.length != 2) {
            throw new Exception("Incorrect number of command line arguments");
        }
        ResampleSeqFile.select(args[0], args[1], numOfSelection, subregion_length);
    } catch (Exception e) {
        new HelpFormatter().printHelp(120, "ResampleSeqFile [options] <infile(dir)> <outdir>", "", options, "");
        System.out.println("ERROR: " + e.getMessage());
        return;
    }
}

From source file:com.example.geomesa.kafka.KafkaLoadTester.java

public static void main(String[] args) throws Exception {
    // read command line args for a connection to Kafka
    CommandLineParser parser = new BasicParser();
    Options options = getCommonRequiredOptions();
    CommandLine cmd = parser.parse(options, args);
    String visibility = getVisibility(cmd);
    Integer delay = getDelay(cmd);

    if (visibility == null) {
        System.out.println("visibility: null");
    } else {// w w  w  .j a  v a 2  s . c  om
        System.out.println("visibility: '" + visibility + "'");
    }

    // create the producer and consumer KafkaDataStore objects
    Map<String, String> dsConf = getKafkaDataStoreConf(cmd);
    System.out.println("KDS config: " + dsConf);
    dsConf.put("kafka.consumer.count", "0");
    DataStore producerDS = DataStoreFinder.getDataStore(dsConf);
    dsConf.put("kafka.consumer.count", "1");
    DataStore consumerDS = DataStoreFinder.getDataStore(dsConf);

    // verify that we got back our KafkaDataStore objects properly
    if (producerDS == null) {
        throw new Exception("Null producer KafkaDataStore");
    }
    if (consumerDS == null) {
        throw new Exception("Null consumer KafkaDataStore");
    }

    try {
        // create the schema which creates a topic in Kafka
        // (only needs to be done once)
        final String sftName = "KafkaStressTest";
        final String sftSchema = "name:String,age:Int,step:Double,lat:Double,dtg:Date,*geom:Point:srid=4326";
        SimpleFeatureType sft = SimpleFeatureTypes.createType(sftName, sftSchema);
        producerDS.createSchema(sft);

        System.out.println("Register KafkaDataStore in GeoServer (Press enter to continue)");
        System.in.read();

        // the live consumer must be created before the producer writes features
        // in order to read streaming data.
        // i.e. the live consumer will only read data written after its instantiation
        SimpleFeatureStore producerFS = (SimpleFeatureStore) producerDS.getFeatureSource(sftName);
        SimpleFeatureSource consumerFS = consumerDS.getFeatureSource(sftName);

        // creates and adds SimpleFeatures to the producer every 1/5th of a second
        System.out.println("Writing features to Kafka... refresh GeoServer layer preview to see changes");

        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(sft);

        Integer numFeats = getLoad(cmd);

        System.out.println("Building a list of " + numFeats + " SimpleFeatures.");
        List<SimpleFeature> features = IntStream.range(1, numFeats)
                .mapToObj(i -> createFeature(builder, i, visibility)).collect(Collectors.toList());

        // set variables to estimate feature production rate
        Long startTime = null;
        Long featuresSinceStartTime = 0L;
        int cycle = 0;
        int cyclesToSkip = 50000 / numFeats; // collect enough features
                                             // to get an accurate rate estimate

        while (true) {
            // write features
            features.forEach(feat -> {
                try {
                    DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
                    featureCollection.add(feat);
                    producerFS.addFeatures(featureCollection);
                } catch (Exception e) {
                    System.out.println("Caught an exception while writing features.");
                    e.printStackTrace();
                }
                updateFeature(feat);
            });

            // count features written
            Integer consumerSize = consumerFS.getFeatures().size();
            cycle++;
            featuresSinceStartTime += consumerSize;
            System.out.println("At " + new Date() + " wrote " + consumerSize + " features");

            // if we've collected enough features, calculate the rate
            if (cycle >= cyclesToSkip || startTime == null) {
                Long endTime = System.currentTimeMillis();
                if (startTime != null) {
                    Long diffTime = endTime - startTime;
                    Double rate = (featuresSinceStartTime.doubleValue() * 1000.0) / diffTime.doubleValue();
                    System.out.printf("%.1f feats/sec (%d/%d)\n", rate, featuresSinceStartTime, diffTime);
                }
                cycle = 0;
                startTime = endTime;
                featuresSinceStartTime = 0L;
            }

            // sleep before next write
            if (delay != null) {
                System.out.printf("Sleeping for %d ms\n", delay);
                Thread.sleep(delay);
            }
        }

    } finally {
        producerDS.dispose();
        consumerDS.dispose();
    }
}

From source file:com.hpe.nv.samples.basic.BasicAnalyze2Scenarios.java

public static void main(String[] args) {
    try {/*w  w  w.j  a v a  2s.  com*/
        // program arguments
        Options options = new Options();
        options.addOption("i", "server-ip", true, "[mandatory] NV Test Manager IP");
        options.addOption("o", "server-port", true, "[mandatory] NV Test Manager port");
        options.addOption("u", "username", true, "[mandatory] NV username");
        options.addOption("w", "password", true, "[mandatory] NV password");
        options.addOption("e", "ssl", true, "[optional] Pass true to use SSL. Default: false");
        options.addOption("y", "proxy", true, "[optional] Proxy server host:port");
        options.addOption("a", "active-adapter-ip", true,
                "[optional] Active adapter IP. Default: --server-ip argument");
        options.addOption("z", "zip-result-file-path", true,
                "[optional] File path to store the analysis results as a .zip file");
        options.addOption("k", "analysis-ports", true,
                "[optional] A comma-separated list of ports for test analysis");
        options.addOption("b", "browser", true,
                "[optional] The browser for which the Selenium WebDriver is built. Possible values: Chrome and Firefox. Default: Firefox");
        options.addOption("d", "debug", true,
                "[optional] Pass true to view console debug messages during execution. Default: false");
        options.addOption("h", "help", false, "[optional] Generates and prints help information");

        // parse and validate the command line arguments
        CommandLineParser parser = new DefaultParser();
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("help")) {
            // print help if help argument is passed
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("BasicAnalyze2Scenarios.java", options);
            return;
        }

        if (line.hasOption("server-ip")) {
            serverIp = line.getOptionValue("server-ip");
            if (serverIp.equals("0.0.0.0")) {
                throw new Exception(
                        "Please replace the server IP argument value (0.0.0.0) with your NV Test Manager IP");
            }
        } else {
            throw new Exception("Missing argument -i/--server-ip <serverIp>");
        }

        if (line.hasOption("server-port")) {
            serverPort = Integer.parseInt(line.getOptionValue("server-port"));
        } else {
            throw new Exception("Missing argument -o/--server-port <serverPort>");
        }

        if (line.hasOption("username")) {
            username = line.getOptionValue("username");
        } else {
            throw new Exception("Missing argument -u/--username <username>");
        }

        if (line.hasOption("password")) {
            password = line.getOptionValue("password");
        } else {
            throw new Exception("Missing argument -w/--password <password>");
        }

        if (line.hasOption("ssl")) {
            ssl = Boolean.parseBoolean(line.getOptionValue("ssl"));
        }

        if (line.hasOption("zip-result-file-path")) {
            zipResultFilePath = line.getOptionValue("zip-result-file-path");
        }

        if (line.hasOption("proxy")) {
            proxySetting = line.getOptionValue("proxy");
        }

        if (line.hasOption("active-adapter-ip")) {
            activeAdapterIp = line.getOptionValue("active-adapter-ip");
        } else {
            activeAdapterIp = serverIp;
        }

        if (line.hasOption("analysis-ports")) {
            String analysisPortsStr = line.getOptionValue("analysis-ports");
            analysisPorts = analysisPortsStr.split(",");
        } else {
            analysisPorts = new String[] { "80", "8080" };
        }

        if (line.hasOption("browser")) {
            browser = line.getOptionValue("browser");
        } else {
            browser = "Firefox";
        }

        if (line.hasOption("debug")) {
            debug = Boolean.parseBoolean(line.getOptionValue("debug"));
        }

        String newLine = System.getProperty("line.separator");
        String testDescription = "***   This sample demonstrates a comparison between two network scenarios - \"WiFi\" and \"3G Busy\".                                 ***"
                + newLine
                + "***                                                                                                                               ***"
                + newLine
                + "***   In this sample, the NV test starts with the \"WiFi\" network scenario, running three transactions (see below).                ***"
                + newLine
                + "***   Then, the sample updates the NV test's network scenario to \"3G Busy\" using the real-time update API and runs the same       ***"
                + newLine
                + "***   transactions again.                                                                                                         ***"
                + newLine
                + "***                                                                                                                               ***"
                + newLine
                + "***   After the sample analyzes the NV test and extracts the transaction times from the analysis results, it prints a             ***"
                + newLine
                + "***   summary to the console. The summary displays the comparative network times for each transaction in both                     ***"
                + newLine
                + "***   network scenarios.                                                                                                          ***"
                + newLine
                + "***                                                                                                                               ***"
                + newLine
                + "***   This sample runs three identical NV transactions before and after the real-time update:                                     ***"
                + newLine
                + "***   1. \"Home Page\" transaction: Navigates to the home page in the HPE Network Virtualization website                            ***"
                + newLine
                + "***   2. \"Get Started\" transaction: Navigates to the Get Started Now page in the HPE Network Virtualization website               ***"
                + newLine
                + "***   3. \"Overview\" transaction: Navigates back to the home page in the HPE Network Virtualization website                        ***"
                + newLine
                + "***                                                                                                                               ***"
                + newLine
                + "***   You can view the actual steps of this sample in the BasicAnalyze2Scenarios.java file.                                       ***"
                + newLine;

        // print the sample's description
        System.out.println(testDescription);

        // start console spinner
        if (!debug) {
            spinner = new Thread(new Spinner());
            spinner.start();
        }

        // sample execution steps
        /*****    Part 1 - Start the NV test with the "WiFi" network scenario                                                                      *****/
        printPartDescription("\b------    Part 1 - Start the NV test with the \"WiFi\" network scenario");
        initTestManager();
        setActiveAdapter();
        startTest();
        testRunning = true;
        printPartSeparator();
        /*****    Part 2 - Run three transactions - "Home Page", "Get Started" and "Overview"                                                      *****/
        printPartDescription(
                "------    Part 2 - Run three transactions - \"Home Page\", \"Get Started\" and \"Overview\"");
        connectToTransactionManager();
        startTransaction(1);
        transactionInProgress = true;
        buildSeleniumWebDriver();
        seleniumNavigateToPage();
        stopTransaction(1);
        transactionInProgress = false;
        startTransaction(2);
        transactionInProgress = true;
        seleniumGetStartedClick();
        stopTransaction(2);
        transactionInProgress = false;
        startTransaction(3);
        transactionInProgress = true;
        seleniumOverviewClick();
        stopTransaction(3);
        transactionInProgress = false;
        driverCloseAndQuit();
        printPartSeparator();
        /*****    Part 3 - Update the NV test in real time to the "3G Busy" network scenario                                                     *****/
        printPartDescription(
                "------    Part 3 - Update the NV test in real time to the \"3G Busy\" network scenario");
        realTimeUpdateTest();
        printPartSeparator();
        /*****    Part 4 - Rerun the transactions                                                                                                *****/
        printPartDescription("------    Part 4 - Rerun the transactions");
        startTransactionAfterRTU(1);
        transactionInProgress = true;
        buildSeleniumWebDriver();
        seleniumNavigateToPage();
        stopTransaction(1);
        transactionInProgress = false;
        startTransactionAfterRTU(2);
        transactionInProgress = true;
        seleniumGetStartedClick();
        stopTransaction(2);
        transactionInProgress = false;
        startTransactionAfterRTU(3);
        transactionInProgress = true;
        seleniumOverviewClick();
        stopTransaction(3);
        transactionInProgress = false;
        driverCloseAndQuit();
        printPartSeparator();
        /*****    Part 5 - Stop the NV test, analyze it and print the results to the console                                                                *****/
        printPartDescription(
                "------    Part 5 - Stop the NV test, analyze it and print the results to the console");
        stopTest();
        testRunning = false;
        analyzeTestZip();
        analyzeTestJson();
        printPartSeparator();
        doneCallback();
    } catch (Exception e) {
        try {
            handleError(e.getMessage());
        } catch (Exception e2) {
            System.out.println("Error occurred: " + e2.getMessage());
        }
    }
}

From source file:com.netscape.cmstools.OCSPClient.java

public static void main(String args[]) throws Exception {

    Options options = createOptions();//from ww w  . j a va2s  . c  o m
    CommandLine cmd = null;

    try {
        CommandLineParser parser = new PosixParser();
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        printError(e);
        System.exit(1);
    }

    if (cmd.hasOption("help")) {
        printHelp();
        System.exit(0);
    }

    boolean verbose = cmd.hasOption("v");

    String databaseDir = cmd.getOptionValue("d", ".");
    String hostname = cmd.getOptionValue("h", InetAddress.getLocalHost().getCanonicalHostName());
    int port = Integer.parseInt(cmd.getOptionValue("p", "8080"));
    String path = cmd.getOptionValue("t", "/ocsp/ee/ocsp");
    String caNickname = cmd.getOptionValue("c", "CA Signing Certificate");
    int times = Integer.parseInt(cmd.getOptionValue("n", "1"));

    String input = cmd.getOptionValue("input");
    String serial = cmd.getOptionValue("serial");
    String output = cmd.getOptionValue("output");

    if (times < 1) {
        printError("Invalid number of submissions");
        System.exit(1);
    }

    try {
        if (verbose)
            System.out.println("Initializing security database");
        CryptoManager.initialize(databaseDir);

        String url = "http://" + hostname + ":" + port + path;

        OCSPProcessor processor = new OCSPProcessor();
        processor.setVerbose(verbose);

        OCSPRequest request;
        if (serial != null) {
            if (verbose)
                System.out.println("Creating request for serial number " + serial);

            BigInteger serialNumber = new BigInteger(serial);
            request = processor.createRequest(caNickname, serialNumber);

        } else if (input != null) {
            if (verbose)
                System.out.println("Loading request from " + input);

            try (FileInputStream in = new FileInputStream(input)) {
                byte[] data = new byte[in.available()];
                in.read(data);
                request = processor.createRequest(data);
            }

        } else {
            throw new Exception("Missing serial number or input file.");
        }

        OCSPResponse response = null;
        for (int i = 0; i < times; i++) {

            if (verbose)
                System.out.println("Submitting OCSP request");
            response = processor.submitRequest(url, request);

            ResponseBytes bytes = response.getResponseBytes();
            BasicOCSPResponse basic = (BasicOCSPResponse) BasicOCSPResponse.getTemplate()
                    .decode(new ByteArrayInputStream(bytes.getResponse().toByteArray()));

            ResponseData rd = basic.getResponseData();
            for (int j = 0; j < rd.getResponseCount(); j++) {
                SingleResponse sr = rd.getResponseAt(j);

                if (sr == null) {
                    throw new Exception("No OCSP Response data.");
                }

                System.out.println("CertID.serialNumber=" + sr.getCertID().getSerialNumber());

                CertStatus status = sr.getCertStatus();
                if (status instanceof GoodInfo) {
                    System.out.println("CertStatus=Good");

                } else if (status instanceof UnknownInfo) {
                    System.out.println("CertStatus=Unknown");

                } else if (status instanceof RevokedInfo) {
                    System.out.println("CertStatus=Revoked");
                }
            }
        }

        if (output != null) {
            if (verbose)
                System.out.println("Storing response into " + output);

            try (FileOutputStream out = new FileOutputStream(output)) {
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                response.encode(os);
                out.write(os.toByteArray());
            }

            System.out.println("Success: Output " + output);
        }

    } catch (Exception e) {
        if (verbose)
            e.printStackTrace();
        printError(e);
        System.exit(1);
    }
}

From source file:com.jgaap.backend.CLI.java

/**
 * Parses the arguments passed to jgaap from the command line. Will either
 * display the help or run jgaap on an experiment.
 * //from w w  w. j  a va2  s.c o m
 * @param args
 *            command line arguments
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    CommandLineParser parser = new GnuParser();
    CommandLine cmd = parser.parse(options, args);
    if (cmd.hasOption('h')) {
        String command = cmd.getOptionValue('h');
        if (command == null) {
            HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.setLeftPadding(5);
            helpFormatter.setWidth(100);
            helpFormatter.printHelp(
                    "jgaap -c [canon canon ...] -es [event] -ec [culler culler ...] -a [analysis] <-d [distance]> -l [file] <-s [file]>",
                    "Welcome to JGAAP the Java Graphical Authorship Attribution Program.\nMore information can be found at http://jgaap.com",
                    options, "Copyright 2013 Evaluating Variation in Language Lab, Duquesne University");
        } else {
            List<Displayable> list = new ArrayList<Displayable>();
            if (command.equalsIgnoreCase("c")) {
                list.addAll(Canonicizers.getCanonicizers());
            } else if (command.equalsIgnoreCase("es")) {
                list.addAll(EventDrivers.getEventDrivers());
            } else if (command.equalsIgnoreCase("ec")) {
                list.addAll(EventCullers.getEventCullers());
            } else if (command.equalsIgnoreCase("a")) {
                list.addAll(AnalysisDrivers.getAnalysisDrivers());
            } else if (command.equalsIgnoreCase("d")) {
                list.addAll(DistanceFunctions.getDistanceFunctions());
            } else if (command.equalsIgnoreCase("lang")) {
                list.addAll(Languages.getLanguages());
            }
            for (Displayable display : list) {
                if (display.showInGUI())
                    System.out.println(display.displayName() + " - " + display.tooltipText());
            }
            if (list.isEmpty()) {
                System.out.println("Option " + command + " was not found.");
                System.out.println("Please use c, es, d, a, or lang");
            }
        }
    } else if (cmd.hasOption('v')) {
        System.out.println("Java Graphical Authorship Attribution Program version 5.2.0");
    } else if (cmd.hasOption("ee")) {
        String eeFile = cmd.getOptionValue("ee");
        String lang = cmd.getOptionValue("lang");
        ExperimentEngine.runExperiment(eeFile, lang);
        System.exit(0);
    } else {
        JGAAP.commandline = true;
        API api = API.getPrivateInstance();
        String documentsFilePath = cmd.getOptionValue('l');
        if (documentsFilePath == null) {
            throw new Exception("No Documents CSV specified");
        }
        List<Document> documents;
        if (documentsFilePath.startsWith(JGAAPConstants.JGAAP_RESOURCE_PACKAGE)) {
            documents = Utils.getDocumentsFromCSV(
                    CSVIO.readCSV(com.jgaap.JGAAP.class.getResourceAsStream(documentsFilePath)));
        } else {
            documents = Utils.getDocumentsFromCSV(CSVIO.readCSV(documentsFilePath));
        }
        for (Document document : documents) {
            api.addDocument(document);
        }
        String language = cmd.getOptionValue("lang", "english");
        api.setLanguage(language);
        String[] canonicizers = cmd.getOptionValues('c');
        if (canonicizers != null) {
            for (String canonicizer : canonicizers) {
                api.addCanonicizer(canonicizer);
            }
        }
        String[] events = cmd.getOptionValues("es");
        if (events == null) {
            throw new Exception("No EventDriver specified");
        }
        for (String event : events) {
            api.addEventDriver(event);
        }
        String[] eventCullers = cmd.getOptionValues("ec");
        if (eventCullers != null) {
            for (String eventCuller : eventCullers) {
                api.addEventCuller(eventCuller);
            }
        }
        String analysis = cmd.getOptionValue('a');
        if (analysis == null) {
            throw new Exception("No AnalysisDriver specified");
        }
        AnalysisDriver analysisDriver = api.addAnalysisDriver(analysis);
        String distanceFunction = cmd.getOptionValue('d');
        if (distanceFunction != null) {
            api.addDistanceFunction(distanceFunction, analysisDriver);
        }
        api.execute();
        List<Document> unknowns = api.getUnknownDocuments();
        OutputStreamWriter outputStreamWriter;
        String saveFile = cmd.getOptionValue('s');
        if (saveFile == null) {
            outputStreamWriter = new OutputStreamWriter(System.out);
        } else {
            outputStreamWriter = new OutputStreamWriter(new FileOutputStream(saveFile));
        }
        Writer writer = new BufferedWriter(outputStreamWriter);
        for (Document unknown : unknowns) {
            writer.append(unknown.getFormattedResult(analysisDriver));
        }
        writer.append('\n');
    }
}

From source file:com.hpe.nv.samples.advanced.AdvMultipleTestsConcurrent.java

public static void main(String[] args) throws Exception {
    try {//  w w  w . j  av a  2 s  . c  o  m
        // program arguments
        Options options = new Options();
        options.addOption("i", "server-ip", true, "[mandatory] NV Test Manager IP");
        options.addOption("o", "server-port", true, "[mandatory] NV Test Manager port");
        options.addOption("u", "username", true, "[mandatory] NV username");
        options.addOption("w", "password", true, "[mandatory] NV password");
        options.addOption("e", "ssl", true, "[optional] Pass true to use SSL. Default: false");
        options.addOption("y", "proxy", true, "[optional] Proxy server host:port");
        options.addOption("t", "site-url", true,
                "[optional] Site under test URL. Default: HPE Network Virtualization site URL. If you change this value, make sure to change the --xpath argument too");
        options.addOption("x", "xpath", true,
                "[optional] Parameter for ExpectedConditions.visibilityOfElementLocated(By.xpath(...)) method. Use an xpath expression of some element in the site. Default: //div[@id='content']");
        options.addOption("a", "active-adapter-ip", true,
                "[optional] Active adapter IP. Default: --server-ip argument");
        options.addOption("f", "first-zip-result-file-path", true,
                "[optional] [optional] File path to store the first test analysis results as a .zip file");
        options.addOption("s", "second-zip-result-file-path", true,
                "[optional] File path to store the second test analysis results as a .zip file");
        options.addOption("c", "first-test-flow-tcp-port", true,
                "[optional] TCP port to define in the flow of the first test");
        options.addOption("p", "second-test-flow-tcp-port", true,
                "[optional] TCP port to define in the flow of the second test");
        options.addOption("k", "analysis-ports", true,
                "[optional] A comma-separated list of ports for test analysis");
        options.addOption("b", "browser", true,
                "[optional] The browser for which the Selenium WebDriver is built. Possible values: Chrome and Firefox. Default: Firefox");
        options.addOption("d", "debug", true,
                "[optional] Pass true to view console debug messages during execution. Default: false");
        options.addOption("h", "help", false, "[optional] Generates and prints help information");

        // parse and validate the command line arguments
        CommandLineParser parser = new DefaultParser();
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("help")) {
            // print help if help argument is passed
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("AdvMultipleTestsConcurrent.java", options);
            return;
        }

        if (line.hasOption("server-ip")) {
            serverIp = line.getOptionValue("server-ip");
            if (serverIp.equals("0.0.0.0")) {
                throw new Exception(
                        "Please replace the server IP argument value (0.0.0.0) with your NV Test Manager IP");
            }
        } else {
            throw new Exception("Missing argument -i/--server-ip <serverIp>");
        }

        if (line.hasOption("server-port")) {
            serverPort = Integer.parseInt(line.getOptionValue("server-port"));
        } else {
            throw new Exception("Missing argument -o/--server-port <serverPort>");
        }

        if (line.hasOption("username")) {
            username = line.getOptionValue("username");
        } else {
            throw new Exception("Missing argument -u/--username <username>");
        }

        if (line.hasOption("password")) {
            password = line.getOptionValue("password");
        } else {
            throw new Exception("Missing argument -w/--password <password>");
        }

        if (line.hasOption("ssl")) {
            ssl = Boolean.parseBoolean(line.getOptionValue("ssl"));
        }

        if (line.hasOption("site-url")) {
            siteUrl = line.getOptionValue("site-url");
        } else {
            siteUrl = "http://www8.hp.com/us/en/software-solutions/network-virtualization/index.html";
        }

        if (line.hasOption("xpath")) {
            xpath = line.getOptionValue("xpath");
        } else {
            xpath = "//div[@id='content']";
        }

        if (line.hasOption("first-zip-result-file-path")) {
            firstZipResultFilePath = line.getOptionValue("first-zip-result-file-path");
        }

        if (line.hasOption("second-zip-result-file-path")) {
            secondZipResultFilePath = line.getOptionValue("second-zip-result-file-path");
        }

        if (line.hasOption("proxy")) {
            proxySetting = line.getOptionValue("proxy");
        }

        if (line.hasOption("active-adapter-ip")) {
            activeAdapterIp = line.getOptionValue("active-adapter-ip");
        } else {
            activeAdapterIp = serverIp;
        }

        if (line.hasOption("analysis-ports")) {
            String analysisPortsStr = line.getOptionValue("analysis-ports");
            analysisPorts = analysisPortsStr.split(",");
        } else {
            analysisPorts = new String[] { "80", "8080" };
        }

        if (line.hasOption("firstTestFlowTcpPort")) {
            firstTestFlowTcpPort = Integer.parseInt(line.getOptionValue("firstTestFlowTcpPort"));
        } else {
            firstTestFlowTcpPort = 8080;
        }

        if (line.hasOption("secondTestFlowTcpPort")) {
            secondTestFlowTcpPort = Integer.parseInt(line.getOptionValue("secondTestFlowTcpPort"));
        } else {
            secondTestFlowTcpPort = 80;
        }

        if (line.hasOption("browser")) {
            browser = line.getOptionValue("browser");
        } else {
            browser = "Firefox";
        }

        if (line.hasOption("debug")) {
            debug = Boolean.parseBoolean(line.getOptionValue("debug"));
        }

        String newLine = System.getProperty("line.separator");
        String testDescription = "***   This sample shows how to run several tests concurrently with different flow definitions.                              ***"
                + newLine
                + "***   When running NV tests in parallel, make sure that:                                                                    ***"
                + newLine
                + "***   * each test is configured to use multi-user mode                                                                      ***"
                + newLine
                + "***   * the include/exclude IP ranges in the tests' flows do not overlap - this ensures data separation between the tests   ***"
                + newLine
                + "***   * your NV Test Manager license supports multiple flows running in parallel                                            ***"
                + newLine
                + "***                                                                                                                         ***"
                + newLine
                + "***   You can view the actual steps of this sample in the AdvMultipleTestsConcurrent.java file.                             ***"
                + newLine;
        // print the sample's description
        System.out.println(testDescription);

        // start console spinner
        if (!debug) {
            spinner = new Thread(new Spinner());
            spinner.start();
        }

        // sample execution steps
        /*****    Part 1 - Initialize the TestManager object and set the active adapter                                     *****/
        printPartDescription(
                "\b------    Part 1 - Initialize the TestManager object and set the active adapter");
        initTestManager();
        setActiveAdapter();
        printPartSeparator();
        /*****    Part 2 - Start the first NV test with the flow "Flow1"                                                    *****/
        printPartDescription("------    Part 2 - Start the first NV test with flow \"Flow1\"");
        startTest("Flow1");
        testRunning = true;
        connectToTransactionManager("Flow1");
        printPartSeparator();
        /*****    Part 3 - Start the second NV test with the flow "Flow2"                                                   *****/
        printPartDescription("------    Part 3 - Start the second NV test with flow \"Flow2\"");
        startTest("Flow2");
        connectToTransactionManager("Flow2");
        printPartSeparator();
        /*****    Part 4 - Run the "Home Page" transactions in both tests                                                   *****/
        printPartDescription("------    Part 4 - Run the \"Home Page\" transactions in both tests");
        startTransaction("Flow1");
        flow1TransactionInProgress = true;
        startTransaction("Flow2");
        flow2TransactionInProgress = true;
        buildSeleniumWebDriver();
        seleniumNavigateToPage();
        stopTransaction("Flow1");
        flow1TransactionInProgress = false;
        stopTransaction("Flow2");
        flow2TransactionInProgress = false;
        printPartSeparator();
        /*****    Part 5 - Stop both tests, analyze them and print the results                                              *****/
        printPartDescription("------    Part 5 - Stop both tests, analyze them and print the results");
        stopTest("Flow1");
        stopTest("Flow2");
        testRunning = false;
        analyzeTest("Flow1");
        analyzeTest("Flow2");
        driverCloseAndQuit();
        printPartSeparator();
        doneCallback();

    } catch (Exception e) {
        try {
            handleError(e.getMessage());
        } catch (Exception e2) {
            System.out.println("Error occurred: " + e2.getMessage());
        }
    }
}

From source file:edu.msu.cme.rdp.graph.utils.ContigMerger.java

public static void main(String[] args) throws IOException {
    final BufferedReader hmmgsResultReader;
    final IndexedSeqReader nuclContigReader;
    final double minBits;
    final int minProtLength;
    final Options options = new Options();
    final PrintStream out;
    final ProfileHMM hmm;
    final FastaWriter protSeqOut;
    final FastaWriter nuclSeqOut;
    final boolean prot;
    final boolean all;
    final String shortSampleName;

    options.addOption("a", "all", false,
            "Generate all combinations for multiple paths, instead of just the best");
    options.addOption("b", "min-bits", true, "Minimum bits score");
    options.addOption("l", "min-length", true, "Minimum length");
    options.addOption("s", "short_samplename", true,
            "short sample name, to be used as part of contig identifiers. This allow analyzing contigs together from different samples in downstream analysis ");
    options.addOption("o", "out", true, "Write output to file instead of stdout");

    try {/*from   w  w  w. j av a 2 s. c  o m*/
        CommandLine line = new PosixParser().parse(options, args);

        if (line.hasOption("min-bits")) {
            minBits = Double.valueOf(line.getOptionValue("min-bits"));
        } else {
            minBits = Double.NEGATIVE_INFINITY;
        }

        if (line.hasOption("min-length")) {
            minProtLength = Integer.valueOf(line.getOptionValue("min-length"));
        } else {
            minProtLength = 0;
        }

        if (line.hasOption("short_samplename")) {
            shortSampleName = line.getOptionValue("short_samplename") + "_";
        } else {
            shortSampleName = "";
        }

        if (line.hasOption("out")) {
            out = new PrintStream(line.getOptionValue("out"));
        } else {
            out = System.err;
        }

        all = line.hasOption("all");

        args = line.getArgs();

        if (args.length != 3) {
            throw new Exception("Unexpected number of arguments");
        }

        hmmgsResultReader = new BufferedReader(new FileReader(new File(args[1])));
        nuclContigReader = new IndexedSeqReader(new File(args[2]));
        hmm = HMMER3bParser.readModel(new File(args[0]));

        prot = (hmm.getAlphabet() == SequenceType.Protein);

        if (prot) {
            protSeqOut = new FastaWriter(new File("prot_merged.fasta"));
        } else {
            protSeqOut = null;
        }
        nuclSeqOut = new FastaWriter(new File("nucl_merged.fasta"));

    } catch (Exception e) {
        new HelpFormatter().printHelp("USAGE: ContigMerger [options] <hmm> <hmmgs_file> <nucl_contig>",
                options);
        System.err.println("Error: " + e.getMessage());
        System.exit(1);
        throw new RuntimeException("I hate you javac");
    }

    String line;
    SearchDirection lastDir = SearchDirection.left; //So this has an assumption built in
    //It depends on hmmgs always outputting left fragments, then right
    //We can't just use the kmer to figure out if we've switched to another starting point
    //because we allow multiple starting model pos, so two different starting
    //positions can have the same starting kmer

    Map<String, Sequence> leftContigs = new HashMap();
    Map<String, Sequence> rightContigs = new HashMap();

    int contigsMerged = 0;
    int writtenMerges = 0;
    long startTime = System.currentTimeMillis();
    String kmer = null;
    String geneName = null;

    while ((line = hmmgsResultReader.readLine()) != null) {
        if (line.startsWith("#")) {
            continue;
        }

        String[] lexemes = line.trim().split("\t");
        if (lexemes.length != 12 || lexemes[0].equals("-")) {
            System.err.println("Skipping line: " + line);
            continue;
        }
        //contig_53493   nirk   1500:6:35:16409:3561/1   ADV15048   tcggcgctctacacgttcctgcagcccggg   40   210   70   left   -44.692   184   0
        int index = 0;

        String seqid = lexemes[0];
        geneName = lexemes[1];
        String readid = lexemes[2];
        String refid = lexemes[3];
        kmer = lexemes[4];
        int modelStart = Integer.valueOf(lexemes[5]);

        int nuclLength = Integer.valueOf(lexemes[6]);
        int protLength = Integer.valueOf(lexemes[7]);

        SearchDirection dir = SearchDirection.valueOf(lexemes[8]);
        if (dir != lastDir) {
            if (dir == SearchDirection.left) {
                List<MergedContig> mergedContigs = all
                        ? mergeAllContigs(leftContigs, rightContigs, kmer, geneName, hmm)
                        : mergeContigs(leftContigs, rightContigs, kmer, geneName, hmm);

                contigsMerged++;

                for (MergedContig mc : mergedContigs) {
                    String mergedId = shortSampleName + geneName + "_" + mc.leftContig + "_" + mc.rightContig;
                    out.println(mergedId + "\t" + mc.length + "\t" + mc.score);

                    if (mc.score > minBits && mc.length > minProtLength) {
                        if (prot) {
                            protSeqOut.writeSeq(mergedId, mc.protSeq);
                        }
                        nuclSeqOut.writeSeq(mergedId, mc.nuclSeq);

                        writtenMerges++;
                    }
                }
                leftContigs.clear();
                rightContigs.clear();
            }

            lastDir = dir;
        }

        Sequence seq = nuclContigReader.readSeq(seqid);

        if (dir == SearchDirection.left) {
            leftContigs.put(seqid, seq);
        } else if (dir == SearchDirection.right) {
            rightContigs.put(seqid, seq);
        } else {
            throw new IOException("Cannot handle search direction " + dir);
        }
    }

    if (!leftContigs.isEmpty() || !rightContigs.isEmpty()) {
        List<MergedContig> mergedContigs = all ? mergeAllContigs(leftContigs, rightContigs, kmer, geneName, hmm)
                : mergeContigs(leftContigs, rightContigs, kmer, geneName, hmm);

        for (MergedContig mc : mergedContigs) {
            String mergedId = shortSampleName + mc.gene + "_" + mc.leftContig + "_" + mc.rightContig;
            out.println(mergedId + "\t" + mc.length + "\t" + mc.score);
            contigsMerged++;

            if (mc.score > minBits && mc.length > minProtLength) {
                if (prot) {
                    protSeqOut.writeSeq(mergedId, mc.protSeq);
                }
                nuclSeqOut.writeSeq(mergedId, mc.nuclSeq);
                writtenMerges++;
            }
        }
    }

    out.close();
    if (prot) {
        protSeqOut.close();
    }
    nuclSeqOut.close();

    System.err.println("Read in " + contigsMerged + " contigs, wrote out " + writtenMerges
            + " merged contigs in " + ((double) (System.currentTimeMillis() - startTime) / 1000) + "s");
}

From source file:com.hpe.nv.samples.advanced.AdvAllTestClassMethods.java

public static void main(String[] args) throws Exception {
    try {//  w  w  w. j  a v  a2  s. c  om
        // program arguments
        Options options = new Options();
        options.addOption("i", "server-ip", true, "[mandatory] NV Test Manager IP");
        options.addOption("o", "server-port", true, "[mandatory] NV Test Manager port");
        options.addOption("u", "username", true, "[mandatory] NV username");
        options.addOption("w", "password", true, "[mandatory] NV password");
        options.addOption("e", "ssl", true, "[optional] Pass true to use SSL. Default: false");
        options.addOption("y", "proxy", true, "[optional] Proxy server host:port");
        options.addOption("t", "site-url", true,
                "[optional] Site under test URL. Default: Default: HPE Network Virtualization site URL. If you change this value, make sure to change the --xpath argument too");
        options.addOption("x", "xpath", true,
                "[optional] Parameter for ExpectedConditions.visibilityOfElementLocated(By.xpath(...)) method. Use an xpath expression of some element in the site. Default: //div[@id='content']");
        options.addOption("a", "active-adapter-ip", true,
                "[optional] Active adapter IP. Default: --server-ip argument");
        options.addOption("m", "mode", true, "[mandatory] Test mode - ntx or custom");
        options.addOption("n", "ntx-file-path", true,
                "[mandatory in ntx mode] File path of an .ntx/.ntxx file - used to start the test in ntx mode");
        options.addOption("z", "zip-result-file-path", true,
                "[optional] File path to store the analysis results as a .zip file");
        options.addOption("k", "analysis-ports", true,
                "[optional] A comma-separated list of ports for test analysis");
        options.addOption("p", "packet-list-id", true,
                "[optional] A packet list ID used for capturing a specific packet list and downloading its corresponding .shunra file");
        options.addOption("c", "packet-list-file-path", true,
                "[optional] .pcap file path - used to store all captured packet lists");
        options.addOption("s", "shunra-file-path", true, "[optional] .shunra file path for download");
        options.addOption("b", "browser", true,
                "[optional] The browser for which the Selenium WebDriver is built. Possible values: Chrome and Firefox. Default: Firefox");
        options.addOption("d", "debug", true,
                "[optional] Pass true to view console debug messages during execution. Default: false");
        options.addOption("h", "help", false, "[optional] Generates and prints help information");

        // parse and validate the command line arguments
        CommandLineParser parser = new DefaultParser();
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("help")) {
            // print help if help argument is passed
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("AdvAllTestClassMethods.java", options);
            return;
        }

        if (line.hasOption("mode")) {
            mode = ((String) line.getOptionValue("mode")).toLowerCase();
        } else {
            throw new Exception("Missing argument -m/--mode <mode>");
        }

        if (!mode.equals("custom") && !mode.equals("ntx")) {
            throw new Exception("Mode not supported. Supported modes are: ntx or custom");
        }

        if (mode.equals("ntx")) {
            if (line.hasOption("ntx-file-path")) {
                ntxFilePath = line.getOptionValue("ntx-file-path");
            } else {
                throw new Exception("Missing argument -n/--ntx-file-path <ntxFilePath>");
            }
        }

        if (line.hasOption("server-ip")) {
            serverIp = line.getOptionValue("server-ip");
            if (serverIp.equals("0.0.0.0")) {
                throw new Exception(
                        "Please replace the server IP argument value (0.0.0.0) with your NV Test Manager IP");
            }
        } else {
            throw new Exception("Missing argument -i/--server-ip <serverIp>");
        }

        if (line.hasOption("server-port")) {
            serverPort = Integer.parseInt(line.getOptionValue("server-port"));
        } else {
            throw new Exception("Missing argument -o/--server-port <serverPort>");
        }

        if (line.hasOption("username")) {
            username = line.getOptionValue("username");
        } else {
            throw new Exception("Missing argument -u/--username <username>");
        }

        if (line.hasOption("password")) {
            password = line.getOptionValue("password");
        } else {
            throw new Exception("Missing argument -w/--password <password>");
        }

        if (line.hasOption("ssl")) {
            ssl = Boolean.parseBoolean(line.getOptionValue("ssl"));
        }

        if (line.hasOption("zip-result-file-path")) {
            zipResultFilePath = line.getOptionValue("zip-result-file-path");
        }

        if (line.hasOption("packet-list-id")) {
            packetListId = line.getOptionValue("packet-list-id");
        }

        if (line.hasOption("packet-list-file-path")) {
            packetListFilePath = line.getOptionValue("packet-list-file-path");
        }

        if (line.hasOption("shunra-file-path")) {
            shunraFilePath = line.getOptionValue("shunra-file-path");
        }

        if (line.hasOption("site-url")) {
            siteUrl = line.getOptionValue("site-url");
        } else {
            siteUrl = "http://www8.hp.com/us/en/software-solutions/network-virtualization/index.html";
        }

        if (line.hasOption("xpath")) {
            xpath = line.getOptionValue("xpath");
        } else {
            xpath = "//div[@id='content']";
        }

        if (line.hasOption("proxy")) {
            proxySetting = line.getOptionValue("proxy");
        }

        if (line.hasOption("active-adapter-ip")) {
            activeAdapterIp = line.getOptionValue("active-adapter-ip");
        } else {
            activeAdapterIp = serverIp;
        }

        if (line.hasOption("analysis-ports")) {
            String analysisPortsStr = line.getOptionValue("analysis-ports");
            analysisPorts = analysisPortsStr.split(",");
        } else {
            analysisPorts = new String[] { "80", "8080" };
        }

        if (line.hasOption("browser")) {
            browser = line.getOptionValue("browser");
        } else {
            browser = "Firefox";
        }

        if (line.hasOption("debug")) {
            debug = Boolean.parseBoolean(line.getOptionValue("debug"));
        }

        String newLine = System.getProperty("line.separator");
        String testDescription = "***   This sample demonstrates all of the Test class APIs except for the                      ***"
                + newLine
                + "***   real-time update API, which is demonstrated in AdvRealtimeUpdate.java.                  ***"
                + newLine
                + "***   You can start the test in this sample using either the NTX or Custom modes.             ***"
                + newLine
                + "***                                                                                           ***"
                + newLine
                + "***   You can view the actual steps of this sample in the AdvAllTestClassMethods.java file.   ***"
                + newLine;

        // print the sample's description
        System.out.println(testDescription);

        // start console spinner
        if (!debug) {
            spinner = new Thread(new Spinner());
            spinner.start();
        }

        // sample execution steps
        /*****    Part 1 - Initialize the TestManager object to pass logon credentials, the NV Test Manager IP, the port, and so on                                                      *****/
        printPartDescription(
                "\b------    Part 1 - Initialize the TestManager object to pass logon credentials, the NV Test Manager IP, the port, and so on");
        initTestManager();
        printPartSeparator();
        /*****    Part 2 - Set the active adapter and start the NV test                                                                                                                  *****/
        printPartDescription("------    Part 2 - Set the active adapter and start the NV test");
        setActiveAdapter();
        startTest();
        testRunning = true;
        connectToTransactionManager();
        printPartSeparator();
        /*****    Part 3 - Start packet list capture, get the packet list information and print it to the console (if the --debug argument is set to true)                               *****/
        printPartDescription(
                "------    Part 3 - Start packet list capture, get the packet list information and print it to the console (if the --debug argument is set to true)");
        startPacketListCapture();
        getPacketListInfo();
        printPartSeparator();
        /*****    Part 4 - Start the NV transaction and navigate to the site                                                                                                             *****/
        printPartDescription("------    Part 4 - Start the NV transaction and navigate to the site");
        startTransaction();
        transactionInProgress = true;
        buildSeleniumWebDriver();
        seleniumNavigateToPage();
        printPartSeparator();
        /*****    Part 5 - Get the NV test statistics and print the Client-in statistics to the console (if the --debug argument is set to true)                                         *****/
        printPartDescription(
                "------    Part 5 - Get the NV test statistics and print the Client-in statistics to the console (if the --debug argument is set to true)");
        getTestStatistics();
        printPartSeparator();
        /*****    Part 6 - Stop the NV transaction and the packet list capture, get the packet list information and print it to the console (if the --debug argument is set to true)     *****/
        printPartDescription(
                "------    Part 6 - Stop the NV transaction and the packet list capture, get the packet list information and print it to the console (if the --debug argument is set to true)");
        stopTransaction();
        transactionInProgress = false;
        stopPacketListCapture();
        getPacketListInfo();
        printPartSeparator();
        /*****    Part 7 - Disconnect from the transaction manager and stop the NV test                                                                                                  *****/
        printPartDescription("------    Part 7 - Disconnect from the transaction manager and stop the NV test");
        disconnectFromTransactionManager();
        stopTest();
        testRunning = false;
        printPartSeparator();
        /*****    Part 8 - Analyze the NV test and print the results to the console                                                                                                      *****/
        printPartDescription("------    Part 8 - Analyze the NV test and print the results to the console");
        analyzeTest();
        printPartSeparator();
        /*****    Part 9 - Download the specified packet list and the .shunra file                                                                                                      *****/
        printPartDescription("------    Part 9 - Download the specified packet list and the .shunra file");
        downloadPacketList();
        downloadShunra();
        printPartSeparator();
        doneCallback();
    } catch (Exception e) {
        try {
            handleError(e.getMessage());
        } catch (Exception e2) {
            System.out.println("Error occurred: " + e2.getMessage());
        }
    }
}