root / branches / v2_0_0_prep / libraries / libTools / src-test / org / gvsig / tools / extensionPoint / TestExtensionPoint.java @ 23154
History | View | Annotate | Download (6.37 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Gobernment (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
*/
|
26 |
package org.gvsig.tools.extensionPoint; |
27 |
|
28 |
import java.lang.reflect.InvocationTargetException; |
29 |
import java.util.Iterator; |
30 |
|
31 |
import junit.framework.TestCase; |
32 |
|
33 |
public class TestExtensionPoint extends TestCase { |
34 |
|
35 |
|
36 |
protected void setUp() throws Exception { |
37 |
super.setUp();
|
38 |
} |
39 |
|
40 |
protected void tearDown() throws Exception { |
41 |
super.tearDown();
|
42 |
} |
43 |
|
44 |
public void testCreacion() { |
45 |
String name = "LayerWizars"; |
46 |
String description = "Punto de extension que registra los distintos Wizars para a?adir capas."; |
47 |
ExtensionPoint ep = null;
|
48 |
|
49 |
ep = new ExtensionPoint(name);
|
50 |
TestExtensionPoint.assertEquals(ep.getName(),name); |
51 |
TestExtensionPoint.assertEquals(ep.getDescription(),null);
|
52 |
ep.setDescripcion(description); |
53 |
TestExtensionPoint.assertEquals(ep.getDescription(),description); |
54 |
|
55 |
|
56 |
ep = new ExtensionPoint(name,description);
|
57 |
TestExtensionPoint.assertEquals(ep.getName(),name); |
58 |
TestExtensionPoint.assertEquals(ep.getDescription(),description); |
59 |
|
60 |
ep.put("WMSLayer",(Object)ExtensionDePrueba2.class); |
61 |
ep.put("WCSLayer",(Object)ExtensionDePrueba1.class); |
62 |
ep.put("WFSLayer",(Object)ExtensionDePrueba1.class); |
63 |
|
64 |
TestExtensionPoint.assertEquals(ep.size(),3);
|
65 |
|
66 |
// Comprobamos que la lista de extensiones
|
67 |
// mantiene el orden de insercion.
|
68 |
Iterator iter = ep.keySet().iterator();
|
69 |
TestExtensionPoint.assertEquals("WMSLayer",iter.next());
|
70 |
TestExtensionPoint.assertEquals("WCSLayer",iter.next());
|
71 |
TestExtensionPoint.assertEquals("WFSLayer",iter.next());
|
72 |
|
73 |
try {
|
74 |
/*Object extension =*/ ep.create("WCSLayer"); |
75 |
} catch (InstantiationException e) { |
76 |
TestExtensionPoint.fail("Ha petado la creacion de WCSLayer con InstantiationException");
|
77 |
} catch (IllegalAccessException e) { |
78 |
TestExtensionPoint.fail("Ha petado la creacion de WCSLayer con IllegalAccessException");
|
79 |
} |
80 |
|
81 |
ExtensionDePrueba2 extension = null;
|
82 |
try {
|
83 |
Object args[] = {"pepe",new Integer(5)}; |
84 |
extension =(ExtensionDePrueba2)ep.create("WMSLayer",args);
|
85 |
} catch (InstantiationException e) { |
86 |
TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con InstantiationException");
|
87 |
} catch (IllegalAccessException e) { |
88 |
TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con IllegalAccessException");
|
89 |
} catch (SecurityException e) { |
90 |
TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con SecurityException");
|
91 |
} catch (IllegalArgumentException e) { |
92 |
TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con IllegalArgumentException");
|
93 |
} catch (NoSuchMethodException e) { |
94 |
TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con NoSuchMethodException");
|
95 |
} catch (InvocationTargetException e) { |
96 |
TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con InvocationTargetException");
|
97 |
} |
98 |
|
99 |
TestExtensionPoint.assertEquals("pepe",extension.nombre);
|
100 |
TestExtensionPoint.assertEquals(5,extension.ancho);
|
101 |
|
102 |
} |
103 |
|
104 |
public void testInsert() { |
105 |
String name = "LayerWizars"; |
106 |
String description = "Punto de extension que registra los distintos Wizars para a?adir capas."; |
107 |
ExtensionPoint ep = null;
|
108 |
|
109 |
ep = new ExtensionPoint(name,description);
|
110 |
|
111 |
ep.put("WMSLayer",(Object)ExtensionDePrueba2.class); |
112 |
ep.put("WCSLayer",(Object)ExtensionDePrueba1.class); |
113 |
ep.put("WFSLayer",(Object)ExtensionDePrueba1.class); |
114 |
Iterator i=ep.keySet().iterator();
|
115 |
TestExtensionPoint.assertEquals("WMSLayer",(String)i.next()); |
116 |
TestExtensionPoint.assertEquals("WCSLayer",(String)i.next()); |
117 |
TestExtensionPoint.assertEquals("WFSLayer",(String)i.next()); |
118 |
|
119 |
ep.insert("WCSLayer","testA",null,(Object)ExtensionDePrueba1.class); |
120 |
|
121 |
i=ep.keySet().iterator(); |
122 |
TestExtensionPoint.assertEquals("WMSLayer",(String)i.next()); |
123 |
TestExtensionPoint.assertEquals("testA",(String)i.next()); |
124 |
TestExtensionPoint.assertEquals("WCSLayer",(String)i.next()); |
125 |
TestExtensionPoint.assertEquals("WFSLayer",(String)i.next()); |
126 |
|
127 |
ep.insert("XXXX","testB",null,(Object)ExtensionDePrueba1.class); |
128 |
i=ep.keySet().iterator(); |
129 |
TestExtensionPoint.assertEquals("WMSLayer",(String)i.next()); |
130 |
TestExtensionPoint.assertEquals("testA",(String)i.next()); |
131 |
TestExtensionPoint.assertEquals("WCSLayer",(String)i.next()); |
132 |
TestExtensionPoint.assertEquals("WFSLayer",(String)i.next()); |
133 |
TestExtensionPoint.assertEquals("testB",(String)i.next()); |
134 |
|
135 |
ep.insert("testB","testC",null,(Object)ExtensionDePrueba1.class); |
136 |
i=ep.keySet().iterator(); |
137 |
TestExtensionPoint.assertEquals("WMSLayer",(String)i.next()); |
138 |
TestExtensionPoint.assertEquals("testA",(String)i.next()); |
139 |
TestExtensionPoint.assertEquals("WCSLayer",(String)i.next()); |
140 |
TestExtensionPoint.assertEquals("WFSLayer",(String)i.next()); |
141 |
TestExtensionPoint.assertEquals("testC",(String)i.next()); |
142 |
TestExtensionPoint.assertEquals("testB",(String)i.next()); |
143 |
|
144 |
ep.insert("WMSLayer","testD",null,(Object)ExtensionDePrueba1.class); |
145 |
i=ep.keySet().iterator(); |
146 |
TestExtensionPoint.assertEquals("testD",(String)i.next()); |
147 |
TestExtensionPoint.assertEquals("WMSLayer",(String)i.next()); |
148 |
TestExtensionPoint.assertEquals("testA",(String)i.next()); |
149 |
TestExtensionPoint.assertEquals("WCSLayer",(String)i.next()); |
150 |
TestExtensionPoint.assertEquals("WFSLayer",(String)i.next()); |
151 |
TestExtensionPoint.assertEquals("testC",(String)i.next()); |
152 |
TestExtensionPoint.assertEquals("testB",(String)i.next()); |
153 |
} |
154 |
} |
155 |
|
156 |
class ExtensionDePrueba1 { |
157 |
public ExtensionDePrueba1() {
|
158 |
; |
159 |
} |
160 |
} |
161 |
class ExtensionDePrueba2 { |
162 |
public int ancho; |
163 |
public String nombre; |
164 |
|
165 |
public ExtensionDePrueba2(String nombre, Integer ancho) { |
166 |
this.ancho = ancho.intValue();
|
167 |
this.nombre = nombre;
|
168 |
} |
169 |
} |