use of org.glassfish.api.ActionReport.MessagePart 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.api.ActionReport.MessagePart 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.api.ActionReport.MessagePart in project Payara by payara.
the class ActionReportJsonProvider method processReport.
/**
* Converts an ActionReport into a JsonObject
* @param ar
* @return
* @throws JsonException
*/
protected JsonObject processReport(ActionReporter ar) throws JsonException {
JsonObjectBuilder result = Json.createObjectBuilder();
if (ar instanceof RestActionReporter) {
result.add("message", ((RestActionReporter) ar).getCombinedMessage());
} else {
String message = decodeEol(ar.getMessage());
if (message != null) {
result.add("message", message);
}
}
String desc = ar.getActionDescription();
if (desc != null) {
result.add("command", ar.getActionDescription());
} else {
result.add("command", JsonValue.NULL);
}
result.add("exit_code", ar.getActionExitCode().toString());
Properties properties = ar.getTopMessagePart().getProps();
if ((properties != null) && (!properties.isEmpty())) {
JsonObject propBuilder = Json.createObjectBuilder((Map) properties).build();
result.add("properties", propBuilder);
}
Properties extraProperties = ar.getExtraProperties();
if ((extraProperties != null) && (!extraProperties.isEmpty())) {
result.add("extraProperties", getExtraProperties(extraProperties));
}
List<MessagePart> children = ar.getTopMessagePart().getChildren();
if ((children != null) && (!children.isEmpty())) {
result.add("children", processChildren(children));
}
List<ActionReporter> subReports = ar.getSubActionsReport();
if ((subReports != null) && (!subReports.isEmpty())) {
result.add("subReports", processSubReports(subReports));
}
return result.build();
}
use of org.glassfish.api.ActionReport.MessagePart in project Payara by payara.
the class ActionReportJsonProvider method processChildren.
protected JsonArray processChildren(List<MessagePart> parts) throws JsonException {
JsonArrayBuilder array = Json.createArrayBuilder();
for (MessagePart part : parts) {
JsonObjectBuilder object = Json.createObjectBuilder();
String message = decodeEol(part.getMessage());
if (message != null) {
object.add("message", decodeEol(part.getMessage()));
} else {
object.add("message", JsonValue.NULL);
}
object.add("properties", Json.createObjectBuilder((Map) part.getProps()).build());
List<MessagePart> children = part.getChildren();
if (children.size() > 0) {
object.add("children", processChildren(part.getChildren()));
}
array.add(object.build());
}
return array.build();
}
use of org.glassfish.api.ActionReport.MessagePart in project Payara by payara.
the class ActionReportXmlProvider method processChildren.
protected XmlArray processChildren(List<MessagePart> parts) {
XmlArray array = new XmlArray("children");
for (MessagePart part : parts) {
XmlMap object = new XmlMap("part");
object.put("message", part.getMessage());
object.put("properties", new XmlMap("properties", part.getProps()));
List<MessagePart> children = part.getChildren();
if (children.size() > 0) {
object.put("children", processChildren(part.getChildren()));
}
array.put(object);
}
return array;
}
Aggregations