From 198517f00ad60a78f5f61d16619a94385c8213b8 Mon Sep 17 00:00:00 2001 From: predic8 Date: Tue, 13 Feb 2024 11:52:20 +0100 Subject: [PATCH 1/5] Migrated HTTP 1.0 & 1.1 Tests to City Service and moved to IntegrationTestsWithoutInternet --- .../core/IntegrationTestsWithoutInternet.java | 4 +++ .../membrane/integration/Http10Test.java | 35 +++++++++++-------- .../membrane/integration/Http11Test.java | 13 ++++--- core/src/test/resources/get-city.xml | 8 +++++ 4 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 core/src/test/resources/get-city.xml diff --git a/core/src/test/java/com/predic8/membrane/core/IntegrationTestsWithoutInternet.java b/core/src/test/java/com/predic8/membrane/core/IntegrationTestsWithoutInternet.java index dad73f5f5a..9403e763ec 100644 --- a/core/src/test/java/com/predic8/membrane/core/IntegrationTestsWithoutInternet.java +++ b/core/src/test/java/com/predic8/membrane/core/IntegrationTestsWithoutInternet.java @@ -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, diff --git a/core/src/test/java/com/predic8/membrane/integration/Http10Test.java b/core/src/test/java/com/predic8/membrane/integration/Http10Test.java index 774abcabb0..0e0c090a48 100644 --- a/core/src/test/java/com/predic8/membrane/integration/Http10Test.java +++ b/core/src/test/java/com/predic8/membrane/integration/Http10Test.java @@ -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; @@ -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), "thomas-bayer.com", 80); + 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(); @@ -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, "\"\""); @@ -72,32 +80,31 @@ public void testPost() throws Exception { 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); assertEquals(200, status); String response = post.getResponseBodyAsString(); assertNotNull(response); - assertTrue(response.length() > 0); + assertFalse(response.isEmpty()); } } diff --git a/core/src/test/java/com/predic8/membrane/integration/Http11Test.java b/core/src/test/java/com/predic8/membrane/integration/Http11Test.java index f8bc3ee944..538aada91b 100644 --- a/core/src/test/java/com/predic8/membrane/integration/Http11Test.java +++ b/core/src/test/java/com/predic8/membrane/integration/Http11Test.java @@ -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; @@ -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), "thomas-bayer.com", 80); + 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(); @@ -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); @@ -84,7 +90,6 @@ private void testPost(boolean useExpect100Continue) throws Exception { assertEquals(200, status); assertNotNull(post.getResponseBodyAsString()); assertFalse(isNullOrEmpty(post.getResponseBodyAsString())); - //System.out.println(post.getResponseBodyAsString()); } @Test diff --git a/core/src/test/resources/get-city.xml b/core/src/test/resources/get-city.xml new file mode 100644 index 0000000000..260c36d189 --- /dev/null +++ b/core/src/test/resources/get-city.xml @@ -0,0 +1,8 @@ + + + + + Bonn + + + \ No newline at end of file From dc425d0b915b3a3fced8273579ca93dbcd689595 Mon Sep 17 00:00:00 2001 From: predic8 Date: Tue, 13 Feb 2024 11:59:22 +0100 Subject: [PATCH 2/5] Migrated HTTP 1.0 & 1.1 Tests to City Service and moved to IntegrationTestsWithoutInternet --- .../com/predic8/membrane/core/IntegrationTestsWithInternet.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/test/java/com/predic8/membrane/core/IntegrationTestsWithInternet.java b/core/src/test/java/com/predic8/membrane/core/IntegrationTestsWithInternet.java index 82e8df2c99..5608b8783c 100644 --- a/core/src/test/java/com/predic8/membrane/core/IntegrationTestsWithInternet.java +++ b/core/src/test/java/com/predic8/membrane/core/IntegrationTestsWithInternet.java @@ -32,8 +32,6 @@ @SelectClasses({ MethodTest.class, RegExReplaceInterceptorTest.class, - Http10Test.class, - Http11Test.class, AccessControlInterceptorIntegrationTest.class, LoadBalancingInterceptorTest.class, REST2SOAPInterceptorIntegrationTest.class, From c9742f6c6ea5c0c6ff5687dee24efb670497d028 Mon Sep 17 00:00:00 2001 From: predic8 Date: Tue, 13 Feb 2024 16:08:59 +0100 Subject: [PATCH 3/5] Set unused target properties to null --- .../test/java/com/predic8/membrane/integration/Http10Test.java | 2 +- .../test/java/com/predic8/membrane/integration/Http11Test.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/com/predic8/membrane/integration/Http10Test.java b/core/src/test/java/com/predic8/membrane/integration/Http10Test.java index 0e0c090a48..d135b51fd7 100644 --- a/core/src/test/java/com/predic8/membrane/integration/Http10Test.java +++ b/core/src/test/java/com/predic8/membrane/integration/Http10Test.java @@ -43,7 +43,7 @@ public class Http10Test { @BeforeAll public static void setUp() throws Exception { - Rule rule2 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 2000), "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); diff --git a/core/src/test/java/com/predic8/membrane/integration/Http11Test.java b/core/src/test/java/com/predic8/membrane/integration/Http11Test.java index 538aada91b..bbdfc6d8c8 100644 --- a/core/src/test/java/com/predic8/membrane/integration/Http11Test.java +++ b/core/src/test/java/com/predic8/membrane/integration/Http11Test.java @@ -46,7 +46,7 @@ public class Http11Test { @BeforeAll public static void setUp() throws Exception { - Rule rule2 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 5000), "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); From 8ba9a5299a3d0651e6002a13bf0e09883a1a3960 Mon Sep 17 00:00:00 2001 From: predic8 Date: Wed, 14 Feb 2024 11:23:40 +0100 Subject: [PATCH 4/5] Added assert for body content --- .../membrane/integration/Http10Test.java | 18 ++++++++++++++++++ .../membrane/integration/Http11Test.java | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/core/src/test/java/com/predic8/membrane/integration/Http10Test.java b/core/src/test/java/com/predic8/membrane/integration/Http10Test.java index d135b51fd7..a7f696b2fa 100644 --- a/core/src/test/java/com/predic8/membrane/integration/Http10Test.java +++ b/core/src/test/java/com/predic8/membrane/integration/Http10Test.java @@ -75,6 +75,15 @@ public void testPost() throws Exception { post.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8); post.setRequestHeader(Header.SOAP_ACTION, "\"\""); int status = client.executeMethod(post); + assertEquals(""" + + + + Germany + 327000 + + + """, post.getResponseBodyAsString().trim()); assertEquals(200, status); assertEquals("HTTP/1.1", post.getStatusLine().getHttpVersion()); @@ -101,6 +110,15 @@ public void testMultiplePost() throws Exception { for (int i = 0; i < 100; i ++) { int status = client.executeMethod(post); + assertEquals(""" + + + + Germany + 327000 + + + """, post.getResponseBodyAsString().trim()); assertEquals(200, status); String response = post.getResponseBodyAsString(); assertNotNull(response); diff --git a/core/src/test/java/com/predic8/membrane/integration/Http11Test.java b/core/src/test/java/com/predic8/membrane/integration/Http11Test.java index bbdfc6d8c8..7aa0fb8ac5 100644 --- a/core/src/test/java/com/predic8/membrane/integration/Http11Test.java +++ b/core/src/test/java/com/predic8/membrane/integration/Http11Test.java @@ -88,6 +88,15 @@ private void testPost(boolean useExpect100Continue) throws Exception { int status = client.executeMethod(post); // also see comment on initExpect100ContinueWithFastFail() assertEquals(200, status); + assertEquals(""" + + + + Germany + 327000 + + + """, post.getResponseBodyAsString().trim()); assertNotNull(post.getResponseBodyAsString()); assertFalse(isNullOrEmpty(post.getResponseBodyAsString())); } From 52349d9d3847294692a11d83346e65f8ef215604 Mon Sep 17 00:00:00 2001 From: predic8 Date: Wed, 14 Feb 2024 11:40:03 +0100 Subject: [PATCH 5/5] Switches equals to contains --- .../membrane/integration/Http10Test.java | 20 ++----------------- .../membrane/integration/Http11Test.java | 12 ++--------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/core/src/test/java/com/predic8/membrane/integration/Http10Test.java b/core/src/test/java/com/predic8/membrane/integration/Http10Test.java index a7f696b2fa..12941e3262 100644 --- a/core/src/test/java/com/predic8/membrane/integration/Http10Test.java +++ b/core/src/test/java/com/predic8/membrane/integration/Http10Test.java @@ -75,15 +75,7 @@ public void testPost() throws Exception { post.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8); post.setRequestHeader(Header.SOAP_ACTION, "\"\""); int status = client.executeMethod(post); - assertEquals(""" - - - - Germany - 327000 - - - """, post.getResponseBodyAsString().trim()); + assertTrue(post.getResponseBodyAsString().contains("population")); assertEquals(200, status); assertEquals("HTTP/1.1", post.getStatusLine().getHttpVersion()); @@ -110,15 +102,7 @@ public void testMultiplePost() throws Exception { for (int i = 0; i < 100; i ++) { int status = client.executeMethod(post); - assertEquals(""" - - - - Germany - 327000 - - - """, post.getResponseBodyAsString().trim()); + assertTrue(post.getResponseBodyAsString().contains("population")); assertEquals(200, status); String response = post.getResponseBodyAsString(); assertNotNull(response); diff --git a/core/src/test/java/com/predic8/membrane/integration/Http11Test.java b/core/src/test/java/com/predic8/membrane/integration/Http11Test.java index 7aa0fb8ac5..71df850d6a 100644 --- a/core/src/test/java/com/predic8/membrane/integration/Http11Test.java +++ b/core/src/test/java/com/predic8/membrane/integration/Http11Test.java @@ -86,17 +86,9 @@ private void testPost(boolean useExpect100Continue) throws Exception { 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); - assertEquals(""" - - - - Germany - 327000 - - - """, post.getResponseBodyAsString().trim()); + assertTrue(post.getResponseBodyAsString().contains("population")); assertNotNull(post.getResponseBodyAsString()); assertFalse(isNullOrEmpty(post.getResponseBodyAsString())); }