Search in sources :

Example 1 with CommandContextConfiguration

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

the class CommandTimeoutHandlerTestCase method beforeTest.

@Before
public void beforeTest() throws CliInitializationException, IOException, CommandLineException {
    container.start();
    consoleOutput.reset();
    ExtensionUtils.createExtensionModule("org.wildfly.extension.blocker-test", BlockerExtension.class, EmptySubsystemParser.class.getPackage());
    CommandContextConfiguration config = new CommandContextConfiguration.Builder().setInitConsole(true).setConsoleOutput(consoleOutput).setController("remote+http://" + TestSuiteEnvironment.getServerAddress() + ":" + TestSuiteEnvironment.getServerPort()).setCommandTimeout(CONFIG_TIMEOUT).build();
    ctx = CommandContextFactory.getInstance().newCommandContext(config);
    ctx.handle("command-timeout reset default");
    ctx.handle("connect");
    ctx.handle("/extension=org.wildfly.extension.blocker-test:add");
    ctx.handle("command-timeout reset config");
}
Also used : EmptySubsystemParser(org.jboss.as.test.integration.management.extension.EmptySubsystemParser) CommandContextConfiguration(org.jboss.as.cli.impl.CommandContextConfiguration) Before(org.junit.Before)

Example 2 with CommandContextConfiguration

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

the class OperatorsTestCase method testPipeRedirectOut.

@Test
public void testPipeRedirectOut() 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 | grep Rel > " + f.getAbsolutePath());
        String out = consoleOutput.toString();
        Assert.assertTrue(out, out.isEmpty());
        List<String> lines = Files.readAllLines(f.toPath());
        Assert.assertTrue(lines.toString(), lines.size() == 1);
        Assert.assertTrue(lines.toString(), lines.get(0).contains("Release:"));
        boolean found = false;
        for (String s : lines) {
            if (s.contains("Release:")) {
                found = true;
            }
        }
        if (!found) {
            throw new RuntimeException("Not right content " + lines);
        }
    } 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 3 with CommandContextConfiguration

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

the class OperatorsTestCase method testAppendOut.

@Test
public void testAppendOut() 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);
    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 in " + f + ": " + 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 4 with CommandContextConfiguration

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

the class OperatorsTestCase method testPipe.

@Test
public void testPipe() throws CliInitializationException, CommandLineException {
    ByteArrayOutputStream consoleOutput = new ByteArrayOutputStream();
    CommandContextConfiguration config = new CommandContextConfiguration.Builder().setConsoleOutput(consoleOutput).build();
    CommandContext ctx = CommandContextFactory.getInstance().newCommandContext(config);
    try {
        ctx.handle("version | grep Rel");
        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 5 with CommandContextConfiguration

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

the class OperatorsTestCase method testAppendOutCreateFile.

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