KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > engine > csv > CsvTest


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: CsvTest.java 1089 2006-09-14 19:57:55Z dutoo $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.engine.csv;
23
24 import static org.easymock.EasyMock.expect;
25 import static org.easymock.classextension.EasyMock.createMock;
26 import static org.easymock.classextension.EasyMock.replay;
27 import static org.easymock.classextension.EasyMock.verify;
28
29 import java.util.logging.Logger JavaDoc;
30
31 import javax.jbi.JBIException;
32 import javax.jbi.component.ComponentContext;
33 import javax.jbi.messaging.MessageExchange;
34 import javax.jbi.servicedesc.ServiceEndpoint;
35 import javax.management.ObjectName JavaDoc;
36 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
37 import javax.xml.parsers.ParserConfigurationException JavaDoc;
38
39 import junit.framework.TestCase;
40
41 import org.easymock.classextension.EasyMock;
42 import org.objectweb.petals.component.common.serviceunitmanager.manager.PetalsServiceUnitManager;
43 import org.objectweb.petals.engine.csv.Csv;
44 import org.objectweb.petals.engine.csv.Mock.MockCsv;
45 import org.objectweb.petals.engine.csv.Mock.MockDeliveryChannel;
46 import org.objectweb.petals.engine.csv.Mock.MockServiceEndpoint;
47 import org.w3c.dom.Document JavaDoc;
48
49
50 /**
51  * Tests the Csv component
52  * @version $Rev: 1069 $Date: ${date}
53  * @since Petals 1.0
54  * @author Marc Dutoo - Open Wide
55  *
56  */

57 public class CsvTest extends TestCase {
58     Logger JavaDoc logger;
59
60     
61     @Override JavaDoc
62     public void setUp() throws Exception JavaDoc {
63         logger = EasyMock.createMock(Logger JavaDoc.class);
64     }
65
66     
67     public void testGetExtensionMBeanName() {
68         // Run Test Case
69
Csv csv = new Csv();
70         ObjectName JavaDoc objectName = csv.getExtensionMBeanName();
71         assertNull(objectName);
72     }
73
74     
75     public void testGetServiceDescription() {
76         // Create Mock Objects
77
PetalsServiceUnitManager suManager = createMock(PetalsServiceUnitManager.class);
78         MockCsv csv = new MockCsv();
79
80         // Create test parameters
81
Document JavaDoc document = null;
82         ServiceEndpoint fooService = createMock(ServiceEndpoint.class);
83         ServiceEndpoint barService = createMock(ServiceEndpoint.class);
84
85         try {
86             document = DocumentBuilderFactory.newInstance()
87             .newDocumentBuilder().newDocument();
88             expect(suManager.getServiceDescription(fooService)).andReturn(
89                 document).anyTimes();
90             expect(suManager.getServiceDescription(barService)).andReturn(null)
91             .anyTimes();
92             expect(suManager.getServiceDescription(null)).andReturn(null)
93             .anyTimes();
94         } catch (ParserConfigurationException JavaDoc e2) {
95             e2.printStackTrace();
96         }
97         replay(suManager);
98
99         csv.setServiceUnitManager(suManager);
100         // Run the test case 1
101
// Asking service description for foo service
102
Document JavaDoc doc = null;
103         doc = csv.getServiceDescription(fooService);
104         assertEquals(document, doc);
105
106         // Run the test case 2
107
// Asking service description for bar service
108
doc = null;
109         doc = csv.getServiceDescription(barService);
110         assertNull("This service description should be null", doc);
111
112         // Run the test case 3
113
// Asking service description for null service
114
doc = null;
115         doc = csv.getServiceDescription(null);
116         assertNull("This service description should be null", doc);
117
118         verify(suManager);
119     }
120
121     
122     public void testInit() {
123         Csv csv = new Csv();
124         ComponentContext componentContext = createMock(ComponentContext.class);
125
126         // Create test parameters
127
Logger JavaDoc logger = Logger.getLogger("", null);
128         MockDeliveryChannel channel = new MockDeliveryChannel();
129
130         // Init mocks
131
try {
132             expect(componentContext.getDeliveryChannel()).andReturn(channel);
133             expect(componentContext.getLogger("", null)).andReturn(logger);
134             expect(componentContext.getComponentName()).andReturn("");
135         } catch (JBIException e) {
136             e.printStackTrace();
137         }
138         replay(componentContext);
139
140         // Run the Test
141
try {
142             csv.init(componentContext);
143         } catch (JBIException e) {
144
145         }
146         verify(componentContext);
147     }
148
149     
150     public void testIsExchangeWithConsumerOkay() {
151         // Create Mock Objects
152
MessageExchange msgExchange = createMock(MessageExchange.class);
153
154         Csv csv = new Csv();
155         csv.logger=logger;
156         // Create test parameters
157
ServiceEndpoint se = new MockServiceEndpoint();
158
159         // Run the Test
160
boolean result = csv.isExchangeWithConsumerOkay(se,
161             msgExchange);
162         assertEquals(result, true);
163     }
164
165     
166     public void testIsExchangeWithProviderOkay() {
167         // Create Mock Objects
168
MessageExchange msgExchange = createMock(MessageExchange.class);
169
170         Csv csv = new Csv();
171         csv.logger=logger;
172         // Create test parameters
173
ServiceEndpoint se = new MockServiceEndpoint();
174
175         // Run the Test
176
boolean result = csv.isExchangeWithProviderOkay(se,
177             msgExchange);
178         assertEquals(result, false);
179     }
180
181 }
182
183
184
Popular Tags