Class TestUtils


  • public final class TestUtils
    extends Object
    Common utility functions.
    • Method Detail

      • buildJwt

        public static String buildJwt​(String webid,
                                      String secret)
        Build a JWT Token.
        Parameters:
        webid - the web ID
        secret - the JWT secret
        Returns:
        the JWT token
      • getIOService

        public static IOService getIOService()
        Get the IO service.
        Returns:
        the I/O service
      • readEntityAsGraph

        public static Graph readEntityAsGraph​(Object entity,
                                              String baseURL,
                                              RDFSyntax syntax)
        Read an entity as an RDF Graph.
        Parameters:
        entity - the HTTP entity
        baseURL - the base URL
        syntax - the RDF syntax
        Returns:
        the graph
      • readEntityAsString

        public static String readEntityAsString​(Object entity)
        Read an http entity as a string.
        Parameters:
        entity - the entity
        Returns:
        the entity as a string
      • readEntityAsJson

        public static <T> T readEntityAsJson​(Object entity,
                                             com.fasterxml.jackson.core.type.TypeReference<T> valueType)
        Parse a JSON entity into the desired type.
        Type Parameters:
        T - the intended return type
        Parameters:
        entity - the entity
        valueType - the type reference
        Returns:
        the entity as the desired type
      • hasConstrainedBy

        public static Predicate<Link> hasConstrainedBy​(IRI iri)
        Test if the given ldp:constrainedBy link is present.
        Parameters:
        iri - the IRI
        Returns:
        true if present; false otherwise
      • hasType

        public static Predicate<Link> hasType​(IRI iri)
        Test if the given type link is present.
        Parameters:
        iri - the IRI
        Returns:
        true if present; false otherwise
      • getResourceAsString

        public static String getResourceAsString​(String path)
        Get a resource as a string.
        Parameters:
        path - the resource path
        Returns:
        the resource as a string
      • getLinks

        public static List<Link> getLinks​(Response res)
        Get the link headers from a response.
        Parameters:
        res - the response
        Returns:
        a list of links
      • checkEventGraph

        public static Predicate<Graph> checkEventGraph​(String resource,
                                                       IRI agent,
                                                       IRI activity,
                                                       IRI ldpType)
        Check an event graph for required properties.
        Parameters:
        resource - the resource IRI
        agent - the agent IRI
        activity - the activity IRI
        ldpType - the LDP type of the resource
        Returns:
        a predicate function
      • checkEventGraph

        public static Predicate<Graph> checkEventGraph​(String resource,
                                                       String agent,
                                                       IRI activity,
                                                       IRI ldpType)
        Check an event graph for required properties.
        Parameters:
        resource - the resource IRI
        agent - the agent IRI
        activity - the activity IRI
        ldpType - the LDP type of the resource
        Returns:
        a predicate function
      • meanwhile

        public static Instant meanwhile()
        Add in a delay.
        Returns:
        an instant
      • isReallyLaterThan

        public static boolean isReallyLaterThan​(Instant time)
        Check that it is now really later than the provided instant.
        Parameters:
        time - an instant
        Returns:
        true if it is now later than the provided instant; false otherwise