Search in sources :

Example 36 with RestActionReporter

use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.

the class Util method applyChanges.

public static RestActionReporter applyChanges(Map<String, String> data, String basePath, Subject subject) {
    ParameterMap parameters = new ParameterMap();
    Map<String, String> currentValues = getCurrentValues(basePath, subject);
    for (Map.Entry<String, String> entry : data.entrySet()) {
        String currentValue = currentValues.get(basePath + entry.getKey());
        if ((currentValue == null) || entry.getValue().equals("") || (!currentValue.equals(entry.getValue()))) {
            parameters.add("DEFAULT", basePath + entry.getKey() + "=" + entry.getValue());
        }
    }
    if (!parameters.entrySet().isEmpty()) {
        return ResourceUtil.runCommand("set", parameters, subject);
    } else {
        // noop
        return new RestActionReporter();
    }
}
Also used : RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ParameterMap(org.glassfish.api.admin.ParameterMap) HashMap(java.util.HashMap) Map(java.util.Map) ParameterMap(org.glassfish.api.admin.ParameterMap)

Example 37 with RestActionReporter

use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.

the class ActionReportTest method actionReportMarshallingTest.

@Test
public void actionReportMarshallingTest() throws IOException {
    RestActionReporter ar = new RestActionReporter();
    ar.setActionDescription("Some description");
    ar.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    ar.setExtraProperties(null);
    basicMarshallingTest(ar);
    ar.getTopMessagePart().setMessage("First message in First report");
    basicMarshallingTest(ar);
    ar.getTopMessagePart().addProperty("AR1-MSG1-PROP1", "1.1.1.");
    basicMarshallingTest(ar);
    ar.getTopMessagePart().addProperty("AR1-MSG1-PROP2", "1.1.2.");
    basicMarshallingTest(ar);
    MessagePart part1 = ar.getTopMessagePart().addChild();
    basicMarshallingTest(ar);
    part1.setMessage("Second message in First report");
    basicMarshallingTest(ar);
    part1.addProperty("AR1-MSG2-PROP1", "1.2.1.");
    part1.addProperty("AR1-MSG2-PROP2", "1.2.2.");
    basicMarshallingTest(ar);
    MessagePart part2 = part1.addChild();
    part2.setMessage("Third message in First report");
    part2.addProperty("AR1-MSG3-PROP1", "1.3.1.");
    part2.addProperty("AR1-MSG3-PROP2", "1.3.2.");
    basicMarshallingTest(ar);
    MessagePart part3 = ar.getTopMessagePart().addChild();
    part3.setMessage("Fourth message in First report");
    part3.addProperty("AR1-MSG4-PROP1", "1.4.1.");
    part3.addProperty("AR1-MSG4-PROP2", "1.4.2.");
    basicMarshallingTest(ar);
    Properties extra = new Properties();
    extra.setProperty("EP1-PROP1", "1.1");
    extra.setProperty("EP1-PROP2", "1.2");
    ar.setExtraProperties(extra);
    ActionReport ar2 = ar.addSubActionsReport();
    ar2.setActionExitCode(ActionReport.ExitCode.WARNING);
    ar2.setActionDescription("Description 2");
    ar2.getTopMessagePart().setMessage("First Message in Second Report");
    MessagePart subPart2 = ar2.getTopMessagePart().addChild();
    subPart2.addProperty("AR2-MSG2-PROP1", "2.2.1.");
    subPart2.setMessage("Second Message in Second Report");
    basicMarshallingTest(ar);
    ActionReport ar3 = ar.addSubActionsReport();
    ar3.setActionExitCode(ActionReport.ExitCode.FAILURE);
    ar3.setActionDescription("Description 3");
    ar3.setFailureCause(new Exception("Some exception message"));
    basicMarshallingTest(ar);
}
Also used : RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) MessagePart(org.glassfish.api.ActionReport.MessagePart) Properties(java.util.Properties) ActionReport(org.glassfish.api.ActionReport) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 38 with RestActionReporter

use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.

the class EncodingTest method encodeAsHtml.

@Test
public void encodeAsHtml() {
    RestActionReporter ar = buildActionReport();
    ActionReportResultHtmlProvider provider = new ActionReportResultHtmlProvider();
    ActionReportResult result = new ActionReportResult("test", ar);
    String html = provider.getContent(result);
// How to test this?
}
Also used : ActionReportResultHtmlProvider(org.glassfish.admin.rest.provider.ActionReportResultHtmlProvider) ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) Test(org.testng.annotations.Test)

