Search in sources :

Example 6 with CustomResource

use of org.glassfish.resources.config.CustomResource in project Payara by payara.

the class DeleteCustomResourceTest method testExecuteSuccessDefaultTarget.

/**
 * Test of execute method, of class DeleteCustomResource.
 * delete-custom-resource sample_custom_resource
 */
@Test
public void testExecuteSuccessDefaultTarget() {
    org.glassfish.resources.admin.cli.CreateCustomResource createCommand = habitat.getService(org.glassfish.resources.admin.cli.CreateCustomResource.class);
    assertTrue(createCommand != null);
    parameters.set("restype", "topic");
    parameters.set("factoryclass", "javax.naming.spi.ObjectFactory");
    parameters.set("jndi_name", "sample_custom_resource");
    cr.getCommandInvocation("create-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    parameters = new ParameterMap();
    org.glassfish.resources.admin.cli.DeleteCustomResource deleteCommand = habitat.getService(org.glassfish.resources.admin.cli.DeleteCustomResource.class);
    assertTrue(deleteCommand != null);
    parameters.set("jndi_name", "sample_custom_resource");
    cr.getCommandInvocation("delete-custom-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 CustomResource) {
            CustomResource jr = (CustomResource) resource;
            if (jr.getJndiName().equals("sample_custom_resource")) {
                isDeleted = false;
                logger.fine("CustomResource config bean sample_custom_resource 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("sample_custom_resource")) {
                    isRefDeleted = false;
                    break;
                }
            }
        }
    }
    assertTrue(isRefDeleted);
}
Also used : CustomResource(org.glassfish.resources.config.CustomResource) CustomResource(org.glassfish.resources.config.CustomResource) 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 7 with CustomResource

use of org.glassfish.resources.config.CustomResource in project Payara by payara.

the class CreateCustomResourceTest method testExecuteSuccess.

/**
 * Test of execute method, of class CreateCustomResource.
 * asadmin create-custom-resource --restype=topic --factoryclass=javax.naming.spi.ObjectFactory
 * sample_custom_resource
 */
@Test
public void testExecuteSuccess() {
    parameters.set("restype", "topic");
    parameters.set("factoryclass", "javax.naming.spi.ObjectFactory");
    parameters.set("jndi_name", "sample_custom_resource");
    // Call CommandRunnerImpl.doCommand(..) to execute the command
    cr.getCommandInvocation("create-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
    // Check the exit code is SUCCESS
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    // Check that the resource was created
    boolean isCreated = false;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof CustomResource) {
            CustomResource r = (CustomResource) resource;
            if (r.getJndiName().equals("sample_custom_resource")) {
                assertEquals("topic", r.getResType());
                assertEquals("javax.naming.spi.ObjectFactory", r.getFactoryClass());
                assertEquals("true", r.getEnabled());
                isCreated = true;
                logger.fine("Custom Resource config bean sample_custom_resource is created.");
                break;
            }
        }
    }
    assertTrue(isCreated);
    logger.fine("msg: " + context.getActionReport().getMessage());
    // Check resource-ref created
    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_custom_resource")) {
                    assertEquals("true", ref.getEnabled());
                    isRefCreated = true;
                    break;
                }
            }
        }
    }
    assertTrue(isRefCreated);
}
Also used : CustomResource(org.glassfish.resources.config.CustomResource) CustomResource(org.glassfish.resources.config.CustomResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ResourceRef(com.sun.enterprise.config.serverbeans.ResourceRef) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 8 with CustomResource

use of org.glassfish.resources.config.CustomResource in project Payara by payara.

the class DeleteCustomResourceTest 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 CustomResource) {
                    CustomResource r = (CustomResource) resource;
                    if (r.getJndiName().equals("sample_custom_resource")) {
                        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) CustomResource(org.glassfish.resources.config.CustomResource) CustomResource(org.glassfish.resources.config.CustomResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ParameterMap(org.glassfish.api.admin.ParameterMap) After(org.junit.After)

Example 9 with CustomResource

use of org.glassfish.resources.config.CustomResource in project Payara by payara.

the class CreateCustomResourceTest method testExecuteFailDuplicateResource.

/**
 * Test of execute method, of class CreateCustomResource.
 * asadmin create-custom-resource --restype=topic --factoryclass=javax.naming.spi.ObjectFactory
 * dupRes
 * asadmin create-custom-resource --restype=topic --factoryclass=javax.naming.spi.ObjectFactory
 * dupRes
 */
@Test
public void testExecuteFailDuplicateResource() {
    parameters.set("restype", "topic");
    parameters.set("factoryclass", "javax.naming.spi.ObjectFactory");
    parameters.set("jndi_name", "dupRes");
    // Call CommandRunnerImpl.doCommand(..) to execute the command
    cr.getCommandInvocation("create-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
    // Check the exit code is SUCCESS
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    // Check that the resource was created
    boolean isCreated = false;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof CustomResource) {
            CustomResource jr = (CustomResource) resource;
            if (jr.getJndiName().equals("dupRes")) {
                isCreated = true;
                logger.fine("Custom Resource config bean dupRes is created.");
                break;
            }
        }
    }
    assertTrue(isCreated);
    // Try to create a duplicate resource dupRes. Get a new instance of the command.
    org.glassfish.resources.admin.cli.CreateCustomResource command2 = habitat.getService(org.glassfish.resources.admin.cli.CreateCustomResource.class);
    cr.getCommandInvocation("create-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command2);
    // Check the exit code is FAILURE
    assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
    // Check that the 2nd resource was NOT created
    int numDupRes = 0;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof CustomResource) {
            CustomResource jr = (CustomResource) resource;
            if (jr.getJndiName().equals("dupRes")) {
                numDupRes = numDupRes + 1;
            }
        }
    }
    assertEquals(1, numDupRes);
    logger.fine("msg: " + context.getActionReport().getMessage());
}
Also used : CustomResource(org.glassfish.resources.config.CustomResource) CustomResource(org.glassfish.resources.config.CustomResource) Resource(com.sun.enterprise.config.serverbeans.Resource) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 10 with CustomResource

