KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > classloader > LoadersTest


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: LoadersTest.java 12:04:13 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.classloader;
23
24 import java.io.File JavaDoc;
25 import java.net.URL JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.List JavaDoc;
28
29 import junit.framework.TestCase;
30
31 /**
32  * Test the Loaders
33  *
34  * @author ddesjardins - eBMWebsourcing
35  */

36 public class LoadersTest extends TestCase {
37
38     private PetalsClassLoader petalsClassLoader;
39
40     public void setUp() throws Exception JavaDoc {
41         List JavaDoc<URL JavaDoc> baseUrls = new ArrayList JavaDoc<URL JavaDoc>();
42         List JavaDoc<String JavaDoc> classpathLocations = new ArrayList JavaDoc<String JavaDoc>();
43         String JavaDoc baseDir = this.getClass().getResource(".").toString();
44         baseDir = baseDir.substring(0, baseDir.indexOf("target"));
45         baseDir = baseDir.substring(baseDir.indexOf(":")+1);
46         baseUrls.add(new URL JavaDoc("file:" + baseDir.replace(File.separator, "/")));
47         baseUrls.add(new URL JavaDoc("file:" + baseDir.replace(File.separator, "/") + "target/test-classes/"));
48         baseUrls.add(new URL JavaDoc("file:" + baseDir.replace(File.separator, "/") + "target/"));
49         baseUrls.add(new URL JavaDoc("file:" + baseDir.replace(File.separator, "/") + "src/test-data/junit-3.8.jar"));
50         petalsClassLoader = new PetalsClassLoader(baseUrls.toArray(new URL JavaDoc[0]),
51                 classpathLocations);
52         petalsClassLoader.setParentFirst(false);
53     }
54
55     public void testPut() {
56         Loaders loaders = Loaders.getInstance();
57         loaders.put("test", petalsClassLoader);
58     }
59
60     public void testContains() {
61         Loaders loaders = Loaders.getInstance();
62         loaders.put("test", petalsClassLoader);
63         assertTrue(loaders.contains("test"));
64     }
65
66     public void testGet() {
67         Loaders loaders = Loaders.getInstance();
68         loaders.put("test", petalsClassLoader);
69         PetalsClassLoader classLoader = loaders.get("test");
70         assertEquals(classLoader, petalsClassLoader);
71     }
72
73     public void testGetSharedLibrariesClassLoader() {
74         Loaders loaders = Loaders.getInstance();
75         assertNotNull(loaders.getSharedLibrariesClassLoader());
76     }
77
78     public void testRemove() {
79         Loaders loaders = Loaders.getInstance();
80         loaders.remove("test");
81     }
82 }
83
Popular Tags