KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > convertor > ConvertorsTest


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.convertor;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.io.FileReader JavaDoc;
25 import java.io.Reader JavaDoc;
26 import java.io.StringReader JavaDoc;
27 import java.io.StringWriter JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Set JavaDoc;
30 import java.util.Collection JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import javax.swing.JLabel JavaDoc;
33 import org.netbeans.junit.*;
34 import junit.textui.TestRunner;
35 import org.netbeans.spi.convertor.Convertor;
36 import org.openide.filesystems.Repository;
37 import org.openide.modules.ModuleInfo;
38 import org.openide.util.Lookup;
39
40
41 /**
42  *
43  * @author David Konecny
44  */

45 public class ConvertorsTest extends NbTestCase {
46     
47
48     public ConvertorsTest(String JavaDoc name) {
49         super (name);
50     }
51     
52     public static void main(String JavaDoc[] args) {
53         TestRunner.run(new NbTestSuite(ConvertorsTest.class));
54     }
55     
56     protected void setUp () throws Exception JavaDoc {
57         Lookup.getDefault().lookup(ModuleInfo.class);
58         Repository.getDefault ().getDefaultFileSystem ().getRoot ();
59     }
60     
61     public void testCanRead() throws Exception JavaDoc {
62         assertFalse(Convertors.canRead("http://www.dot.com/ns/smth", "tag"));
63     }
64     
65     public void testCanWrite() throws Exception JavaDoc {
66         assertFalse(Convertors.canWrite(new JLabel JavaDoc("aaa")));
67     }
68     
69     public void testListeners() throws Exception JavaDoc {
70         ModuleUtils.DEFAULT.install();
71         
72         Listener JavaDoc l = new Listener JavaDoc();
73         Convertors.getDefault().addPropertyChangeListener(l);
74         Collection JavaDoc col = Convertors.getDefault().getConvertorDescriptors();
75         int initialSize = col.size();
76         ModuleUtils.DEFAULT.enableBookModule(true);
77         col = Convertors.getDefault().getConvertorDescriptors();
78         assertTrue("Number of items in list of convertors does not much", col.size() == 1+initialSize);
79         assertTrue("Event not received", l.e.size() == 1);
80         assertTrue("Event name incorrect", ((PropertyChangeEvent JavaDoc)l.e.get(0)).getPropertyName().equals(Convertors.CONVERTOR_DESCRIPTORS));
81         assertTrue("Number of old events incorrect", ((Set JavaDoc)((PropertyChangeEvent JavaDoc)l.e.get(0)).getOldValue()).size() == 0+initialSize);
82         assertTrue("Number of new events incorrect", ((Set JavaDoc)((PropertyChangeEvent JavaDoc)l.e.get(0)).getNewValue()).size() == 1+initialSize);
83         assertEquals("Event has incorrect new value", col, ((PropertyChangeEvent JavaDoc)l.e.get(0)).getNewValue());
84         l.reset();
85     
86         ModuleUtils.DEFAULT.enableDVDConvertorModule(true);
87         col = Convertors.getDefault().getConvertorDescriptors();
88         assertTrue("Number of items in list of convertors does not much", col.size() == 2+initialSize);
89         assertTrue("Event not received", l.e.size() == 1);
90         assertTrue("Event name incorrect", ((PropertyChangeEvent JavaDoc)l.e.get(0)).getPropertyName().equals(Convertors.CONVERTOR_DESCRIPTORS));
91         assertTrue("Number of old events incorrect", ((Set JavaDoc)((PropertyChangeEvent JavaDoc)l.e.get(0)).getOldValue()).size() == 1+initialSize);
92         assertTrue("Number of new events incorrect", ((Set JavaDoc)((PropertyChangeEvent JavaDoc)l.e.get(0)).getNewValue()).size() == 2+initialSize);
93         assertEquals("Event has incorrect new value", col, ((PropertyChangeEvent JavaDoc)l.e.get(0)).getNewValue());
94         l.reset();
95
96         ModuleUtils.DEFAULT.enableShoppingCartConvertorModule(true);
97         col = Convertors.getDefault().getConvertorDescriptors();
98         assertTrue("Number of items in list of convertors does not much", col.size() == 3+initialSize);
99         assertTrue("Event not received", l.e.size() == 1);
100         assertTrue("Event name incorrect", ((PropertyChangeEvent JavaDoc)l.e.get(0)).getPropertyName().equals(Convertors.CONVERTOR_DESCRIPTORS));
101         assertTrue("Number of old events incorrect", ((Set JavaDoc)((PropertyChangeEvent JavaDoc)l.e.get(0)).getOldValue()).size() == 2+initialSize);
102         assertTrue("Number of new events incorrect", ((Set JavaDoc)((PropertyChangeEvent JavaDoc)l.e.get(0)).getNewValue()).size() == 3+initialSize);
103         assertEquals("Event has incorrect new value", col, ((PropertyChangeEvent JavaDoc)l.e.get(0)).getNewValue());
104         l.reset();
105         
106         ModuleUtils.DEFAULT.enableShoppingCartConvertorModule(false);
107         col = Convertors.getDefault().getConvertorDescriptors();
108         assertTrue("Number of items in list of convertors does not much", col.size() == 2+initialSize);
109         assertTrue("Event not received", l.e.size() == 1);
110         assertTrue("Event name incorrect", ((PropertyChangeEvent JavaDoc)l.e.get(0)).getPropertyName().equals(Convertors.CONVERTOR_DESCRIPTORS));
111         assertTrue("Number of old events incorrect", ((Set JavaDoc)((PropertyChangeEvent JavaDoc)l.e.get(0)).getOldValue()).size() == 3+initialSize);
112         assertTrue("Number of new events incorrect", ((Set JavaDoc)((PropertyChangeEvent JavaDoc)l.e.get(0)).getNewValue()).size() == 2+initialSize);
113         assertEquals("Event has incorrect new value", col, ((PropertyChangeEvent JavaDoc)l.e.get(0)).getNewValue());
114         l.reset();
115         
116         ModuleUtils.DEFAULT.enableDVDConvertorModule(false);
117         col = Convertors.getDefault().getConvertorDescriptors();
118         assertTrue("Number of items in list of convertors does not much", col.size() == 1+initialSize);
119         assertTrue("Event not received", l.e.size() == 1);
120         assertTrue("Event name incorrect", ((PropertyChangeEvent JavaDoc)l.e.get(0)).getPropertyName().equals(Convertors.CONVERTOR_DESCRIPTORS));
121         assertTrue("Number of old events incorrect", ((Set JavaDoc)((PropertyChangeEvent JavaDoc)l.e.get(0)).getOldValue()).size() == 2+initialSize);
122         assertTrue("Number of new events incorrect", ((Set JavaDoc)((PropertyChangeEvent JavaDoc)l.e.get(0)).getNewValue()).size() == 1+initialSize);
123         assertEquals("Event has incorrect new value", col, ((PropertyChangeEvent JavaDoc)l.e.get(0)).getNewValue());
124         l.reset();
125
126         ModuleUtils.DEFAULT.enableBookModule(false);
127         col = Convertors.getDefault().getConvertorDescriptors();
128         assertTrue("Number of items in list of convertors does not much", col.size() == 0+initialSize);
129         assertTrue("Event not received", l.e.size() == 1);
130         assertTrue("Event name incorrect", ((PropertyChangeEvent JavaDoc)l.e.get(0)).getPropertyName().equals(Convertors.CONVERTOR_DESCRIPTORS));
131         assertTrue("Number of old events incorrect", ((Set JavaDoc)((PropertyChangeEvent JavaDoc)l.e.get(0)).getOldValue()).size() == 1+initialSize);
132         assertTrue("Number of new events incorrect", ((Set JavaDoc)((PropertyChangeEvent JavaDoc)l.e.get(0)).getNewValue()).size() == 0+initialSize);
133         assertEquals("Event has incorrect new value", col, ((PropertyChangeEvent JavaDoc)l.e.get(0)).getNewValue());
134         l.reset();
135
136         ModuleUtils.DEFAULT.uninstall();
137         Convertors.getDefault().removePropertyChangeListener(l);
138     }
139     
140     private static class Listener implements PropertyChangeListener JavaDoc {
141
142         ArrayList JavaDoc e = new ArrayList JavaDoc();
143         
144         public Listener() {
145         }
146         
147         public void reset() {
148             e = new ArrayList JavaDoc();
149         }
150         
151         public void propertyChange(java.beans.PropertyChangeEvent JavaDoc evt) {
152             e.add(evt);
153         }
154         
155     }
156     
157 }
158
Popular Tags