1 17 package org.apache.servicemix.jbi.deployment; 18 19 import org.apache.servicemix.jbi.config.DebugClassPathXmlApplicationContext; 20 import org.apache.servicemix.jbi.config.spring.XBeanProcessor; 21 import org.apache.servicemix.jbi.deployment.ClassPath; 22 import org.apache.servicemix.jbi.deployment.Component; 23 import org.apache.servicemix.jbi.deployment.Descriptor; 24 import org.apache.servicemix.jbi.deployment.Identification; 25 import org.apache.servicemix.jbi.deployment.InstallationDescriptorExtension; 26 import org.apache.servicemix.jbi.deployment.SharedLibraryList; 27 import org.apache.servicemix.jbi.jaxp.SourceTransformer; 28 import org.springframework.context.support.AbstractXmlApplicationContext; 29 import org.w3c.dom.DocumentFragment ; 30 31 import javax.xml.transform.dom.DOMSource ; 32 33 import java.util.Arrays ; 34 35 import junit.framework.TestCase; 36 37 40 public class DeploymentTest extends TestCase { 41 42 protected AbstractXmlApplicationContext context; 43 protected SourceTransformer transformer = new SourceTransformer(); 44 45 public void testParse() throws Exception { 46 47 Descriptor root = (Descriptor) context.getBean("jbi"); 49 assertNotNull("JBI Container not found in spring!", root); 50 51 Component component = root.getComponent(); 53 assertNotNull("component is null", component); 54 assertEquals("getBootstrapClassName", "com.foo.Engine1Bootstrap", component.getBootstrapClassName()); 55 assertEquals("getComponentClassName", "com.foo.Engine1", component.getComponentClassName()); 56 assertEquals("getComponentClassPath", new ClassPath(new String [] {"Engine1.jar"}), component.getComponentClassPath()); 57 assertEquals("getBootstrapClassPath", new ClassPath(new String [] {"Engine2.jar"}), component.getBootstrapClassPath()); 58 59 assertEquals("getDescription", "foo", component.getDescription()); 60 61 assertArrayEquals("getSharedLibraries", new SharedLibraryList[] {new SharedLibraryList("slib1")}, component.getSharedLibraries()); 62 63 Identification identification = component.getIdentification(); 64 assertNotNull("identification is null", identification); 65 assertEquals("getName", "example-engine-1", identification.getName()); 66 assertEquals("getDescription", "An example service engine", identification.getDescription()); 67 68 InstallationDescriptorExtension descriptorExtension = component.getDescriptorExtension(); 69 assertNotNull("descriptorExtension is null", descriptorExtension); 70 71 DocumentFragment fragment = descriptorExtension.getDescriptorExtension(); 72 assertNotNull("fragment is null", fragment); 73 74 System.out.println("Created document fragment: " + fragment); 75 System.out.println("XML: " + transformer.toString(new DOMSource (fragment))); 76 } 77 78 protected void assertArrayEquals(String text, Object [] expected, Object [] actual) { 79 assertTrue(text + ". Expected <" + toString(expected) + "> Actual <" + toString(actual) + ">", Arrays.equals(expected, actual)); 80 } 81 82 protected String toString(Object [] objects) { 83 if (objects == null) { 84 return "null Object[]"; 85 } 86 StringBuffer buffer = new StringBuffer ("["); 87 for (int i = 0; i < objects.length; i++) { 88 Object object = objects[i]; 89 if (i > 0) { 90 buffer.append(", "); 91 } 92 buffer.append(object); 93 } 94 buffer.append("]"); 95 return buffer.toString(); 96 } 97 98 protected void setUp() throws Exception { 99 context = createBeanFactory(); 100 } 101 102 protected AbstractXmlApplicationContext createBeanFactory() throws Exception { 103 return new DebugClassPathXmlApplicationContext("org/apache/servicemix/jbi/deployment/example.xml", 104 Arrays.asList(new Object [] { new XBeanProcessor() })); 105 } 106 107 } 108 | Popular Tags |