Search in sources :

Example 71 with ParameterMap

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

the class ListCustomResourcesTest method createCustomResource.

private void createCustomResource() {
    org.glassfish.resources.admin.cli.CreateCustomResource createCommand = habitat.getService(org.glassfish.resources.admin.cli.CreateCustomResource.class);
    assertTrue(createCommand != null);
    ParameterMap parameters = new ParameterMap();
    parameters.set("restype", "topic");
    parameters.set("factoryclass", "javax.naming.spi.ObjectFactory");
    parameters.set("jndi_name", "custom_resource1");
    cr.getCommandInvocation("create-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap)

Example 72 with ParameterMap

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

the class DeleteJdbcResourceTest method setUp.

@Before
public void setUp() {
    assertTrue(resources != null);
    // Create a JDBC Resource jdbc/foo for each test
    CreateJdbcResource createCommand = habitat.getService(CreateJdbcResource.class);
    assertTrue(createCommand != null);
    parameters.add("connectionpoolid", "DerbyPool");
    parameters.add("DEFAULT", "jdbc/foo");
    context = new AdminCommandContextImpl(LogDomains.getLogger(DeleteJdbcResourceTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
    cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    // Setup for delete-jdbc-resource
    parameters = new ParameterMap();
    deleteCommand = habitat.getService(DeleteJdbcResource.class);
    assertTrue(deleteCommand != null);
}
Also used : AdminCommandContextImpl(org.glassfish.api.admin.AdminCommandContextImpl) ParameterMap(org.glassfish.api.admin.ParameterMap) PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) Before(org.junit.Before)

Example 73 with ParameterMap

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

the class CreateJdbcResourceTest method testExecuteSuccessDefaultValues.

/**
 * Test of execute method, of class CreateJdbcResource.
 * asadmin create-jdbc-resource --connectionpoolid DerbyPool jdbc/alldefaults
 */
@Test
public void testExecuteSuccessDefaultValues() {
    // Only pass the required option and operand
    parameters = new ParameterMap();
    parameters.set("connectionpoolid", "DerbyPool");
    parameters.set("DEFAULT", "jdbc/alldefaults");
    // Call CommandRunnerImpl.doCommand(..) to execute the command
    cr.getCommandInvocation("create-jdbc-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 JdbcResource) {
            JdbcResource jr = (JdbcResource) resource;
            if (jr.getJndiName().equals("jdbc/alldefaults")) {
                assertEquals("DerbyPool", jr.getPoolName());
                assertEquals("true", jr.getEnabled());
                assertNull(jr.getDescription());
                isCreated = true;
                logger.fine("JdbcResource config bean jdbc/alldefaults is created.");
                continue;
            }
        }
    }
    assertTrue(isCreated);
    logger.fine("msg: " + context.getActionReport().getMessage());
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) JdbcResource(org.glassfish.jdbc.config.JdbcResource) ParameterMap(org.glassfish.api.admin.ParameterMap) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 74 with ParameterMap

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

the class ListJdbcResourcesTest method testExecuteSuccessListBob.

/**
 * Test of execute method, of class ListJdbcResource.
 * create-jdbc-resource --connectionpoolid DerbyPool bob
 * list-jdbc-resources
 */
@Test
public void testExecuteSuccessListBob() {
    // Create JDBC Resource bob
    assertTrue(resources != null);
    // Get an instance of the CreateJdbcResource command
    createCommand = habitat.getService(CreateJdbcResource.class);
    assertTrue(createCommand != null);
    parameters.add("connectionpoolid", "DerbyPool");
    parameters.add("DEFAULT", "bob");
    context = new AdminCommandContextImpl(LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
    cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    // List JDBC Resources and check if bob is in the list
    // Get an instance of the ListJdbcResources command
    listCommand = habitat.getService(ListJdbcResources.class);
    parameters = new ParameterMap();
    context = new AdminCommandContextImpl(LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
    // Call CommandRunnerImpl.doCommand(..) to execute the command
    cr.getCommandInvocation("list-jdbc-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();
    for (MessagePart mp : list) {
        listStr.add(mp.getMessage());
    }
    assertTrue(listStr.contains("bob"));
    // Check the exit code is SUCCESS
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
}
Also used : AdminCommandContextImpl(org.glassfish.api.admin.AdminCommandContextImpl) MessagePart(org.glassfish.api.ActionReport.MessagePart) ParameterMap(org.glassfish.api.admin.ParameterMap) PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 75 with ParameterMap

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

the class ListJndiResourcesTest method testExecuteSuccessListResource.

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

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