svn-gvsig-desktop / tags / v1_0_2_Build_899 / libraries / libIverUtiles / src-test / com / iver / utiles / extensionPoints / TestExtensionPoints.java @ 10517
History | View | Annotate | Download (4.34 KB)
1 | 4320 | jjdelcerro | package com.iver.utiles.extensionPoints; |
---|---|---|---|
2 | |||
3 | 4689 | jjdelcerro | import java.util.Iterator; |
4 | |||
5 | 4320 | jjdelcerro | import junit.framework.TestCase; |
6 | |||
7 | public class TestExtensionPoints extends TestCase { |
||
8 | |||
9 | protected void setUp() throws Exception { |
||
10 | super.setUp();
|
||
11 | } |
||
12 | |||
13 | protected void tearDown() throws Exception { |
||
14 | super.tearDown();
|
||
15 | } |
||
16 | 4327 | jmvivo | |
17 | public void test() { |
||
18 | ExtensionPoints extensionPoints = new ExtensionPoints();
|
||
19 | |||
20 | extensionPoints.add("LayerWizars","WMS",UnaExtensionDePrueba1.class); |
||
21 | extensionPoints.add("LayerWizars","WCS",UnaExtensionDePrueba2.class); |
||
22 | extensionPoints.add("OtherWizars","uno",UnaExtensionDePrueba1.class); |
||
23 | extensionPoints.add("OtherWizars","dos",UnaExtensionDePrueba2.class); |
||
24 | |||
25 | 4689 | jjdelcerro | // Comprobamos que el orden de las extensiones es el que hemos fijado.
|
26 | ExtensionPoint x = (ExtensionPoint)extensionPoints.get("LayerWizars");
|
||
27 | Iterator i =x.keySet().iterator();
|
||
28 | String[] nombres = {"WMS", "WCS" }; |
||
29 | int n = 0; |
||
30 | while( i.hasNext() ) {
|
||
31 | String nombre = (String)i.next(); |
||
32 | assertTrue(nombres[n].equals(nombre)); |
||
33 | n++; |
||
34 | } |
||
35 | |||
36 | |||
37 | 4327 | jmvivo | ExtensionPoint extensionPointLayerWizars; |
38 | extensionPointLayerWizars = (ExtensionPoint)extensionPoints.get("LayerWizars");
|
||
39 | assertTrue(extensionPointLayerWizars.containsKey("WMS"));
|
||
40 | assertTrue(extensionPointLayerWizars.containsKey("WCS"));
|
||
41 | |||
42 | assertEquals(extensionPoints.size(),2);
|
||
43 | assertEquals(extensionPointLayerWizars.size(),2);
|
||
44 | |||
45 | ExtensionPoint extensionPointLayerWizars2 = new ExtensionPoint("LayerWizars"); |
||
46 | |||
47 | |||
48 | extensionPointLayerWizars2.put("File",UnaExtensionDePrueba3.class);
|
||
49 | extensionPointLayerWizars2.put("JDBC",UnaExtensionDePrueba4.class);
|
||
50 | |||
51 | extensionPoints.put("LayerWizars",extensionPointLayerWizars2);
|
||
52 | |||
53 | extensionPointLayerWizars = (ExtensionPoint)extensionPoints.get("LayerWizars");
|
||
54 | assertEquals(extensionPoints.size(),2);
|
||
55 | assertEquals(extensionPointLayerWizars.size(),4);
|
||
56 | assertEquals(((ExtensionPoint)extensionPoints.get("OtherWizars")).size(),2); |
||
57 | |||
58 | assertTrue(extensionPointLayerWizars.containsKey("WMS"));
|
||
59 | assertTrue(extensionPointLayerWizars.containsKey("WCS"));
|
||
60 | assertTrue(extensionPointLayerWizars.containsKey("File"));
|
||
61 | assertTrue(extensionPointLayerWizars.containsKey("JDBC"));
|
||
62 | |||
63 | assertEquals((extensionPointLayerWizars.get("JDBC")),UnaExtensionDePrueba4.class);
|
||
64 | assertEquals((extensionPointLayerWizars.get("WMS")),UnaExtensionDePrueba1.class);
|
||
65 | |||
66 | assertEquals(((ExtensionPoint)extensionPoints.get("OtherWizars")).get("uno"),UnaExtensionDePrueba1.class); |
||
67 | |||
68 | ExtensionPoint extensionPointOther2 = new ExtensionPoint("OtherWizars"); |
||
69 | extensionPointOther2.put("tres",UnaExtensionDePrueba3.class);
|
||
70 | extensionPointOther2.put("cuatro",UnaExtensionDePrueba4.class);
|
||
71 | |||
72 | extensionPoints.put(extensionPointOther2); |
||
73 | |||
74 | ExtensionPoint extensionPointOther = (ExtensionPoint)extensionPoints.get("OtherWizars");
|
||
75 | assertEquals(extensionPoints.size(),2);
|
||
76 | assertEquals(extensionPointLayerWizars.size(),4);
|
||
77 | assertEquals(extensionPointOther.size(),4);
|
||
78 | |||
79 | assertTrue(extensionPointOther.containsKey("uno"));
|
||
80 | assertTrue(extensionPointOther.containsKey("dos"));
|
||
81 | assertTrue(extensionPointOther.containsKey("tres"));
|
||
82 | assertTrue(extensionPointOther.containsKey("cuatro"));
|
||
83 | |||
84 | assertEquals((extensionPointOther.get("tres")),UnaExtensionDePrueba3.class);
|
||
85 | assertEquals((extensionPointOther.get("dos")),UnaExtensionDePrueba2.class);
|
||
86 | |||
87 | assertEquals(extensionPoints.get("Ninguno"),null); |
||
88 | } |
||
89 | 4320 | jjdelcerro | |
90 | 4642 | jjdelcerro | public void testSingleton() { |
91 | ExtensionPoints extensionPoints1 = ExtensionPointsSingleton.getInstance(); |
||
92 | |||
93 | extensionPoints1.add("LayerWizars","WMS",UnaExtensionDePrueba1.class); |
||
94 | extensionPoints1.add("LayerWizars","WCS",UnaExtensionDePrueba2.class); |
||
95 | extensionPoints1.add("OtherWizars","uno",UnaExtensionDePrueba1.class); |
||
96 | extensionPoints1.add("OtherWizars","dos",UnaExtensionDePrueba2.class); |
||
97 | |||
98 | ExtensionPoints extensionPoints2 = ExtensionPointsSingleton.getInstance(); |
||
99 | assertEquals(extensionPoints2.size(),2);
|
||
100 | |||
101 | ExtensionPoint extensionPointLayerWizars; |
||
102 | extensionPointLayerWizars = (ExtensionPoint)extensionPoints2.get("LayerWizars");
|
||
103 | assertTrue(extensionPointLayerWizars.containsKey("WMS"));
|
||
104 | assertTrue(extensionPointLayerWizars.containsKey("WCS"));
|
||
105 | } |
||
106 | 4320 | jjdelcerro | } |
107 | 4327 | jmvivo | |
108 | class UnaExtensionDePrueba1 { |
||
109 | public UnaExtensionDePrueba1() {
|
||
110 | ; |
||
111 | } |
||
112 | } |
||
113 | class UnaExtensionDePrueba2 { |
||
114 | public UnaExtensionDePrueba2() {
|
||
115 | } |
||
116 | } |
||
117 | |||
118 | class UnaExtensionDePrueba3 { |
||
119 | public UnaExtensionDePrueba3() {
|
||
120 | } |
||
121 | } |
||
122 | |||
123 | class UnaExtensionDePrueba4 { |
||
124 | public UnaExtensionDePrueba4() {
|
||
125 | } |
||
126 | } |