use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class DeleteJavaMailResourceTest method testExecuteSuccessDefaultTarget.
/**
* Test of execute method, of class DeleteJavaMailResource.
* asadmin create-javamail-resource --mailuser=test --mailhost=localhost
* --fromaddress=test@sun.com mail/MyMailSession
* delete-javamail-resource mail/MyMailSession
*/
@Test
public void testExecuteSuccessDefaultTarget() {
parameters.set("mailhost", "localhost");
parameters.set("mailuser", "test");
parameters.set("fromaddress", "test@sun.com");
parameters.set("jndi_name", "mail/MyMailSession");
org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource createCommand = habitat.getService(org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource.class);
assertTrue(createCommand != null);
cr.getCommandInvocation("create-javamail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
parameters = new ParameterMap();
parameters.set("jndi_name", "mail/MyMailSession");
org.glassfish.resources.javamail.admin.cli.DeleteJavaMailResource deleteCommand = habitat.getService(org.glassfish.resources.javamail.admin.cli.DeleteJavaMailResource.class);
assertTrue(deleteCommand != null);
cr.getCommandInvocation("delete-javamail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
boolean isDeleted = true;
for (Resource resource : resources.getResources()) {
if (resource instanceof MailResource) {
MailResource jr = (MailResource) resource;
if (jr.getJndiName().equals("mail/MyMailSession")) {
isDeleted = false;
logger.fine("JavaMailResource config bean mail/MyMailSession is deleted.");
break;
}
}
}
assertTrue(isDeleted);
logger.fine("msg: " + context.getActionReport().getMessage());
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
Servers servers = habitat.getService(Servers.class);
boolean isRefDeleted = true;
for (Server server : servers.getServer()) {
if (server.getName().equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
for (ResourceRef ref : server.getResourceRef()) {
if (ref.getRef().equals("mail/MyMailSession")) {
isRefDeleted = false;
break;
}
}
}
}
assertTrue(isRefDeleted);
}
use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class DeleteJavaMailResourceTest method tearDown.
@After
public void tearDown() throws TransactionFailure {
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
Resource target = null;
for (Resource resource : param.getResources()) {
if (resource instanceof MailResource) {
MailResource r = (MailResource) resource;
if (r.getJndiName().equals("mail/MyMailSession")) {
target = resource;
break;
}
}
}
if (target != null) {
param.getResources().remove(target);
}
return null;
}
}, resources);
parameters = new ParameterMap();
}
use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class ListJavaMailResourcesTest method testExecuteSuccessListNoMailResource.
/**
* Test of execute method, of class ListJdbcResource.
* delete-javamail-resource mailresource
* list-javamail-resources
*/
@Test
public void testExecuteSuccessListNoMailResource() {
createJavaMailResource();
parameters = new ParameterMap();
org.glassfish.resources.javamail.admin.cli.ListJavaMailResources listCommand = habitat.getService(org.glassfish.resources.javamail.admin.cli.ListJavaMailResources.class);
cr.getCommandInvocation("list-javamail-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
List<ActionReport.MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
assertEquals(origNum + 1, list.size());
// as we newly created a resource after test "setup".
origNum = origNum + 1;
deleteJavaMailResource();
parameters = new ParameterMap();
listCommand = habitat.getService(org.glassfish.resources.javamail.admin.cli.ListJavaMailResources.class);
context = new AdminCommandContextImpl(LogDomains.getLogger(ListJavaMailResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
cr.getCommandInvocation("list-javamail-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
list = context.getActionReport().getTopMessagePart().getChildren();
if ((origNum - 1) == 0) {
// Nothing to list.
} else {
assertEquals(origNum - 1, list.size());
}
List<String> listStr = new ArrayList<String>();
for (MessagePart mp : list) {
listStr.add(mp.getMessage());
}
assertFalse(listStr.contains("mailresource"));
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
}
use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class ListJavaMailResourcesTest method deleteJavaMailResource.
private void deleteJavaMailResource() {
parameters = new ParameterMap();
parameters.set("jndi_name", "mailresource");
DeleteJavaMailResource deleteCommand = habitat.getService(DeleteJavaMailResource.class);
assertTrue(deleteCommand != null);
cr.getCommandInvocation("delete-javamail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
}
use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class ListJavaMailResourcesTest method createJavaMailResource.
private void createJavaMailResource() {
parameters = new ParameterMap();
parameters.set("mailhost", "localhost");
parameters.set("mailuser", "test");
parameters.set("fromaddress", "test@sun.com");
parameters.set("jndi_name", "mailresource");
CreateJavaMailResource createCommand = habitat.getService(CreateJavaMailResource.class);
assertTrue(createCommand != null);
cr.getCommandInvocation("create-javamail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
}
Aggregations