Package org.trellisldp.test
Class TestUtils
- java.lang.Object
-
- org.trellisldp.test.TestUtils
-
public final class TestUtils extends Object
Common utility functions.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
buildJwt(String webid, String secret)
Build a JWT Token.static Predicate<Graph>
checkEventGraph(String resource, String agent, IRI activity, IRI ldpType)
Check an event graph for required properties.static Predicate<Graph>
checkEventGraph(String resource, IRI agent, IRI activity, IRI ldpType)
Check an event graph for required properties.static IOService
getIOService()
Get the IO service.static List<Link>
getLinks(Response res)
Get the link headers from a response.static String
getResourceAsString(String path)
Get a resource as a string.static Predicate<Link>
hasConstrainedBy(IRI iri)
Test if the given ldp:constrainedBy link is present.static Predicate<Link>
hasType(IRI iri)
Test if the given type link is present.static boolean
isReallyLaterThan(Instant time)
Check that it is now really later than the provided instant.static Instant
meanwhile()
Add in a delay.static Graph
readEntityAsGraph(Object entity, String baseURL, RDFSyntax syntax)
Read an entity as an RDF Graph.static <T> T
readEntityAsJson(Object entity, com.fasterxml.jackson.core.type.TypeReference<T> valueType)
Parse a JSON entity into the desired type.static String
readEntityAsString(Object entity)
Read an http entity as a string.
-
-
-
Method Detail
-
buildJwt
public static String buildJwt(String webid, String secret)
Build a JWT Token.- Parameters:
webid
- the web IDsecret
- 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 entitybaseURL
- the base URLsyntax
- 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 entityvalueType
- 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 IRIagent
- the agent IRIactivity
- the activity IRIldpType
- 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 IRIagent
- the agent IRIactivity
- the activity IRIldpType
- 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
-
-