Statistics
| Revision:

root / org.gvsig.proj / branches / refactor2018 / org.gvsig.proj / org.gvsig.proj.catalog / org.gvsig.proj.catalog.api / src / test / java / org / gvsig / proj / catalog / CRSCatalogManagerIT.java @ 838

History | View | Annotate | Download (6.52 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2012 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.proj.catalog;
24

    
25
import java.util.List;
26

    
27
import org.gvsig.proj.catalog.exception.UnsupportedCoordinateReferenceSystemException;
28
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
29

    
30
import junit.framework.TestCase;
31

    
32
/**
33
 * {@link CRSCatalogManager} API acceptance tests.
34
 * 
35
 * @author gvSIG Team
36
 */
37
public abstract class CRSCatalogManagerIT extends TestCase {
38
    protected CRSCatalogManager manager;
39
    
40
        /**
41
         * @see TestCase#TestCase() 
42
         */
43
        public CRSCatalogManagerIT() {
44
                super();
45
        }
46

    
47
        /**
48
         * @see TestCase#TestCase(String) 
49
         */
50
        public CRSCatalogManagerIT(String name) {
51
                super(name);
52
        }
53
        
54
    
55
        protected final void setUp() throws Exception {
56
                DefaultLibrariesInitializer initializer = new DefaultLibrariesInitializer();
57
                initializer.initialize();
58
                doInitializeLibraries();
59
                initializer.postInitialize();
60
                doSetUp();
61
        }
62

    
63
        protected void doInitializeLibraries() {
64
                
65
        }
66
        
67
    protected void doSetUp() throws Exception {
68
        manager = createProjectionManager();
69
    }
70
    
71

    
72
    /**
73
     * Returns the WKT string to create the CRSs to test.
74
     * 
75
     * @return the authority name
76
     */
77
    protected abstract String getCoordinateReferenceSystemWKT();
78

    
79
    /**
80
     * Test method for
81
     * {@link org.gvsig.proj.CoordinateReferenceSystemManager#getCoordinateReferenceSystem(java.lang.String)}
82
     */
83
    public void testGetCoordinateReferenceSystemFromWKT() throws Exception {
84
        CRSDefinition crs =
85
            manager.parseCRSDefinition(getCoordinateReferenceSystemWKT());
86
        assertNotNull(crs);
87
    }
88
 
89
    /**
90
     * Returns the WKT string to create the CoordinateTransformation to test.
91
     * 
92
     * @return the authority name
93
     */
94
    protected abstract String getCoordinateTransformationWKT();
95
    
96
    protected abstract String getCoordinateTransformationSource();
97
    
98
    protected abstract String getCoordinateTransformationTarget();
99
    
100
    /**
101
     * Test method for
102
     * {@link org.gvsig.proj.CoordinateReferenceSystemManager#getCoordinateTransformation(java.lang.String)}
103
     */
104
    public void testGetTransformationFromWKT() throws Exception {
105
        TransformationDefinition ct =
106
            manager.parseTransformationDefinition(getCoordinateTransformationWKT(),
107
                            getCoordinateTransformationSource(),
108
                            getCoordinateTransformationTarget());
109
        assertNotNull(ct);
110
    }
111
    
112

    
113
    /**
114
     * Creates a {@link CoordinateReferenceSystemManager} instance.
115
     * 
116
     * @return the {@link CoordinateReferenceSystemManager} instance
117
     */
118
    protected abstract CRSCatalogManager createProjectionManager();
119

    
120
    /**
121
     * Returns the authority name to use to create the projections to test.
122
     * 
123
     * @return the authority name
124
     */
125
    protected abstract String getAuthorityName();
126

    
127
    /**
128
     * Returns the code to use to create the projections to test.
129
     * 
130
     * @return the code
131
     */
132
    protected abstract String getCode();
133
    
134
    /**
135
     * Returns the string to use to test search methods
136
     * 
137
     * @return the code
138
     */
139
    protected abstract String getSearchString();
140

    
141
    /**
142
     * Test method for
143
     * {@link org.gvsig.proj.catalogue.CRSCatalogManager#getAuthorityNames()}
144
     * .
145
     */
146
    public void testGetAuthorityNames() {
147
        List<String> names = manager.getAuthorityNames();
148
        assertTrue(names.contains("EPSG"));
149
        assertNotNull(names);
150
        assertTrue("Authority names list is empty", names.size() > 0);
151
        for (int i = 0; i < names.size(); i++) {
152
            if (!(names.get(i) instanceof String)) {
153
                fail("At least one authority name is not a String");
154
            }
155
        }
156
    }
157

    
158
    /**
159
     * Test method for
160
     * {@linkorg.gvsig.proj.catalogue.CRSCatalogManager#getCoordinateReferenceSystem(java.lang.String)}
161
     */
162
    public void testGetDefinition() throws Exception {
163
            String code = getCode();
164
        CRSDefinition crs =
165
            manager.getCRSDefinition(code);
166
        assertNotNull(crs);
167
        assertEquals(code, crs.getIdentifier());
168
        assertEquals(getAuthorityName(), crs.getAuthorityName());
169
        assertEquals(getCode(), crs.getIdentifier());
170
    }
171
    
172
    /**
173
     * Test method for
174
     * {@link org.gvsig.proj.catalogue.CRSCatalogManager#getCodes(java.lang.String)}
175
     * and check all existing definitions
176
     */
177
    public void testAllDefinitions() throws Exception {
178
        List<String> names = manager.getAuthorityNames();
179
        for (String name: names) {
180
            List<String> codes = manager.getCodes(name);
181
            for (String code: codes) {
182
                    checkDefinitionInstantiation(name, code);
183
            }
184
        }
185
    }
186
    
187
    /**
188
     * Test method for
189
     * {@link org.gvsig.proj.catalogue.CRSCatalogManager#getCodes(java.lang.String)}
190
     * .
191
     */
192
    protected void checkDefinitionInstantiation(String authorityName, String code) throws Exception{
193
            try {
194
                    
195
                    CRSDefinition crs =
196
                                    manager.getCRSDefinition(code);
197
                    assertNotNull(crs);
198
                    assertTrue(crs.getIdentifiers().contains(code));
199
                    //assertEquals(code, crs.getIdentifier());
200
                    assertEquals(authorityName, crs.getAuthorityName());
201
                    //assertEquals(getCode(), crs.getIdentifier());
202
            } catch(UnsupportedCoordinateReferenceSystemException ex) {
203
                    //System.out.println(identifier);
204
            }
205
    }
206

    
207
    /**
208
     * Test method for {@link CRSCatalogManager#search(String)}
209
     */
210
    public void testSearch() {
211
            String searchString = getSearchString();
212
            List<String> results = manager.search(searchString);
213
            assertTrue(results.size()>0);
214
            results = manager.search(getCode());
215
            assertTrue(results.size()>0);
216
    }
217
}