Search in sources :

Example 1 with CommandContext

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

the class MPScriptTestCase method setupConfig.

private void setupConfig() throws Exception {
    System.setProperty(CONFIG_FILE_PROP, currentConfig);
    try {
        Files.copy(CONFIG_DIR.resolve(currentConfig), CONFIG_DIR.resolve(PREFIX + currentConfig));
        CommandContext ctx = CommandContextFactory.getInstance().newCommandContext();
        for (String line : Files.readAllLines(SCRIPT_FILE, Charset.forName("UTF-8"))) {
            ctx.handle(line);
        }
    } finally {
        System.clearProperty(CONFIG_FILE_PROP);
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext)

Example 2 with CommandContext

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

the class CLIServerSetupTask method executeCommands.

private void executeCommands(ManagementClient managementClient, List<String> commands, boolean useBatch, boolean reload) throws Exception {
    if (commands.isEmpty())
        return;
    CommandContext context = CLITestUtil.getCommandContext();
    context.connectController();
    if (useBatch) {
        context.getBatchManager().activateNewBatch();
        Batch batch = context.getBatchManager().getActiveBatch();
        for (String command : commands) {
            batch.add(context.toBatchedCommand(command));
        }
        ModelNode commandModel = batch.toRequest();
        // Add {allow-resource-service-restart=true} operation flag manually since its not exposed on the Batch
        // Currently fails with: https://issues.jboss.org/browse/ARQ-1135
        // commandModel.get(ModelDescriptionConstants.OPERATION_HEADERS).get(ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART).set(true);
        ModelNode result = managementClient.getControllerClient().execute(commandModel);
        LOG.debugf("Executed batch %s with result %s", commands, result.toJSONString(true));
        this.checkResult(result);
    } else {
        for (String command : commands) {
            ModelNode commandModel = context.buildRequest(command);
            ModelNode result = managementClient.getControllerClient().execute(commandModel);
            LOG.debugf("Executed single command %s with result %s", commands, result.toJSONString(true));
            this.checkResult(result);
        }
    }
    if (reload) {
        LOG.debugf("Reloading server %s if its in a 'reload-required' state.", managementClient.getMgmtAddress());
        ServerReload.reloadIfRequired(managementClient);
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) Batch(org.jboss.as.cli.batch.Batch) ModelNode(org.jboss.dmr.ModelNode)

Example 3 with CommandContext

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

the class MultipleLinesCommandsTestCase method handleAsOneString.

protected void handleAsOneString(String[] arr) throws Exception {
    final StringBuilder buf = new StringBuilder();
    for (String line : arr) {
        buf.append(line);
    }
    final CommandContext ctx = CLITestUtil.getCommandContext();
    try {
        ctx.connectController();
        ctx.handle(buf.toString());
    } finally {
        ctx.terminateSession();
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext)

Example 4 with CommandContext

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

the class NonExistingPathComparisonTestCase method testLessThan.

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

Example 5 with CommandContext

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

the class NonExistingPathComparisonTestCase method testUndefined.

// It does not work with 6.3.x
@Ignore
@Test
public void testUndefined() throws Exception {
    final CommandContext ctx = CLITestUtil.getCommandContext(cliOut);
    try {
        ctx.connectController();
        ctx.handle(this.getAddPropertyReqWithoutValue());
        assertEquals("undefined", runIf(ctx, "==", "&&", "undefined"));
        assertEquals("true", runIf(ctx, "==", "||", "undefined"));
    } finally {
        ctx.handleSafe(this.getRemovePropertyReq());
        ctx.terminateSession();
        cliOut.reset();
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) Ignore(org.junit.Ignore) 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