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.camel.integration;
017
018import static java.lang.Integer.parseInt;
019import static java.lang.System.getProperty;
020
021/**
022 * Utility functions for integration testing
023 * @author Aaron Coburn
024 * @since November 7, 2014
025 */
026public final class FcrepoTestUtils {
027
028    private static final int FCREPO_PORT = parseInt(getProperty(
029                "fcrepo.dynamic.test.port", "8080"));
030
031    /**
032     * This is a utility class; the constructor is off-limits
033     */
034    private FcrepoTestUtils() {
035    }
036
037    /**
038     * Retrieve the baseUrl for the fcrepo instance
039     *
040     * @return string containing base url
041     */
042    public static String getFcrepoBaseUrl() {
043        if (FCREPO_PORT == 80) {
044            return "http://localhost/rest";
045        }
046        return "http://localhost:" + FCREPO_PORT + "/rest";
047    }
048
049    /**
050     * Retrieve the endpoint uri for fcrepo
051     *
052     * @return string containing endpoint uri
053     */
054    public static String getFcrepoEndpointUri() {
055        if (FCREPO_PORT == 80) {
056            return "fcrepo://localhost/rest";
057        }
058        return "fcrepo://localhost:" + FCREPO_PORT + "/rest";
059    }
060
061    /**
062     * Retrieve the endpoint uri with an explicit scheme
063     *
064     * @return string containing endpoint uri
065     */
066    public static String getFcrepoEndpointUriWithScheme() {
067        if (FCREPO_PORT == 80) {
068            return "fcrepo:http://localhost/rest";
069        }
070        return "fcrepo:http://localhost:" + FCREPO_PORT + "/rest";
071    }
072
073    /**
074     * Retrieve an RDF document serialized in TTL
075     *
076     * @return string containing RDF doc in TTL
077     */
078    public static String getTurtleDocument() {
079        return "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n\n" +
080                "<> dc:title \"some title & other\" .";
081    }
082
083    /**
084     * Retrieve an N3 document
085     *
086     * @return string containing NS document
087     */
088    public static String getN3Document() {
089        return "<http://localhost/rest/path/a/b/c> <http://purl.org/dc/elements/1.1/author> \"Author\" .\n" +
090                "<http://localhost/rest/path/a/b/c> <http://purl.org/dc/elements/1.1/title> \"This & That\" .";
091    }
092
093    /**
094     * Retrieve a simple text document
095     *
096     * @return string containing text document
097     */
098    public static String getTextDocument() {
099        return "Simple plain text document";
100    }
101
102    /**
103     * Retrieve a sparql-update document
104     *
105     * @return string containing sparql document
106     */
107    public static String getPatchDocument() {
108        return "PREFIX dc: <http://purl.org/dc/elements/1.1/> \n\n" +
109                "INSERT { <> dc:title \"another title\" . } \nWHERE { }";
110    }
111}