1 22 package org.objectweb.petals.binding.xquarebc; 23 24 import java.util.logging.Logger ; 25 26 import javax.jbi.messaging.MessageExchange; 27 import javax.jbi.servicedesc.ServiceEndpoint; 28 import javax.management.ObjectName ; 29 import javax.xml.parsers.DocumentBuilderFactory ; 30 import javax.xml.parsers.ParserConfigurationException ; 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 ; 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 54 public class XQuareBCTest extends TestCase { 55 56 Logger logger; 57 58 @Override 59 public void setUp() throws Exception { 60 logger = EasyMock.createMock(Logger .class); 61 } 62 63 public void testGetExtensionMBeanName() { 64 XQuareBC xquareBC = new XQuareBC(); 66 ObjectName objectName = xquareBC.getExtensionMBeanName(); 67 assertNull(objectName); 68 } 69 70 public void testGetServiceDescription() { 71 73 PetalsServiceUnitManager suManager = createMock(PetalsServiceUnitManager.class); 75 MockXQuareBC xquareBC = new MockXQuareBC(); 76 77 Document document = null; 79 ServiceEndpoint fooService = createMock(ServiceEndpoint.class); 80 ServiceEndpoint barService = createMock(ServiceEndpoint.class); 83 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 e2) { 95 e2.printStackTrace(); 96 } 97 replay(suManager); 98 99 xquareBC.setServiceUnitManager(suManager); 100 Document doc = null; 103 doc = xquareBC.getServiceDescription(fooService); 104 assertEquals(document, doc); 105 106 doc = null; 109 doc = xquareBC.getServiceDescription(barService); 110 assertNull("This service description should be null", doc); 111 112 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 MessageExchange msgExchange = createMock(MessageExchange.class); 125 126 XQuareBC xquareBC = new XQuareBC(); 127 128 ServiceEndpoint se = new MockServiceEndpoint(); 130 131 boolean result = xquareBC.isExchangeWithConsumerOkay(se, 133 msgExchange); 134 assertEquals(result, true); 135 } 136 137 public void testIsExchangeWithProviderOkay() { 138 MessageExchange msgExchange = createMock(MessageExchange.class); 140 141 XQuareBC xquareBC = new XQuareBC(); 142 143 ServiceEndpoint se = new MockServiceEndpoint(); 145 146 boolean result = xquareBC.isExchangeWithProviderOkay(se, 148 msgExchange); 149 assertEquals(result, true); 150 } 151 152 } | Popular Tags |