use of com.enonic.xp.script.serializer.JsonMapGenerator in project xp by enonic.
the class IndexConfigDocMapperTest method all.
@Test
public void all() throws Exception {
final IndexConfigDocument doc = PatternIndexConfigDocument.create().defaultConfig(IndexConfig.BY_TYPE).add("path", IndexConfig.PATH).add("none", IndexConfig.NONE).add("minimal", IndexConfig.MINIMAL).add("full", IndexConfig.FULLTEXT).add("byType", IndexConfig.BY_TYPE).add("property1", IndexConfig.BY_TYPE).add("property1.*", IndexConfig.BY_TYPE).add("property1.x", IndexConfig.BY_TYPE).add("property1.property2", IndexConfig.BY_TYPE).add("property1.*.property3", IndexConfig.create(IndexConfig.BY_TYPE).addLanguage("en").build()).build();
final JsonMapGenerator jsonGenerator = new JsonMapGenerator();
new IndexConfigDocMapper(doc).serialize(jsonGenerator);
assertJson("index_config_full.json", jsonGenerator);
}
use of com.enonic.xp.script.serializer.JsonMapGenerator in project xp by enonic.
the class ScriptEventListenerImplTest method testEvent.
@Test
public void testEvent() {
final Event event = Event.create("application").localOrigin(true).value("a", 1).build();
this.listener.onEvent(event);
assertNotNull(this.event);
assertTrue(this.event instanceof MapSerializable);
final MapSerializable serializable = (MapSerializable) this.event;
final JsonMapGenerator generator = new JsonMapGenerator();
serializable.serialize(generator);
}
use of com.enonic.xp.script.serializer.JsonMapGenerator in project xp by enonic.
the class JsonAssert method assertJson.
public static void assertJson(final Class context, final String name, final MapSerializable value) throws Exception {
final String resource = "/" + context.getName().replace('.', '/') + "-" + name + ".json";
final URL url = context.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);
}
use of com.enonic.xp.script.serializer.JsonMapGenerator in project xp by enonic.
the class QueryContentHandlerTest method testExecute.
@Test
public void testExecute() throws Exception {
FindContentIdsByQueryResult queryResult = FindContentIdsByQueryResult.create().contents(ContentIds.from("contentId")).sort(Collections.singletonMap(ContentId.from("contentId"), SortValuesProperty.create().values(10).build())).build();
Contents contents = Contents.create().add(Content.create().id(ContentId.from("contentId")).name("name").parentPath(ContentPath.ROOT).build()).build();
Mockito.when(contentService.find(Mockito.any(ContentQuery.class))).thenReturn(queryResult);
Mockito.when(contentService.getByIds(Mockito.any(GetContentByIdsParams.class))).thenReturn(contents);
QueryContentHandler instance = new QueryContentHandler();
instance.initialize(newBeanContext(ResourceKey.from("myapp:/test")));
final ScriptValue sort = Mockito.mock(ScriptValue.class);
final ScriptValue query = Mockito.mock(ScriptValue.class);
Mockito.when(sort.getValue(String.class)).thenReturn("getDistance(\"location\", \"83,80\", \"km\")");
Mockito.when(query.getValue(String.class)).thenReturn("_name = \"cityName\"");
Mockito.when(query.isValue()).thenReturn(true);
Mockito.when(sort.isValue()).thenReturn(true);
instance.setSort(sort);
instance.setQuery(query);
JsonMapGenerator generator = new JsonMapGenerator();
ContentsResultMapper resultMapper = (ContentsResultMapper) instance.execute();
resultMapper.serialize(generator);
final JsonNode actualJson = (JsonNode) generator.getRoot();
Assertions.assertEquals(1, actualJson.path("count").asInt());
Assertions.assertTrue(actualJson.path("hits").get(0).path("_sort").isArray());
Assertions.assertEquals(10, actualJson.path("hits").get(0).path("_sort").get(0).asInt());
}
use of com.enonic.xp.script.serializer.JsonMapGenerator in project xp by enonic.
the class PushNodesResultMapperTest method single_failed.
@Test
public void single_failed() throws Exception {
final PushNodesResult result = PushNodesResult.create().addFailed(createEntry("a"), PushNodesResult.Reason.ACCESS_DENIED).build();
final JsonMapGenerator jsonGenerator = new JsonMapGenerator();
new PushNodesResultMapper(result, NodeIds.empty()).serialize(jsonGenerator);
assertJson("nodeResult/single_failed.json", jsonGenerator);
}
Aggregations