KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > deployment > DeploymentTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

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 JavaDoc;
30
31 import javax.xml.transform.dom.DOMSource JavaDoc;
32
33 import java.util.Arrays JavaDoc;
34
35 import junit.framework.TestCase;
36
37 /**
38  * @version $Revision: 426415 $
39  */

40 public class DeploymentTest extends TestCase {
41
42     protected AbstractXmlApplicationContext context;
43     protected SourceTransformer transformer = new SourceTransformer();
44
45     public void testParse() throws Exception JavaDoc {
46
47         // lets force the JBI container to be constructed first
48
Descriptor root = (Descriptor) context.getBean("jbi");
49         assertNotNull("JBI Container not found in spring!", root);
50
51         // component stuff
52
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 JavaDoc[] {"Engine1.jar"}), component.getComponentClassPath());
57         assertEquals("getBootstrapClassPath", new ClassPath(new String JavaDoc[] {"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 JavaDoc 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 JavaDoc(fragment)));
76     }
77
78     protected void assertArrayEquals(String JavaDoc text, Object JavaDoc[] expected, Object JavaDoc[] actual) {
79         assertTrue(text + ". Expected <" + toString(expected) + "> Actual <" + toString(actual) + ">", Arrays.equals(expected, actual));
80     }
81
82     protected String JavaDoc toString(Object JavaDoc[] objects) {
83         if (objects == null) {
84             return "null Object[]";
85         }
86         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("[");
87         for (int i = 0; i < objects.length; i++) {
88             Object JavaDoc 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 JavaDoc {
99         context = createBeanFactory();
100     }
101
102     protected AbstractXmlApplicationContext createBeanFactory() throws Exception JavaDoc {
103         return new DebugClassPathXmlApplicationContext("org/apache/servicemix/jbi/deployment/example.xml",
104                                                        Arrays.asList(new Object JavaDoc[] { new XBeanProcessor() }));
105     }
106
107 }
108
Popular Tags