Search in sources :

Example 11 with JsonMapGenerator

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);
}
Also used : PushNodesResult(com.enonic.xp.node.PushNodesResult) JsonMapGenerator(com.enonic.xp.script.serializer.JsonMapGenerator) Test(org.junit.jupiter.api.Test)

Example 12 with JsonMapGenerator

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);
}
Also used : PushNodesResult(com.enonic.xp.node.PushNodesResult) JsonMapGenerator(com.enonic.xp.script.serializer.JsonMapGenerator) Test(org.junit.jupiter.api.Test)

Example 13 with JsonMapGenerator

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());
}
Also used : FindNodesByMultiRepoQueryResult(com.enonic.xp.node.FindNodesByMultiRepoQueryResult) JsonMapGenerator(com.enonic.xp.script.serializer.JsonMapGenerator) Test(org.junit.jupiter.api.Test)

Example 14 with JsonMapGenerator

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);
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) JsonMapGenerator(com.enonic.xp.script.serializer.JsonMapGenerator) ResolveSyncWorkResult(com.enonic.xp.node.ResolveSyncWorkResult) Test(org.junit.jupiter.api.Test)

Example 15 with JsonMapGenerator

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);
}
Also used : JsonMapGenerator(com.enonic.xp.script.serializer.JsonMapGenerator) JsonNode(com.fasterxml.jackson.databind.JsonNode) URL(java.net.URL)

Aggregations

JsonMapGenerator (com.enonic.xp.script.serializer.JsonMapGenerator)15 Test (org.junit.jupiter.api.Test)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 URL (java.net.URL)5 PushNodesResult (com.enonic.xp.node.PushNodesResult)4 ContentQuery (com.enonic.xp.content.ContentQuery)1 Contents (com.enonic.xp.content.Contents)1 FindContentIdsByQueryResult (com.enonic.xp.content.FindContentIdsByQueryResult)1 GetContentByIdsParams (com.enonic.xp.content.GetContentByIdsParams)1 Context (com.enonic.xp.context.Context)1 Event (com.enonic.xp.event.Event)1 IndexConfigDocument (com.enonic.xp.index.IndexConfigDocument)1 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)1 ContentsResultMapper (com.enonic.xp.lib.content.mapper.ContentsResultMapper)1 FindNodesByMultiRepoQueryResult (com.enonic.xp.node.FindNodesByMultiRepoQueryResult)1 NodeComparison (com.enonic.xp.node.NodeComparison)1 ResolveSyncWorkResult (com.enonic.xp.node.ResolveSyncWorkResult)1 ScriptValue (com.enonic.xp.script.ScriptValue)1 MapSerializable (com.enonic.xp.script.serializer.MapSerializable)1 User (com.enonic.xp.security.User)1