001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006package org.fcrepo.integration;
007
008import static java.lang.Integer.MAX_VALUE;
009import static java.lang.Integer.parseInt;
010import static org.slf4j.LoggerFactory.getLogger;
011
012import java.util.Objects;
013
014import org.apache.http.auth.AuthScope;
015import org.apache.http.auth.Credentials;
016import org.apache.http.auth.UsernamePasswordCredentials;
017import org.apache.http.client.CredentialsProvider;
018import org.apache.http.client.HttpClient;
019import org.apache.http.impl.client.BasicCredentialsProvider;
020import org.apache.http.impl.client.HttpClientBuilder;
021import org.junit.Before;
022import org.slf4j.Logger;
023
024import com.google.common.base.Strings;
025
026/**
027 * Base class for ITs
028 * @author awoods
029 * @author escowles
030**/
031public abstract class AbstractResourceIT {
032
033    protected Logger logger;
034
035    public static final Credentials FEDORA_ADMIN_CREDENTIALS = new UsernamePasswordCredentials("fedoraAdmin",
036            "fedoraAdmin");
037
038    @Before
039    public void setLogger() {
040        logger = getLogger(this.getClass());
041    }
042
043    private static final int SERVER_PORT = parseInt(Objects.requireNonNullElse(
044            Strings.emptyToNull(System.getProperty("fcrepo.dynamic.test.port")), "8080"));
045
046    private static final String CONTEXT_PATH = System
047            .getProperty("fcrepo.test.context.path");
048
049    private static final String HOSTNAME = "localhost";
050
051    private static final String PROTOCOL = "http";
052
053    protected static final String serverAddress = PROTOCOL + "://" + HOSTNAME + ":" +
054            SERVER_PORT + CONTEXT_PATH + "rest/";
055
056    protected static final HttpClient client = createClient();
057
058    private static HttpClient createClient() {
059        final Credentials credentials = new UsernamePasswordCredentials("fedoraAdmin", "fedoraAdmin");
060        final CredentialsProvider credsProvider = new BasicCredentialsProvider();
061        credsProvider.setCredentials(AuthScope.ANY, credentials);
062        return HttpClientBuilder.create().setMaxConnPerRoute(MAX_VALUE)
063                .setMaxConnTotal(MAX_VALUE).setDefaultCredentialsProvider(credsProvider).build();
064    }
065
066}