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 | 23154 | cordinyana | /* 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 | 4320 | jjdelcerro | |
23 | 23154 | cordinyana | /*
|
24 | * AUTHORS (In addition to CIT):
|
||
25 | */
|
||
26 | package org.gvsig.tools.extensionPoint; |
||
27 | |||
28 | 4327 | jmvivo | import java.lang.reflect.InvocationTargetException; |
29 | 4323 | jjdelcerro | import java.util.Iterator; |
30 | |||
31 | 4320 | jjdelcerro | import junit.framework.TestCase; |
32 | |||
33 | public class TestExtensionPoint extends TestCase { |
||
34 | 4323 | jjdelcerro | |
35 | 4327 | jmvivo | |
36 | 4320 | jjdelcerro | protected void setUp() throws Exception { |
37 | super.setUp();
|
||
38 | } |
||
39 | |||
40 | protected void tearDown() throws Exception { |
||
41 | super.tearDown();
|
||
42 | } |
||
43 | |||
44 | 4323 | jjdelcerro | 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 | 4642 | jjdelcerro | TestExtensionPoint.assertEquals(ep.getName(),name); |
51 | TestExtensionPoint.assertEquals(ep.getDescription(),null);
|
||
52 | 4323 | jjdelcerro | ep.setDescripcion(description); |
53 | 4642 | jjdelcerro | TestExtensionPoint.assertEquals(ep.getDescription(),description); |
54 | 4323 | jjdelcerro | |
55 | |||
56 | ep = new ExtensionPoint(name,description);
|
||
57 | 4642 | jjdelcerro | TestExtensionPoint.assertEquals(ep.getName(),name); |
58 | TestExtensionPoint.assertEquals(ep.getDescription(),description); |
||
59 | 4323 | jjdelcerro | |
60 | ep.put("WMSLayer",(Object)ExtensionDePrueba2.class); |
||
61 | ep.put("WCSLayer",(Object)ExtensionDePrueba1.class); |
||
62 | ep.put("WFSLayer",(Object)ExtensionDePrueba1.class); |
||
63 | |||
64 | 4642 | jjdelcerro | TestExtensionPoint.assertEquals(ep.size(),3);
|
65 | 4323 | jjdelcerro | |
66 | // Comprobamos que la lista de extensiones
|
||
67 | // mantiene el orden de insercion.
|
||
68 | Iterator iter = ep.keySet().iterator();
|
||
69 | 4642 | jjdelcerro | TestExtensionPoint.assertEquals("WMSLayer",iter.next());
|
70 | TestExtensionPoint.assertEquals("WCSLayer",iter.next());
|
||
71 | TestExtensionPoint.assertEquals("WFSLayer",iter.next());
|
||
72 | 4323 | jjdelcerro | |
73 | try {
|
||
74 | 4642 | jjdelcerro | /*Object extension =*/ ep.create("WCSLayer"); |
75 | 4323 | jjdelcerro | } catch (InstantiationException e) { |
76 | 4642 | jjdelcerro | TestExtensionPoint.fail("Ha petado la creacion de WCSLayer con InstantiationException");
|
77 | 4323 | jjdelcerro | } catch (IllegalAccessException e) { |
78 | 4642 | jjdelcerro | TestExtensionPoint.fail("Ha petado la creacion de WCSLayer con IllegalAccessException");
|
79 | 4323 | jjdelcerro | } |
80 | 4327 | jmvivo | |
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 | 4642 | jjdelcerro | TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con InstantiationException");
|
87 | 4327 | jmvivo | } catch (IllegalAccessException e) { |
88 | 4642 | jjdelcerro | TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con IllegalAccessException");
|
89 | 4327 | jmvivo | } catch (SecurityException e) { |
90 | 4642 | jjdelcerro | TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con SecurityException");
|
91 | 4327 | jmvivo | } catch (IllegalArgumentException e) { |
92 | 4642 | jjdelcerro | TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con IllegalArgumentException");
|
93 | 4327 | jmvivo | } catch (NoSuchMethodException e) { |
94 | 4642 | jjdelcerro | TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con NoSuchMethodException");
|
95 | 4327 | jmvivo | } catch (InvocationTargetException e) { |
96 | 4642 | jjdelcerro | TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con InvocationTargetException");
|
97 | 4327 | jmvivo | } |
98 | |||
99 | 4642 | jjdelcerro | TestExtensionPoint.assertEquals("pepe",extension.nombre);
|
100 | TestExtensionPoint.assertEquals(5,extension.ancho);
|
||
101 | 4327 | jmvivo | |
102 | 4323 | jjdelcerro | } |
103 | 10559 | cesar | |
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 | 4320 | jjdelcerro | } |
155 | 4327 | jmvivo | |
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 | } |