Search in sources :

Example 11 with PropsFileActionReporter

use of com.sun.enterprise.v3.common.PropsFileActionReporter in project Payara by payara.

the class ListJdbcResourcesTest method testExecuteSuccessValidTargetOperand.

/**
 * Test of execute method, of class ListJdbcResource.
 * list-jdbc-resources server
 */
@Test
public void testExecuteSuccessValidTargetOperand() {
    // List the original set of JDBC Resources
    // Get an instance of the ListJdbcResources command
    listCommand = habitat.getService(ListJdbcResources.class);
    parameters.add("DEFAULT", "server");
    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, list.size());
    // 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) PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 12 with PropsFileActionReporter

use of com.sun.enterprise.v3.common.PropsFileActionReporter in project Payara by payara.

the class ListJdbcResourcesTest method testExecuteSuccessListNoBob.

/**
 * Test of execute method, of class ListJdbcResource.
 * delete-jdbc-resource bob
 * list-jdbc-resources
 */
@Test
public void testExecuteSuccessListNoBob() {
    // 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", "bob2");
    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());
    // Delete JDBC Resource bob
    // assertTrue(resources!=null);
    // Get an instance of the CreateJdbcResource command
    deleteCommand = habitat.getService(DeleteJdbcResource.class);
    assertTrue(deleteCommand != null);
    parameters = new ParameterMap();
    parameters.add("DEFAULT", "bob2");
    cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
    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();
    int numResources = 0;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof JdbcResource) {
            numResources = numResources + 1;
        }
    }
    assertEquals(numResources, list.size());
    List<String> listStr = new java.util.ArrayList();
    for (MessagePart mp : list) {
        listStr.add(mp.getMessage());
    }
    assertFalse(listStr.contains("bob2"));
    // Check the exit code is SUCCESS
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) MessagePart(org.glassfish.api.ActionReport.MessagePart) JdbcResource(org.glassfish.jdbc.config.JdbcResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ParameterMap(org.glassfish.api.admin.ParameterMap) PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) AdminCommandContextImpl(org.glassfish.api.admin.AdminCommandContextImpl) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 13 with PropsFileActionReporter

use of com.sun.enterprise.v3.common.PropsFileActionReporter in project Payara by payara.

the class ListJdbcResourcesTest method testExecuteFailInvalidTargetOperand.

/**
 * Test of execute method, of class ListJdbcResource.
 * list-jdbc-resources invalid
 */
@Ignore
@Test
public void testExecuteFailInvalidTargetOperand() {
    // List the original set of JDBC Resources
    // Get an instance of the ListJdbcResources command
    listCommand = habitat.getService(ListJdbcResources.class);
    parameters.add("DEFAULT", "invalid");
    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);
// Need bug fix before uncommenting assertion
// List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
// assertEquals(0, list.size());
// Check the exit code is FAILURE
// Need bug fix before uncommenting assertion
// assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
// Check error msg 'Invalid target: invalid'
}
Also used : AdminCommandContextImpl(org.glassfish.api.admin.AdminCommandContextImpl) PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) Ignore(org.junit.Ignore) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 14 with PropsFileActionReporter

use of com.sun.enterprise.v3.common.PropsFileActionReporter in project Payara by payara.

the class CommandResource method executeCommand.

