KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > sca > AssemblyLoaderTest


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.sca;
18
19 import java.io.File JavaDoc;
20 import java.net.URL JavaDoc;
21 import java.net.URLClassLoader JavaDoc;
22
23 import junit.framework.Assert;
24 import junit.framework.TestCase;
25
26 import org.apache.servicemix.sca.assembly.JbiBinding;
27 import org.apache.servicemix.sca.tuscany.TuscanyRuntime;
28 import org.apache.tuscany.common.monitor.impl.NullMonitorFactory;
29 import org.apache.tuscany.model.assembly.Binding;
30 import org.apache.tuscany.model.assembly.Component;
31 import org.apache.tuscany.model.assembly.EntryPoint;
32 import org.apache.tuscany.model.assembly.ExternalService;
33 import org.apache.tuscany.model.assembly.Module;
34
35 /**
36  * @author delfinoj
37  */

38 public class AssemblyLoaderTest extends TestCase {
39
40     protected void setUp() throws Exception JavaDoc {
41         super.setUp();
42         Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
43     }
44
45     public void testLoader() throws Exception JavaDoc {
46         String JavaDoc name = "bigbank";
47         String JavaDoc uri = getClass().getResource("bigbank/sca.module").toString();
48         
49         URL JavaDoc url = getClass().getResource("bigbank/sca.module");
50         URL JavaDoc parentUrl = new File JavaDoc(url.toURI()).getParentFile().toURL();
51         ClassLoader JavaDoc cl = new URLClassLoader JavaDoc(new URL JavaDoc[] { parentUrl }, getClass().getClassLoader());
52         
53         TuscanyRuntime rt = new TuscanyRuntime(name, uri, cl, new NullMonitorFactory());
54         assertNotNull(rt);
55         
56         Module module = rt.getModuleComponent().getModuleImplementation();
57
58         Assert.assertTrue(module.getName().equals("org.apache.servicemix.sca.bigbank"));
59
60         Component component = module.getComponent("AccountServiceComponent");
61         Assert.assertTrue(component != null);
62
63         EntryPoint entryPoint = module.getEntryPoint("AccountService");
64         Assert.assertTrue(entryPoint != null);
65
66         ExternalService externalService = module.getExternalService("StockQuoteService");
67         Assert.assertTrue(externalService != null);
68
69         Binding binding = externalService.getBindings().get(0);
70         Assert.assertTrue(binding instanceof JbiBinding);
71     }
72 }
73
Popular Tags