Skip to content

Commit

Permalink
Migrated HTTP 1.0 & 1.1 tests to SampleSoapService (#868)
Browse files Browse the repository at this point in the history
* Migrated HTTP 1.0 & 1.1 Tests to City Service and moved to IntegrationTestsWithoutInternet

* Migrated HTTP 1.0 & 1.1 Tests to City Service and moved to IntegrationTestsWithoutInternet

* Set unused target properties to null

* Added assert for body content

* Switches equals to contains
  • Loading branch information
t-burch authored Feb 14, 2024
1 parent 37d3275 commit 50cbc6b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,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 @@ -25,12 +25,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
37 changes: 23 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,48 +63,50 @@ 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, "\"\"");
int status = client.executeMethod(post);
assertTrue(post.getResponseBodyAsString().contains("population"));
assertEquals(200, status);
assertEquals("HTTP/1.1", post.getStatusLine().getHttpVersion());

String response = post.getResponseBodyAsString();
assertNotNull(response);
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);
assertTrue(post.getResponseBodyAsString().contains("population"));
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,19 +78,19 @@ 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);
post.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8);
post.setRequestHeader(Header.SOAP_ACTION, "");

int status = client.executeMethod(post); // also see comment on initExpect100ContinueWithFastFail()
int status = client.executeMethod(post);
assertEquals(200, status);
assertTrue(post.getResponseBodyAsString().contains("population"));
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>

0 comments on commit 50cbc6b

Please sign in to comment.