private static JsonNode GetSingle(JsonNode node, string key) { JsonNode data = node.get(key); assertEquals(1, data.size()); return(data.get(0)); }
//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 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)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleArrayOfPointsUsingGraphResultDataContent() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleArrayOfPointsUsingGraphResultDataContent() { //Given GraphDatabaseFacade db = Server().Database.Graph; using (Transaction tx = Db.beginTx()) { Node node = Db.createNode(label("N")); node.SetProperty("coordinates", new Point[] { pointValue(WGS84, 30.655691, 104.081602) }); tx.Success(); } //When HTTP.Response response = RunQuery("MATCH (n:N) RETURN n", "graph"); assertEquals(200, response.Status()); AssertNoErrors(response); //Then JsonNode row = response.Get("results").get(0).get("data").get(0).get("graph").get("nodes").get(0).get("properties").get("coordinates").get(0); AssertGeometryTypeEqual(GeometryType.GEOMETRY_POINT, row); AssertCoordinatesEqual(new double[] { 30.655691, 104.081602 }, row); AssertCrsEqual(WGS84, row); }
//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()); }
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()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldWorkWithTime() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldWorkWithTime() { HTTP.Response response = RunQuery("RETURN time({hour: 23, minute: 19, second: 55, timezone:\\\"-07:00\\\"})"); assertEquals(200, response.Status()); AssertNoErrors(response); JsonNode data = GetSingleData(response); AssertTemporalEquals(data, "23:19:55-07:00", "time"); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldWorkWithDuration() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldWorkWithDuration() { HTTP.Response response = RunQuery("RETURN duration({weeks:2, days:3})"); assertEquals(200, response.Status()); AssertNoErrors(response); JsonNode data = GetSingleData(response); AssertTemporalEquals(data, "P17D", "duration"); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldWorkWithLocalDateTime() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldWorkWithLocalDateTime() { HTTP.Response response = RunQuery("RETURN localdatetime({year: 1984, month: 10, day: 21, hour: 12, minute: 34})"); assertEquals(200, response.Status()); AssertNoErrors(response); JsonNode data = GetSingleData(response); AssertTemporalEquals(data, "1984-10-21T12:34", "localdatetime"); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldWorkWithDate() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldWorkWithDate() { HTTP.Response response = RunQuery("RETURN date({year: 1984, month: 10, day: 11})"); assertEquals(200, response.Status()); AssertNoErrors(response); JsonNode data = GetSingleData(response); AssertTemporalEquals(data, "1984-10-11", "date"); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldWorkWithLocalTime() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldWorkWithLocalTime() { HTTP.Response response = RunQuery("RETURN localtime({hour:12, minute:31, second:14, nanosecond: 645876123})"); assertEquals(200, response.Status()); AssertNoErrors(response); JsonNode data = GetSingleData(response); AssertTemporalEquals(data, "12:31:14.645876123", "localtime"); }
//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)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldWorkWithDateTime() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldWorkWithDateTime() { HTTP.Response response = RunQuery("RETURN datetime({year: 1, month:10, day:2, timezone:\\\"+01:00\\\"})"); assertEquals(200, response.Status()); AssertNoErrors(response); JsonNode data = GetSingleData(response); AssertTemporalEquals(data, "0001-10-02T00:00+01:00", "datetime"); }
//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 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 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.")); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static void testPoint(String query, double[] expectedCoordinate, org.neo4j.values.storable.CoordinateReferenceSystem expectedCrs, String expectedType) throws Exception private static void TestPoint(string query, double[] expectedCoordinate, CoordinateReferenceSystem expectedCrs, string expectedType) { HTTP.Response response = RunQuery(query); assertEquals(200, response.Status()); AssertNoErrors(response); JsonNode element = ExtractSingleElement(response); AssertGeometryTypeEqual(GeometryType.GEOMETRY_POINT, element); AssertCoordinatesEqual(expectedCoordinate, element); AssertCrsEqual(expectedCrs, element); AssertTypeEqual(expectedType, response); }
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.")); }
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); } }
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"))); }
//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 TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleTemporalUsingGraphResultDataContent() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleTemporalUsingGraphResultDataContent() { //Given GraphDatabaseFacade db = Server().Database.Graph; ZonedDateTime date = ZonedDateTime.of(1980, 3, 11, 0, 0, 0, 0, ZoneId.of("Europe/Stockholm")); using (Transaction tx = Db.beginTx()) { Node node = Db.createNode(label("N")); node.SetProperty("date", date); tx.Success(); } //When HTTP.Response response = RunQuery("MATCH (n:N) RETURN n", "graph"); //Then assertEquals(200, response.Status()); AssertNoErrors(response); JsonNode row = response.Get("results").get(0).get("data").get(0).get("graph").get("nodes").get(0).get("properties").get("date"); assertEquals("\"1980-03-11T00:00+01:00[Europe/Stockholm]\"", row.ToString()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleDurationArraysUsingGraphResultDataContent() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleDurationArraysUsingGraphResultDataContent() { //Given GraphDatabaseFacade db = Server().Database.Graph; Duration duration = Duration.ofSeconds(73); using (Transaction tx = Db.beginTx()) { Node node = Db.createNode(label("N")); node.SetProperty("durations", new Duration[] { duration }); tx.Success(); } //When HTTP.Response response = RunQuery("MATCH (n:N) RETURN n", "graph"); //Then assertEquals(200, response.Status()); AssertNoErrors(response); JsonNode row = response.Get("results").get(0).get("data").get(0).get("graph").get("nodes").get(0).get("properties").get("durations").get(0); assertEquals("\"PT1M13S\"", row.ToString()); }
private static void AssertGeometryTypeEqual(GeometryType expected, JsonNode element) { assertEquals(expected.Name, element.get("type").asText()); }
private static void AssertCoordinatesEqual(double[] expected, JsonNode element) { assertArrayEquals(expected, CoordinatesAsArray(element), 0.000001); }
private static double[] CoordinatesAsArray(JsonNode element) { return(Iterables.stream(element.get("coordinates")).mapToDouble(JsonNode.asDouble).toArray()); }
private static void AssertCrsEqual(CoordinateReferenceSystem crs, JsonNode element) { assertEquals(crs.Name, element.get("crs").get("name").asText()); }