use of org.apache.activemq.console.CommandContext in project activemq-artemis by apache.
the class AMQ3411Test method testFactorySetWrong1.
public void testFactorySetWrong1() throws Exception {
AmqBrowseCommand command = new AmqBrowseCommand();
CommandContext context = new CommandContext();
context.setFormatter(new CommandShellOutputFormatter(System.out));
command.setCommandContext(context);
List<String> tokens = new ArrayList<>();
tokens.addAll(DEFAULT_OPTIONS);
tokens.add("--passwordFactory");
tokens.add("org.apache.activemq.console.command.TestAMQ3411.DoesntExistFactory");
tokens.add("--password");
tokens.add(origPassword);
tokens.addAll(DEFAULT_TOKENS);
try {
command.execute(tokens);
} catch (Throwable e) {
Throwable cause = e;
while (null != cause) {
if (cause instanceof java.lang.ClassNotFoundException)
return;
cause = cause.getCause();
}
assertFalse(e.toString(), true);
}
assertFalse("No exception caught", true);
}
use of org.apache.activemq.console.CommandContext in project activemq-artemis by apache.
the class AMQ3411Test method testNoFactorySet.
public void testNoFactorySet() throws Exception {
AmqBrowseCommand command = new AmqBrowseCommand();
CommandContext context = new CommandContext();
context.setFormatter(new CommandShellOutputFormatter(System.out));
command.setCommandContext(context);
List<String> tokens = new ArrayList<>();
tokens.addAll(DEFAULT_OPTIONS);
tokens.addAll(DEFAULT_TOKENS);
command.execute(tokens);
assertNotNull(command.getPasswordFactory());
assertTrue(command.getPasswordFactory() instanceof DefaultPasswordFactory);
assertNull(command.getPassword());
}
use of org.apache.activemq.console.CommandContext in project activemq-artemis by apache.
the class AMQ3411Test method testFactorySetWrong2.
public void testFactorySetWrong2() throws Exception {
AmqBrowseCommand command = new AmqBrowseCommand();
CommandContext context = new CommandContext();
context.setFormatter(new CommandShellOutputFormatter(System.out));
command.setCommandContext(context);
List<String> tokens = new ArrayList<>();
tokens.addAll(DEFAULT_OPTIONS);
tokens.add("--passwordFactory");
tokens.add("java.lang.Object");
tokens.add("--password");
tokens.add(origPassword);
tokens.addAll(DEFAULT_TOKENS);
try {
command.execute(tokens);
} catch (Throwable e) {
Throwable cause = e;
while (null != cause) {
if (cause instanceof java.lang.ClassCastException)
return;
cause = cause.getCause();
}
assertFalse(e.toString(), true);
}
assertFalse("No exception caught", true);
}
use of org.apache.activemq.console.CommandContext in project activemq-artemis by apache.
the class AMQ3411Test method testUsernamePasswordSet.
public void testUsernamePasswordSet() throws Exception {
AmqBrowseCommand command = new AmqBrowseCommand();
CommandContext context = new CommandContext();
String username = "user";
String password = "password";
context.setFormatter(new CommandShellOutputFormatter(System.out));
command.setCommandContext(context);
List<String> tokens = new ArrayList<>();
tokens.addAll(DEFAULT_OPTIONS);
tokens.add("--password");
tokens.add(password);
tokens.add("--user");
tokens.add(username);
tokens.addAll(DEFAULT_TOKENS);
command.execute(tokens);
assertNotNull(command.getPasswordFactory());
assertTrue(command.getPasswordFactory() instanceof DefaultPasswordFactory);
assertEquals(password, command.getPassword());
assertEquals(username, command.getUsername());
}
use of org.apache.activemq.console.CommandContext in project activemq-artemis by apache.
the class AMQ3411Test method testFactorySet.
public void testFactorySet() throws Exception {
AmqBrowseCommand command = new AmqBrowseCommand();
CommandContext context = new CommandContext();
context.setFormatter(new CommandShellOutputFormatter(System.out));
command.setCommandContext(context);
List<String> tokens = new ArrayList<>();
tokens.addAll(DEFAULT_OPTIONS);
tokens.add("--passwordFactory");
tokens.add(LowercasingPasswordFactory.class.getCanonicalName());
tokens.add("--password");
tokens.add(origPassword);
tokens.addAll(DEFAULT_TOKENS);
command.execute(tokens);
assertNotNull(command.getPasswordFactory());
assertTrue(command.getPasswordFactory() instanceof LowercasingPasswordFactory);
// validate that the factory is indeed being used for the password.
assertEquals(origPassword.toLowerCase(), command.getPassword());
}
Aggregations