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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations