Search in sources :

Example 21 with JsonFormat

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));
}
Also used : JsonFormat(org.neo4j.server.rest.repr.formats.JsonFormat) URI(java.net.URI) Test(org.junit.Test)

Example 22 with JsonFormat

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));
}
Also used : JsonFormat(org.neo4j.server.rest.repr.formats.JsonFormat) URI(java.net.URI) Map(java.util.Map) Test(org.junit.Test)

Example 23 with JsonFormat

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"));
}
Also used : Response(javax.ws.rs.core.Response) JsonFormat(org.neo4j.server.rest.repr.formats.JsonFormat) URI(java.net.URI) Test(org.junit.Test)

Example 24 with JsonFormat

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);
}
Also used : GraphDbHelper(org.neo4j.server.rest.domain.GraphDbHelper) JsonFormat(org.neo4j.server.rest.repr.formats.JsonFormat) LeaseManager(org.neo4j.server.rest.paging.LeaseManager) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) WrappedDatabase(org.neo4j.server.database.WrappedDatabase) EntityOutputFormat(org.neo4j.test.server.EntityOutputFormat) Before(org.junit.Before)

Aggregations

JsonFormat (org.neo4j.server.rest.repr.formats.JsonFormat)24 URI (java.net.URI)21 Test (org.junit.Test)21 EntityOutputFormat (org.neo4j.test.server.EntityOutputFormat)17 Response (javax.ws.rs.core.Response)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 OutputFormat (org.neo4j.server.rest.repr.OutputFormat)13 Matchers.containsString (org.hamcrest.Matchers.containsString)7 BasicAuthManager (org.neo4j.server.security.auth.BasicAuthManager)5 WrappedDatabase (org.neo4j.server.database.WrappedDatabase)3 GraphDbHelper (org.neo4j.server.rest.domain.GraphDbHelper)3 LeaseManager (org.neo4j.server.rest.paging.LeaseManager)3 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)3 Map (java.util.Map)2 Before (org.junit.Before)2 BeforeClass (org.junit.BeforeClass)1 UserManager (org.neo4j.kernel.api.security.UserManager)1 Config (org.neo4j.kernel.configuration.Config)1 ConfigAdapter (org.neo4j.server.plugins.ConfigAdapter)1