Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.trellisldp.test;
import static java.util.function.Predicate.isEqual;
import static javax.ws.rs.client.Entity.entity;
import static javax.ws.rs.core.Response.Status.Family.CLIENT_ERROR;
import static org.apache.commons.rdf.api.RDFSyntax.NTRIPLES;
import static org.apache.commons.rdf.api.RDFSyntax.TURTLE;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
import static org.trellisldp.api.TrellisUtils.getInstance;
import static org.trellisldp.http.core.HttpConstants.SLUG;
import static org.trellisldp.http.core.RdfMediaType.APPLICATION_LD_JSON_TYPE;
import static org.trellisldp.http.core.RdfMediaType.APPLICATION_N_TRIPLES_TYPE;
import static org.trellisldp.http.core.RdfMediaType.APPLICATION_SPARQL_UPDATE;
import static org.trellisldp.http.core.RdfMediaType.TEXT_TURTLE;
import static org.trellisldp.http.core.RdfMediaType.TEXT_TURTLE_TYPE;
import static org.trellisldp.test.TestUtils.getLinks;
import static org.trellisldp.test.TestUtils.getResourceAsString;
import static org.trellisldp.test.TestUtils.hasConstrainedBy;
import static org.trellisldp.test.TestUtils.readEntityAsGraph;
import static org.trellisldp.test.TestUtils.readEntityAsJson;
import static org.trellisldp.vocabulary.RDF.type;
import com.fasterxml.jackson.core.type.TypeReference;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.ws.rs.ProcessingException;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.Response;
import org.apache.commons.rdf.api.Graph;
import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.api.Triple;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.trellisldp.vocabulary.DC;
import org.trellisldp.vocabulary.LDP;
import org.trellisldp.vocabulary.SKOS;
import org.trellisldp.vocabulary.Trellis;
/**
* Test the RDF responses to LDP resources.
*/
@TestInstance(PER_CLASS)
public interface LdpRdfTests extends CommonTests {
String SIMPLE_RESOURCE = "/simpleResource.ttl";
String BASIC_CONTAINER = "/basicContainer.ttl";
String ANNOTATION_RESOURCE = "/annotation.ttl";
/**
* Set the location of the test resource.
* @param location the location
*/
void setResourceLocation(String location);
/**
* Get the location of the test resource.
* @return the test resource location
*/
String getResourceLocation();
/**
* Return a set of valid JSON-LD profiles that the server supports.
* @return the JSON-LD profiles
*/
Set supportedJsonLdProfiles();
/**
* Initialize the RDF tests.
*/
@BeforeAll
@DisplayName("Initialize RDF tests")
default void beforeAllTests() {
final String content = getResourceAsString(SIMPLE_RESOURCE);
// POST an LDP-RS
try (final Response res = target().request().header(SLUG, generateRandomValue(getClass().getSimpleName()))
.post(entity(content, TEXT_TURTLE))) {
setResourceLocation(checkCreateResponseAssumptions(res, LDP.RDFSource));
}
}
/**
* Fetch the default RDF serialization.
*/
@Test
@DisplayName("Fetch the default RDF serialization")
default void testGetDefault() {
try (final Response res = target(getResourceLocation()).request().get()) {
assertAll("Check for an LDP-RS as Turtle", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE));
}
}
/**
* Fetch the default JSON-LD serialization.
*/
@Test
@DisplayName("Fetch the default JSON-LD serialization")
default void testGetJsonLdDefault() {
final String location = createAnnotationResource();
try (final Response res = target(location).request().accept("application/ld+json").get()) {
assertAll("Check for an LDP-RS as JSONLD", checkRdfResponse(res, LDP.RDFSource, APPLICATION_LD_JSON_TYPE));
final Map obj = readEntityAsJson(res.getEntity(),
new TypeReference