KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > splitter > SplitterComponentTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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 org.apache.servicemix.components.splitter;
18
19 import javax.xml.namespace.QName JavaDoc;
20
21 import junit.framework.TestCase;
22
23 import org.apache.servicemix.jbi.container.ActivationSpec;
24 import org.apache.servicemix.jbi.container.JBIContainer;
25 import org.apache.servicemix.tck.ReceiverComponent;
26 import org.apache.servicemix.tck.SenderComponent;
27
28 public class SplitterComponentTest extends TestCase {
29     private JBIContainer jbiContainer;
30
31     protected SenderComponent sender;
32
33     protected ReceiverComponent receiver;
34
35     protected SplitterComponent fec;
36
37     protected void setUp() throws Exception JavaDoc {
38         jbiContainer = new JBIContainer();
39         jbiContainer.setUseMBeanServer(false);
40         jbiContainer.setCreateMBeanServer(false);
41         jbiContainer.setFlowName("seda");
42         jbiContainer.init();
43         jbiContainer.start();
44         setUpReceiver();
45         setUpSender();
46         setUpComponent();
47     }
48
49     protected QName JavaDoc getComponentService() {
50         return new QName JavaDoc("http://www.neogrid.com.br", "component");
51     }
52
53     private void setUpSender() throws Exception JavaDoc {
54         sender = new SenderComponent();
55         ActivationSpec as = new ActivationSpec(SenderComponent.ENDPOINT, sender);
56         as.setService(SenderComponent.SERVICE);
57         as.setDestinationService(getComponentService());
58         jbiContainer.activateComponent(as);
59     }
60
61     private void setUpReceiver() throws Exception JavaDoc {
62         receiver = new ReceiverComponent();
63         ActivationSpec as = new ActivationSpec(ReceiverComponent.ENDPOINT,
64                 receiver);
65         as.setService(ReceiverComponent.SERVICE);
66         jbiContainer.activateComponent(as);
67     }
68
69     private void setUpComponent() throws Exception JavaDoc {
70         fec = new SplitterComponent();
71         fec.setNodePath("");
72         ActivationSpec as = new ActivationSpec("component", fec);
73         as.setService(getComponentService());
74         as.setDestinationService(ReceiverComponent.SERVICE);
75         jbiContainer.activateComponent(as);
76     }
77
78     public void testForEach() throws Exception JavaDoc {
79         fec.setNodePath("ROOT/DOC[@att = 2]");
80         sender
81                 .setMessage("<ROOT><DOC att=\"1\"/><DOC att=\"2\"/><DOC att=\"2\"/></ROOT>");
82         sender.sendMessages(1);
83         Thread.sleep(1000);
84         assertEquals(2, receiver.getMessageList().getMessageCount());
85     }
86
87     protected void tearDown() throws Exception JavaDoc {
88         if (jbiContainer != null)
89             jbiContainer.shutDown();
90     }
91 }
92
Popular Tags