Search in sources :

Example 21 with CommandContext

use of org.jboss.as.cli.CommandContext in project wildfly by wildfly.

the class ArchiveTestCase method testDeployArchive.

@Test
public void testDeployArchive() throws Exception {
    final CommandContext ctx = CLITestUtil.getCommandContext();
    try {
        ctx.connectController();
        ctx.handle("deploy " + cliArchiveFile.getAbsolutePath() + " --script=install.scr");
        // check that now both wars are deployed
        String response = HttpRequest.get(getBaseURL(url) + "deployment0/SimpleServlet", 10, TimeUnit.SECONDS);
        assertTrue("Invalid response: " + response, response.indexOf("SimpleServlet") >= 0);
        response = HttpRequest.get(getBaseURL(url) + "deployment1/SimpleServlet", 10, TimeUnit.SECONDS);
        assertTrue("Invalid response: " + response, response.indexOf("SimpleServlet") >= 0);
        assertTrue(checkUndeployed(getBaseURL(url) + "deployment2/SimpleServlet"));
        ctx.handle("deploy " + cliArchiveFile.getAbsolutePath() + " --script=uninstall.scr");
        // check that both wars are undeployed
        assertTrue(checkUndeployed(getBaseURL(url) + "deployment0/SimpleServlet"));
        assertTrue(checkUndeployed(getBaseURL(url) + "deployment1/SimpleServlet"));
    } finally {
        ctx.terminateSession();
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) Test(org.junit.Test)

Example 22 with CommandContext

use of org.jboss.as.cli.CommandContext in project wildfly by wildfly.

the class ArchiveDefaultScriptNamesTestCase method testDeployUndeployArchive.

@Test
public void testDeployUndeployArchive() throws Exception {
    final CommandContext ctx = CLITestUtil.getCommandContext();
    try {
        ctx.connectController();
        ctx.handle("deploy " + cliArchiveFile.getAbsolutePath());
        // check that now both wars are deployed
        String response = HttpRequest.get(getBaseURL(url) + "deployment0/SimpleServlet", 10, TimeUnit.SECONDS);
        assertTrue("Invalid response: " + response, response.indexOf("SimpleServlet") >= 0);
        response = HttpRequest.get(getBaseURL(url) + "deployment1/SimpleServlet", 10, TimeUnit.SECONDS);
        assertTrue("Invalid response: " + response, response.indexOf("SimpleServlet") >= 0);
        assertTrue(checkUndeployed(getBaseURL(url) + "deployment2/SimpleServlet"));
        ctx.handle("undeploy " + "--path=" + cliArchiveFile.getAbsolutePath());
        // check that both wars are undeployed
        assertTrue(checkUndeployed(getBaseURL(url) + "deployment0/SimpleServlet"));
        assertTrue(checkUndeployed(getBaseURL(url) + "deployment1/SimpleServlet"));
    } finally {
        ctx.terminateSession();
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) Test(org.junit.Test)

Example 23 with CommandContext

use of org.jboss.as.cli.CommandContext in project quickstarts by jboss-switchyard.

the class JBossCliUtil method executeCliScript.

/**
 * Executes CLI script file.
 * @param path file path
 * @throws Exception exception
 */
public static void executeCliScript(String path) throws Exception {
    File file = new File(path);
    if (!file.exists() || !file.isFile()) {
        throw new IllegalArgumentException(path + " is not a valid CLI script file");
    }
    final CommandContext cmdCtx = CommandContextFactory.getInstance().newCommandContext(HOST, PORT, USER, PASSWORD != null ? PASSWORD.toCharArray() : null, NO_LOCAL_AUTH, INIT_CONSOLE, CONNECTION_TIMEOUT);
    if (_logger.isDebugEnabled()) {
        cmdCtx.addEventListener(new CliEventListener() {

            @Override
            public void cliEvent(CliEvent event, CommandContext ctx) {
                _logger.debug("CLI Event: " + event.toString());
            }
        });
    }
    cmdCtx.connectController();
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new FileReader(file));
        _logger.info("Executing CLI script file: " + path);
        String line = reader.readLine();
        while (cmdCtx.getExitCode() == 0 && !cmdCtx.isTerminated() && line != null) {
            if (_logger.isDebugEnabled()) {
                _logger.debug(">>> " + line.trim());
            }
            cmdCtx.handleSafe(line.trim());
            line = reader.readLine();
        }
    } finally {
        StreamUtils.safeClose(reader);
        cmdCtx.terminateSession();
        _logger.info("CLI session is terminated with exit code '" + cmdCtx.getExitCode() + "'");
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) CliEventListener(org.jboss.as.cli.CliEventListener) BufferedReader(java.io.BufferedReader) CliEvent(org.jboss.as.cli.CliEvent) FileReader(java.io.FileReader) File(java.io.File)

Example 24 with CommandContext

use of org.jboss.as.cli.CommandContext in project eap-additional-testsuite by jboss-set.

the class NonExistingPathComparisonTestCase method testGreaterThan.

@Test
public void testGreaterThan() throws Exception {
    final CommandContext ctx = CLITestUtil.getCommandContext(cliOut);
    try {
        ctx.connectController();
        ctx.handle(this.getAddPropertyReq("\"5\""));
        assertEquals("5", runIf(ctx, ">", "&&", "\"1\""));
        assertEquals("true", runIf(ctx, ">", "||", "\"1\""));
    } finally {
        ctx.handleSafe(this.getRemovePropertyReq());
        ctx.terminateSession();
        cliOut.reset();
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) Test(org.junit.Test)

Example 25 with CommandContext

use of org.jboss.as.cli.CommandContext in project eap-additional-testsuite by jboss-set.

the class NonExistingPathComparisonTestCase method testEquals.

@Test
public void testEquals() throws Exception {
    final CommandContext ctx = CLITestUtil.getCommandContext(cliOut);
    try {
        ctx.connectController();
        ctx.handle(this.getAddPropertyReq("\"false\""));
        assertEquals("false", runIf(ctx, "==", "&&", "\"false\""));
        assertEquals("true", runIf(ctx, "==", "||", "\"false\""));
    } finally {
        ctx.handleSafe(this.getRemovePropertyReq());
        ctx.terminateSession();
        cliOut.reset();
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) Test(org.junit.Test)

Aggregations

CommandContext (org.jboss.as.cli.CommandContext)37 Test (org.junit.Test)33 ModelNode (org.jboss.dmr.ModelNode)7 CommandLineException (org.jboss.as.cli.CommandLineException)4 Batch (org.jboss.as.cli.batch.Batch)3 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)3 InSequence (org.jboss.arquillian.junit.InSequence)2 Property (org.jboss.dmr.Property)2 Ignore (org.junit.Ignore)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 CliEvent (org.jboss.as.cli.CliEvent)1 CliEventListener (org.jboss.as.cli.CliEventListener)1