Example 39 with RestActionReporter

use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.

the class EncodingTest method buildActionReport.

private RestActionReporter buildActionReport() {
    RestActionReporter ar = new RestActionReporter();
    ar.setActionDescription("test description");
    ar.setActionExitCode(ExitCode.SUCCESS);
    ar.setMessage("test message");
    // top message properties
    ar.getTopMessagePart().getProps().put("property1", "value1");
    ar.getTopMessagePart().getProps().put("property2", "value2");
    // extra properties
    Properties props = new Properties();
    props.put("test1", new ArrayList() {

        {
            add("value1");
            add("value2");
        }
    });
    props.put("test2", new ArrayList() {

        {
            add("value1");
            add(new HashMap() {

                {
                    put("entry1", "value1");
                    put("entry2", new Long(1000));
                    put("entry3", new HashMap() {

                        {
                            put("foo", new ArrayList() {

                                {
                                    add("bar");
                                    add(new BigDecimal(1000));
                                }
                            });
                        }
                    });
                }
            });
        }
    });
    props.put("test3", new BigInteger("2100"));
    props.put("test4", "A String property");
    ar.setExtraProperties(props);
    // child parts
    MessagePart child1 = ar.getTopMessagePart().addChild();
    child1.setMessage("child 1 message");
    child1.getProps().put("child1 prop1", "child1 value1");
    child1.getProps().put("child1 prop2", "child1 value2");
    MessagePart child2 = ar.getTopMessagePart().addChild();
    child2.setMessage("child 2 message");
    child2.getProps().put("child2 prop1", "child2 value1");
    child2.getProps().put("child2 prop2", "child2 value2");
    MessagePart grandChild1 = child2.addChild();
    grandChild1.setMessage("grand child 1 message");
    grandChild1.getProps().put("gc1 prop1", "gc1 value1");
    grandChild1.getProps().put("gc1 prop2", "gc1 value2");
    // sub reports
    ActionReport subReport1 = ar.addSubActionsReport();
    subReport1.setActionDescription("sub report 1");
    subReport1.setMessage("sub report 1 message");
    ActionReport subReport2 = ar.addSubActionsReport();
    subReport2.setActionDescription("sub report 2");
    subReport2.setMessage("sub report 2 message");
    return ar;
}
Also used : RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) HashMap(java.util.HashMap) MessagePart(org.glassfish.api.ActionReport.MessagePart) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) Properties(java.util.Properties) ActionReport(org.glassfish.api.ActionReport) BigDecimal(java.math.BigDecimal)

Example 40 with RestActionReporter

use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.

the class EncodingTest method encodeAsJson.

@Test
public void encodeAsJson() {
    RestActionReporter ar = buildActionReport();
    ActionReportResultJsonProvider provider = new ActionReportResultJsonProvider();
    ActionReportResult result = new ActionReportResult("test", ar);
    String json = provider.getContent(result);
    Map responseMap = MarshallingUtils.buildMapFromDocument(json);
    assertEquals(7, responseMap.size());
    assertEquals(4, ((Map) responseMap.get("extraProperties")).size());
    assertTrue(responseMap.get("children") instanceof List);
    assertTrue(responseMap.get("subReports") instanceof List);
}
Also used : ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ArrayList(java.util.ArrayList) List(java.util.List) ActionReportResultJsonProvider(org.glassfish.admin.rest.provider.ActionReportResultJsonProvider) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Aggregations

RestActionReporter (org.glassfish.admin.rest.utils.xml.RestActionReporter)44 ActionReportResult (org.glassfish.admin.rest.results.ActionReportResult)23 OptionsResult (org.glassfish.admin.rest.results.OptionsResult)13 ActionReport (org.glassfish.api.ActionReport)12 Produces (javax.ws.rs.Produces)9 WebApplicationException (javax.ws.rs.WebApplicationException)8 HashMap (java.util.HashMap)7 Properties (java.util.Properties)7 GET (javax.ws.rs.GET)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 Consumes (javax.ws.rs.Consumes)5 MethodMetaData (org.glassfish.admin.rest.provider.MethodMetaData)5 MessagePart (org.glassfish.api.ActionReport.MessagePart)5 ParameterMap (org.glassfish.api.admin.ParameterMap)5 CommandRunner (org.glassfish.api.admin.CommandRunner)4 Test (org.testng.annotations.Test)4 ActionReporter (com.sun.enterprise.v3.common.ActionReporter)3 List (java.util.List)3 MultiException (org.glassfish.hk2.api.MultiException)3