use of com.enonic.xp.script.serializer.JsonMapGenerator in project xp by enonic.
the class PushNodesResultMapperTest method single_successful.
@Test
public void single_successful() throws Exception {
final PushNodesResult result = PushNodesResult.create().addSuccess(createEntry("a")).build();
final JsonMapGenerator jsonGenerator = new JsonMapGenerator();
new PushNodesResultMapper(result, NodeIds.empty()).serialize(jsonGenerator);
assertJson("nodeResult/single_successful.json", jsonGenerator);
}
use of com.enonic.xp.script.serializer.JsonMapGenerator in project xp by enonic.
the class PushNodesResultMapperTest method complex.
@Test
public void complex() throws Exception {
final PushNodesResult result = PushNodesResult.create().addSuccess(createEntry("a")).addSuccess(createEntry("b")).addSuccess(createEntry("c")).addFailed(createEntry("d"), PushNodesResult.Reason.ACCESS_DENIED).addFailed(createEntry("e"), PushNodesResult.Reason.PARENT_NOT_FOUND).addFailed(createEntry("f"), PushNodesResult.Reason.PARENT_NOT_FOUND).build();
final JsonMapGenerator jsonGenerator = new JsonMapGenerator();
new PushNodesResultMapper(result, NodeIds.from("g", "h", "i")).serialize(jsonGenerator);
assertJson("nodeResult/full.json", jsonGenerator);
}
use of com.enonic.xp.script.serializer.JsonMapGenerator in project xp by enonic.
the class NodeMultiRepoQueryResultMapperTest method name.
@Test
public void name() throws Exception {
final FindNodesByMultiRepoQueryResult result = FindNodesByMultiRepoQueryResult.create().addNodeHit(MultiRepoNodeHit.create().nodeId(NodeId.from("abc")).branch(Branch.from("fisk")).repositoryId(RepositoryId.from("repo")).explanation(QueryExplanation.create().description("myDescription").value(123L).addDetail(QueryExplanation.create().description("myDescription").value(123L).build()).build()).build()).build();
final NodeMultiRepoQueryResultMapper mapper = new NodeMultiRepoQueryResultMapper(result);
final JsonMapGenerator gen = new JsonMapGenerator();
mapper.serialize(gen);
System.out.println(gen.getRoot());
}
use of com.enonic.xp.script.serializer.JsonMapGenerator in project xp by enonic.
the class ResolveSyncWorkResultMapperTest method full.
@Test
public void full() throws Exception {
final ResolveSyncWorkResult result = ResolveSyncWorkResult.create().add(new NodeComparison(createEntry("a"), createEntry("a"), CompareStatus.NEW)).add(new NodeComparison(createEntry("b"), createEntry("b"), CompareStatus.MOVED)).add(new NodeComparison(createEntry("c"), createEntry("c"), CompareStatus.NEWER)).build();
final JsonMapGenerator jsonGenerator = new JsonMapGenerator();
new ResolveSyncWorkResultMapper(result).serialize(jsonGenerator);
assertJson("resolveSyncWork/full.json", jsonGenerator);
}
use of com.enonic.xp.script.serializer.JsonMapGenerator in project xp by enonic.
the class MacroContextMapperTest method assertJson.
private void assertJson(final String name, final MapSerializable value) throws Exception {
final String resource = "/" + getClass().getName().replace('.', '/') + "-" + name + ".json";
final URL url = getClass().getResource(resource);
assertNotNull(url, "File [" + resource + "] not found");
final JsonNode expectedJson = MAPPER.readTree(url);
final JsonMapGenerator generator = new JsonMapGenerator();
value.serialize(generator);
final JsonNode actualJson = (JsonNode) generator.getRoot();
final String expectedStr = MAPPER.writeValueAsString(expectedJson);
final String actualStr = MAPPER.writeValueAsString(actualJson);
assertEquals(expectedStr, actualStr);
}
Aggregations