private Response executeCommand(CommandName commandName, Payload.Inbound inbound, ParameterMap params, boolean supportsMultiparResult, String xIndentHeader, String modelETag, Cookie jSessionId) throws WebApplicationException {
    // Scope support
    if (RestLogging.restLogger.isLoggable(Level.FINEST)) {
        RestLogging.restLogger.log(Level.FINEST, "executeCommand(): ", commandName);
    }
    // Check command model
    CommandModel model = getCommandModel(commandName);
    checkCommandModelETag(model, modelETag);
    // Execute it
    boolean notifyOption = false;
    if (params != null) {
        notifyOption = params.containsKey("notify");
    }
    // new RestActionReporter(); //Must use PropsFileActionReporter because some commands react diferently on it :-(
    ActionReporter ar = new PropsFileActionReporter();
    final RestPayloadImpl.Outbound outbound = new RestPayloadImpl.Outbound(false);
    final CommandRunner.CommandInvocation commandInvocation = getCommandRunner().getCommandInvocation(commandName.getScope(), commandName.getName(), ar, getSubject(), notifyOption);
    if (inbound != null) {
        commandInvocation.inbound(inbound);
    }
    commandInvocation.outbound(outbound).parameters(params).execute();
    ar = (ActionReporter) commandInvocation.report();
    fixActionReporterSpecialCases(ar);
    ActionReport.ExitCode exitCode = ar.getActionExitCode();
    int status = HttpURLConnection.HTTP_OK;
    /*200 - ok*/
    if (exitCode == ActionReport.ExitCode.FAILURE) {
        status = HttpURLConnection.HTTP_INTERNAL_ERROR;
    }
    ResponseBuilder rb = Response.status(status);
    if (xIndentHeader != null) {
        rb.header("X-Indent", xIndentHeader);
    }
    if (supportsMultiparResult && outbound.size() > 0) {
        ParamsWithPayload pwp = new ParamsWithPayload(outbound, ar);
        rb.entity(pwp);
    } else {
        rb.type(MediaType.APPLICATION_JSON_TYPE);
        rb.entity(ar);
    }
    if (isSingleInstanceCommand(model)) {
        rb.cookie(getJSessionCookie(jSessionId));
    }
    return rb.build();
}
Also used : PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) ActionReport(org.glassfish.api.ActionReport) PlainTextActionReporter(com.sun.enterprise.v3.common.PlainTextActionReporter) PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) ActionReporter(com.sun.enterprise.v3.common.ActionReporter) CachedCommandModel(com.sun.enterprise.admin.util.CachedCommandModel) ParamsWithPayload(com.sun.enterprise.admin.remote.ParamsWithPayload) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) RestPayloadImpl(com.sun.enterprise.admin.remote.RestPayloadImpl)

Example 15 with PropsFileActionReporter

use of com.sun.enterprise.v3.common.PropsFileActionReporter in project Payara by payara.

the class CommandResource method executeSseCommand.

private Response executeSseCommand(CommandName commandName, Payload.Inbound inbound, ParameterMap params, String modelETag, Cookie jSessionId) throws WebApplicationException {
    // Scope support
    if (RestLogging.restLogger.isLoggable(Level.FINEST)) {
        RestLogging.restLogger.log(Level.FINEST, "executeSseCommand(): ", commandName);
    }
    // Check command model
    CommandModel model = getCommandModel(commandName);
    checkCommandModelETag(model, modelETag);
    // Execute it
    boolean notifyOption = false;
    if (params != null) {
        notifyOption = params.containsKey("notify");
    }
    final CommandRunner.CommandInvocation commandInvocation = getCommandRunner().getCommandInvocation(commandName.getScope(), commandName.getName(), new PropsFileActionReporter(), getSubject(), notifyOption);
    if (inbound != null) {
        commandInvocation.inbound(inbound);
    }
    commandInvocation.outbound(new RestPayloadImpl.Outbound(false)).managedJob().parameters(params);
    ResponseBuilder rb = Response.status(HttpURLConnection.HTTP_OK);
    if (isSingleInstanceCommand(model)) {
        rb.cookie(getJSessionCookie(jSessionId));
    }
    rb.entity(SseCommandHelper.invokeAsync(commandInvocation, null));
    return rb.build();
}
Also used : CachedCommandModel(com.sun.enterprise.admin.util.CachedCommandModel) PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) RestPayloadImpl(com.sun.enterprise.admin.remote.RestPayloadImpl)

Aggregations

PropsFileActionReporter (com.sun.enterprise.v3.common.PropsFileActionReporter)30 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)23 ParameterMap (org.glassfish.api.admin.ParameterMap)19 Before (org.junit.Before)14 CommandRunner (org.glassfish.api.admin.CommandRunner)13 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)9 Test (org.junit.Test)9 MessagePart (org.glassfish.api.ActionReport.MessagePart)7 ActionReport (org.glassfish.api.ActionReport)5 Domain (com.sun.enterprise.config.serverbeans.Domain)4 Resource (com.sun.enterprise.config.serverbeans.Resource)4 Resources (com.sun.enterprise.config.serverbeans.Resources)3 IiopService (org.glassfish.orb.admin.config.IiopService)3 RestPayloadImpl (com.sun.enterprise.admin.remote.RestPayloadImpl)2 CachedCommandModel (com.sun.enterprise.admin.util.CachedCommandModel)2 ArrayList (java.util.ArrayList)2 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 Ignore (org.junit.Ignore)2 ParamsWithPayload (com.sun.enterprise.admin.remote.ParamsWithPayload)1 ActionReporter (com.sun.enterprise.v3.common.ActionReporter)1