From 0910e92ac11cea94ed7fa242991aa505a19f5b6b Mon Sep 17 00:00:00 2001 From: t-burch <119930761+t-burch@users.noreply.github.com> Date: Tue, 12 Nov 2024 11:33:51 +0100 Subject: [PATCH] Adjust content length test update (#1326) * Rewrite AdjustContentLengthIntegrationTest to use local proxies instead of online SOAP service * Rename AdjustContentLengthIntegrationTest to AdjustContentLengthTest and move to unit test suite. Removed unnecessary test resources. --------- Co-authored-by: Tobias Polley Co-authored-by: Thomas Bayer --- .../core/IntegrationTestsWithInternet.java | 3 +- .../com/predic8/membrane/core/UnitTests.java | 1 + ...Test.java => AdjustContentLengthTest.java} | 52 +++++++++++++------ .../adjustContentLength/customer2person.xsl | 22 -------- .../adjustContentLength/xslt.proxies.xml | 14 ----- 5 files changed, 39 insertions(+), 53 deletions(-) rename core/src/test/java/com/predic8/membrane/core/interceptor/{AdjustContentLengthIntegrationTest.java => AdjustContentLengthTest.java} (50%) delete mode 100644 core/src/test/resources/adjustContentLength/customer2person.xsl delete mode 100644 core/src/test/resources/adjustContentLength/xslt.proxies.xml 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 beda7320b7..80efeff37a 100644 --- a/core/src/test/java/com/predic8/membrane/core/IntegrationTestsWithInternet.java +++ b/core/src/test/java/com/predic8/membrane/core/IntegrationTestsWithInternet.java @@ -16,7 +16,7 @@ import com.predic8.membrane.core.exchangestore.LimitedMemoryExchangeStoreIntegrationTest; import com.predic8.membrane.core.http.LargeBodyTest; import com.predic8.membrane.core.http.MethodTest; -import com.predic8.membrane.core.interceptor.AdjustContentLengthIntegrationTest; +import com.predic8.membrane.core.interceptor.AdjustContentLengthTest; import com.predic8.membrane.core.interceptor.RegExReplaceInterceptorTest; import com.predic8.membrane.core.rules.UnavailableSoapProxyTest; import com.predic8.membrane.integration.ProxySSLConnectionMethodTest; @@ -33,7 +33,6 @@ LoadBalancingInterceptorTest.class, ViaProxyTest.class, ProxySSLConnectionMethodTest.class, - AdjustContentLengthIntegrationTest.class, LimitedMemoryExchangeStoreIntegrationTest.class, UnavailableSoapProxyTest.class, LargeBodyTest.class, diff --git a/core/src/test/java/com/predic8/membrane/core/UnitTests.java b/core/src/test/java/com/predic8/membrane/core/UnitTests.java index 2a9a66362f..f1a11eea5e 100644 --- a/core/src/test/java/com/predic8/membrane/core/UnitTests.java +++ b/core/src/test/java/com/predic8/membrane/core/UnitTests.java @@ -176,6 +176,7 @@ SetHeaderInterceptor.class, SetPropertyInterceptor.class, APIProxyKeyTest.class, + AdjustContentLengthTest.class }) @SelectPackages({"com.predic8.membrane.core.openapi", "com.predic8.membrane.core.interceptor.flow.invocation", diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthIntegrationTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java similarity index 50% rename from core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthIntegrationTest.java rename to core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java index 36c6c580b9..2dd9b07762 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java @@ -14,39 +14,63 @@ package com.predic8.membrane.core.interceptor; +import com.predic8.membrane.core.HttpRouter; +import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.interceptor.misc.ReturnInterceptor; +import com.predic8.membrane.core.interceptor.templating.StaticInterceptor; +import com.predic8.membrane.core.rules.ServiceProxy; +import com.predic8.membrane.core.rules.ServiceProxyKey; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.GetMethod; - -import com.predic8.membrane.core.Router; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; -public class AdjustContentLengthIntegrationTest { +public class AdjustContentLengthTest { private static Router router; @BeforeAll public static void setUp() throws Exception { - router = Router.init("classpath:/adjustContentLength/xslt.proxies.xml"); + router = new HttpRouter(); + router.getRuleManager().addProxyAndOpenPortIfNew(createMonitorRule()); + router.getRuleManager().addProxyAndOpenPortIfNew(createEndpointRule()); + router.init(); + } + + private static ServiceProxy createMonitorRule() { + ServiceProxy rule = new ServiceProxy(new ServiceProxyKey("localhost","*", "*", 3000), "localhost", 4000); + rule.getInterceptors().add(new StaticInterceptor() {{ + setTextTemplate("Ping Pong"); + }}); + return rule; + } + + private static ServiceProxy createEndpointRule() { + ServiceProxy rule = new ServiceProxy(new ServiceProxyKey("localhost","*", "*", 4000), "localhost", 80); + rule.getInterceptors().add(new StaticInterceptor() {{ + setTextTemplate("Pong"); + }}); + rule.getInterceptors().add(new ReturnInterceptor()); + return rule; } @Test public void testAdjustContentLength() throws Exception { - GetMethod direktRequest = getDirektRequest(); - new HttpClient().executeMethod(direktRequest); + GetMethod directRequest = getDirectRequest(); + new HttpClient().executeMethod(directRequest); GetMethod monitoredRequest = getMonitoredRequest(); new HttpClient().executeMethod(monitoredRequest); - assertTrue(direktRequest.getResponseContentLength() == direktRequest + assertTrue(directRequest.getResponseContentLength() == directRequest .getResponseBody().length); assertTrue(monitoredRequest.getResponseContentLength() == monitoredRequest .getResponseBody().length); - assertTrue(direktRequest.getResponseContentLength() != monitoredRequest + assertTrue(directRequest.getResponseContentLength() != monitoredRequest .getResponseContentLength()); } @@ -56,15 +80,13 @@ public static void tearDown() throws Exception { router.shutdown(); } - private GetMethod getDirektRequest() { - GetMethod get = new GetMethod( - "http://thomas-bayer.com/samples/sqlrest/CUSTOMER/7/"); - return get; + private GetMethod getDirectRequest() { + return new GetMethod( + "http://localhost:4000/"); } private GetMethod getMonitoredRequest() { - GetMethod get = new GetMethod( - "http://localhost:3010/samples/sqlrest/CUSTOMER/7/"); - return get; + return new GetMethod( + "http://localhost:3000/"); } } diff --git a/core/src/test/resources/adjustContentLength/customer2person.xsl b/core/src/test/resources/adjustContentLength/customer2person.xsl deleted file mode 100644 index e1ee6f95ba..0000000000 --- a/core/src/test/resources/adjustContentLength/customer2person.xsl +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - -
- - -
-
-
- - - - - - - -
\ No newline at end of file diff --git a/core/src/test/resources/adjustContentLength/xslt.proxies.xml b/core/src/test/resources/adjustContentLength/xslt.proxies.xml deleted file mode 100644 index 1077b92733..0000000000 --- a/core/src/test/resources/adjustContentLength/xslt.proxies.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - -