Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated HTTP 1.0 & 1.1 tests to SampleSoapService #868

Merged
merged 7 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
@SelectClasses({
MethodTest.class,
RegExReplaceInterceptorTest.class,
Http10Test.class,
Http11Test.class,
AccessControlInterceptorIntegrationTest.class,
LoadBalancingInterceptorTest.class,
REST2SOAPInterceptorIntegrationTest.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@
import com.predic8.membrane.core.transport.ExceptionHandlingTest;
import com.predic8.membrane.core.transport.http.BoundConnectionTest;
import com.predic8.membrane.core.transport.http.IllegalCharactersInURLTest;
import com.predic8.membrane.integration.Http10Test;
import com.predic8.membrane.integration.Http11Test;
import com.predic8.membrane.integration.SessionManager;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

@Suite
@SelectClasses({
Http10Test.class,
Http11Test.class,
RegExReplaceInterceptorTest.class,
BoundConnectionTest.class,
ExceptionHandlingTest.class,
Expand Down
35 changes: 21 additions & 14 deletions core/src/test/java/com/predic8/membrane/integration/Http10Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.InputStream;

import com.predic8.membrane.core.interceptor.soap.SampleSoapServiceInterceptor;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpVersion;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
Expand All @@ -36,12 +37,18 @@
import com.predic8.membrane.core.rules.Rule;


@SuppressWarnings("deprecation")
public class Http10Test {
private static HttpRouter router;
private static HttpRouter router;

@BeforeAll
public static void setUp() throws Exception {
Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3000), "thomas-bayer.com", 80);
Rule rule2 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 2000), null, 0);
rule2.getInterceptors().add(new SampleSoapServiceInterceptor());
HttpRouter router2 = new HttpRouter();
router2.getRuleManager().addProxyAndOpenPortIfNew(rule2);
router2.init();
Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3000), "localhost", 2000);
router = new HttpRouter();
router.getRuleManager().addProxyAndOpenPortIfNew(rule);
router.init();
Expand All @@ -56,13 +63,14 @@ public static void tearDown() throws Exception {
public void testPost() throws Exception {

HttpClient client = new HttpClient();
client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION , HttpVersion.HTTP_1_0);
client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);

PostMethod post = new PostMethod("http://localhost:3000/axis2/services/BLZService");
InputStream stream = this.getClass().getResourceAsStream("/getBank.xml");
PostMethod post = new PostMethod("http://localhost:3000/");
InputStream stream = this.getClass().getResourceAsStream("/get-city.xml");


InputStreamRequestEntity entity = new InputStreamRequestEntity(stream);
assert stream != null;
InputStreamRequestEntity entity = new InputStreamRequestEntity(stream);
post.setRequestEntity(entity);
post.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8);
post.setRequestHeader(Header.SOAP_ACTION, "\"\"");
Expand All @@ -72,32 +80,31 @@ public void testPost() throws Exception {

String response = post.getResponseBodyAsString();
assertNotNull(response);
predic8 marked this conversation as resolved.
Show resolved Hide resolved
assertTrue(response.length() > 0);
assertFalse(response.isEmpty());
}


@Test
public void testMultiplePost() throws Exception {

HttpClient client = new HttpClient();
client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION , HttpVersion.HTTP_1_0);
client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);

PostMethod post = new PostMethod("http://localhost:3000/axis2/services/BLZService");
InputStream stream = this.getClass().getResourceAsStream("/getBank.xml");
PostMethod post = new PostMethod("http://localhost:3000/");
InputStream stream = this.getClass().getResourceAsStream("/get-city.xml");


InputStreamRequestEntity entity = new InputStreamRequestEntity(stream);
assert stream != null;
InputStreamRequestEntity entity = new InputStreamRequestEntity(stream);
post.setRequestEntity(entity);
post.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8);
post.setRequestHeader(Header.SOAP_ACTION, "\"\"");

for (int i = 0; i < 100; i ++) {
//System.out.println("Iteration: " + i);
int status = client.executeMethod(post);
assertEquals(200, status);
String response = post.getResponseBodyAsString();
assertNotNull(response);
assertTrue(response.length() > 0);
assertFalse(response.isEmpty());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.InputStream;

import com.predic8.membrane.core.interceptor.soap.SampleSoapServiceInterceptor;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpMethodRetryHandler;
Expand All @@ -45,7 +46,12 @@ public class Http11Test {

@BeforeAll
public static void setUp() throws Exception {
Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 4000), "thomas-bayer.com", 80);
Rule rule2 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 5000), null, 0);
rule2.getInterceptors().add(new SampleSoapServiceInterceptor());
HttpRouter router2 = new HttpRouter();
router2.getRuleManager().addProxyAndOpenPortIfNew(rule2);
router2.init();
Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 4000), "localhost", 5000);
router = new HttpRouter();
router.getRuleManager().addProxyAndOpenPortIfNew(rule);
router.init();
Expand All @@ -72,8 +78,8 @@ private void testPost(boolean useExpect100Continue) throws Exception {
HttpClient client = new HttpClient();
if (useExpect100Continue)
initExpect100ContinueWithFastFail(client);
PostMethod post = new PostMethod("http://localhost:4000/axis2/services/BLZService");
InputStream stream = this.getClass().getResourceAsStream("/getBank.xml");
PostMethod post = new PostMethod("http://localhost:4000/");
InputStream stream = this.getClass().getResourceAsStream("/get-city.xml");

InputStreamRequestEntity entity = new InputStreamRequestEntity(stream);
post.setRequestEntity(entity);
Expand All @@ -84,7 +90,6 @@ private void testPost(boolean useExpect100Continue) throws Exception {
assertEquals(200, status);
predic8 marked this conversation as resolved.
Show resolved Hide resolved
assertNotNull(post.getResponseBodyAsString());
assertFalse(isNullOrEmpty(post.getResponseBodyAsString()));
//System.out.println(post.getResponseBodyAsString());
}

@Test
Expand Down
8 changes: 8 additions & 0 deletions core/src/test/resources/get-city.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cit="https://predic8.de/cities">
<s:Header/>
<s:Body>
<cit:getCity>
<name>Bonn</name>
</cit:getCity>
</s:Body>
</s:Envelope>
Loading