Skip to content

Commit

Permalink
Classic test suits to execute in plain and TLS modes
Browse files Browse the repository at this point in the history
  • Loading branch information
ok2c committed Nov 28, 2023
1 parent 9ec6347 commit efe2598
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* ====================================================================
* 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.hc.client5.testing.sync;

import org.apache.hc.core5.http.URIScheme;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;

public class HttpIntegrationTests {

@Nested
@DisplayName("Request execution (HTTP/1.1)")
public class RequestExecution extends TestClientRequestExecution {

public RequestExecution() throws Exception {
super(URIScheme.HTTP);
}

}

@Nested
@DisplayName("Request execution (HTTP/1.1, TLS)")
public class RequestExecutionTls extends TestClientRequestExecution {

public RequestExecutionTls() throws Exception {
super(URIScheme.HTTPS);
}

}

@Nested
@DisplayName("Authentication (HTTP/1.1)")
public class Authentication extends TestClientAuthentication {

public Authentication() throws Exception {
super(URIScheme.HTTP);
}

}

@Nested
@DisplayName("Authentication (HTTP/1.1, TLS)")
public class AuthenticationTls extends TestClientAuthentication {

public AuthenticationTls() throws Exception {
super(URIScheme.HTTPS);
}

}

@Nested
@DisplayName("Content coding (HTTP/1.1)")
public class ContentCoding extends TestContentCodings {

public ContentCoding() throws Exception {
super(URIScheme.HTTP);
}

}

@Nested
@DisplayName("Content coding (HTTP/1.1, TLS)")
public class ContentCodingTls extends TestContentCodings {

public ContentCodingTls() throws Exception {
super(URIScheme.HTTPS);
}

}

@Nested
@DisplayName("Redirects (HTTP/1.1)")
public class Redirects extends TestRedirects {

public Redirects() throws Exception {
super(URIScheme.HTTP);
}

}

@Nested
@DisplayName("Redirects (HTTP/1.1, TLS)")
public class RedirectsTls extends TestRedirects {

public RedirectsTls() throws Exception {
super(URIScheme.HTTPS);
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* ====================================================================
* 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.hc.client5.testing.sync;

import org.apache.hc.core5.http.URIScheme;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;

public class HttpMinimalIntegrationTests {

@Nested
@DisplayName("Request execution (HTTP/1.1)")
public class RequestExecution extends TestMinimalClientRequestExecution {

public RequestExecution() throws Exception {
super(URIScheme.HTTP);
}

}

@Nested
@DisplayName("Request execution (HTTP/1.1, TLS)")
public class RequestExecutionTls extends TestMinimalClientRequestExecution {

public RequestExecutionTls() throws Exception {
super(URIScheme.HTTPS);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,20 @@
/**
* Unit tests for automatic client authentication.
*/
public class TestClientAuthentication {
public abstract class TestClientAuthentication {

public static final Timeout TIMEOUT = Timeout.ofMinutes(1);

@RegisterExtension
private TestClientResources testResources = new TestClientResources(URIScheme.HTTP, TIMEOUT);
private TestClientResources testResources;

protected TestClientAuthentication(final URIScheme scheme) {
this.testResources = new TestClientResources(scheme, TIMEOUT);
}

public URIScheme scheme() {
return testResources.scheme();
}

public ClassicTestServer startServer(final Authenticator authenticator) throws IOException {
return testResources.startServer(
Expand All @@ -117,11 +125,11 @@ public ClassicTestServer startServer() throws IOException {
return startServer(new BasicTestAuthenticator("test:test", "test realm"));
}

public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) {
public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) throws Exception {
return testResources.startClient(clientCustomizer);
}

public CloseableHttpClient startClient() {
public CloseableHttpClient startClient() throws Exception {
return testResources.startClient(builder -> {});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,30 @@
/**
* Client protocol handling tests.
*/
public class TestClientRequestExecution {
public abstract class TestClientRequestExecution {

public static final Timeout TIMEOUT = Timeout.ofMinutes(1);

@RegisterExtension
private TestClientResources testResources = new TestClientResources(URIScheme.HTTP, TIMEOUT);
private TestClientResources testResources;

protected TestClientRequestExecution(final URIScheme scheme) {
this.testResources = new TestClientResources(scheme, TIMEOUT);
}

public URIScheme scheme() {
return testResources.scheme();
}

public ClassicTestServer startServer() throws IOException {
return testResources.startServer(null, null, null);
}

public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) {
public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) throws Exception {
return testResources.startClient(clientCustomizer);
}

public CloseableHttpClient startClient() {
public CloseableHttpClient startClient() throws Exception {
return testResources.startClient(builder -> {});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ClassicTestServer startServer() throws IOException {
return testResources.startServer(null, null, null);
}

public CloseableHttpClient startClient() {
public CloseableHttpClient startClient() throws Exception {
return testResources.startClient(b -> {}, b -> {});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,30 @@
* require no intervention from the user of HttpClient, but we still want to let clients do their
* own thing if they so wish.
*/
public class TestContentCodings {
public abstract class TestContentCodings {

public static final Timeout TIMEOUT = Timeout.ofMinutes(1);

@RegisterExtension
private TestClientResources testResources = new TestClientResources(URIScheme.HTTP, TIMEOUT);
private TestClientResources testResources;

protected TestContentCodings(final URIScheme scheme) {
this.testResources = new TestClientResources(scheme, TIMEOUT);
}

public URIScheme scheme() {
return testResources.scheme();
}

public ClassicTestServer startServer() throws IOException {
return testResources.startServer(null, null, null);
}

public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) {
public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) throws Exception {
return testResources.startClient(clientCustomizer);
}

public CloseableHttpClient startClient() {
public CloseableHttpClient startClient() throws Exception {
return testResources.startClient(builder -> {});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,20 @@
/**
* Client protocol handling tests.
*/
public class TestMinimalClientRequestExecution {
public abstract class TestMinimalClientRequestExecution {

public static final Timeout TIMEOUT = Timeout.ofMinutes(1);

@RegisterExtension
private TestClientResources testResources = new TestClientResources(URIScheme.HTTP, TIMEOUT);
private TestClientResources testResources;

protected TestMinimalClientRequestExecution(final URIScheme scheme) {
this.testResources = new TestClientResources(scheme, TIMEOUT);
}

public URIScheme scheme() {
return testResources.scheme();
}
private static class SimpleService implements HttpRequestHandler {

public SimpleService() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,31 @@
/**
* Redirection test cases.
*/
public class TestRedirects {
public abstract class TestRedirects {

public static final Timeout TIMEOUT = Timeout.ofMinutes(1);

@RegisterExtension
private TestClientResources testResources = new TestClientResources(URIScheme.HTTP, TIMEOUT);
private TestClientResources testResources;

protected TestRedirects(final URIScheme scheme) {
this.testResources = new TestClientResources(scheme, TIMEOUT);
}

public URIScheme scheme() {
return testResources.scheme();
}

public ClassicTestServer startServer(final HttpProcessor httpProcessor,
final Decorator<HttpServerRequestHandler> handlerDecorator) throws IOException {
return testResources.startServer(null, httpProcessor, handlerDecorator);
}

public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) {
public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) throws Exception {
return testResources.startClient(clientCustomizer);
}

public CloseableHttpClient startClient() {
public CloseableHttpClient startClient() throws Exception {
return testResources.startClient(builder -> {});
}

Expand Down
Loading

0 comments on commit efe2598

Please sign in to comment.