Search in sources :

Example 1 with RolePlayer

use of ai.grakn.engine.controller.response.RolePlayer in project grakn by graknlabs.

the class ConceptControllerTest method whenGettingRelationships_EnsureRolePlayersAreReturned.

@Test
public void whenGettingRelationships_EnsureRolePlayersAreReturned() throws IOException {
    // Get Expected Relationships
    Set<RolePlayer> relationshipsExpected = new HashSet<>();
    try (GraknTx tx = factory.tx(keyspace, GraknTxType.READ)) {
        entity.plays().forEach(role -> {
            Link roleWrapper = Link.create(role);
            entity.relationships(role).forEach(relationship -> {
                Link relationshipWrapper = Link.create(relationship);
                relationshipsExpected.add(RolePlayer.create(roleWrapper, relationshipWrapper));
            });
        });
    }
    // Make the request
    String request = entityWrapper.relationships().id();
    Response response = RestAssured.when().get(request);
    assertEquals(SC_OK, response.getStatusCode());
    // Check relationships are embedded
    RolePlayer[] relationships = response.jsonPath().getObject("relationships", RolePlayer[].class);
    assertThat(relationships, arrayContainingInAnyOrder(relationshipsExpected.toArray()));
}
Also used : Response(com.jayway.restassured.response.Response) GraknTx(ai.grakn.GraknTx) Matchers.containsString(org.hamcrest.Matchers.containsString) RolePlayer(ai.grakn.engine.controller.response.RolePlayer) Link(ai.grakn.engine.controller.response.Link) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

GraknTx (ai.grakn.GraknTx)1 Link (ai.grakn.engine.controller.response.Link)1 RolePlayer (ai.grakn.engine.controller.response.RolePlayer)1 Response (com.jayway.restassured.response.Response)1 HashSet (java.util.HashSet)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1