Skip to content

Commit

Permalink
Adjust content length test update (#1326)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Thomas Bayer <[email protected]>
  • Loading branch information
3 people authored Nov 12, 2024
1 parent d457ad2 commit 0910e92
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +33,6 @@
LoadBalancingInterceptorTest.class,
ViaProxyTest.class,
ProxySSLConnectionMethodTest.class,
AdjustContentLengthIntegrationTest.class,
LimitedMemoryExchangeStoreIntegrationTest.class,
UnavailableSoapProxyTest.class,
LargeBodyTest.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

}
Expand All @@ -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/");
}
}
22 changes: 0 additions & 22 deletions core/src/test/resources/adjustContentLength/customer2person.xsl

This file was deleted.

14 changes: 0 additions & 14 deletions core/src/test/resources/adjustContentLength/xslt.proxies.xml

This file was deleted.

0 comments on commit 0910e92

Please sign in to comment.