@Test public void shouldBeAbleToIndexValuesContainingSpaces() throws Exception { final long nodeId = helper.createNode(); final String key = "key"; final String value = "value with spaces in it"; String indexName = "spacey-values"; helper.createNodeIndex(indexName); final RestRequest request = RestRequest.req(); JaxRsResponse response = request.post( functionalTestHelper.indexNodeUri(indexName), createJsonStringFor(nodeId, key, value)); assertEquals(Status.CREATED.getStatusCode(), response.getStatus()); URI location = response.getLocation(); response.close(); response = request.get(functionalTestHelper.indexNodeUri(indexName, key, URIHelper.encode(value))); assertEquals(Status.OK.getStatusCode(), response.getStatus()); Collection<?> hits = (Collection<?>) JsonHelper.jsonToSingleValue(response.getEntity()); assertEquals(1, hits.size()); response.close(); CLIENT.resource(location).delete(); response = request.get(functionalTestHelper.indexNodeUri(indexName, key, URIHelper.encode(value))); hits = (Collection<?>) JsonHelper.jsonToSingleValue(response.getEntity()); assertEquals(0, hits.size()); }
@Test public void shouldGet200AndArrayOfNodeRepsWhenGettingFromIndex() throws PropertyValueException { String key = "myKey"; String value = "myValue"; String name1 = "Thomas Anderson"; String name2 = "Agent Smith"; String indexName = "matrix"; final RestRequest request = RestRequest.req(); JaxRsResponse responseToPost = request.post(functionalTestHelper.nodeUri(), "{\"name\":\"" + name1 + "\"}"); assertEquals(201, responseToPost.getStatus()); String location1 = responseToPost.getHeaders().getFirst(HttpHeaders.LOCATION); responseToPost.close(); responseToPost = request.post(functionalTestHelper.nodeUri(), "{\"name\":\"" + name2 + "\"}"); assertEquals(201, responseToPost.getStatus()); String location2 = responseToPost.getHeaders().getFirst(HttpHeaders.LOCATION); responseToPost.close(); responseToPost = request.post( functionalTestHelper.indexNodeUri(indexName), createJsonStringFor(functionalTestHelper.getNodeIdFromUri(location1), key, value)); assertEquals(201, responseToPost.getStatus()); String indexLocation1 = responseToPost.getHeaders().getFirst(HttpHeaders.LOCATION); responseToPost.close(); responseToPost = request.post( functionalTestHelper.indexNodeUri(indexName), createJsonStringFor(functionalTestHelper.getNodeIdFromUri(location2), key, value)); assertEquals(201, responseToPost.getStatus()); String indexLocation2 = responseToPost.getHeaders().getFirst(HttpHeaders.LOCATION); Map<String, String> uriToName = new HashMap<>(); uriToName.put(indexLocation1, name1); uriToName.put(indexLocation2, name2); responseToPost.close(); JaxRsResponse response = RestRequest.req().get(functionalTestHelper.indexNodeUri(indexName, key, value)); assertEquals(200, response.getStatus()); Collection<?> items = (Collection<?>) JsonHelper.jsonToSingleValue(response.getEntity()); int counter = 0; for (Object item : items) { Map<?, ?> map = (Map<?, ?>) item; Map<?, ?> properties = (Map<?, ?>) map.get("data"); assertNotNull(map.get("self")); String indexedUri = (String) map.get("indexed"); assertEquals(uriToName.get(indexedUri), properties.get("name")); counter++; } assertEquals(2, counter); response.close(); }
@Test public void shouldBeValidJSONOnResponse() throws JsonParseException { JaxRsResponse response = RestRequest.req().get(getPropertyUri("foo")); assertThat(response.getType().toString(), containsString(MediaType.APPLICATION_JSON)); assertNotNull(JsonHelper.createJsonFrom(response.getEntity())); response.close(); }
@Test public void shouldReturn404WhenPropertySentToANodeWhichDoesNotExist() throws Exception { JaxRsResponse response = RestRequest.req().put(badUri.toString() + "/foo", JsonHelper.createJsonFrom("bar")); assertEquals(404, response.getStatus()); response.close(); }
@Test public void shouldGet404ForPropertiesOnNonExistentRelationship() { JaxRsResponse response = RestRequest.req().get(functionalTestHelper.dataUri() + "relationship/999999/properties"); assertEquals(404, response.getStatus()); response.close(); }
@Test public void shouldGet404ForNonExistingRelationship() { String uri = functionalTestHelper.dataUri() + "relationship/999999/properties/foo"; JaxRsResponse response = RestRequest.req().get(uri); assertEquals(404, response.getStatus()); response.close(); }
@Test public void shouldGetNodeIndexRoot() { JaxRsResponse response = RestRequest.req().get(functionalTestHelper.nodeIndexUri(), MediaType.TEXT_HTML_TYPE); assertEquals(Status.OK.getStatusCode(), response.getStatus()); assertValidHtml(response.getEntity()); response.close(); }
@Test public void shouldHaveJsonDataInResponse() throws Exception { JaxRsResponse response = retrieveNodeFromService(nodeUri.toString()); Map<String, Object> map = JsonHelper.jsonToMap(response.getEntity()); assertTrue(map.containsKey("self")); response.close(); }
@Test public void shouldReturn400WhenSendinIncompatibleJsonProperties() throws JsonParseException { Map<String, Object> map = new HashMap<String, Object>(); map.put("jim", new HashMap<String, Object>()); JaxRsResponse response = updateNodePropertiesOnServer(map); assertEquals(400, response.getStatus()); response.close(); }
@Test public void shouldReturn404WhenPropertiesSentToANodeWhichDoesNotExist() throws JsonParseException { Map<String, Object> map = new HashMap<String, Object>(); map.put("jim", "tobias"); JaxRsResponse response = RestRequest.req().put(badUri, JsonHelper.createJsonFrom(map)); assertEquals(404, response.getStatus()); response.close(); }
@Test public void shouldBeJSONContentTypeOnPropertiesResponse() { long relId = helper.createRelationship("LIKES"); helper.setRelationshipProperties(relId, Collections.<String, Object>singletonMap("foo", "bar")); JaxRsResponse response = RestRequest.req() .get(functionalTestHelper.dataUri() + "relationship/" + relId + "/properties"); assertThat(response.getType().toString(), containsString(MediaType.APPLICATION_JSON)); response.close(); }
@Test public void shouldRespondWith200AndEmptyListOfRelationshipRepresentationsWhenGettingOutgoingRelationshipsForANodeWithoutRelationships() throws JsonParseException { JaxRsResponse response = sendRetrieveRequestToServer(nodeWithoutRelationships, "/out"); assertEquals(200, response.getStatus()); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); verifyRelReps(0, response.getEntity(String.class)); response.close(); }
@Test public void shouldGet200WhenRetrievingValidRelationship() throws DatabaseBlockedException { long relationshipId = helper.createRelationship("LIKES"); JaxRsResponse response = RestRequest.req().get(functionalTestHelper.relationshipUri(relationshipId)); assertEquals(200, response.getStatus()); response.close(); }
@Test public void shouldRespondWith400WhenSendingCorruptJson() throws Exception { final String indexName = "botherable-index"; helper.createNodeIndex(indexName); final String corruptJson = "{\"key\" \"myKey\"}"; JaxRsResponse response = RestRequest.req().post(functionalTestHelper.indexNodeUri(indexName), corruptJson); assertEquals(400, response.getStatus()); response.close(); }
@Test public void shouldGetThomasAndersonDirectly() { JaxRsResponse response = RestRequest.req() .get(functionalTestHelper.nodeUri(thomasAnderson), MediaType.TEXT_HTML_TYPE); assertEquals(Status.OK.getStatusCode(), response.getStatus()); String entity = response.getEntity(); assertTrue(entity.contains("Thomas Anderson")); assertValidHtml(entity); response.close(); }
@Test public void shouldGet200AndContentLengthForProperties() { long relId = helper.createRelationship("LIKES"); helper.setRelationshipProperties(relId, Collections.<String, Object>singletonMap("foo", "bar")); JaxRsResponse response = RestRequest.req() .get(functionalTestHelper.dataUri() + "relationship/" + relId + "/properties"); assertEquals(200, response.getStatus()); assertNotNull(response.getHeaders().get("Content-Length")); response.close(); }
/** * Property values can not be nested. * * <p>Nesting properties is not supported. You could for example store the nested json as a string * instead. */ @Documented @Test public void shouldReturn400WhenSendinIncompatibleJsonProperty() throws Exception { gen.get() .payload("{\"foo\" : {\"bar\" : \"baz\"}}") .expectedStatus(400) .post(functionalTestHelper.nodeUri()); JaxRsResponse response = setNodePropertyOnServer("jim", new HashMap<String, Object>()); assertEquals(400, response.getStatus()); response.close(); }
@Test public void shouldGet200WhenGettingNodesFromIndexWithNoHits() { String indexName = "empty-index"; helper.createNodeIndex(indexName); JaxRsResponse response = RestRequest.req() .get( functionalTestHelper.indexNodeUri( indexName, "non-existent-key", "non-existent-value")); assertEquals(200, response.getStatus()); response.close(); }
@Test public void assertResponseHaveCorrectContentFromGet() throws Exception { JaxRsResponse response = RestRequest.req().get(functionalTestHelper.dataUri()); String body = response.getEntity(String.class); Map<String, Object> map = JsonHelper.jsonToMap(body); assertEquals(functionalTestHelper.nodeUri(), map.get("node")); assertNotNull(map.get("reference_node")); assertNotNull(map.get("node_index")); assertNotNull(map.get("relationship_index")); assertNotNull(map.get("extensions_info")); assertNotNull(map.get("batch")); response.close(); // Make sure advertised urls work response = RestRequest.req().get((String) map.get("reference_node")); assertEquals(200, response.getStatus()); response.close(); response = RestRequest.req().get((String) map.get("node_index")); assertEquals(204, response.getStatus()); response.close(); response = RestRequest.req().get((String) map.get("relationship_index")); assertEquals(204, response.getStatus()); response.close(); response = RestRequest.req().get((String) map.get("extensions_info")); assertEquals(200, response.getStatus()); response.close(); response = RestRequest.req().post((String) map.get("batch"), "[]"); assertEquals(200, response.getStatus()); response.close(); }
@Test public void shouldGetTrinityWhenSearchingForHer() { JaxRsResponse response = RestRequest.req() .get( functionalTestHelper.indexNodeUri("node", "name", "Trinity"), MediaType.TEXT_HTML_TYPE); assertEquals(Status.OK.getStatusCode(), response.getStatus()); String entity = response.getEntity(); assertTrue(entity.contains("Trinity")); assertValidHtml(entity); response.close(); }
@Test public void shouldGetARelationshipRepresentationInJsonWhenRetrievingValidRelationship() throws Exception { long relationshipId = helper.createRelationship("LIKES"); JaxRsResponse response = RestRequest.req().get(functionalTestHelper.relationshipUri(relationshipId)); String entity = response.getEntity(String.class); assertNotNull(entity); isLegalJson(entity); response.close(); }
@Test public void shouldGetSomeRelationships() { final RestRequest request = RestRequest.req(); JaxRsResponse response = request.get( functionalTestHelper.relationshipsUri( thomasAnderson, RelationshipDirection.all.name(), "KNOWS"), MediaType.TEXT_HTML_TYPE); assertEquals(Status.OK.getStatusCode(), response.getStatus()); String entity = response.getEntity(); assertTrue(entity.contains("KNOWS")); assertFalse(entity.contains("LOVES")); assertValidHtml(entity); response.close(); response = request.get( functionalTestHelper.relationshipsUri( thomasAnderson, RelationshipDirection.all.name(), "LOVES"), MediaType.TEXT_HTML_TYPE); entity = response.getEntity(); assertFalse(entity.contains("KNOWS")); assertTrue(entity.contains("LOVES")); assertValidHtml(entity); response.close(); response = request.get( functionalTestHelper.relationshipsUri( thomasAnderson, RelationshipDirection.all.name(), "LOVES", "KNOWS"), MediaType.TEXT_HTML_TYPE); entity = response.getEntity(); assertTrue(entity.contains("KNOWS")); assertTrue(entity.contains("LOVES")); assertValidHtml(entity); response.close(); }
@Test public void shouldGetThomasAndersonLovesTrinityRelationship() { JaxRsResponse response = RestRequest.req() .get( functionalTestHelper.relationshipUri(thomasAndersonLovesTrinity), MediaType.TEXT_HTML_TYPE); assertEquals(Status.OK.getStatusCode(), response.getStatus()); String entity = response.getEntity(); assertTrue(entity.contains("strength")); assertTrue(entity.contains("100")); assertTrue(entity.contains("LOVES")); assertValidHtml(entity); response.close(); }
@Test public void shouldHaveJsonDataInResponse() throws Exception { JaxRsResponse response = getDiscoveryDocument(); Map<String, Object> map = JsonHelper.jsonToMap(response.getEntity()); String managementKey = "management"; assertTrue(map.containsKey(managementKey)); assertNotNull(map.get(managementKey)); String dataKey = "data"; assertTrue(map.containsKey(dataKey)); assertNotNull(map.get(dataKey)); response.close(); }
@Test public void shouldReturn400WhenSendingCorruptJsonProperties() { JaxRsResponse response = RestRequest.req().put(propertiesUri, "this:::Is::notJSON}"); assertEquals(400, response.getStatus()); response.close(); }
@Test public void shouldGetContentLengthHeaderWhenRetrievingNode() throws Exception { JaxRsResponse response = retrieveNodeFromService(nodeUri.toString()); assertNotNull(response.getHeaders().get("Content-Length")); response.close(); }
@Test public void shouldGet404ForNoProperty() { JaxRsResponse response = RestRequest.req().get(getPropertyUri("baz")); assertEquals(404, response.getStatus()); response.close(); }
@Test public void shouldHaveJsonMediaTypeOnResponse() { JaxRsResponse response = retrieveNodeFromService(nodeUri.toString()); assertThat(response.getType().toString(), containsString(MediaType.APPLICATION_JSON)); response.close(); }
@Test public void shouldReturn400WhenSendingCorruptJsonProperty() throws Exception { JaxRsResponse response = RestRequest.req().put(getPropertyUri("foo"), "this:::Is::notJSON}"); assertEquals(400, response.getStatus()); response.close(); }
@Test public void shouldRespondWith404WhenGettingOutgoingRelationshipsForNonExistingNode() { JaxRsResponse response = sendRetrieveRequestToServer(nonExistingNode, "/out"); assertEquals(404, response.getStatus()); response.close(); }