Search in sources :

Example 11 with MailResource

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());
}
Also used : MailResource(org.glassfish.resources.javamail.config.MailResource) Resource(com.sun.enterprise.config.serverbeans.Resource) MailResource(org.glassfish.resources.javamail.config.MailResource) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 12 with MailResource

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());
}
Also used : MailResource(org.glassfish.resources.javamail.config.MailResource) Resource(com.sun.enterprise.config.serverbeans.Resource) MailResource(org.glassfish.resources.javamail.config.MailResource) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 13 with MailResource

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;
}
Also used : HashMap(java.util.HashMap) Property(org.jvnet.hk2.config.types.Property) MailResource(org.glassfish.resources.javamail.config.MailResource)

Example 14 with MailResource

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);
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) MailResource(org.glassfish.resources.javamail.config.MailResource)

Example 15 with MailResource

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);
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) MailResource(org.glassfish.resources.javamail.config.MailResource)

Aggregations

MailResource (org.glassfish.resources.javamail.config.MailResource)16 Resource (com.sun.enterprise.config.serverbeans.Resource)6 Resources (com.sun.enterprise.config.serverbeans.Resources)4 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)4 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)4 Test (org.junit.Test)4 PropertyVetoException (java.beans.PropertyVetoException)3 ParameterMap (org.glassfish.api.admin.ParameterMap)3 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)3 ResourceRef (com.sun.enterprise.config.serverbeans.ResourceRef)2 ActionReport (org.glassfish.api.ActionReport)2 Domain (com.sun.enterprise.config.serverbeans.Domain)1 Server (com.sun.enterprise.config.serverbeans.Server)1 Servers (com.sun.enterprise.config.serverbeans.Servers)1 PropsFileActionReporter (com.sun.enterprise.v3.common.PropsFileActionReporter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)1 CommandRunner (org.glassfish.api.admin.CommandRunner)1 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)1