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; 017 018import org.apache.http.HttpResponse; 019import org.apache.http.client.HttpClient; 020import org.apache.http.client.methods.HttpPost; 021import org.apache.http.impl.client.HttpClientBuilder; 022import org.junit.runner.RunWith; 023import org.slf4j.Logger; 024import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 025 026import java.io.IOException; 027 028import static java.lang.Integer.MAX_VALUE; 029import static java.lang.Integer.parseInt; 030import static java.lang.System.getProperty; 031import static javax.ws.rs.core.Response.Status.CREATED; 032import static org.junit.Assert.assertEquals; 033import static org.slf4j.LoggerFactory.getLogger; 034 035/** 036 * <p>Abstract AbstractResourceIT class.</p> 037 * 038 * @author cbeer 039 * @author ajs6f 040 */ 041@RunWith(SpringJUnit4ClassRunner.class) 042public abstract class AbstractResourceIT { 043 044 protected static Logger logger = getLogger(AbstractResourceIT.class); 045 046 protected static final int SERVER_PORT = parseInt(getProperty("fcrepo.dynamic.test.port", 047 "8080")); 048 protected static final String HOSTNAME = "localhost"; 049 050 protected static final String serverAddress = "http://" + HOSTNAME + ":" 051 + SERVER_PORT; 052 053 protected static HttpClient client; 054 055 public AbstractResourceIT() { 056 final HttpClientBuilder b = 057 HttpClientBuilder.create().setMaxConnPerRoute(MAX_VALUE) 058 .setMaxConnTotal(MAX_VALUE); 059 client = b.build(); 060 } 061 062 protected static HttpPost postObjMethod(final String pid) { 063 return new HttpPost(serverAddress + pid); 064 } 065 066 protected HttpResponse createObject(final String pid) throws IOException { 067 final HttpPost httpPost = postObjMethod("/"); 068 if (pid.length() > 0) { 069 httpPost.addHeader("Slug", pid); 070 } 071 final HttpResponse response = client.execute(httpPost); 072 assertEquals(CREATED.getStatusCode(), response.getStatusLine().getStatusCode()); 073 return response; 074 } 075}