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 6bc8c39400..beda7320b7 100644 --- a/core/src/test/java/com/predic8/membrane/core/IntegrationTestsWithInternet.java +++ b/core/src/test/java/com/predic8/membrane/core/IntegrationTestsWithInternet.java @@ -19,7 +19,6 @@ import com.predic8.membrane.core.interceptor.AdjustContentLengthIntegrationTest; import com.predic8.membrane.core.interceptor.RegExReplaceInterceptorTest; import com.predic8.membrane.core.rules.UnavailableSoapProxyTest; -import com.predic8.membrane.core.transport.http.InterceptorInvocationTest; import com.predic8.membrane.integration.ProxySSLConnectionMethodTest; import com.predic8.membrane.integration.SoapAndInternalProxyTest; import com.predic8.membrane.integration.ViaProxyTest; @@ -32,7 +31,6 @@ MethodTest.class, RegExReplaceInterceptorTest.class, LoadBalancingInterceptorTest.class, - InterceptorInvocationTest.class, ViaProxyTest.class, ProxySSLConnectionMethodTest.class, AdjustContentLengthIntegrationTest.class, diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/InterceptorInvocationTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/InterceptorInvocationTest.java deleted file mode 100644 index 4b12755a5f..0000000000 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/InterceptorInvocationTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/* Copyright 2011, 2012 predic8 GmbH, www.predic8.com - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ -package com.predic8.membrane.core.transport.http; - - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; -import org.apache.commons.httpclient.methods.InputStreamRequestEntity; -import org.apache.commons.httpclient.methods.PostMethod; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import com.predic8.membrane.core.HttpRouter; -import com.predic8.membrane.core.http.Header; -import com.predic8.membrane.core.http.MimeType; -import com.predic8.membrane.core.http.Request; -import com.predic8.membrane.core.interceptor.MockInterceptor; -import com.predic8.membrane.core.rules.ServiceProxy; -import com.predic8.membrane.core.rules.ServiceProxyKey; - -public class InterceptorInvocationTest { - - private static HttpRouter router; - - List backboneInterceptorNames; - - static List regularInterceptorNames; - - static List ruleInterceptorNames; - - static List interceptorSequence; - - @BeforeAll - public static void setUp() throws Exception { - - MockInterceptor.clear(); - - ruleInterceptorNames = Arrays.asList("Rule 1", "Rule 2", "Rule 3"); - - regularInterceptorNames = Arrays.asList("TR Normal 1", "TR Normal 2", "TR Normal 3", "TR Normal 4"); - - router = createRouter(); - - interceptorSequence = createInterceptorSequence(); - - } - - @AfterAll - public static void tearDown() throws Exception { - router.shutdown(); - } - - @Test - public void testInterceptorSequence() throws Exception { - callService(); - - MockInterceptor.assertContent( - interceptorSequence, - getReverseList(interceptorSequence), - Arrays.asList()); - } - - private static ServiceProxy createServiceProxy() { - ServiceProxy rule = new ServiceProxy(new ServiceProxyKey("localhost", Request.METHOD_POST, "*", 4000), "thomas-bayer.com", 80); - for (String label : ruleInterceptorNames) { - rule.getInterceptors().add(new MockInterceptor(label)); - } - return rule; - } - - private void callService() throws HttpException, IOException { - new HttpClient().executeMethod(createPostMethod()); - } - - private PostMethod createPostMethod() { - PostMethod post = new PostMethod("http://localhost:4000/axis2/services/BLZService"); - post.setRequestEntity(new InputStreamRequestEntity(this.getClass().getResourceAsStream("/getBank.xml"))); - post.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8); - post.setRequestHeader(Header.SOAP_ACTION, ""); - return post; - } - - private List getReverseList(List list) { - List res = new ArrayList<>(list); - Collections.reverse(res); - return res; - } - - private static List createInterceptorSequence() { - List sequense = new ArrayList<>(); - sequense.addAll(regularInterceptorNames); - sequense.addAll(ruleInterceptorNames); - return sequense; - } - - private static HttpRouter createRouter() throws Exception { - HttpRouter router = new HttpRouter(); - router.getRuleManager().addProxyAndOpenPortIfNew(createServiceProxy()); - addMockInterceptors(router, regularInterceptorNames); - router.init(); - return router; - } - - private static void addMockInterceptors(HttpRouter router, List labels) { - for (String label : labels) { - router.addUserFeatureInterceptor(new MockInterceptor(label)); - } - } -} diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java index 19302e96dd..03404b771a 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java @@ -13,13 +13,16 @@ limitations under the License. */ package com.predic8.membrane.core.transport.http; - import java.io.IOException; +import com.predic8.membrane.core.interceptor.misc.ReturnInterceptor; +import com.predic8.membrane.core.interceptor.templating.StaticInterceptor; +import com.predic8.membrane.core.rules.InternalProxy; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.methods.InputStreamRequestEntity; import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.StringRequestEntity; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -59,28 +62,36 @@ public void tearDown() throws Exception { } private ServiceProxy createFirstRule() { - ServiceProxy rule = new ServiceProxy(new ServiceProxyKey("localhost", Request.METHOD_POST, "*", 3016), "thomas-bayer.com", 80); + ServiceProxy rule = new ServiceProxy(new ServiceProxyKey("localhost", Request.METHOD_POST, "*", 2000), "localhost", 80); rule.setTargetURL("service:log"); rule.getInterceptors().add(new MockInterceptor("process")); return rule; } private ServiceProxy createServiceRule() { - ServiceProxy rule = new ServiceProxy(new ServiceProxyKey("localhost","*", "*", 3012), "thomas-bayer.com", 80); + ServiceProxy rule = new ServiceProxy(new ServiceProxyKey("localhost","*", "*", 3000), "localhost", 4000); rule.setName("log"); rule.getInterceptors().add(new MockInterceptor("log")); return rule; } - private void callService() throws HttpException, IOException { + private 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; + } + + private void callService() throws IOException { new HttpClient().executeMethod(createPostMethod()); } private PostMethod createPostMethod() { - PostMethod post = new PostMethod("http://localhost:3016/axis2/services/BLZService?wsdl"); - post.setRequestEntity(new InputStreamRequestEntity(this.getClass().getResourceAsStream("/getBank.xml"))); - post.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8); - post.setRequestHeader(Header.SOAP_ACTION, ""); + PostMethod post = new PostMethod("http://localhost:2000"); + post.setRequestEntity(new StringRequestEntity("Ping")); + post.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_PLAIN_UTF8); return post; } @@ -88,6 +99,7 @@ private HttpRouter createRouter() throws Exception { HttpRouter router = new HttpRouter(); router.getRuleManager().addProxyAndOpenPortIfNew(createFirstRule()); router.getRuleManager().addProxyAndOpenPortIfNew(createServiceRule()); + router.getRuleManager().addProxyAndOpenPortIfNew(createEndpointRule()); router.getTransport().getInterceptors().add(router.getTransport().getInterceptors().size()-1, new MockInterceptor("transport-log")); router.init(); return router;