Search in sources :

Example 21 with ParameterMap

use of org.glassfish.api.admin.ParameterMap 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 22 with ParameterMap

use of org.glassfish.api.admin.ParameterMap in project Payara by payara.

the class CreateCustomResourceTest method setUp.

@Before
public void setUp() {
    parameters = new ParameterMap();
    resources = habitat.<Domain>getService(Domain.class).getResources();
    assertTrue(resources != null);
    command = habitat.getService(org.glassfish.resources.admin.cli.CreateCustomResource.class);
    assertTrue(command != null);
    context = new AdminCommandContextImpl(LogDomains.getLogger(CreateCustomResourceTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
    cr = habitat.getService(CommandRunner.class);
}
Also used : AdminCommandContextImpl(org.glassfish.api.admin.AdminCommandContextImpl) ParameterMap(org.glassfish.api.admin.ParameterMap) PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) CommandRunner(org.glassfish.api.admin.CommandRunner) Before(org.junit.Before)

Example 23 with ParameterMap

use of org.glassfish.api.admin.ParameterMap in project Payara by payara.

the class CreateCustomResourceTest method tearDown.

@After
public void tearDown() throws TransactionFailure {
    org.glassfish.resources.admin.cli.DeleteCustomResource deleteCommand = habitat.getService(org.glassfish.resources.admin.cli.DeleteCustomResource.class);
    parameters = new ParameterMap();
    parameters.set("jndi_name", "sample_custom_resource");
    cr.getCommandInvocation("delete-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
    parameters = new ParameterMap();
    parameters.set("jndi_name", "dupRes");
    cr.getCommandInvocation("delete-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap) After(org.junit.After)

Example 24 with ParameterMap

use of org.glassfish.api.admin.ParameterMap in project Payara by payara.

the class ListCustomResourcesTest method testExecuteSuccessListResource.

/**
 * Test of execute method, of class ListCustomResources.
 * create-custom-resource ---restype=topic --factoryclass=javax.naming.spi.ObjectFactory
 * Resource1
 * list-custom-resources
 */
@Test
public void testExecuteSuccessListResource() {
    createCustomResource();
    ParameterMap parameters = new ParameterMap();
    org.glassfish.resources.admin.cli.ListCustomResources listCommand = habitat.getService(org.glassfish.resources.admin.cli.ListCustomResources.class);
    cr.getCommandInvocation("list-custom-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
    List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
    assertEquals(origNum + 1, list.size());
    List<String> listStr = new java.util.ArrayList<String>();
    for (MessagePart mp : list) {
        listStr.add(mp.getMessage());
    }
    assertTrue(listStr.contains("custom_resource1"));
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    deleteCustomResource();
}
Also used : MessagePart(org.glassfish.api.ActionReport.MessagePart) ParameterMap(org.glassfish.api.admin.ParameterMap) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 25 with ParameterMap

use of org.glassfish.api.admin.ParameterMap in project Payara by payara.

the class ListCustomResourcesTest method setUp.

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

Aggregations

ParameterMap (org.glassfish.api.admin.ParameterMap)149 ActionReport (org.glassfish.api.ActionReport)68 CommandRunner (org.glassfish.api.admin.CommandRunner)37 Test (org.junit.Test)25 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)24 Map (java.util.Map)20 PropsFileActionReporter (com.sun.enterprise.v3.common.PropsFileActionReporter)19 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)18 List (java.util.List)16 ArrayList (java.util.ArrayList)15 CommandRunner (org.glassfish.embeddable.CommandRunner)15 IOException (java.io.IOException)14 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)13 Before (org.junit.Before)13 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)13 CommandException (org.glassfish.api.admin.CommandException)12 File (java.io.File)11 MessagePart (org.glassfish.api.ActionReport.MessagePart)11 Resource (com.sun.enterprise.config.serverbeans.Resource)10 Logger (java.util.logging.Logger)9