Java tutorial
/** * Copyright 2013 DuraSpace, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.fcrepo.integration.syndication; import static java.lang.Integer.parseInt; import static java.lang.System.getProperty; import java.io.IOException; import java.util.concurrent.TimeUnit; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.PoolingClientConnectionManager; import org.junit.Before; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) public abstract class AbstractResourceIT { protected Logger logger; @Before public void setLogger() { logger = LoggerFactory.getLogger(this.getClass()); } protected static final int SERVER_PORT = parseInt(getProperty("test.port", "8080")); protected static final String HOSTNAME = "localhost"; protected static final String serverAddress = "http://" + HOSTNAME + ":" + SERVER_PORT; protected final PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(); protected static HttpClient client; public AbstractResourceIT() { connectionManager.setMaxTotal(Integer.MAX_VALUE); connectionManager.setDefaultMaxPerRoute(5); connectionManager.closeIdleConnections(3, TimeUnit.SECONDS); client = new DefaultHttpClient(connectionManager); } protected int getStatus(HttpUriRequest method) throws ClientProtocolException, IOException { logger.debug("Executing: " + method.getMethod() + " to " + method.getURI()); return client.execute(method).getStatusLine().getStatusCode(); } }