use of org.glassfish.resources.javamail.config.MailResource in project Payara by payara.
the class CreateJavaMailResourceTest method testExecuteFailDuplicateResource.
/**
* Test of execute method, of class CreateJavaMailResource.
* asadmin create-javamail-resource --mailuser=test --mailhost=localhost
* --fromaddress=test@sun.com dupRes
* asadmin create-javamail-resource --mailuser=test --mailhost=localhost
* --fromaddress=test@sun.com dupRes
*/
@Test
public void testExecuteFailDuplicateResource() {
parameters.set("mailhost", "localhost");
parameters.set("mailuser", "test");
parameters.set("fromaddress", "test@sun.com");
parameters.set("jndi_name", "dupRes");
org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource command1 = habitat.getService(org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource.class);
assertTrue(command1 != null);
cr.getCommandInvocation("create-javamail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command1);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
boolean isCreated = false;
for (Resource resource : resources.getResources()) {
if (resource instanceof MailResource) {
MailResource jr = (MailResource) resource;
if (jr.getJndiName().equals("dupRes")) {
isCreated = true;
logger.fine("MailResource config bean dupRes is created.");
break;
}
}
}
assertTrue(isCreated);
org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource command2 = habitat.getService(org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource.class);
cr.getCommandInvocation("create-javamail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command2);
assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
int numDupRes = 0;
for (Resource resource : resources.getResources()) {
if (resource instanceof MailResource) {
MailResource jr = (MailResource) resource;
if (jr.getJndiName().equals("dupRes")) {
numDupRes = numDupRes + 1;
}
}
}
assertEquals(1, numDupRes);
logger.fine("msg: " + context.getActionReport().getMessage());
}
use of org.glassfish.resources.javamail.config.MailResource in project Payara by payara.
the class CreateJavaMailResourceTest method testExecuteWithOptionalValuesSet.
/**
* Test of execute method, of class CreateJavaMailResource when enabled has no value
* asadmin create-javamail-resource --mailuser=test --mailhost=localhost
* --fromaddress=test@sun.com --enabled=false --debug=true
* --storeprotocol=pop
* --storeprotocolclass=com.sun.mail.pop.POPStore
* --transprotocol=lmtp
* --transprotocolclass=com.sun.mail.lmtop.LMTPTransport
* mail/MyMailSession
*/
@Test
public void testExecuteWithOptionalValuesSet() {
parameters.set("mailhost", "localhost");
parameters.set("mailuser", "test");
parameters.set("fromaddress", "test@sun.com");
parameters.set("enabled", "false");
parameters.set("debug", "true");
parameters.set("storeprotocol", "pop");
parameters.set("storeprotocolclass", "com.sun.mail.pop.POPStore");
parameters.set("transprotocol", "lmtp");
parameters.set("transprotocolclass", "com.sun.mail.lmtp.LMTPTransport");
parameters.set("jndi_name", "mail/MyMailSession");
org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource command = habitat.getService(org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource.class);
assertTrue(command != null);
cr.getCommandInvocation("create-javamail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
boolean isCreated = false;
for (Resource resource : resources.getResources()) {
if (resource instanceof MailResource) {
MailResource r = (MailResource) resource;
if (r.getJndiName().equals("mail/MyMailSession")) {
// expect enabled for the resource to be true as resource-ref's enabled
// would be set to false
assertEquals("true", r.getEnabled());
assertEquals("true", r.getDebug());
assertEquals("pop", r.getStoreProtocol());
assertEquals("com.sun.mail.pop.POPStore", r.getStoreProtocolClass());
assertEquals("lmtp", r.getTransportProtocol());
assertEquals("com.sun.mail.lmtp.LMTPTransport", r.getTransportProtocolClass());
assertEquals("false", r.getAuth());
isCreated = true;
break;
}
}
}
assertTrue(isCreated);
logger.fine("msg: " + context.getActionReport().getMessage());
}
use of org.glassfish.resources.javamail.config.MailResource in project Payara by payara.
the class JavaMailResourceManager method createConfigBean.
private MailResource createConfigBean(Resources param, Properties props) throws PropertyVetoException, TransactionFailure {
MailResource newResource = param.createChild(MailResource.class);
newResource.setJndiName(jndiName);
newResource.setFrom(fromAddress);
newResource.setUser(mailUser);
newResource.setPassword(mailPassword);
newResource.setAuth(auth);
newResource.setHost(mailHost);
newResource.setEnabled(enabled);
newResource.setStoreProtocol(storeProtocol);
newResource.setStoreProtocolClass(storeProtocolClass);
newResource.setTransportProtocol(transportProtocol);
newResource.setTransportProtocolClass(transportProtocolClass);
newResource.setDebug(debug);
if (description != null) {
newResource.setDescription(description);
}
if (props != null) {
for (java.util.Map.Entry e : props.entrySet()) {
Property prop = newResource.createChild(Property.class);
prop.setName((String) e.getKey());
prop.setValue((String) e.getValue());
newResource.getProperty().add(prop);
}
}
return newResource;
}
use of org.glassfish.resources.javamail.config.MailResource in project Payara by payara.
the class MailResourceDeployer method undeployResource.
/**
* {@inheritDoc}
*/
@Override
public synchronized void undeployResource(Object resource) throws Exception {
MailResource mailRes = (MailResource) resource;
// converts the config data to j2ee resource
ResourceInfo resourceInfo = ResourceUtil.getResourceInfo(mailRes);
deleteResource(mailRes, resourceInfo);
}
use of org.glassfish.resources.javamail.config.MailResource in project Payara by payara.
the class MailResourceDeployer method deployResource.
/**
* {@inheritDoc}
*/
@Override
public synchronized void deployResource(Object resource, String applicationName, String moduleName) throws Exception {
MailResource mailRes = (MailResource) resource;
if (mailRes == null) {
_logger.log(Level.INFO, "Error in resource deploy.");
} else {
ResourceInfo resourceInfo = new ResourceInfo(mailRes.getJndiName(), applicationName, moduleName);
// registers the jsr77 object for the mail resource deployed
/* TODO Not needed any more ?
/*ManagementObjectManager mgr =
getAppServerSwitchObject().getManagementObjectManager();
mgr.registerJavaMailResource(mailRes.getJndiName());*/
installResource(mailRes, resourceInfo);
}
}
Aggregations