//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReplyNicelyToTooManyFailedAuthAttempts() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReplyNicelyToTooManyFailedAuthAttempts() { // Given StartServerWithConfiguredUser(); long timeout = DateTimeHelper.CurrentUnixTimeMillis() + 30_000; // When HTTP.Response response = null; while (DateTimeHelper.CurrentUnixTimeMillis() < timeout) { // Done in a loop because we're racing with the clock to get enough failed requests into 5 seconds response = HTTP.withBasicAuth("neo4j", "incorrect").POST(Server.baseUri().resolve("authentication").ToString(), HTTP.RawPayload.quotedJson("{'username':'******', 'password':'******'}")); if (response.Status() == 429) { break; } } // Then assertThat(response.Status(), equalTo(429)); JsonNode firstError = response.Get("errors").get(0); assertThat(firstError.get("code").asText(), equalTo("Neo.ClientError.Security.AuthenticationRateLimit")); assertThat(firstError.get("message").asText(), equalTo("Too many failed authentication requests. Please wait 5 seconds and try again.")); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnReadOnlyStatusWhenCreatingNodes() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReturnReadOnlyStatusWhenCreatingNodes() { // Given HTTP.Response response = _http.POST("db/data/transaction/commit", quotedJson("{ 'statements': [ { 'statement': 'CREATE (node)' } ] }")); // Then JsonNode error = response.Get("errors").get(0); string code = error.get("code").asText(); string message = error.get("message").asText(); assertEquals("Neo.ClientError.General.ForbiddenOnReadOnlyDatabase", code); assertThat(message, containsString("This is a read only Neo4j instance")); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldWriteNestedMaps() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldWriteNestedMaps() { MemoryStream @out = new MemoryStream(); JsonGenerator json = (new JsonFactory(new Neo4jJsonCodec())).createJsonGenerator(@out); JsonNode row = Serialize(@out, json, new RowWriter()); MatcherAssert.assertThat(row.size(), equalTo(1)); JsonNode firstCell = row.get(0); MatcherAssert.assertThat(firstCell.get("one").get("two").size(), @is(2)); MatcherAssert.assertThat(firstCell.get("one").get("two").get(0).asBoolean(), @is(true)); MatcherAssert.assertThat(firstCell.get("one").get("two").get(1).get("three").asInt(), @is(42)); }
public virtual void IncorrectAuthentication() { // Given StartServerWithConfiguredUser(); // Document RESTRequestGenerator.ResponseEntity response = Gen.get().expectedStatus(401).withHeader(HttpHeaders.AUTHORIZATION, HTTP.basicAuthHeader("neo4j", "incorrect")).expectedHeader("WWW-Authenticate", "Basic realm=\"Neo4j\"").post(DataURL()); // Then JsonNode data = JsonHelper.jsonNode(response.Entity()); JsonNode firstError = data.get("errors").get(0); assertThat(firstError.get("code").asText(), equalTo("Neo.ClientError.Security.Unauthorized")); assertThat(firstError.get("message").asText(), equalTo("Invalid username or password.")); }
public virtual void SuccessfulAuthentication() { // Given StartServerWithConfiguredUser(); // Document RESTRequestGenerator.ResponseEntity response = Gen.get().expectedStatus(200).withHeader(HttpHeaders.AUTHORIZATION, HTTP.basicAuthHeader("neo4j", "secret")).get(UserURL("neo4j")); // Then JsonNode data = JsonHelper.jsonNode(response.Entity()); assertThat(data.get("username").asText(), equalTo("neo4j")); assertThat(data.get("password_change_required").asBoolean(), equalTo(false)); assertThat(data.get("password_change").asText(), equalTo(PasswordURL("neo4j"))); }
public virtual void MissingAuthorization() { // Given StartServerWithConfiguredUser(); // Document RESTRequestGenerator.ResponseEntity response = Gen.get().expectedStatus(401).expectedHeader("WWW-Authenticate", "Basic realm=\"Neo4j\"").get(DataURL()); // Then JsonNode data = JsonHelper.jsonNode(response.Entity()); JsonNode firstError = data.get("errors").get(0); assertThat(firstError.get("code").asText(), equalTo("Neo.ClientError.Security.Unauthorized")); assertThat(firstError.get("message").asText(), equalTo("No authentication header supplied.")); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static org.codehaus.jackson.JsonNode getSingleData(org.neo4j.test.server.HTTP.Response response) throws org.neo4j.server.rest.domain.JsonParseException private static JsonNode GetSingleData(HTTP.Response response) { JsonNode data = response.Get("results").get(0).get("data"); assertEquals(1, data.size()); return(data.get(0)); }
private static JsonNode GetSingle(JsonNode node, string key) { JsonNode data = node.get(key); assertEquals(1, data.size()); return(data.get(0)); }
public virtual void PasswordChangeRequired() { // Given StartServer(true); // Document RESTRequestGenerator.ResponseEntity response = Gen.get().expectedStatus(403).withHeader(HttpHeaders.AUTHORIZATION, HTTP.basicAuthHeader("neo4j", "neo4j")).get(DataURL()); // Then JsonNode data = JsonHelper.jsonNode(response.Entity()); JsonNode firstError = data.get("errors").get(0); assertThat(firstError.get("code").asText(), equalTo("Neo.ClientError.Security.Forbidden")); assertThat(firstError.get("message").asText(), equalTo("User is required to change their password.")); assertThat(data.get("password_change").asText(), equalTo(PasswordURL("neo4j"))); }
protected internal override bool matchesSafely(HTTP.Response response) { try { JsonNode list = TransactionMatchers.GetJsonNodeWithName(response, "rest").GetEnumerator().next(); assertThat(list.get(0).get("metadata").get("deleted").asBoolean(), equalTo(true)); assertThat(list.get(1).get("someKey").get("metadata").get("deleted").asBoolean(), equalTo(true)); return(true); } catch (JsonParseException) { return(false); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static void assertTypeEqual(String expectedType, org.neo4j.test.server.HTTP.Response response) throws org.neo4j.server.rest.domain.JsonParseException private static void AssertTypeEqual(string expectedType, HTTP.Response response) { JsonNode data = response.Get("results").get(0).get("data"); JsonNode meta = data.get(0).get("meta"); assertEquals(1, meta.size()); assertEquals(expectedType, meta.get(0).get("type").asText()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldOnlyGetNodeTypeInMetaAsNodeProperties() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldOnlyGetNodeTypeInMetaAsNodeProperties() { HTTP.Response response = RunQuery("CREATE (account {name: \\\"zhen\\\", creationTime: localdatetime({year: 1984, month: 10, day: 21, hour: 12, minute: 34})}) RETURN account"); assertEquals(200, response.Status()); AssertNoErrors(response); JsonNode data = GetSingleData(response); JsonNode row = GetSingle(data, "row"); assertThat(row.get("creationTime").asText(), equalTo("1984-10-21T12:34")); assertThat(row.get("name").asText(), equalTo("zhen")); JsonNode meta = GetSingle(data, "meta"); assertThat(meta.get("type").asText(), equalTo("node")); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static org.codehaus.jackson.JsonNode extractSingleElement(org.neo4j.test.server.HTTP.Response response) throws org.neo4j.server.rest.domain.JsonParseException private static JsonNode ExtractSingleElement(HTTP.Response response) { JsonNode data = response.Get("results").get(0).get("data"); assertEquals(1, data.size()); JsonNode row = data.get(0).get("row"); assertEquals(1, row.size()); return(row.get(0)); }
private void AssertTemporalEquals(JsonNode data, string value, string type) { JsonNode row = GetSingle(data, "row"); assertThat(row.asText(), equalTo(value)); JsonNode meta = GetSingle(data, "meta"); assertEquals(type, meta.get("type").asText()); }
private static void AssertGeometryTypeEqual(GeometryType expected, JsonNode element) { assertEquals(expected.Name, element.get("type").asText()); }
private static void AssertCrsEqual(CoordinateReferenceSystem crs, JsonNode element) { assertEquals(crs.Name, element.get("crs").get("name").asText()); }
private static double[] CoordinatesAsArray(JsonNode element) { return(Iterables.stream(element.get("coordinates")).mapToDouble(JsonNode.asDouble).toArray()); }