use of org.glassfish.resources.config.CustomResource in project Payara by payara.

the class CreateCustomResourceTest method testExecuteWithOptionalValuesSet.

/**
 * Test of execute method, of class CreateCustomResource.
 * asadmin create-custom-resource --restype=topic --factoryclass=javax.naming.spi.ObjectFactory
 * --enabled=false --description=Administered Object sample_custom_resource
 */
@Test
public void testExecuteWithOptionalValuesSet() {
    parameters.set("restype", "topic");
    parameters.set("factoryclass", "javax.naming.spi.ObjectFactory");
    parameters.set("enabled", "false");
    parameters.set("description", "Administered Object");
    parameters.set("jndi_name", "sample_custom_resource");
    // Call CommandRunnerImpl.doCommand(..) to execute the command
    cr.getCommandInvocation("create-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
    // Check the exit code is SUCCESS
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    // Check that the resource was created
    boolean isCreated = false;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof CustomResource) {
            CustomResource r = (CustomResource) resource;
            if (r.getJndiName().equals("sample_custom_resource")) {
                assertEquals("topic", r.getResType());
                assertEquals("javax.naming.spi.ObjectFactory", r.getFactoryClass());
                // expect enabled for the resource to be true as resource-ref's enabled
                // would be set to false
                assertEquals("true", r.getEnabled());
                assertEquals("Administered Object", r.getDescription());
                isCreated = true;
                logger.fine("Custom Resource config bean sample_custom_resource is created.");
                break;
            }
        }
    }
    assertTrue(isCreated);
    logger.fine("msg: " + context.getActionReport().getMessage());
}
Also used : CustomResource(org.glassfish.resources.config.CustomResource) CustomResource(org.glassfish.resources.config.CustomResource) Resource(com.sun.enterprise.config.serverbeans.Resource) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Aggregations

CustomResource (org.glassfish.resources.config.CustomResource)16 Resource (com.sun.enterprise.config.serverbeans.Resource)5 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 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)3 ResourceRef (com.sun.enterprise.config.serverbeans.ResourceRef)2 Resources (com.sun.enterprise.config.serverbeans.Resources)2 ActionReport (org.glassfish.api.ActionReport)2 ParameterMap (org.glassfish.api.admin.ParameterMap)2 Property (org.jvnet.hk2.config.types.Property)2 ResourceProperty (com.sun.enterprise.repository.ResourceProperty)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ResourceUtil (org.glassfish.resourcebase.resources.admin.cli.ResourceUtil)1 After (org.junit.After)1