Search in sources :

Example 36 with Resource

use of com.sun.enterprise.config.serverbeans.Resource 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 37 with Resource

use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.

the class ListJavaMailResourcesTest method setUp.

@Before
public void setUp() {
    habitat = getHabitat();
    parameters = new ParameterMap();
    cr = habitat.getService(CommandRunner.class);
    assertTrue(cr != null);
    Resources resources = habitat.<Domain>getService(Domain.class).getResources();
    context = new AdminCommandContextImpl(LogDomains.getLogger(ListJavaMailResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
    for (Resource resource : resources.getResources()) {
        if (resource instanceof MailResource) {
            origNum = origNum + 1;
        }
    }
}
Also used : AdminCommandContextImpl(org.glassfish.api.admin.AdminCommandContextImpl) MailResource(org.glassfish.resources.javamail.config.MailResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ParameterMap(org.glassfish.api.admin.ParameterMap) Resources(com.sun.enterprise.config.serverbeans.Resources) Domain(com.sun.enterprise.config.serverbeans.Domain) PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) CommandRunner(org.glassfish.api.admin.CommandRunner) MailResource(org.glassfish.resources.javamail.config.MailResource) Before(org.junit.Before)

Example 38 with Resource

use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.

the class CreateJndiResourceTest method testExecuteSuccess.

/**
 * Test of execute method, of class CreateJndiResource.
 * asadmin create-jndi-resource --restype=queue --factoryclass=sampleClass --jndilookupname=sample_jndi
 * sample_jndi_resource
 */
@Test
public void testExecuteSuccess() {
    parameters.set("jndilookupname", "sample_jndi");
    parameters.set("restype", "queue");
    parameters.set("factoryclass", "sampleClass");
    parameters.set("jndi_name", "sample_jndi_resource");
    org.glassfish.resources.admin.cli.CreateJndiResource command = habitat.getService(org.glassfish.resources.admin.cli.CreateJndiResource.class);
    cr.getCommandInvocation("create-jndi-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 ExternalJndiResource) {
            ExternalJndiResource r = (ExternalJndiResource) resource;
            if (r.getJndiName().equals("sample_jndi_resource")) {
                assertEquals("queue", r.getResType());
                assertEquals("sample_jndi", r.getJndiLookupName());
                assertEquals("sampleClass", r.getFactoryClass());
                assertEquals("true", r.getEnabled());
                isCreated = true;
                logger.fine("Jndi Resource config bean sample_jndi_resource is created.");
                break;
            }
        }
    }
    assertTrue(isCreated);
    logger.fine("msg: " + context.getActionReport().getMessage());
    Servers servers = habitat.getService(Servers.class);
    boolean isRefCreated = false;
    for (Server server : servers.getServer()) {
        if (server.getName().equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
            for (ResourceRef ref : server.getResourceRef()) {
                if (ref.getRef().equals("sample_jndi_resource")) {
                    assertEquals("true", ref.getEnabled());
                    isRefCreated = true;
                    break;
                }
            }
        }
    }
    assertTrue(isRefCreated);
}
Also used : BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ResourceRef(com.sun.enterprise.config.serverbeans.ResourceRef) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 39 with Resource

use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.

the class CreateJndiResourceTest method testExecuteFailDuplicateResource.

/**
 * Test of execute method, of class CreateJndiResource.
 * asadmin create-jndi-resource --restype=queue --factoryclass=sampleClass --jndilookupname=sample_jndi
 * dupRes
 * asadmin create-jndi-resource --restype=queue --factoryclass=sampleClass --jndilookupname=sample_jndi
 * dupRes
 */
@Test
public void testExecuteFailDuplicateResource() {
    parameters.set("jndilookupname", "sample_jndi");
    parameters.set("restype", "queue");
    parameters.set("factoryclass", "sampleClass");
    parameters.set("jndi_name", "dupRes");
    org.glassfish.resources.admin.cli.CreateJndiResource command1 = habitat.getService(org.glassfish.resources.admin.cli.CreateJndiResource.class);
    cr.getCommandInvocation("create-jndi-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 BindableResource) {
            BindableResource jr = (BindableResource) resource;
            if (jr.getJndiName().equals("dupRes")) {
                isCreated = true;
                logger.fine("Jndi Resource config bean dupRes is created.");
                break;
            }
        }
    }
    assertTrue(isCreated);
    org.glassfish.resources.admin.cli.CreateJndiResource command2 = habitat.getService(org.glassfish.resources.admin.cli.CreateJndiResource.class);
    cr.getCommandInvocation("create-jndi-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 BindableResource) {
            BindableResource jr = (BindableResource) resource;
            if (jr.getJndiName().equals("dupRes")) {
                numDupRes = numDupRes + 1;
            }
        }
    }
    assertEquals(1, numDupRes);
    logger.fine("msg: " + context.getActionReport().getMessage());
}
Also used : BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource) Resource(com.sun.enterprise.config.serverbeans.Resource) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 40 with Resource

use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.

the class DeleteJndiResourceTest method tearDown.

@After
public void tearDown() throws TransactionFailure {
    parameters = new ParameterMap();
    ConfigSupport.apply(new SingleConfigCode<Resources>() {

        public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
            Resource target = null;
            for (Resource resource : param.getResources()) {
                if (resource instanceof BindableResource) {
                    BindableResource r = (BindableResource) resource;
                    if (r.getJndiName().equals("sample_jndi_resource") || r.getJndiName().equals("dupRes")) {
                        target = resource;
                        break;
                    }
                }
            }
            if (target != null) {
                param.getResources().remove(target);
            }
            return null;
        }
    }, resources);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ParameterMap(org.glassfish.api.admin.ParameterMap) After(org.junit.After)

Aggregations

Resource (com.sun.enterprise.config.serverbeans.Resource)44 Resources (com.sun.enterprise.config.serverbeans.Resources)14 Test (org.junit.Test)14 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)13 ParameterMap (org.glassfish.api.admin.ParameterMap)10 BindableResource (com.sun.enterprise.config.serverbeans.BindableResource)9 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)9 Domain (com.sun.enterprise.config.serverbeans.Domain)6 ResourceRef (com.sun.enterprise.config.serverbeans.ResourceRef)6 JdbcResource (org.glassfish.jdbc.config.JdbcResource)6 MailResource (org.glassfish.resources.javamail.config.MailResource)6 ResourceException (javax.resource.ResourceException)5 AdminObjectResource (org.glassfish.connectors.config.AdminObjectResource)5 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)5 Resource (org.glassfish.resources.api.Resource)5 CustomResource (org.glassfish.resources.config.CustomResource)5 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)5 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)4 PropsFileActionReporter (com.sun.enterprise.v3.common.PropsFileActionReporter)4 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)4