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