Search in sources :

Example 11 with Resource

use of com.sun.enterprise.config.serverbeans.Resource 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();
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) 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) MailResource(org.glassfish.resources.javamail.config.MailResource) After(org.junit.After)

Example 12 with Resource

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

the class CreateJndiResourceTest method testExecuteWithOptionalValuesSet.

/**
 * Test of execute method, of class CreateJndiResource.
 * asadmin create-jndi-resource --restype=queue --factoryclass=sampleClass --jndilookupname=sample_jndi
 * --enabled=false --description=External JNDI Resource
 * sample_jndi_resource
 */
@Test
public void testExecuteWithOptionalValuesSet() {
    parameters.set("jndilookupname", "sample_jndi");
    parameters.set("restype", "queue");
    parameters.set("factoryclass", "sampleClass");
    parameters.set("enabled", "false");
    parameters.set("description", "External JNDI Resource");
    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("sampleClass", r.getFactoryClass());
                assertEquals("sample_jndi", r.getJndiLookupName());
                // expect enabled for the resource to be true as resource-ref's enabled
                // would be set to false
                assertEquals("true", r.getEnabled());
                assertEquals("External JNDI Resource", r.getDescription());
                isCreated = true;
                logger.fine("Jndi Resource config bean sample_jndi_resource is created.");
                break;
            }
        }
    }
    assertTrue(isCreated);
    /*
        ResourceRef ref = server.getResourceRef("sample_jndi_resource");
        assertTrue(ref != null);
        assertEquals("false", ref.getEnabled());
*/
    logger.fine("msg: " + context.getActionReport().getMessage());
}
Also used : BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 13 with Resource

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

the class DeleteJndiResourceTest method testExecuteSuccessDefaultTarget.

/**
 * Test of execute method, of class DeleteJndiResource.
 * asadmin create-jndi-resource --restype=queue --factoryclass=sampleClass --jndilookupname=sample_jndi
 * sample_jndi_resource
 * delete-jndi-resource sample_jndi_resource
 */
@Test
public void testExecuteSuccessDefaultTarget() {
    parameters.set("restype", "topic");
    parameters.set("jndilookupname", "sample_jndi");
    parameters.set("factoryclass", "javax.naming.spi.ObjectFactory");
    parameters.set("jndi_name", "sample_jndi_resource");
    org.glassfish.resources.admin.cli.CreateJndiResource createCommand = habitat.getService(org.glassfish.resources.admin.cli.CreateJndiResource.class);
    cr.getCommandInvocation("create-jndi-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    parameters = new ParameterMap();
    parameters.set("jndi_name", "sample_jndi_resource");
    org.glassfish.resources.admin.cli.DeleteJndiResource deleteCommand = habitat.getService(org.glassfish.resources.admin.cli.DeleteJndiResource.class);
    cr.getCommandInvocation("delete-jndi-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 BindableResource) {
            BindableResource jr = (BindableResource) resource;
            if (jr.getJndiName().equals("sample_jndi_resource")) {
                isDeleted = false;
                logger.fine("Jndi Resource config bean sample_jndi_resource is created.");
                break;
            }
        }
    }
    assertTrue(isDeleted);
    logger.fine("msg: " + context.getActionReport().getMessage());
    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("sample_jndi_resource")) {
                    isRefDeleted = false;
                    break;
                }
            }
        }
    }
    assertTrue(isRefDeleted);
}
Also used : 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) ResourceRef(com.sun.enterprise.config.serverbeans.ResourceRef) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 14 with Resource

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

the class ConnectorApplication method deployGlobalResources.

private void deployGlobalResources() {
    Resources allResources = resourceManager.getAllResources();
    Collection<Resource> resources = resourcesUtil.filterConnectorResources(allResources, moduleName, false);
    resourceManager.deployResources(resources);
}
Also used : AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) Resource(com.sun.enterprise.config.serverbeans.Resource) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 15 with Resource

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

the class ConnectorService method loadDeferredResources.

public void loadDeferredResources(Resource[] resourcesToLoad) throws Exception {
    if (resourcesToLoad == null || resourcesToLoad.length == 0) {
        return;
    }
    for (Resource resource : resourcesToLoad) {
        if (resource == null) {
            continue;
        } else if (getResourcesUtil().isEnabled(resource)) {
            try {
                _runtime.getResourceDeployer(resource).deployResource(resource);
            } catch (Exception e) {
                ConnectorRuntimeException cre = new ConnectorRuntimeException(e.getMessage());
                cre.initCause(e);
                throw cre;
            }
        }
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) Resource(com.sun.enterprise.config.serverbeans.Resource) URISyntaxException(java.net.URISyntaxException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)

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