Search in sources :

Example 31 with CommandContext

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

the class TryCatchFinallyTestCase method testErrorInTryErroInCatchFinally.

@Test
public void testErrorInTryErroInCatchFinally() throws Exception {
    cliOut.reset();
    final CommandContext ctx = CLITestUtil.getCommandContext(cliOut);
    try {
        ctx.connectController();
        ctx.handle("try");
        ctx.handle(this.getReadNonexistingPropReq());
        ctx.handle("catch");
        ctx.handle(this.getReadNonexistingPropReq());
        ctx.handle("finally");
        ctx.handle(this.getAddPropertyReq("finally"));
        ctx.handle("end-try");
        fail("catch is expceted to throw an exception");
    } catch (CommandLineException e) {
        cliOut.reset();
        ctx.handle(getReadPropertyReq());
        assertEquals("finally", getValue());
    } finally {
        ctx.handleSafe(getRemovePropertyReq());
        ctx.terminateSession();
        cliOut.reset();
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) CommandLineException(org.jboss.as.cli.CommandLineException) Test(org.junit.Test)

Example 32 with CommandContext

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

the class TryCatchFinallyTestCase method testErrorInFinally.

@Test
public void testErrorInFinally() throws Exception {
    cliOut.reset();
    final CommandContext ctx = CLITestUtil.getCommandContext(cliOut);
    try {
        ctx.connectController();
        ctx.handle("try");
        ctx.handle(this.getAddPropertyReq("try"));
        ctx.handle("finally");
        ctx.handle(this.getReadNonexistingPropReq());
        ctx.handle("end-try");
        fail("finally is expceted to throw an exception");
    } catch (CommandLineException e) {
        cliOut.reset();
        ctx.handle(getReadPropertyReq());
        assertEquals("try", getValue());
    } finally {
        ctx.handleSafe(getRemovePropertyReq());
        ctx.terminateSession();
        cliOut.reset();
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) CommandLineException(org.jboss.as.cli.CommandLineException) Test(org.junit.Test)

Example 33 with CommandContext

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

the class BatchFileTestCase method testBatchFile.

@Test
public void testBatchFile() throws Exception {
    createFile(new String[] { "/system-property=batchfiletest:add(value=true)" });
    final CommandContext ctx = CLITestUtil.getCommandContext();
    try {
        ctx.connectController();
        ctx.handle("batch --file=" + TMP_FILE.getAbsolutePath());
        final ModelNode batchRequest = ctx.buildRequest("run-batch");
        assertTrue(batchRequest.hasDefined("operation"));
        assertEquals("composite", batchRequest.get("operation").asString());
        assertTrue(batchRequest.hasDefined("address"));
        assertTrue(batchRequest.get("address").asList().isEmpty());
        assertTrue(batchRequest.hasDefined("steps"));
        List<ModelNode> steps = batchRequest.get("steps").asList();
        assertEquals(1, steps.size());
        final ModelNode op = steps.get(0);
        assertTrue(op.hasDefined("address"));
        List<Property> address = op.get("address").asPropertyList();
        assertEquals(1, address.size());
        assertEquals("system-property", address.get(0).getName());
        assertEquals("batchfiletest", address.get(0).getValue().asString());
        assertTrue(op.hasDefined("operation"));
        assertEquals("add", op.get("operation").asString());
        assertEquals("true", op.get("value").asString());
        ctx.handle("discard-batch");
    } finally {
        ctx.terminateSession();
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property) Test(org.junit.Test)

Example 34 with CommandContext

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

the class CdTestCase method testInvalidAddress.

@Test
public void testInvalidAddress() throws Exception {
    final CommandContext ctx = CLITestUtil.getCommandContext();
    try {
        ctx.connectController();
        ctx.handle("cd subsystem=subsystem");
        Assert.fail("Can't cd into a non-existing nodepath.");
    } catch (CommandLineException e) {
    // expected
    } finally {
        ctx.terminateSession();
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) CommandLineException(org.jboss.as.cli.CommandLineException) Test(org.junit.Test)

Example 35 with CommandContext

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

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)

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