1 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 ; 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 ; 36 import javax.xml.parsers.DocumentBuilderFactory ; 37 import javax.xml.parsers.ParserConfigurationException ; 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 ; 48 49 50 57 public class CsvTest extends TestCase { 58 Logger logger; 59 60 61 @Override 62 public void setUp() throws Exception { 63 logger = EasyMock.createMock(Logger .class); 64 } 65 66 67 public void testGetExtensionMBeanName() { 68 Csv csv = new Csv(); 70 ObjectName objectName = csv.getExtensionMBeanName(); 71 assertNull(objectName); 72 } 73 74 75 public void testGetServiceDescription() { 76 PetalsServiceUnitManager suManager = createMock(PetalsServiceUnitManager.class); 78 MockCsv csv = new MockCsv(); 79 80 Document 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 e2) { 95 e2.printStackTrace(); 96 } 97 replay(suManager); 98 99 csv.setServiceUnitManager(suManager); 100 Document doc = null; 103 doc = csv.getServiceDescription(fooService); 104 assertEquals(document, doc); 105 106 doc = null; 109 doc = csv.getServiceDescription(barService); 110 assertNull("This service description should be null", doc); 111 112 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 Logger logger = Logger.getLogger("", null); 128 MockDeliveryChannel channel = new MockDeliveryChannel(); 129 130 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 try { 142 csv.init(componentContext); 143 } catch (JBIException e) { 144 145 } 146 verify(componentContext); 147 } 148 149 150 public void testIsExchangeWithConsumerOkay() { 151 MessageExchange msgExchange = createMock(MessageExchange.class); 153 154 Csv csv = new Csv(); 155 csv.logger=logger; 156 ServiceEndpoint se = new MockServiceEndpoint(); 158 159 boolean result = csv.isExchangeWithConsumerOkay(se, 161 msgExchange); 162 assertEquals(result, true); 163 } 164 165 166 public void testIsExchangeWithProviderOkay() { 167 MessageExchange msgExchange = createMock(MessageExchange.class); 169 170 Csv csv = new Csv(); 171 csv.logger=logger; 172 ServiceEndpoint se = new MockServiceEndpoint(); 174 175 boolean result = csv.isExchangeWithProviderOkay(se, 177 msgExchange); 178 assertEquals(result, false); 179 } 180 181 } 182 183 184 | Popular Tags |