@Test public void connectionsLoopbackTest() { CustomCollection things = context.collection("things"); UUID thing1Id = getEntityId(things.create(hashMap("name", "thing1")), 0); UUID thing2Id = getEntityId(things.create(hashMap("name", "thing2")), 0); // create the connection things.entity(thing1Id).connection("likes").entity(thing2Id).post(); // test we have the "likes" in our connection meta data response JsonNode response = things.entity("thing1").get(); String url = getEntity(response, 0).get("metadata").get("connections").get("likes").asText(); assertNotNull("Connection url returned in entity", url); // trim off the start / url = url.substring(1); // now that we know the URl is correct, follow it response = context.collection(url).get(); UUID returnedUUID = getEntityId(response, 0); assertEquals(thing2Id, returnedUUID); // now follow the loopback, which should be pointers to the other entity url = getEntity(response, 0).get("metadata").get("connecting").get("likes").asText(); assertNotNull("Incoming edge URL provited", url); // trim off the start / url = url.substring(1); // now we should get thing1 from the loopback url response = context.collection(url).get(); UUID returned = getEntityId(response, 0); assertEquals("Should point to thing1 as an incoming entity connection", thing1Id, returned); }
@Test public void connectionsQueryTest() { CustomCollection activities = context.collection("peeps"); Map stuff = hashMap("type", "chicken"); activities.create(stuff); Map<String, Object> payload = new LinkedHashMap<String, Object>(); payload.put("username", "todd"); Map<String, Object> objectOfDesire = new LinkedHashMap<String, Object>(); objectOfDesire.put("codingmunchies", "doritoes"); resource() .path("/test-organization/test-app/users") .queryParam("access_token", access_token) .accept(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON_TYPE) .post(JsonNode.class, payload); payload.put("username", "scott"); resource() .path("/test-organization/test-app/users") .queryParam("access_token", access_token) .accept(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON_TYPE) .post(JsonNode.class, payload); /*finish setting up the two users */ ClientResponse toddWant = resource() .path("/test-organization/test-app/users/todd/likes/peeps") .queryParam("access_token", access_token) .accept(MediaType.TEXT_HTML) .type(MediaType.APPLICATION_JSON_TYPE) .post(ClientResponse.class, objectOfDesire); assertEquals(200, toddWant.getStatus()); JsonNode node = resource() .path("/test-organization/test-app/peeps") .queryParam("access_token", access_token) .accept(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON_TYPE) .get(JsonNode.class); String uuid = node.get("entities").get(0).get("uuid").getTextValue(); try { node = resource() .path("/test-organization/test-app/users/scott/likes/" + uuid) .queryParam("access_token", access_token) .accept(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON_TYPE) .get(JsonNode.class); assert (false); } catch (UniformInterfaceException uie) { assertEquals(404, uie.getResponse().getClientResponseStatus().getStatusCode()); return; } }