You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2015/08/25 12:05:06 UTC
svn commit: r1697635 - in
/httpcomponents/httpcore/branches/4.4.x/httpcore-osgi: ./ src/test/
src/test/java/ src/test/java/org/ src/test/java/org/apache/
src/test/java/org/apache/http/ src/test/java/org/apache/http/osgi/
Author: olegk
Date: Tue Aug 25 10:05:05 2015
New Revision: 1697635
URL: http://svn.apache.org/r1697635
Log:
HTTTPCORE-405: Add basic PAX-EXAM tests to show that the OSGi bundle works a little.
More complex testing is certainly possible.
Added:
httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/
httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/
httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/
httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/
httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/
httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/
httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/AnnotationIT.java (with props)
httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/BasicIT.java (with props)
httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/Common.java (with props)
httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/ConcurrentIT.java (with props)
Modified:
httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/pom.xml
Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/pom.xml?rev=1697635&r1=1697634&r2=1697635&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/pom.xml (original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/pom.xml Tue Aug 25 10:05:05 2015
@@ -38,7 +38,11 @@
</description>
<url>http://hc.apache.org/httpcomponents-core-ga</url>
<packaging>bundle</packaging>
-
+ <properties>
+ <pax.url.version>2.0.0</pax.url.version>
+ <pax.exam.version>3.5.0</pax.exam.version>
+ <slf4j.version>1.5.4</slf4j.version>
+ </properties>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
@@ -50,11 +54,71 @@
<artifactId>httpcore-nio</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-native</artifactId>
+ <version>${pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit4</artifactId>
+ <scope>test</scope>
+ <version>${pax.exam.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-link-mvn</artifactId>
+ <scope>test</scope>
+ <version>${pax.exam.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.url</groupId>
+ <artifactId>pax-url-aether</artifactId>
+ <version>${pax.url.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>test</scope>
+ <version>${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ <version>${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
<plugin>
+ <groupId>org.apache.servicemix.tooling</groupId>
+ <artifactId>depends-maven-plugin</artifactId>
+ <version>1.2</version>
+ <executions>
+ <execution>
+ <id>generate-depends-file</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>generate-depends-file</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
@@ -74,6 +138,30 @@
<skip>true</skip>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>${hc.surefire.version}</version>
+ <executions>
+ <execution>
+ <id>it</id>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ <configuration>
+ <includes>
+ <include>**/*IT.class</include>
+ </includes>
+ <systemPropertyVariables>
+ <project.build.directory>${project.build.directory}</project.build.directory>
+ <project.version>${project.version}</project.version>
+ <java.awt.headless>true</java.awt.headless>
+ </systemPropertyVariables>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
<finalName>org.apache.httpcomponents.httpcore_${project.version}</finalName>
</build>
Added: httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/AnnotationIT.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/AnnotationIT.java?rev=1697635&view=auto
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/AnnotationIT.java (added)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/AnnotationIT.java Tue Aug 25 10:05:05 2015
@@ -0,0 +1,47 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.osgi;
+
+import org.apache.http.annotation.Immutable;
+import org.junit.Test;
+
+/**
+ * Are the annotations to be had?
+ */
+public class AnnotationIT extends Common {
+
+ @Immutable
+ static class SomeClass {
+ //
+ }
+
+ @Test
+ public void anything() {
+ new SomeClass();
+ }
+}
Propchange: httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/AnnotationIT.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/AnnotationIT.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/AnnotationIT.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/BasicIT.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/BasicIT.java?rev=1697635&view=auto
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/BasicIT.java (added)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/BasicIT.java Tue Aug 25 10:05:05 2015
@@ -0,0 +1,110 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.osgi;
+
+import org.apache.http.ConnectionClosedException;
+import org.apache.http.ConnectionReuseStrategy;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpResponseFactory;
+import org.apache.http.HttpServerConnection;
+import org.apache.http.HttpStatus;
+import org.apache.http.HttpVersion;
+import org.apache.http.MethodNotSupportedException;
+import org.apache.http.NoHttpResponseException;
+import org.apache.http.ProtocolException;
+import org.apache.http.UnsupportedHttpVersionException;
+import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.message.BasicHttpResponse;
+import org.apache.http.protocol.HttpCoreContext;
+import org.apache.http.protocol.HttpProcessor;
+import org.apache.http.protocol.HttpRequestHandlerMapper;
+import org.apache.http.protocol.HttpService;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ * Try basic classes
+ */
+public class BasicIT extends Common {
+ @Test
+ public void testBasicExecution() throws Exception {
+ final HttpProcessor httprocessor = Mockito.mock(HttpProcessor.class);
+ final ConnectionReuseStrategy connReuseStrategy = Mockito.mock(ConnectionReuseStrategy.class);
+ final HttpResponseFactory responseFactory = Mockito.mock(HttpResponseFactory.class);
+ final HttpRequestHandlerMapper handlerResolver = Mockito.mock(HttpRequestHandlerMapper.class);
+
+ final HttpService httpservice = new HttpService(
+ httprocessor,
+ connReuseStrategy,
+ responseFactory,
+ handlerResolver);
+ final HttpCoreContext context = HttpCoreContext.create();
+ final HttpServerConnection conn = Mockito.mock(HttpServerConnection.class);
+ final HttpRequest request = new BasicHttpRequest("GET", "/");
+ Mockito.when(conn.receiveRequestHeader()).thenReturn(request);
+ final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
+ Mockito.when(responseFactory.newHttpResponse(HttpVersion.HTTP_1_1, 200, context)).thenReturn(response);
+ Mockito.when(connReuseStrategy.keepAlive(response, context)).thenReturn(Boolean.FALSE);
+
+ httpservice.handleRequest(conn, context);
+
+ Assert.assertEquals(HttpStatus.SC_NOT_IMPLEMENTED, response.getStatusLine().getStatusCode());
+
+ Assert.assertSame(conn, context.getConnection());
+ Assert.assertSame(request, context.getRequest());
+ Assert.assertSame(response, context.getResponse());
+
+ Mockito.verify(httprocessor).process(request, context);
+ Mockito.verify(httprocessor).process(response, context);
+ Mockito.verify(conn).sendResponseHeader(response);
+ Mockito.verify(conn).sendResponseEntity(response);
+ Mockito.verify(conn).flush();
+ Mockito.verify(conn).close();
+ }
+
+ @Test
+ public void testConstructor() {
+ final Throwable cause = new Exception();
+ new HttpException();
+ new HttpException("Oppsie");
+ new HttpException("Oppsie", cause);
+ new ProtocolException();
+ new ProtocolException("Oppsie");
+ new ProtocolException("Oppsie", cause);
+ new NoHttpResponseException("Oppsie");
+ new ConnectionClosedException("Oppsie");
+ new MethodNotSupportedException("Oppsie");
+ new MethodNotSupportedException("Oppsie", cause);
+ new UnsupportedHttpVersionException();
+ new UnsupportedHttpVersionException("Oppsie");
+ }
+
+}
Propchange: httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/BasicIT.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/BasicIT.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/BasicIT.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/Common.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/Common.java?rev=1697635&view=auto
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/Common.java (added)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/Common.java Tue Aug 25 10:05:05 2015
@@ -0,0 +1,84 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.osgi;
+
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Properties;
+
+import static org.ops4j.pax.exam.CoreOptions.bundle;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemPackages;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+/**
+ * Test inherit from this.
+ */
+public class Common {
+
+ public static String getDependencyVersion(final String groupId, final String artifactId) {
+ final URL depPropsUrl = BasicIT.class.getResource("META-INF/maven/dependencies.properties");
+ final Properties depProps = new Properties();
+ try {
+ depProps.load(depPropsUrl.openStream());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ String ver = (String) depProps.get(String.format("%s/%s/version", groupId, artifactId));
+ if (ver == null) {
+ throw new RuntimeException(String.format("No version available for %s:%s", groupId, artifactId));
+ }
+ ver = ver.replace("-SNAPSHOT", ".SNAPSHOT");
+ return ver;
+ }
+
+
+ @Configuration
+ public Option[] config() {
+ final String projectVersion = System.getProperty("project.version");
+ final String paxLoggingLevel = System.getProperty("bt.osgi.pax.logging.level", "WARN");
+
+ return options(
+ bundle(String.format("org.apache.httpcomponents.httpcore_%s", projectVersion)),
+ mavenBundle("org.apache.httpcomponents", "httpcore-osgi", projectVersion),
+ mavenBundle("org.mockito", "mockito-core", getDependencyVersion("org.mockito", "mockito-core")),
+ systemPackages(
+ String.format("org.slf4j;version=\"%s\"", getDependencyVersion("org.slf4j", "slf4j-api"))
+
+ ),
+ junitBundles(),
+ systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value(paxLoggingLevel)
+ );
+ }
+}
Propchange: httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/Common.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/Common.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/Common.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/ConcurrentIT.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/ConcurrentIT.java?rev=1697635&view=auto
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/ConcurrentIT.java (added)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/ConcurrentIT.java Tue Aug 25 10:05:05 2015
@@ -0,0 +1,58 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.osgi;
+
+import org.apache.http.concurrent.BasicFuture;
+import org.apache.http.concurrent.FutureCallback;
+import org.junit.Test;
+
+/**
+ * Is the concurrent package to be had?
+ */
+public class ConcurrentIT extends Common {
+
+ @Test
+ public void testCompleted() throws Exception {
+ new BasicFuture<Void>(new FutureCallback<Void>() {
+ @Override
+ public void completed(final Void result) {
+ //
+ }
+
+ @Override
+ public void failed(final Exception ex) {
+ //
+ }
+
+ @Override
+ public void cancelled() {
+ //
+ }
+ }) {};
+ }
+}
Propchange: httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/ConcurrentIT.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/ConcurrentIT.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/branches/4.4.x/httpcore-osgi/src/test/java/org/apache/http/osgi/ConcurrentIT.java
------------------------------------------------------------------------------
svn:mime-type = text/plain