use of org.neo4j.server.rest.repr.formats.JsonFormat in project neo4j by neo4j.
the class MapRepresentationTest method shouldSerializeMapWithSimpleTypes.
@Test
public void shouldSerializeMapWithSimpleTypes() throws Exception {
MapRepresentation rep = new MapRepresentation(map("nulls", null, "strings", "a string", "numbers", 42, "booleans", true));
OutputFormat format = new OutputFormat(new JsonFormat(), new URI("http://localhost/"), null);
String serializedMap = format.assemble(rep);
Map<String, Object> map = JsonHelper.jsonToMap(serializedMap);
assertThat(map.get("nulls"), is(nullValue()));
assertThat((String) map.get("strings"), is("a string"));
assertThat((Integer) map.get("numbers"), is(42));
assertThat((Boolean) map.get("booleans"), is(true));
}
use of org.neo4j.server.rest.repr.formats.JsonFormat in project neo4j by neo4j.
the class MapRepresentationTest method shouldSerializeArbitrarilyNestedMapsAndLists.
@Test
@SuppressWarnings("unchecked")
public void shouldSerializeArbitrarilyNestedMapsAndLists() throws Exception {
MapRepresentation rep = new MapRepresentation(map("a map with a list in it", map("a list", asList(42, 87)), "a list with a map in it", asList(map("foo", "bar", "baz", false))));
OutputFormat format = new OutputFormat(new JsonFormat(), new URI("http://localhost/"), null);
String serializedMap = format.assemble(rep);
Map<String, Object> map = JsonHelper.jsonToMap(serializedMap);
assertThat((List<Integer>) ((Map) map.get("a map with a list in it")).get("a list"), is(asList(42, 87)));
assertThat((String) ((Map) ((List) map.get("a list with a map in it")).get(0)).get("foo"), is("bar"));
assertThat((Boolean) ((Map) ((List) map.get("a list with a map in it")).get(0)).get("baz"), is(false));
}
use of org.neo4j.server.rest.repr.formats.JsonFormat in project neo4j by neo4j.
the class OutputFormatTest method shouldReturnAbsoluteURIForSeeOther.
@Test
public void shouldReturnAbsoluteURIForSeeOther() throws Exception {
URI relativeURI = new URI("/test/path");
OutputFormat outputFormat = new OutputFormat(new JsonFormat(), new URI("http://base.local:8765/"), null);
Response response = outputFormat.seeOther(relativeURI);
assertEquals(303, response.getStatus());
assertEquals(new URI("http://base.local:8765/test/path"), response.getMetadata().getFirst("Location"));
}
use of org.neo4j.server.rest.repr.formats.JsonFormat in project neo4j by neo4j.
the class RestfulGraphDatabasePagedTraversalTest method startDatabase.
@Before
public void startDatabase() throws IOException {
graph = (GraphDatabaseFacade) new TestGraphDatabaseFactory().newImpermanentDatabase();
database = new WrappedDatabase(graph);
helper = new GraphDbHelper(database);
output = new EntityOutputFormat(new JsonFormat(), URI.create(BASE_URI), null);
leaseManager = new LeaseManager(Clocks.fakeClock());
service = new RestfulGraphDatabase(new JsonFormat(), output, new DatabaseActions(leaseManager, true, database.getGraph()), null);
service = new TransactionWrappingRestfulGraphDatabase(graph, service);
}
Aggregations