use of org.neo4j.test.server.EntityOutputFormat in project neo4j by neo4j.
the class UserServiceTest method shouldReturnValidUserRepresentation.
@Test
public void shouldReturnValidUserRepresentation() throws Exception {
// Given
HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getUserPrincipal()).thenReturn(neo4jPrinciple);
OutputFormat outputFormat = new EntityOutputFormat(new JsonFormat(), new URI("http://www.example.com"), null);
UserService userService = new UserService(userManagerSupplier, new JsonFormat(), outputFormat);
// When
Response response = userService.getUser("neo4j", req);
// Then
assertThat(response.getStatus(), equalTo(200));
String json = new String((byte[]) response.getEntity());
assertNotNull(json);
assertThat(json, containsString("\"username\" : \"neo4j\""));
assertThat(json, containsString("\"password_change\" : \"http://www.example.com/user/neo4j/password\""));
assertThat(json, containsString("\"password_change_required\" : true"));
}
use of org.neo4j.test.server.EntityOutputFormat in project neo4j by neo4j.
the class UserServiceTest method shouldReturn422IfEmptyPassword.
@Test
public void shouldReturn422IfEmptyPassword() throws Exception {
// Given
HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getUserPrincipal()).thenReturn(neo4jPrinciple);
OutputFormat outputFormat = new EntityOutputFormat(new JsonFormat(), new URI("http://www.example.com"), null);
UserService userService = new UserService(userManagerSupplier, new JsonFormat(), outputFormat);
// When
Response response = userService.setPassword("neo4j", req, "{ \"password\" : \"\" }");
// Then
assertThat(response.getStatus(), equalTo(422));
String json = new String((byte[]) response.getEntity());
assertNotNull(json);
assertThat(json, containsString("\"code\" : \"Neo.ClientError.General.InvalidArguments\""));
assertThat(json, containsString("\"message\" : \"A password cannot be empty.\""));
}
use of org.neo4j.test.server.EntityOutputFormat in project neo4j by neo4j.
the class DiscoveryServiceTest method shouldReturnRedirectToAbsoluteAPIUsingOutputFormat.
@Test
public void shouldReturnRedirectToAbsoluteAPIUsingOutputFormat() throws Exception {
Config mockConfig = mock(Config.class);
URI browserUri = new URI("/browser/");
when(mockConfig.get(ServerSettings.browser_path)).thenReturn(browserUri);
String baseUri = "http://www.example.com:5435";
DiscoveryService ds = new DiscoveryService(mockConfig, new EntityOutputFormat(new JsonFormat(), new URI(baseUri), null));
Response response = ds.redirectToBrowser();
assertThat(response.getMetadata().getFirst("Location"), is(new URI("http://www.example" + ".com:5435/browser/")));
}
use of org.neo4j.test.server.EntityOutputFormat in project neo4j by neo4j.
the class RestfulGraphDatabaseTest method doBefore.
@BeforeClass
public static void doBefore() 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);
service = new TransactionWrappingRestfulGraphDatabase(graph, new RestfulGraphDatabase(new JsonFormat(), output, new DatabaseActions(new LeaseManager(Clocks.fakeClock()), true, database.getGraph()), new ConfigAdapter(Config.embeddedDefaults())));
}
use of org.neo4j.test.server.EntityOutputFormat in project neo4j by neo4j.
the class PagingTraversalTest method startDatabase.
@Before
public void startDatabase() throws IOException {
graph = (GraphDatabaseFacade) new TestGraphDatabaseFactory().newImpermanentDatabase();
database = new WrappedDatabase(graph);
helper = new GraphDbHelper(database);
EntityOutputFormat 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