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.integration;
019
020import static java.lang.Integer.MAX_VALUE;
021import static java.lang.Integer.parseInt;
022import static org.slf4j.LoggerFactory.getLogger;
023
024import java.util.Objects;
025
026import org.apache.http.auth.AuthScope;
027import org.apache.http.auth.Credentials;
028import org.apache.http.auth.UsernamePasswordCredentials;
029import org.apache.http.client.CredentialsProvider;
030import org.apache.http.client.HttpClient;
031import org.apache.http.impl.client.BasicCredentialsProvider;
032import org.apache.http.impl.client.HttpClientBuilder;
033import org.junit.Before;
034import org.slf4j.Logger;
035
036import com.google.common.base.Strings;
037
038/**
039 * Base class for ITs
040 * @author awoods
041 * @author escowles
042**/
043public abstract class AbstractResourceIT {
044
045    protected Logger logger;
046
047    public static final Credentials FEDORA_ADMIN_CREDENTIALS = new UsernamePasswordCredentials("fedoraAdmin",
048            "fedoraAdmin");
049
050    @Before
051    public void setLogger() {
052        logger = getLogger(this.getClass());
053    }
054
055    private static final int SERVER_PORT = parseInt(Objects.requireNonNullElse(
056            Strings.emptyToNull(System.getProperty("fcrepo.dynamic.test.port")), "8080"));
057
058    private static final String CONTEXT_PATH = System
059            .getProperty("fcrepo.test.context.path");
060
061    private static final String HOSTNAME = "localhost";
062
063    private static final String PROTOCOL = "http";
064
065    protected static final String serverAddress = PROTOCOL + "://" + HOSTNAME + ":" +
066            SERVER_PORT + CONTEXT_PATH + "rest/";
067
068    protected static final HttpClient client = createClient();
069
070    private static HttpClient createClient() {
071        final Credentials credentials = new UsernamePasswordCredentials("fedoraAdmin", "fedoraAdmin");
072        final CredentialsProvider credsProvider = new BasicCredentialsProvider();
073        credsProvider.setCredentials(AuthScope.ANY, credentials);
074        return HttpClientBuilder.create().setMaxConnPerRoute(MAX_VALUE)
075                .setMaxConnTotal(MAX_VALUE).setDefaultCredentialsProvider(credsProvider).build();
076    }
077
078}