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();
}
}
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);
}
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?
}
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;
}
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);
}
Aggregations