1 22 23 package org.objectweb.petals.tools.jbicommon.descriptor; 24 25 import java.io.File ; 26 import java.io.IOException ; 27 import java.lang.reflect.Method ; 28 import java.net.URI ; 29 import java.util.logging.Logger ; 30 31 import javax.xml.transform.TransformerException ; 32 33 import junit.framework.TestCase; 34 35 import org.easymock.classextension.EasyMock; 36 import org.objectweb.petals.tools.jbicommon.util.XMLUtil; 37 import org.w3c.dom.Document ; 38 import org.xml.sax.SAXException ; 39 40 46 public class JBIDescriptorBuilderTest extends TestCase { 48 private static final String TARGET = "target"; 49 50 private String baseDir; 51 52 public void setUp() { 53 baseDir = this.getClass().getResource(".").toString(); 54 baseDir = baseDir.substring(0, baseDir.indexOf(TARGET)); 55 baseDir = baseDir.substring(baseDir.indexOf(':') + 1); 56 } 57 58 81 112 public void testParseJbiXml() throws SecurityException , 113 NoSuchMethodException , SAXException , IOException { 114 File jbiFile = new File (baseDir + "src" + File.separator + "test-data" 115 + File.separator + "descriptors" + File.separator 116 + "emptyDescriptor.xml"); 117 118 JBIDescriptorBuilder builder = EasyMock.createMock( 119 JBIDescriptorBuilder.class, new Method [] { 120 JBIDescriptorBuilder.class.getDeclaredMethod( 121 "validateJbiXml", new Class [] { URI .class }), 122 JBIDescriptorBuilder.class.getDeclaredMethod( 123 "buildDescriptor", 124 new Class [] { Document .class }) }); 125 126 try { 127 assertNotNull(builder.parseJbiXml(jbiFile.toURI())); 128 } catch (JBIDescriptorException e) { 129 e.printStackTrace(); 130 } 131 } 132 133 public void testValidateJbiXml() throws SecurityException , 134 NoSuchMethodException , SAXException , IOException { 135 File jbiFile = new File (baseDir + "src" + File.separator + "test-data" 136 + File.separator + "descriptors" + File.separator 137 + "componentInstallationDescriptor.xml"); 138 139 JBIDescriptorBuilder builder = EasyMock.createMock( 140 JBIDescriptorBuilder.class, 141 new Method [] { JBIDescriptorBuilder.class.getDeclaredMethod( 142 "buildDescriptor", new Class [] { Document .class }) }); 143 Logger logger = EasyMock.createMock(Logger .class); 144 145 EasyMock.replay(logger); 146 147 builder.setLog(logger); 148 149 assertTrue(builder.validateJbiXml(jbiFile.toURI())); 150 } 151 152 public void testValidateJbiXmlException() throws SecurityException , 153 NoSuchMethodException , SAXException , IOException { 154 File jbiFile = new File (baseDir + "src" + File.separator + "test-data" 155 + File.separator + "descriptors" + File.separator 156 + "badDescriptor.xml"); 157 158 JBIDescriptorBuilder builder = EasyMock.createMock( 159 JBIDescriptorBuilder.class, 160 new Method [] { JBIDescriptorBuilder.class.getDeclaredMethod( 161 "buildDescriptor", new Class [] { Document .class }) }); 162 Logger logger = EasyMock.createMock(Logger .class); 163 164 builder.setLog(logger); 165 166 assertFalse(builder.validateJbiXml(jbiFile.toURI())); 167 } 168 169 public void testComponentDescriptorBuild() { 170 File jbiFile = new File (baseDir + "src" + File.separator + "test-data" 171 + File.separator + "descriptors" + File.separator 172 + "componentInstallationDescriptor.xml"); 173 Logger logger = EasyMock.createMock(Logger .class); 174 JBIDescriptorBuilder descriptorBuilder = new JBIDescriptorBuilder( 175 jbiFile.toURI(), logger); 176 177 try { 178 JBIDescriptor generatedDescriptor = descriptorBuilder.build(); 179 System.out.println("###### A Component Descriptor"); 180 System.out.println(generatedDescriptor); 181 System.out.println(generatedDescriptor.getComponent() 182 .getExtensions()); 183 System.out.println(generatedDescriptor.getComponent() 184 .getIdentification().getExtensions()); 185 System.out.println(XMLUtil 186 .createStringFromDOMDocument(generatedDescriptor 187 .getComponent().getExtensions() 188 .getDocumentFragment())); 189 } catch (JBIDescriptorException e) { 190 e.printStackTrace(); 191 } catch (TransformerException e) { 192 e.printStackTrace(); 193 } 194 195 } 196 197 public void testSharedLibDescriptorBuild() { 198 File jbiFile = new File (baseDir + "src" + File.separator + "test-data" 199 + File.separator + "descriptors" + File.separator 200 + "sharedLibraryInstallationDescriptor.xml"); 201 Logger logger = EasyMock.createMock(Logger .class); 202 JBIDescriptorBuilder descriptorBuilder = new JBIDescriptorBuilder( 203 jbiFile.toURI(), logger); 204 205 try { 206 JBIDescriptor generatedDescriptor = descriptorBuilder.build(); 207 System.out.println("###### A Shared Lib Descriptor"); 208 System.out.println(generatedDescriptor); 209 System.out.println(generatedDescriptor.getSharedLibrary() 210 .getIdentification().getExtensions()); 211 } catch (JBIDescriptorException e) { 212 e.printStackTrace(); 213 } 214 215 } 216 217 public void testServiceAssemblyDescriptorBuild() { 218 File jbiFile = new File (baseDir + "src" + File.separator + "test-data" 219 + File.separator + "descriptors" + File.separator 220 + "serviceAssemblyDescriptor.xml"); 221 Logger logger = EasyMock.createMock(Logger .class); 222 JBIDescriptorBuilder descriptorBuilder = new JBIDescriptorBuilder( 223 jbiFile.toURI(), logger); 224 225 try { 226 JBIDescriptor generatedDescriptor = descriptorBuilder.build(); 227 System.out.println("###### A Service Assembly Descriptor"); 228 System.out.println(generatedDescriptor); 229 System.out.println(generatedDescriptor.getServiceAssembly() 230 .getExtensions()); 231 System.out.println(generatedDescriptor.getServiceAssembly() 232 .getServiceUnits().get(1).getExtensions()); 233 System.out.println(generatedDescriptor.getServiceAssembly() 234 .getIdentification().getExtensions()); 235 } catch (JBIDescriptorException e) { 236 e.printStackTrace(); 237 } 238 } 239 240 public void testServicesDescriptorBuild() { 241 File jbiFile = new File (baseDir + "src" + File.separator + "test-data" 242 + File.separator + "descriptors" + File.separator 243 + "servicesDescriptor.xml"); 244 Logger logger = EasyMock.createMock(Logger .class); 245 JBIDescriptorBuilder descriptorBuilder = new JBIDescriptorBuilder( 246 jbiFile.toURI(), logger); 247 248 try { 249 JBIDescriptor generatedDescriptor = descriptorBuilder.build(); 250 System.out.println("###### A Services Descriptor"); 251 System.out.println(generatedDescriptor); 252 System.out.println(generatedDescriptor.getServices().getConsumes() 253 .get(0).getExtensions()); 254 System.out.println(generatedDescriptor.getServices().getProvides() 255 .get(0).getExtensions()); 256 } catch (JBIDescriptorException e) { 257 e.printStackTrace(); 258 } 259 } 260 } 261 | Popular Tags |