001/*
002 * Copyright 2015 DuraSpace, Inc.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.fcrepo.integration.rdf;
017
018import com.hp.hpl.jena.update.GraphStore;
019import org.apache.http.HttpResponse;
020import org.apache.http.client.methods.HttpGet;
021import org.apache.http.client.methods.HttpPost;
022import org.junit.Test;
023
024import java.io.IOException;
025
026import static javax.ws.rs.core.Response.Status.CREATED;
027import static org.junit.Assert.assertFalse;
028
029/**
030 * @author cabeer
031 */
032public class LdpIT extends AbstractIntegrationRdfIT {
033    @Test
034    public void testExample10() throws IOException {
035        final String pid = getRandomUniqueId();
036        final HttpResponse response = createObject(pid);
037        final String location = response.getFirstHeader("Location").getValue();
038
039        final String body = "\n" +
040                "@prefix ldp: <http://www.w3.org/ns/ldp#>.\n" +
041                "@prefix dcterms: <http://purl.org/dc/terms/>.\n" +
042                "@prefix o: <http://example.org/ontology#>.\n" +
043                "<> a ldp:DirectContainer ;" +
044                "   dcterms:title \"The liabilities of JohnZSmith\";\n" +
045                "   ldp:membershipResource <" + location + ">;\n" +
046                "   ldp:hasMemberRelation o:liability;\n";
047
048        createLDPRSAndCheckResponse(pid + "/liabilities", body);
049
050        final HttpPost httpPost1 = new HttpPost(serverAddress + pid + "/liabilities");
051        httpPost1.setHeader("Slug", "l1");
052        checkResponse(execute(httpPost1), CREATED);
053
054        final HttpPost httpPost2 = new HttpPost(serverAddress + pid + "/liabilities");
055        httpPost2.setHeader("Slug", "l2");
056        checkResponse(execute(httpPost2), CREATED);
057
058        final HttpPost httpPost3 = new HttpPost(serverAddress + pid + "/liabilities");
059        httpPost3.setHeader("Slug", "l3");
060        checkResponse(execute(httpPost3), CREATED);
061
062        final HttpGet httpGet = new HttpGet(location);
063        httpGet.addHeader("Prefer", "return=representation; " +
064                "include=\"http://www.w3.org/ns/ldp#PreferMembership " +
065                    "http://www.w3.org/ns/ldp#PreferMinimalContainer\"; " +
066                "omit=\"http://fedora.info/definitions/v4/repository#ServerManaged\"");
067        final GraphStore graphStore = getGraphStore(httpGet);
068
069        assertFalse(graphStore.isEmpty());
070    }
071}