01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package loanbroker;
18:
19: import javax.jbi.messaging.ExchangeStatus;
20: import javax.jbi.messaging.InOnly;
21: import javax.jbi.messaging.InOut;
22: import javax.xml.namespace.QName;
23:
24: import org.w3c.dom.Element;
25:
26: import org.apache.servicemix.client.DefaultServiceMixClient;
27: import org.apache.servicemix.client.ServiceMixClient;
28: import org.apache.servicemix.drools.DroolsComponent;
29: import org.apache.servicemix.drools.DroolsEndpoint;
30: import org.apache.servicemix.jbi.container.JBIContainer;
31: import org.apache.servicemix.jbi.jaxp.SourceTransformer;
32: import org.apache.servicemix.jbi.jaxp.StringSource;
33: import org.apache.servicemix.tck.ReceiverComponent;
34: import org.springframework.core.io.ClassPathResource;
35:
36: import junit.framework.TestCase;
37:
38: public class CreditAgencyTest extends TestCase {
39:
40: private JBIContainer jbi;
41: private DroolsComponent drools;
42: private ServiceMixClient client;
43:
44: protected void setUp() throws Exception {
45: super .setUp();
46: jbi = new JBIContainer();
47: jbi.setEmbedded(true);
48: jbi.init();
49: client = new DefaultServiceMixClient(jbi);
50: }
51:
52: protected void tearDown() throws Exception {
53: jbi.shutDown();
54: }
55:
56: public void testCreditHistory() throws Exception {
57: drools = new DroolsComponent();
58: DroolsEndpoint endpoint = new DroolsEndpoint(drools
59: .getServiceUnit(), new QName("drools"), "endpoint");
60: endpoint.setRuleBaseResource(new ClassPathResource(
61: "credit-agency.drl"));
62: drools.setEndpoints(new DroolsEndpoint[] { endpoint });
63: jbi.activateComponent(drools, "servicemix-drools");
64:
65: jbi.start();
66:
67: InOut me = client.createInOutExchange();
68: me.setService(new QName("drools"));
69: me.setOperation(new QName("urn:logicblaze:soa:creditagency",
70: "getCreditHistoryLength"));
71: me
72: .getInMessage()
73: .setContent(
74: new StringSource(
75: "<getCreditHistoryLengthRequest xmlns='urn:logicblaze:soa:creditagency'><ssn>123456</ssn></getCreditHistoryLengthRequest>"));
76: client.sendSync(me);
77: Element e = new SourceTransformer().toDOMElement(me
78: .getOutMessage());
79: assertEquals("getCreditHistoryLengthResponse", e.getLocalName());
80: client.done(me);
81:
82: Thread.sleep(50);
83: }
84:
85: }
|