KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > project > libraries > LibraryTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.project.libraries;
21
22 import java.net.URL JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25 import org.netbeans.api.project.TestUtil;
26 import org.netbeans.junit.NbTestCase;
27 import org.netbeans.spi.project.libraries.LibraryImplementation;
28 import org.netbeans.spi.project.libraries.LibraryProvider;
29 import org.openide.util.lookup.Lookups;
30 /**
31  *
32  * @author Tomas Zezula
33  */

34 public class LibraryTest extends NbTestCase {
35
36     private LibraryManagerTest.TestLibraryProvider lp;
37
38     /** Creates a new instance of LibraryManagerTest */
39     public LibraryTest (String JavaDoc testName) {
40         super (testName);
41     }
42     
43     protected void setUp() throws Exception JavaDoc {
44         super.setUp();
45         lp = new LibraryManagerTest.TestLibraryProvider ();
46         TestUtil.setLookup (Lookups.fixed(new Object JavaDoc[] {lp}));
47     }
48     
49     public void testGetLibraries () throws Exception JavaDoc {
50         LibraryManager lm = LibraryManager.getDefault();
51         Library[] libs = lm.getLibraries();
52         LibraryImplementation[] impls = LibraryManagerTest.createTestLibs ();
53         lp.setLibraries(impls);
54         libs = lm.getLibraries();
55         assertEquals ("Libraries count", 2, libs.length);
56         LibraryManagerTest.assertLibsEquals (libs, impls);
57         LibraryManagerTest.TestListener tl = new LibraryManagerTest.TestListener ();
58         libs[0].addPropertyChangeListener(tl);
59         impls[0].setName("NewLibrary1");
60         LibraryManagerTest.assertEventsEquals(tl.getEventNames(), new String JavaDoc[] {Library.PROP_NAME});
61         tl.reset();
62         LibraryManagerTest.assertLibsEquals (new Library[] {libs[0]}, new LibraryImplementation[] {impls[0]});
63         
64         impls[0].setDescription("NewLibrary1Description");
65         LibraryManagerTest.assertEventsEquals(tl.getEventNames(), new String JavaDoc[] {Library.PROP_DESCRIPTION});
66         tl.reset();
67         LibraryManagerTest.assertLibsEquals (new Library[] {libs[0]}, new LibraryImplementation[] {impls[0]});
68         List JavaDoc<URL JavaDoc> urls = new ArrayList JavaDoc<URL JavaDoc>();
69         urls.add (new URL JavaDoc ("file:/lib/libnew1.so"));
70         urls.add (new URL JavaDoc ("file:/lib/libnew2.so"));
71         impls[0].setContent ("bin",urls);
72         LibraryManagerTest.assertEventsEquals(tl.getEventNames(), new String JavaDoc[] {Library.PROP_CONTENT});
73         tl.reset();
74         LibraryManagerTest.assertLibsEquals (new Library[] {libs[0]}, new LibraryImplementation[] {impls[0]});
75         urls = new ArrayList JavaDoc<URL JavaDoc>();
76         urls.add (new URL JavaDoc ("file:/src/new/src/"));
77         impls[0].setContent ("src",urls);
78         LibraryManagerTest.assertEventsEquals(tl.getEventNames(), new String JavaDoc[] {Library.PROP_CONTENT});
79         tl.reset();
80         LibraryManagerTest.assertLibsEquals (new Library[] {libs[0]}, new LibraryImplementation[] {impls[0]});
81     }
82     
83 }
84
Popular Tags