Search in sources :

Example 6 with CommandContextConfiguration

use of org.jboss.as.cli.impl.CommandContextConfiguration in project wildfly-core by wildfly.

the class OperatorsTestCase method testRedirectOut.

@Test
public void testRedirectOut() throws CliInitializationException, CommandLineException, IOException {
    ByteArrayOutputStream consoleOutput = new ByteArrayOutputStream();
    CommandContextConfiguration config = new CommandContextConfiguration.Builder().setConsoleOutput(consoleOutput).build();
    CommandContext ctx = CommandContextFactory.getInstance().newCommandContext(config);
    File f = File.createTempFile("cli_test" + System.currentTimeMillis(), null);
    f.delete();
    try {
        ctx.handle("version > " + f.getAbsolutePath());
        String out = consoleOutput.toString();
        Assert.assertTrue(out, out.isEmpty());
        List<String> lines = Files.readAllLines(f.toPath());
        boolean found = false;
        for (String s : lines) {
            if (s.contains("Release:")) {
                found = true;
            }
        }
        if (!found) {
            throw new RuntimeException("Not right content " + lines);
        }
        consoleOutput.reset();
        ctx.handle("grep Rel " + f.getAbsolutePath());
        out = consoleOutput.toString();
        Assert.assertTrue(out, out.contains("Release:"));
    } finally {
        f.delete();
        ctx.terminateSession();
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) CommandContextConfiguration(org.jboss.as.cli.impl.CommandContextConfiguration) File(java.io.File) Test(org.junit.Test)

Example 7 with CommandContextConfiguration

use of org.jboss.as.cli.impl.CommandContextConfiguration in project wildfly-core by wildfly.

the class EchoDMRTestCase method testCompact.

@Test
public void testCompact() throws CliInitializationException, CommandLineException {
    ByteArrayOutputStream consoleOutput = new ByteArrayOutputStream();
    CommandContextConfiguration config = new CommandContextConfiguration.Builder().setConsoleOutput(consoleOutput).build();
    CommandContext ctx = CommandContextFactory.getInstance().newCommandContext(config);
    try {
        String cmd = "/subsystem=foo:op(arg1=14, arg2=[{i1=\"val1\", i2=\"val2\"}], arg3=\"val3\")";
        ctx.handle("echo-dmr " + cmd);
        String out = consoleOutput.toString();
        out = out.substring(0, out.lastIndexOf("\n"));
        consoleOutput.reset();
        ctx.handle("echo-dmr --compact " + cmd);
        String compact = consoleOutput.toString();
        compact = compact.substring(0, compact.lastIndexOf("\n"));
        Assert.assertTrue(out, out.contains("\n"));
        Assert.assertFalse(compact, compact.contains("\n"));
        ModelNode mn = ModelNode.fromString(out);
        ModelNode mnCompact = ModelNode.fromString(compact);
        Assert.assertEquals(mnCompact.toString(), mn, mnCompact);
    } finally {
        ctx.terminateSession();
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) CommandContextConfiguration(org.jboss.as.cli.impl.CommandContextConfiguration) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 8 with CommandContextConfiguration

use of org.jboss.as.cli.impl.CommandContextConfiguration in project wildfly-core by wildfly.

the class EchoDMRTestCase method testHeaders.

@Test
public void testHeaders() throws CliInitializationException, CommandLineException {
    ByteArrayOutputStream consoleOutput = new ByteArrayOutputStream();
    CommandContextConfiguration config = new CommandContextConfiguration.Builder().setConsoleOutput(consoleOutput).build();
    CommandContext ctx = CommandContextFactory.getInstance().newCommandContext(config);
    try {
        String cmd = "/subsystem=foo:op(arg1=14, arg2=[{i1=\"val1\", i2=\"val2\"}], arg3=\"val3\"){allow-resource-service-restart=true;foo=\"1 2 3\";blocking-timeout=12}";
        ctx.handle("echo-dmr " + cmd);
        String out = consoleOutput.toString();
        out = out.substring(0, out.lastIndexOf("\n"));
        ModelNode mn = ModelNode.fromString(out);
        ModelNode headers = mn.get(Util.OPERATION_HEADERS);
        Assert.assertEquals("1 2 3", headers.get("foo").asString());
        Assert.assertEquals("true", headers.get("allow-resource-service-restart").asString());
        Assert.assertEquals("12", headers.get("blocking-timeout").asString());
    } finally {
        ctx.terminateSession();
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) CommandContextConfiguration(org.jboss.as.cli.impl.CommandContextConfiguration) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 9 with CommandContextConfiguration

use of org.jboss.as.cli.impl.CommandContextConfiguration in project wildfly-core by wildfly.

the class OperatorsTestCase method testVariables.

@Test
public void testVariables() throws CliInitializationException, CommandLineException, IOException {
    ByteArrayOutputStream consoleOutput = new ByteArrayOutputStream();
    CommandContextConfiguration config = new CommandContextConfiguration.Builder().setConsoleOutput(consoleOutput).build();
    CommandContext ctx = CommandContextFactory.getInstance().newCommandContext(config);
    ctx.handle("set varName=Rel");
    try {
        ctx.handle("version | grep $varName");
        String out = consoleOutput.toString();
        Assert.assertTrue(out, out.contains("Release:"));
    } finally {
        ctx.terminateSession();
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) CommandContextConfiguration(org.jboss.as.cli.impl.CommandContextConfiguration) Test(org.junit.Test)

Example 10 with CommandContextConfiguration

use of org.jboss.as.cli.impl.CommandContextConfiguration in project wildfly-core by wildfly.

the class OperatorsTestCase method testErrors.

@Test
public void testErrors() throws Exception {
    ByteArrayOutputStream consoleOutput = new ByteArrayOutputStream();
    CommandContextConfiguration config = new CommandContextConfiguration.Builder().setConsoleOutput(consoleOutput).build();
    CommandContext ctx = CommandContextFactory.getInstance().newCommandContext(config);
    try {
        ctx.handle("version ||");
        throw new Exception("Should have failed");
    } catch (CommandLineException ex) {
        Assert.assertTrue(ex.toString(), ex.getMessage().contains("aesh: syntax error near unexpected token '|'"));
    } finally {
        ctx.terminateSession();
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) CommandContextConfiguration(org.jboss.as.cli.impl.CommandContextConfiguration) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

CommandContextConfiguration (org.jboss.as.cli.impl.CommandContextConfiguration)11 Test (org.junit.Test)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 File (java.io.File)4 ModelNode (org.jboss.dmr.ModelNode)2 IOException (java.io.IOException)1 CommandContext (org.jboss.as.cli.CommandContext)1 EmptySubsystemParser (org.jboss.as.test.integration.management.extension.EmptySubsystemParser)1 Before (org.junit.Before)1