/** * Check an event graph for required properties. * @param resource the resource IRI * @param agent the agent IRI * @param activity the activity IRI * @param ldpType the LDP type of the resource * @return a predicate function */ public static Predicate<Graph> checkEventGraph(final String resource, final String agent, final IRI activity, final IRI ldpType) { return checkEventGraph(resource, getInstance().createIRI(agent), activity, ldpType); }
/** * Check an event graph for required properties. * @param resource the resource IRI * @param agent the agent IRI * @param activity the activity IRI * @param ldpType the LDP type of the resource * @return a predicate function */ public static Predicate<Graph> checkEventGraph(final String resource, final String agent, final IRI activity, final IRI ldpType) { return checkEventGraph(resource, getInstance().createIRI(agent), activity, ldpType); }
/** * Check the activity of a resource and its parent. * @param resource the resource IRI * @param parent the parent IRI * @param agent the agent IRI * @param activityType the activity type * @param resourceType the resource type * @param parentType the parentType * @return a stream of tests */ default Stream<Executable> checkResourceParentActivity(final String resource, final String parent, final String agent, final IRI activityType, final IRI resourceType, final IRI parentType) { return of( () -> await().atMost(15, SECONDS).until(() -> getMessages().stream() .anyMatch(checkEventGraph(resource, agent, activityType, resourceType))), () -> await().atMost(15, SECONDS).until(() -> getMessages().stream() .anyMatch(checkEventGraph(parent, agent, AS.Update, parentType)))); } }
/** * Check the activity of a resource and its parent. * @param resource the resource IRI * @param parent the parent IRI * @param agent the agent IRI * @param activityType the activity type * @param resourceType the resource type * @param parentType the parentType * @return a stream of tests */ default Stream<Executable> checkResourceParentActivity(final String resource, final String parent, final String agent, final IRI activityType, final IRI resourceType, final IRI parentType) { return of( () -> await().atMost(15, SECONDS).until(() -> getMessages().stream() .anyMatch(checkEventGraph(resource, agent, activityType, resourceType))), () -> await().atMost(15, SECONDS).until(() -> getMessages().stream() .anyMatch(checkEventGraph(parent, agent, AS.Update, parentType)))); } }
/** * Check the activity of a resource and its parent. * @param resource the resource IRI * @param agent the agent IRI * @param activityType the activity type * @param resourceType the resource type * @param memberType the member type * @return a stream of tests */ default Stream<Executable> checkResourceParentLdpIC(final String resource, final String agent, final IRI activityType, final IRI resourceType, final IRI memberType) { return concat( checkResourceParentActivity(resource, getIndirectContainerLocation(), agent, activityType, resourceType, LDP.IndirectContainer), of(() -> await().atMost(15, SECONDS).until(() -> getMessages().stream() .anyMatch(checkEventGraph(getMemberLocation(), agent, AS.Update, memberType))))); }
/** * Check the activity of a resource and its parent. * @param resource the resource IRI * @param agent the agent IRI * @param activityType the activity type * @param resourceType the resource type * @param memberType the member type * @return a stream of tests */ default Stream<Executable> checkResourceParentLdpIC(final String resource, final String agent, final IRI activityType, final IRI resourceType, final IRI memberType) { return concat( checkResourceParentActivity(resource, getIndirectContainerLocation(), agent, activityType, resourceType, LDP.IndirectContainer), of(() -> await().atMost(15, SECONDS).until(() -> getMessages().stream() .anyMatch(checkEventGraph(getMemberLocation(), agent, AS.Update, memberType))))); }
/** * Check the activity of a resource and its parent. * @param resource the resource IRI * @param agent the agent IRI * @param activityType the activity type * @param resourceType the resource type * @param memberType the member type * @return a stream of tests */ default Stream<Executable> checkResourceParentLdpDC(final String resource, final String agent, final IRI activityType, final IRI resourceType, final IRI memberType) { return concat( checkResourceParentActivity(resource, getDirectContainerLocation(), agent, activityType, resourceType, LDP.DirectContainer), of(() -> await().atMost(15, SECONDS).until(() -> getMessages().stream() .anyMatch(checkEventGraph(getMemberLocation(), agent, AS.Update, memberType))))); }
/** * Check the activity of a resource and its parent. * @param resource the resource IRI * @param agent the agent IRI * @param activityType the activity type * @param resourceType the resource type * @param memberType the member type * @return a stream of tests */ default Stream<Executable> checkResourceParentLdpDC(final String resource, final String agent, final IRI activityType, final IRI resourceType, final IRI memberType) { return concat( checkResourceParentActivity(resource, getDirectContainerLocation(), agent, activityType, resourceType, LDP.DirectContainer), of(() -> await().atMost(15, SECONDS).until(() -> getMessages().stream() .anyMatch(checkEventGraph(getMemberLocation(), agent, AS.Update, memberType))))); }
/** * Test receiving a creation event message. */ @Test @DisplayName("Test receiving a JMS creation message") default void testReceiveCreateMessage() { await().atMost(15, SECONDS).until(() -> getMessages().stream().anyMatch(checkEventGraph(getContainerLocation(), Trellis.AdministratorAgent, AS.Create, LDP.BasicContainer))); }
/** * Test receiving a creation event message. */ @Test @DisplayName("Test receiving a JMS creation message") default void testReceiveCreateMessage() { await().atMost(15, SECONDS).until(() -> getMessages().stream().anyMatch(checkEventGraph(getContainerLocation(), Trellis.AdministratorAgent, AS.Create, LDP.BasicContainer))); }
/** * Test receiving a replace message. */ @Test @DisplayName("Test receiving a replace message in a LDP-IC") default void testReceiveReplaceMessageIC() { final String resource; final String agent = "http://example.com/parker#i"; final String childContent = getResourceAsString("/childResource.ttl"); // POST an LDP-RS try (final Response res = target(getIndirectContainerLocation()).request() .header(AUTHORIZATION, buildJwt(agent, getJwtSecret())).post(entity(childContent, TEXT_TURTLE))) { assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful POST to an LDP-IC"); resource = res.getLocation().toString(); } assertAll("Check the LDP-IC parent resource", checkResourceParentLdpIC(resource, agent, AS.Create, LDP.RDFSource, LDP.Container)); final String agent2 = "https://hayden.example.com/profile#me"; // Replace the LDP-RS try (final Response res = target(resource).request().header(AUTHORIZATION, buildJwt(agent2, getJwtSecret())) .put(entity(childContent + "\n<> a <http://example.com/Type3> .", TEXT_TURTLE))) { assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful PUT in an LDP-IC"); } await().atMost(15, SECONDS).until(() -> getMessages().stream() .anyMatch(checkEventGraph(resource, agent2, AS.Update, LDP.RDFSource))); await().atMost(15, SECONDS).until(() -> getMessages().stream() .anyMatch(checkEventGraph(getMemberLocation(), agent2, AS.Update, LDP.Container))); }
/** * Test receiving a replace message. */ @Test @DisplayName("Test receiving a replace message in a LDP-IC") default void testReceiveReplaceMessageIC() { final String resource; final String agent = "http://example.com/parker#i"; final String childContent = getResourceAsString("/childResource.ttl"); // POST an LDP-RS try (final Response res = target(getIndirectContainerLocation()).request() .header(AUTHORIZATION, buildJwt(agent, getJwtSecret())).post(entity(childContent, TEXT_TURTLE))) { assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful POST to an LDP-IC"); resource = res.getLocation().toString(); } assertAll("Check the LDP-IC parent resource", checkResourceParentLdpIC(resource, agent, AS.Create, LDP.RDFSource, LDP.Container)); final String agent2 = "https://hayden.example.com/profile#me"; // Replace the LDP-RS try (final Response res = target(resource).request().header(AUTHORIZATION, buildJwt(agent2, getJwtSecret())) .put(entity(childContent + "\n<> a <http://example.com/Type3> .", TEXT_TURTLE))) { assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful PUT in an LDP-IC"); } await().atMost(15, SECONDS).until(() -> getMessages().stream() .anyMatch(checkEventGraph(resource, agent2, AS.Update, LDP.RDFSource))); await().atMost(15, SECONDS).until(() -> getMessages().stream() .anyMatch(checkEventGraph(getMemberLocation(), agent2, AS.Update, LDP.Container))); }