Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ServiceInvocationTest to use local rules instead of contacting BLZ Service #1325

Merged
merged 4 commits into from
Nov 7, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,35 +62,44 @@ 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;
}

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;
Expand Down
Loading