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.indexer.integration.webapp; import static org.junit.Assert.assertEquals; import java.io.IOException; import java.util.concurrent.TimeUnit; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.PoolingClientConnectionManager; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.inject.Inject; /** * @author Andrew Woods * Date: Aug 22, 2013 */ public class SanityCheckIT { private Logger logger = LoggerFactory.getLogger(this.getClass()); @Inject private ActiveMQConnectionFactory connectionFactory; /** * The server port of the application, set as system property by * maven-failsafe-plugin. */ private static final String SERVER_PORT = System.getProperty("test.port"); /** * The context path of the application (including the leading "/"), set as * system property by maven-failsafe-plugin. */ private static final String CONTEXT_PATH = System.getProperty("test.context.path"); private static final String HOSTNAME = "localhost"; private static final String serverAddress = "http://" + HOSTNAME + ":" + SERVER_PORT + CONTEXT_PATH; private static final PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(); private static HttpClient client; static { connectionManager.setMaxTotal(Integer.MAX_VALUE); connectionManager.setDefaultMaxPerRoute(5); connectionManager.closeIdleConnections(3, TimeUnit.SECONDS); client = new DefaultHttpClient(connectionManager); } @Test public void doASanityCheck() throws IOException { assertEquals(200, getStatus(new HttpGet(serverAddress))); } protected int getStatus(final HttpUriRequest method) throws IOException { logger.info("Executing: " + method.getMethod() + " to " + method.getURI()); return client.execute(method).getStatusLine().getStatusCode(); } }