KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > binding > xquarebc > XQuareBCTest


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 : $
20  * -------------------------------------------------------------------------
21  */

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

54 public class XQuareBCTest extends TestCase {
55
56     Logger JavaDoc logger;
57
58     @Override JavaDoc
59     public void setUp() throws Exception JavaDoc {
60         logger = EasyMock.createMock(Logger JavaDoc.class);
61     }
62
63     public void testGetExtensionMBeanName() {
64         // Run Test Case
65
XQuareBC xquareBC = new XQuareBC();
66         ObjectName JavaDoc objectName = xquareBC.getExtensionMBeanName();
67         assertNull(objectName);
68     }
69
70     public void testGetServiceDescription() {
71         // Create mock object and set suManager in a new method
72

73         // Create Mock Objects
74
PetalsServiceUnitManager suManager = createMock(PetalsServiceUnitManager.class);
75         MockXQuareBC xquareBC = new MockXQuareBC();
76
77         // Create test parameters
78
Document JavaDoc document = null;
79         ServiceEndpoint fooService = createMock(ServiceEndpoint.class);
80         // new InternalEndpoint(new QName(
81
// "fooService"), "fooServiceEndpoint", null, null, null);
82
ServiceEndpoint barService = createMock(ServiceEndpoint.class);
83         // new InternalEndpoint(new QName(
84
// "barService"), "barServiceEndpoint", null, null, null);
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         xquareBC.setServiceUnitManager(suManager);
100         // Run the test case 1
101
// Asking service description for foo service
102
Document JavaDoc doc = null;
103         doc = xquareBC.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 = xquareBC.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 = xquareBC.getServiceDescription(null);
116         assertNull("This service description should be null", doc);
117
118         verify(suManager);
119     }
120
121
122     public void testIsExchangeWithConsumerOkay() {
123         // Create Mock Objects
124
MessageExchange msgExchange = createMock(MessageExchange.class);
125
126         XQuareBC xquareBC = new XQuareBC();
127
128         // Create test parameters
129
ServiceEndpoint se = new MockServiceEndpoint();
130
131         // Run the Test
132
boolean result = xquareBC.isExchangeWithConsumerOkay(se,
133             msgExchange);
134         assertEquals(result, true);
135     }
136
137     public void testIsExchangeWithProviderOkay() {
138         // Create Mock Objects
139
MessageExchange msgExchange = createMock(MessageExchange.class);
140
141         XQuareBC xquareBC = new XQuareBC();
142
143         // Create test parameters
144
ServiceEndpoint se = new MockServiceEndpoint();
145
146         // Run the Test
147
boolean result = xquareBC.isExchangeWithProviderOkay(se,
148             msgExchange);
149         assertEquals(result, true);
150     }
151
152 }
Popular Tags