Package org.fcrepo.integration.http.api
Class AbstractResourceIT
- java.lang.Object
-
- org.fcrepo.integration.http.api.AbstractResourceIT
-
- Direct Known Subclasses:
ConcurrencyIT,ExternalContentHandlerIT,ExternalContentPathValidatorIT,FedoraAclIT,FedoraCrudConcurrentIT,FedoraFixityIT,FedoraHtmlIT,FedoraLdpIT,FedoraReindexIT,FedoraRelaxedLdpIT,FedoraSearchIT,FedoraTombstonesIT,FedoraVersioningIT,LDPContainerIT,OcflPersistenceIT,PrefersLdpIT,RebuildIT,RepositoryInitializerIT,StateTokensIT,TransactionsIT
@ContextConfiguration("/spring-test/test-container.xml") public abstract class AbstractResourceIT extends ObjectAbstract AbstractResourceIT class.
- Author:
- awoods, ajs6f
-
-
Field Summary
Fields Modifier and Type Field Description protected org.fcrepo.config.AuthPropsConfigauthPropsConfigprotected static StringBASIC_CONTAINER_LINK_HEADERprotected static org.apache.http.impl.client.CloseableHttpClientclientprotected org.fcrepo.http.commons.test.util.ContainerWrappercontainerWrapperprotected static org.apache.jena.graph.NodeDCTITLEprotected static StringDIRECT_CONTAINER_LINK_HEADERprotected static org.slf4j.Loggerloggerprotected static StringNON_RDF_SOURCE_LINK_HEADERprotected org.fcrepo.config.FedoraPropsConfigpropsConfigprotected static StringserverAddress
-
Constructor Summary
Constructors Constructor Description AbstractResourceIT()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T extends org.apache.http.client.methods.HttpRequestBase>
TaddTxTo(T req, String txId)Add a transaction id to a http request.protected static voidassertConstrainedByPresent(org.apache.http.client.methods.CloseableHttpResponse response)protected static voidassertDeleted(String id)protected static voidassertNoLinkHeader(org.apache.http.HttpResponse response, String uri, String rel)Test a response for the absence of a specific LINK headerprotected static voidassertNotDeleted(String id)protected static voidassertNotFound(String id)protected static voidcheckForLinkHeader(org.apache.http.HttpResponse response, String uri, String rel)Test a response for a specific LINK headerprotected static voidconfirmResponseBodyNTriplesAreEqual(String responseBodyA, String responseBodyB)Compare two N-Triple response bodies to determine if they are identicalprotected static org.apache.http.impl.client.CloseableHttpClientcreateClient()protected static org.apache.http.impl.client.CloseableHttpClientcreateClient(boolean disableRedirects)protected StringcreateDatastream(String id, String content)protected StringcreateDatastream(String pid, String dsid, String content)protected org.apache.http.client.methods.CloseableHttpResponsecreateObject()protected org.apache.http.client.methods.CloseableHttpResponsecreateObject(String pid)protected voidcreateObjectAndClose(String pid)protected voidcreateObjectAndClose(String pid, String... linkHeaders)protected StringcreateTransaction()Creates a transaction, asserts that it's successful and returns the transaction location.protected static Map<String,String>decodeDigestHeader(String digestHeader)Decode the Digest headerprotected static org.apache.http.client.methods.HttpDeletedeleteObjMethod(String id)protected static org.apache.http.client.methods.CloseableHttpResponseexecute(org.apache.http.client.methods.HttpUriRequest req)Execute an HTTP request and return the open response.protected static voidexecuteAndClose(org.apache.http.client.methods.HttpUriRequest req)Execute an HTTP request and close the response.protected org.apache.http.client.methods.CloseableHttpResponseexecuteWithBasicAuth(org.apache.http.client.methods.HttpUriRequest request, String username, String password)Execute an HTTP request with preemptive basic authentication.protected <T> TgetBean(Class<T> type)protected <T> TgetBean(String name, Class<T> type)protected static StringgetContentLocation(org.apache.http.HttpResponse response)Retrieve the value of the first Content-Location header from an open HTTP response.protected StringgetContentType(org.apache.http.client.methods.HttpUriRequest method)protected StringgetContentType(org.apache.http.client.methods.HttpUriRequest method, javax.ws.rs.core.Response.Status httpStatus)protected org.fcrepo.http.commons.test.util.CloseableDatasetgetDataset(org.apache.http.client.methods.HttpUriRequest req)Executes an HTTP request and parses the RDF found in the response, returning it in aCloseableDataset, then closes the response.protected org.fcrepo.http.commons.test.util.CloseableDatasetgetDataset(org.apache.http.HttpResponse response)Parses the RDF found in and HTTP response, returning it in aCloseableDataset.protected static org.apache.http.client.methods.HttpGetgetDSDescMethod(String pid, String ds)protected static org.apache.http.client.methods.HttpGetgetDSMethod(String pid, String ds)protected StringgetEtag(String uri)Get the etag of the given URI, as returned from a HEAD requestprotected StringgetEtag(org.apache.http.client.methods.HttpUriRequest method)Get the etag returned when executing the provided methodprotected StringgetEtag(org.apache.http.HttpResponse response)Get the etag header value present in the provided responseprotected StringgetExternalContentLinkHeader(String url, String handling, String mimeType)protected static Collection<String>getHeader(org.apache.http.HttpResponse response, String header)protected Collection<String>getLinkHeaders(org.apache.http.client.methods.HttpUriRequest method)protected static Collection<String>getLinkHeaders(org.apache.http.HttpResponse response)protected static StringgetLocation(org.apache.http.client.methods.HttpUriRequest req)Executes an HTTP request and returns the first Location header in the response, then closes the response.protected static StringgetLocation(org.apache.http.HttpResponse response)Retrieve the value of the first Location header from an open HTTP response.protected org.apache.jena.rdf.model.ModelgetModel(String pid)protected org.apache.jena.rdf.model.ModelgetModel(String pid, boolean omitSMTs)protected org.apache.jena.rdf.model.ModelgetModel(String txUri, String pid)protected org.apache.jena.rdf.model.ModelgetModel(String txUri, String pid, boolean omitSMTs)Get a model of the triples for the resource.protected static org.apache.http.client.methods.HttpGetgetObjMethod(String id)protected static StringgetOriginalResourceUri(org.apache.http.client.methods.CloseableHttpResponse response)protected static StringgetRandomUniqueId()Gets a random (but valid) id for use in testing.protected static intgetStatus(org.apache.http.client.methods.HttpUriRequest req)Executes an HTTP request and returns the status code of the response, closing the response.protected static intgetStatus(org.apache.http.HttpResponse response)Retrieve the HTTP status code from an open response.protected static StringgetTTLThatUpdatesServerManagedTriples(String createdBy, Calendar created, String modifiedBy, Calendar modified)protected static List<String>headerValues(org.apache.http.HttpResponse response, String headerName)protected static org.apache.http.client.methods.HttpHeadheadObjMethod(String id)protected static org.apache.http.client.methods.HttpPatchpatchObjMethod(String id)protected static org.apache.http.client.methods.HttpPostpostObjMethod()protected static org.apache.http.client.methods.HttpPostpostObjMethod(String id)protected static StringpreferLink(String includes, String omits)Create a Prefer headerprotected static org.apache.http.client.methods.HttpPutputDSMethod(String id, String content)protected static org.apache.http.client.methods.HttpPutputDSMethod(String pid, String ds, String content)protected static org.apache.http.client.methods.HttpPutputObjMethod(String id)protected static org.apache.http.client.methods.HttpPutputObjMethod(String pid, String contentType, String content)protected voidrestartContainer()protected org.apache.http.client.methods.CloseableHttpResponsesetDescriptionProperty(String id, String txId, String propertyUri, String value)voidsetLogger()protected org.apache.http.client.methods.CloseableHttpResponsesetProperty(String pid, String propertyUri, String value)protected org.apache.http.client.methods.CloseableHttpResponsesetProperty(String pid, String propertyUri, URI value)protected static InputStreamstreamModel(org.apache.jena.rdf.model.Model model, org.apache.jena.riot.RDFFormat format)
-
-
-
Field Detail
-
logger
protected static org.slf4j.Logger logger
-
NON_RDF_SOURCE_LINK_HEADER
protected static final String NON_RDF_SOURCE_LINK_HEADER
-
BASIC_CONTAINER_LINK_HEADER
protected static final String BASIC_CONTAINER_LINK_HEADER
-
DIRECT_CONTAINER_LINK_HEADER
protected static final String DIRECT_CONTAINER_LINK_HEADER
-
DCTITLE
protected static final org.apache.jena.graph.Node DCTITLE
-
containerWrapper
@Inject protected org.fcrepo.http.commons.test.util.ContainerWrapper containerWrapper
-
propsConfig
protected org.fcrepo.config.FedoraPropsConfig propsConfig
-
authPropsConfig
protected org.fcrepo.config.AuthPropsConfig authPropsConfig
-
serverAddress
protected static final String serverAddress
-
client
protected static final org.apache.http.impl.client.CloseableHttpClient client
-
-
Constructor Detail
-
AbstractResourceIT
public AbstractResourceIT()
-
-
Method Detail
-
restartContainer
protected void restartContainer() throws Exception
- Throws:
Exception
-
decodeDigestHeader
protected static Map<String,String> decodeDigestHeader(String digestHeader)
Decode the Digest header- Parameters:
digestHeader- the digest header value.- Returns:
- Map with keys of algorithms and values of hashes.
-
setLogger
public void setLogger()
-
createClient
protected static org.apache.http.impl.client.CloseableHttpClient createClient()
-
createClient
protected static org.apache.http.impl.client.CloseableHttpClient createClient(boolean disableRedirects)
-
postObjMethod
protected static org.apache.http.client.methods.HttpPost postObjMethod()
-
postObjMethod
protected static org.apache.http.client.methods.HttpPost postObjMethod(String id)
-
putObjMethod
protected static org.apache.http.client.methods.HttpPut putObjMethod(String id)
-
getObjMethod
protected static org.apache.http.client.methods.HttpGet getObjMethod(String id)
-
headObjMethod
protected static org.apache.http.client.methods.HttpHead headObjMethod(String id)
-
deleteObjMethod
protected static org.apache.http.client.methods.HttpDelete deleteObjMethod(String id)
-
patchObjMethod
protected static org.apache.http.client.methods.HttpPatch patchObjMethod(String id)
-
putDSMethod
protected static org.apache.http.client.methods.HttpPut putDSMethod(String pid, String ds, String content) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
putDSMethod
protected static org.apache.http.client.methods.HttpPut putDSMethod(String id, String content) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
putObjMethod
protected static org.apache.http.client.methods.HttpPut putObjMethod(String pid, String contentType, String content) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
getDSMethod
protected static org.apache.http.client.methods.HttpGet getDSMethod(String pid, String ds)
-
getDSDescMethod
protected static org.apache.http.client.methods.HttpGet getDSDescMethod(String pid, String ds)
-
execute
protected static org.apache.http.client.methods.CloseableHttpResponse execute(org.apache.http.client.methods.HttpUriRequest req) throws IOException
Execute an HTTP request and return the open response.- Parameters:
req- Request to execute- Returns:
- the open response
- Throws:
IOException- in case of an IOException
-
executeAndClose
protected static void executeAndClose(org.apache.http.client.methods.HttpUriRequest req)
Execute an HTTP request and close the response.- Parameters:
req- the request to execute
-
executeWithBasicAuth
protected org.apache.http.client.methods.CloseableHttpResponse executeWithBasicAuth(org.apache.http.client.methods.HttpUriRequest request, String username, String password) throws IOException
Execute an HTTP request with preemptive basic authentication.- Parameters:
request- the request to executeusername- usename to usepassword- password to use- Returns:
- the open responses
- Throws:
IOException- in case of IOException
-
getStatus
protected static int getStatus(org.apache.http.HttpResponse response)
Retrieve the HTTP status code from an open response.- Parameters:
response- the open response- Returns:
- the HTTP status code of the response
-
getStatus
protected static int getStatus(org.apache.http.client.methods.HttpUriRequest req)
Executes an HTTP request and returns the status code of the response, closing the response.- Parameters:
req- the request to execute- Returns:
- the HTTP status code of the response
-
getLocation
protected static String getLocation(org.apache.http.client.methods.HttpUriRequest req) throws IOException
Executes an HTTP request and returns the first Location header in the response, then closes the response.- Parameters:
req- the request to execute- Returns:
- the value of the first Location header in the response
- Throws:
IOException- in case of IOException
-
getLocation
protected static String getLocation(org.apache.http.HttpResponse response)
Retrieve the value of the first Location header from an open HTTP response.- Parameters:
response- the open response- Returns:
- the value of the first Location header in the response
-
getContentLocation
protected static String getContentLocation(org.apache.http.HttpResponse response)
Retrieve the value of the first Content-Location header from an open HTTP response.- Parameters:
response- the open response- Returns:
- the value of the first Content-Location header in the response
-
getContentType
protected String getContentType(org.apache.http.client.methods.HttpUriRequest method) throws IOException
- Throws:
IOException
-
getContentType
protected String getContentType(org.apache.http.client.methods.HttpUriRequest method, javax.ws.rs.core.Response.Status httpStatus) throws IOException
- Throws:
IOException
-
getEtag
protected String getEtag(String uri) throws IOException
Get the etag of the given URI, as returned from a HEAD request- Parameters:
uri- uri of the resource- Returns:
- etag
- Throws:
IOException- if the uri is invalid
-
getEtag
protected String getEtag(org.apache.http.client.methods.HttpUriRequest method) throws IOException
Get the etag returned when executing the provided method- Parameters:
method- method to execute- Returns:
- etag
- Throws:
IOException- in case of a problem or the connection was aborted
-
getEtag
protected String getEtag(org.apache.http.HttpResponse response)
Get the etag header value present in the provided response- Parameters:
response- response- Returns:
- etag header value or null
-
getLinkHeaders
protected static Collection<String> getLinkHeaders(org.apache.http.HttpResponse response)
-
getLinkHeaders
protected Collection<String> getLinkHeaders(org.apache.http.client.methods.HttpUriRequest method) throws IOException
- Throws:
IOException
-
headerValues
protected static List<String> headerValues(org.apache.http.HttpResponse response, String headerName)
-
getHeader
protected static Collection<String> getHeader(org.apache.http.HttpResponse response, String header)
-
getDataset
protected org.fcrepo.http.commons.test.util.CloseableDataset getDataset(org.apache.http.HttpResponse response) throws IOException
Parses the RDF found in and HTTP response, returning it in aCloseableDataset.- Parameters:
response- the response to parse- Returns:
- the graph retrieved
- Throws:
IOException- in case of IOException
-
getDataset
protected org.fcrepo.http.commons.test.util.CloseableDataset getDataset(org.apache.http.client.methods.HttpUriRequest req) throws IOException
Executes an HTTP request and parses the RDF found in the response, returning it in aCloseableDataset, then closes the response.- Parameters:
req- the request to execute- Returns:
- the constructed graph
- Throws:
IOException- in case of IOException
-
getModel
protected org.apache.jena.rdf.model.Model getModel(String pid) throws Exception
- Throws:
Exception
-
getModel
protected org.apache.jena.rdf.model.Model getModel(String pid, boolean omitSMTs) throws IOException
- Throws:
IOException
-
getModel
protected org.apache.jena.rdf.model.Model getModel(String txUri, String pid) throws Exception
- Throws:
Exception
-
getModel
protected org.apache.jena.rdf.model.Model getModel(String txUri, String pid, boolean omitSMTs) throws IOException
Get a model of the triples for the resource.- Parameters:
txUri- id of the transactionpid- id of the resourceomitSMTs- whether to omit server managed triples from the response.- Returns:
- the model of the resource triples.
- Throws:
IOException- on problems getting response.
-
streamModel
protected static InputStream streamModel(org.apache.jena.rdf.model.Model model, org.apache.jena.riot.RDFFormat format) throws IOException
- Throws:
IOException
-
createObject
protected org.apache.http.client.methods.CloseableHttpResponse createObject()
-
createObject
protected org.apache.http.client.methods.CloseableHttpResponse createObject(String pid)
-
createObjectAndClose
protected void createObjectAndClose(String pid)
-
createObjectAndClose
protected void createObjectAndClose(String pid, String... linkHeaders)
-
createDatastream
protected String createDatastream(String id, String content) throws IOException
- Throws:
IOException
-
createDatastream
protected String createDatastream(String pid, String dsid, String content) throws IOException
- Throws:
IOException
-
setProperty
protected org.apache.http.client.methods.CloseableHttpResponse setProperty(String pid, String propertyUri, String value) throws IOException
- Throws:
IOException
-
setProperty
protected org.apache.http.client.methods.CloseableHttpResponse setProperty(String pid, String propertyUri, URI value) throws IOException
- Throws:
IOException
-
setDescriptionProperty
protected org.apache.http.client.methods.CloseableHttpResponse setDescriptionProperty(String id, String txId, String propertyUri, String value) throws IOException
- Throws:
IOException
-
createTransaction
protected String createTransaction() throws IOException
Creates a transaction, asserts that it's successful and returns the transaction location.- Returns:
- string containing transaction location
- Throws:
IOException- exception thrown during the function
-
addTxTo
protected <T extends org.apache.http.client.methods.HttpRequestBase> T addTxTo(T req, String txId)
Add a transaction id to a http request.- Parameters:
req- a http request object.txId- the transaction id.- Returns:
- the http request object with the transaction id added as a header.
-
getRandomUniqueId
protected static String getRandomUniqueId()
Gets a random (but valid) id for use in testing. This id is guaranteed to be unique within runs of this application.- Returns:
- string containing new id
-
assertDeleted
protected static void assertDeleted(String id)
-
assertNotFound
protected static void assertNotFound(String id)
-
assertNotDeleted
protected static void assertNotDeleted(String id)
-
getTTLThatUpdatesServerManagedTriples
protected static String getTTLThatUpdatesServerManagedTriples(String createdBy, Calendar created, String modifiedBy, Calendar modified)
-
assertNoLinkHeader
protected static void assertNoLinkHeader(org.apache.http.HttpResponse response, String uri, String rel)
Test a response for the absence of a specific LINK header- Parameters:
response- the HTTP responseuri- the URI not to exist in the LINK headerrel- the rel argument to check for
-
checkForLinkHeader
protected static void checkForLinkHeader(org.apache.http.HttpResponse response, String uri, String rel)
Test a response for a specific LINK header- Parameters:
response- the HTTP responseuri- the URI expected in the LINK headerrel- the rel argument to check for
-
getOriginalResourceUri
protected static String getOriginalResourceUri(org.apache.http.client.methods.CloseableHttpResponse response)
-
getExternalContentLinkHeader
protected String getExternalContentLinkHeader(String url, String handling, String mimeType)
-
assertConstrainedByPresent
protected static void assertConstrainedByPresent(org.apache.http.client.methods.CloseableHttpResponse response)
-
preferLink
protected static String preferLink(String includes, String omits)
Create a Prefer header- Parameters:
includes- String of include URIs or null if noneomits- String of omit URIs or null if none- Returns:
- The Prefer header.
-
confirmResponseBodyNTriplesAreEqual
protected static void confirmResponseBodyNTriplesAreEqual(String responseBodyA, String responseBodyB)
Compare two N-Triple response bodies to determine if they are identical- Parameters:
responseBodyA- the first n-triple bodyresponseBodyB- the second n-triple body
-
-