001/*
002 * Licensed to DuraSpace under one or more contributor license agreements.
003 * See the NOTICE file distributed with this work for additional information
004 * regarding copyright ownership.
005 *
006 * DuraSpace licenses this file to you under the Apache License,
007 * Version 2.0 (the "License"); you may not use this file except in
008 * compliance with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.fcrepo.camel.integration;
019
020import static java.lang.Integer.parseInt;
021import static java.lang.System.getProperty;
022
023/**
024 * Utility functions for integration testing
025 * @author Aaron Coburn
026 * @since November 7, 2014
027 */
028public final class FcrepoTestUtils {
029
030    private static final int FCREPO_PORT = parseInt(getProperty(
031                "fcrepo.dynamic.test.port", "8080"));
032
033    /**
034     * This is a utility class; the constructor is off-limits
035     */
036    private FcrepoTestUtils() {
037    }
038
039    /**
040     * Retrieve the baseUrl for the fcrepo instance
041     *
042     * @return string containing base url
043     */
044    public static String getFcrepoBaseUrl() {
045        if (FCREPO_PORT == 80) {
046            return "http://localhost/fcrepo/rest";
047        }
048        return "http://localhost:" + FCREPO_PORT + "/fcrepo/rest";
049    }
050
051    /**
052     * Retrieve the endpoint uri for fcrepo
053     *
054     * @return string containing endpoint uri
055     */
056    public static String getFcrepoEndpointUri() {
057        if (FCREPO_PORT == 80) {
058            return "fcrepo://localhost/fcrepo/rest";
059        }
060        return "fcrepo://localhost:" + FCREPO_PORT + "/fcrepo/rest";
061    }
062
063    /**
064     * Retrieve the endpoint uri with an explicit scheme
065     *
066     * @return string containing endpoint uri
067     */
068    public static String getFcrepoEndpointUriWithScheme() {
069        if (FCREPO_PORT == 80) {
070            return "fcrepo:http://localhost/fcrepo/rest";
071        }
072        return "fcrepo:http://localhost:" + FCREPO_PORT + "/fcrepo/rest";
073    }
074
075    /**
076     * Retrieve an RDF document serialized in TTL
077     *
078     * @return string containing RDF doc in TTL
079     */
080    public static String getTurtleDocument() {
081        return "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n\n" +
082                "<> dc:title \"some title & other\" .";
083    }
084
085    /**
086     * Retrieve an N3 document
087     *
088     * @return string containing NS document
089     */
090    public static String getN3Document() {
091        return "<http://localhost/fcrepo/rest/path/a/b/c> <http://purl.org/dc/elements/1.1/author> \"Author\" .\n" +
092                "<http://localhost/fcrepo/rest/path/a/b/c> <http://purl.org/dc/elements/1.1/title> \"This & That\" .";
093    }
094
095    /**
096     * Retrieve a simple text document
097     *
098     * @return string containing text document
099     */
100    public static String getTextDocument() {
101        return "Simple plain text document";
102    }
103
104    /**
105     * Retrieve a sparql-update document
106     *
107     * @return string containing sparql document
108     */
109    public static String getPatchDocument() {
110        return "PREFIX dc: <http://purl.org/dc/elements/1.1/> \n\n" +
111                "INSERT { <> dc:title \"another title\" . } \nWHERE { }";
112    }
113}