Search in sources :

Example 16 with MessagePart

use of org.glassfish.api.ActionReport.MessagePart 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 17 with MessagePart

use of org.glassfish.api.ActionReport.MessagePart in project Payara by payara.

the class ListJavaMailResourcesTest method testExecuteSuccessListMailResource.

/**
 * Test of execute method, of class ListJavaMailResource.
 * create-javamail-resource --mailuser=test --mailhost=localhost
 * --fromaddress=test@sun.com mailresource
 * list-javamail-resources
 */
@Test
public void testExecuteSuccessListMailResource() {
    createJavaMailResource();
    parameters = new ParameterMap();
    org.glassfish.resources.javamail.admin.cli.ListJavaMailResources listCommand = habitat.getService(org.glassfish.resources.javamail.admin.cli.ListJavaMailResources.class);
    assertTrue(listCommand != null);
    cr.getCommandInvocation("list-javamail-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
    List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
    assertEquals(origNum + 1, list.size());
    List<String> listStr = new ArrayList<String>();
    for (MessagePart mp : list) {
        listStr.add(mp.getMessage());
    }
    assertTrue(listStr.contains("mailresource"));
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    deleteJavaMailResource();
}
Also used : MessagePart(org.glassfish.api.ActionReport.MessagePart) ArrayList(java.util.ArrayList) ParameterMap(org.glassfish.api.admin.ParameterMap) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 18 with MessagePart

use of org.glassfish.api.ActionReport.MessagePart in project Payara by payara.

the class ListIiopListenersTest method testExecuteSuccessListListener.

/**
 * Test of execute method, of class ListIiopListeners.
 * asadmin create-iiop-listener --listeneraddress localhost
 * --iiopport 4440 listener
 * list-iiop-listeners
 * delete-iiop-listener listener
 */
@Test
public void testExecuteSuccessListListener() {
    parameters.set("listeneraddress", "localhost");
    parameters.set("iiopport", "4440");
    parameters.set("listener_id", "listener");
    CreateIiopListener createCommand = services.getService(CreateIiopListener.class);
    cr.getCommandInvocation("create-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
    CreateIiopListenerTest.checkActionReport(context.getActionReport());
    parameters = new ParameterMap();
    ListIiopListeners listCommand = services.getService(ListIiopListeners.class);
    cr.getCommandInvocation("list-iiop-listeners", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
    List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
    assertEquals(origNum + 1, list.size());
    List<String> listStr = new ArrayList<String>();
    for (MessagePart mp : list) {
        listStr.add(mp.getMessage());
    }
    assertTrue(listStr.contains("listener"));
    CreateIiopListenerTest.checkActionReport(context.getActionReport());
    parameters = new ParameterMap();
    parameters.set("listener_id", "listener");
    DeleteIiopListener deleteCommand = services.getService(DeleteIiopListener.class);
    cr.getCommandInvocation("delete-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
    CreateIiopListenerTest.checkActionReport(context.getActionReport());
}
Also used : MessagePart(org.glassfish.api.ActionReport.MessagePart) ArrayList(java.util.ArrayList) ParameterMap(org.glassfish.api.admin.ParameterMap) Test(org.junit.Test)

Example 19 with MessagePart

use of org.glassfish.api.ActionReport.MessagePart in project Payara by payara.

the class SetRestMonitoringConfigurationCommand method defaultRestMonitoringUserExists.

private boolean defaultRestMonitoringUserExists(ActionReport subActionReport, Subject subject) {
    boolean exists = false;
    CommandInvocation invocation = commandRunner.getCommandInvocation("list-file-users", subActionReport, subject, false);
    ParameterMap parameters = new ParameterMap();
    parameters.add("authrealmname", "file");
    invocation.parameters(parameters).execute();
    for (MessagePart message : subActionReport.getTopMessagePart().getChildren()) {
        if (message.getMessage().equals(DEFAULT_USER_NAME)) {
            exists = true;
            break;
        }
    }
    return exists;
}
Also used : MessagePart(org.glassfish.api.ActionReport.MessagePart) ParameterMap(org.glassfish.api.admin.ParameterMap) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

Example 20 with MessagePart

use of org.glassfish.api.ActionReport.MessagePart in project Payara by payara.

the class Util method getCurrentValues.

public static Map<String, String> getCurrentValues(String basePath, ServiceLocator habitat, Subject subject) {
    Map<String, String> values = new HashMap<String, String>();
    final String path = (basePath.endsWith(".")) ? basePath.substring(0, basePath.length() - 1) : basePath;
    RestActionReporter gr = ResourceUtil.runCommand("get", new ParameterMap() {

        {
            add("DEFAULT", path);
        }
    }, subject);
    MessagePart top = gr.getTopMessagePart();
    for (MessagePart child : top.getChildren()) {
        String message = child.getMessage();
        if (message.contains("=")) {
            String[] parts = message.split("=");
            values.put(parts[0], (parts.length > 1) ? parts[1] : "");
        }
    }
    return values;
}
Also used : RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) HashMap(java.util.HashMap) MessagePart(org.glassfish.api.ActionReport.MessagePart) ParameterMap(org.glassfish.api.admin.ParameterMap)

Aggregations

MessagePart (org.glassfish.api.ActionReport.MessagePart)25 ParameterMap (org.glassfish.api.admin.ParameterMap)11 Test (org.junit.Test)11 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)9 PropsFileActionReporter (com.sun.enterprise.v3.common.PropsFileActionReporter)7 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)7 ArrayList (java.util.ArrayList)5 RestActionReporter (org.glassfish.admin.rest.utils.xml.RestActionReporter)5 Properties (java.util.Properties)4 ActionReport (org.glassfish.api.ActionReport)4 HashMap (java.util.HashMap)3 ActionReporter (com.sun.enterprise.v3.common.ActionReporter)2 Map (java.util.Map)2 JsonObject (javax.json.JsonObject)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 XmlMap (org.glassfish.admin.rest.utils.xml.XmlMap)2 CommandInvocation (org.glassfish.api.admin.CommandRunner.CommandInvocation)2 RemoteCLICommand (com.sun.enterprise.admin.cli.remote.RemoteCLICommand)1 Resource (com.sun.enterprise.config.serverbeans.Resource)1 IOException (java.io.IOException)1