Revision 167 org.gvsig.educa.thematicmap/trunk/org.gvsig.educa.thematicmap/org.gvsig.educa.thematicmap.lib/org.gvsig.educa.thematicmap.lib.impl/src/test/java/org/gvsig/educa/thematicmap/impl/DefaultThematicMapCompilationProcessTest.java
DefaultThematicMapCompilationProcessTest.java | ||
---|---|---|
23 | 23 |
|
24 | 24 |
import java.io.File; |
25 | 25 |
import java.net.URL; |
26 |
import java.util.List; |
|
26 | 27 |
|
27 | 28 |
import org.slf4j.Logger; |
28 | 29 |
import org.slf4j.LoggerFactory; |
29 | 30 |
|
30 | 31 |
import org.gvsig.educa.thematicmap.ThematicMapCompilationProcessTest; |
32 |
import org.gvsig.educa.thematicmap.compilation.ThematicMapCompilation; |
|
33 |
import org.gvsig.educa.thematicmap.compilation.ThematicMapCompiler; |
|
34 |
import org.gvsig.educa.thematicmap.compilation.ThematicMapCompilerStatus; |
|
35 |
import org.gvsig.educa.thematicmap.map.ThematicMap; |
|
36 |
import org.gvsig.fmap.crs.CRSFactory; |
|
37 |
import org.gvsig.fmap.dal.store.shp.SHPStoreParameters; |
|
38 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
39 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
40 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
41 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
31 | 42 |
|
32 | 43 |
/** |
33 | 44 |
* @author gvSIG Team |
... | ... | |
68 | 79 |
return LOG; |
69 | 80 |
} |
70 | 81 |
|
82 |
|
|
83 |
/** |
|
84 |
* <p> |
|
85 |
* Clone of {@link ThematicMapCompilationProcessTest#testSimpleThematicMapGeneration()} |
|
86 |
* but use 2 layer with the same SHP. |
|
87 |
* </p> |
|
88 |
* <p> |
|
89 |
* This checks that source files are copied into container once |
|
90 |
* </p> |
|
91 |
* <p> |
|
92 |
* see https://projects.gvsig.org/redmine/issues/369 |
|
93 |
* </p> |
|
94 |
* @throws Throwable |
|
95 |
*/ |
|
96 |
public void testThematicMapGenerationLayerFiles() throws Throwable { |
|
97 |
// Create compilation instance |
|
98 |
ThematicMapCompilation compilation = |
|
99 |
manager.createCompilationInstance(); |
|
100 |
|
|
101 |
assertNotNull("Can't get compilation instance from manager", |
|
102 |
compilation); |
|
103 |
|
|
104 |
// prepare information values |
|
105 |
final String ID = "S_".concat(testId); |
|
106 |
final String NAME = testId.concat(" Simple"); |
|
107 |
final String DESCRIPTION = "Description: ".concat(NAME); |
|
108 |
final int VERSION = 1; |
|
109 |
// TODO add more data |
|
110 |
|
|
111 |
// set information values |
|
112 |
compilation.getInformation().setId(ID); |
|
113 |
compilation.getInformation().setName(NAME); |
|
114 |
compilation.getInformation().setDescription(DESCRIPTION); |
|
115 |
compilation.getInformation().setVersion(VERSION); |
|
116 |
// TODO add more data |
|
117 |
|
|
118 |
// create MapContext |
|
119 |
MapContext mapContext = |
|
120 |
new MapContext(new ViewPort(CRSFactory.getCRS(DEFAULT_CRS))); |
|
121 |
SHPStoreParameters shpParam = |
|
122 |
(SHPStoreParameters) dataManager.createStoreParameters("Shape"); |
|
123 |
assertNotNull("Can't create 'Shape' Store parameters", shpParam); |
|
124 |
File shpFile = getShapeFileToUseInTest(); |
|
125 |
assertNotNull("Missing shp for test", shpFile); |
|
126 |
shpParam.setSHPFile(shpFile); |
|
127 |
shpParam.setCRS(DEFAULT_CRS); |
|
128 |
FLayer layer1 = mapContextManager.createLayer("test-layer", shpParam); |
|
129 |
assertNotNull( |
|
130 |
"Can't create layer for shape:".concat(getShapeFileToUseInTest() |
|
131 |
.getAbsolutePath()), layer1); |
|
132 |
FLayer layer2 = mapContextManager.createLayer("test-layer2", shpParam); |
|
133 |
|
|
134 |
mapContext.getLayers().addLayer(layer1); |
|
135 |
mapContext.getLayers().addLayer(layer2); |
|
136 |
compilation.setMapContext(mapContext); |
|
137 |
|
|
138 |
// Create compiler |
|
139 |
ThematicMapCompiler compiler = manager.createCompilerInstance(); |
|
140 |
compiler.setCompilerListener(new MyProcessListener(getLogger())); |
|
141 |
compiler.setWorkFolder(compilerWorkFolder.getAbsolutePath()); |
|
142 |
compiler.setTargetFolder(installFolder.getAbsolutePath()); |
|
143 |
|
|
144 |
// Run process |
|
145 |
ThematicMapCompilerStatus status = compiler.compile(compilation); |
|
146 |
if (getLogger().isDebugEnabled()) { |
|
147 |
getLogger() |
|
148 |
.debug( |
|
149 |
"Compilation result:\n\tStatus: {}\n\tMessage: '{}'\n\tException: {}", |
|
150 |
new Object[] { status.getStatus().name(), |
|
151 |
status.getFailMessage(), |
|
152 |
formatException(status.getException()) }); |
|
153 |
} |
|
154 |
// Check status |
|
155 |
assertTrue("Status != finish_ok", |
|
156 |
status.getStatus() == ThematicMapCompilerStatus.Status.finished_ok); |
|
157 |
assertEquals("Final percent != 100", 100, status.getCompleted()); |
|
158 |
assertNull("Final status error != null", status.getException()); |
|
159 |
assertNotNull("Missing generated file", |
|
160 |
status.getGeneratedThematicMapFile()); |
|
161 |
getLogger().debug("Generated file: '{}'", |
|
162 |
status.getGeneratedThematicMapFile()); |
|
163 |
|
|
164 |
// Check generated file and folder |
|
165 |
File resultFile = status.getGeneratedThematicMapFile(); |
|
166 |
File resultIntallFolder = |
|
167 |
status.getGeneratedInstalationThematicMapFolder(); |
|
168 |
assertNotNull("Final file null", resultFile); |
|
169 |
assertNotNull("Final installed folder null", resultIntallFolder); |
|
170 |
assertTrue("Final file not exists", resultFile.exists()); |
|
171 |
assertTrue("Final file not a file", resultFile.isFile()); |
|
172 |
assertTrue("Final file bad folder", resultFile.getParentFile() |
|
173 |
.getAbsolutePath().startsWith(installFolder.getAbsolutePath())); |
|
174 |
|
|
175 |
assertTrue("Final installed folder not exists", resultFile.exists()); |
|
176 |
assertTrue("Final installed folder not a folder", |
|
177 |
resultIntallFolder.isDirectory()); |
|
178 |
assertTrue( |
|
179 |
"Final installed folder bad folder", |
|
180 |
resultIntallFolder.getParentFile().getAbsolutePath() |
|
181 |
.startsWith(installFolder.getAbsolutePath())); |
|
182 |
|
|
183 |
// Check format |
|
184 |
assertTrue("Bad final folder", |
|
185 |
manager.isAThematicMapIntalledFolder(resultIntallFolder)); |
|
186 |
assertTrue("Bad final file format", manager.isMap(resultFile)); |
|
187 |
ThematicMap map = manager.getMapFromFile(resultFile); |
|
188 |
assertNotNull("Map not loaded from file", map); |
|
189 |
|
|
190 |
// Check information |
|
191 |
assertEquals("Map id not match", ID, map.getInformation().getId()); |
|
192 |
assertEquals("Map name not match", NAME, map.getInformation().getName()); |
|
193 |
assertEquals("Map description not match", DESCRIPTION, map |
|
194 |
.getInformation().getDescription()); |
|
195 |
assertEquals("Map version not match", DESCRIPTION, map.getInformation() |
|
196 |
.getDescription()); |
|
197 |
|
|
198 |
assertEquals("BuildNumber wrong", 1, map.getInformation() |
|
199 |
.getBuildNumber()); |
|
200 |
assertNotNull("Missing creation timestamp", map.getInformation() |
|
201 |
.getCreationTimestamp()); |
|
202 |
long timeDiff = |
|
203 |
System.currentTimeMillis() |
|
204 |
- map.getInformation().getCreationTimestamp().getTime(); |
|
205 |
assertTrue("Wrong creation timestamp ( > 20 sec or in future)", |
|
206 |
timeDiff < 20000 && timeDiff > 0); |
|
207 |
|
|
208 |
// Check for no-opened exception |
|
209 |
Throwable exception = null; |
|
210 |
try { |
|
211 |
map.getMapContext(); |
|
212 |
} catch (Throwable e) { |
|
213 |
exception = e; |
|
214 |
} |
|
215 |
assertNotNull("Missing opened check in map.getMapConext", exception); |
|
216 |
|
|
217 |
// Try to open |
|
218 |
map.open(); |
|
219 |
|
|
220 |
// Compare map context |
|
221 |
MapContext resultMapContext = map.getMapContext(); |
|
222 |
assertEquals("MapContext Layers count", mapContext.getLayers() |
|
223 |
.getLayersCount(), resultMapContext.getLayers().getLayersCount()); |
|
224 |
|
|
225 |
assertEquals("Layer name", |
|
226 |
mapContext.getLayers().getLayer(0).getName(), resultMapContext |
|
227 |
.getLayers().getLayer(0).getName()); |
|
228 |
assertEquals("Layer name", |
|
229 |
mapContext.getLayers().getLayer(1).getName(), resultMapContext |
|
230 |
.getLayers().getLayer(1).getName()); |
|
231 |
|
|
232 |
// Compare shp result file |
|
233 |
SHPStoreParameters resultShpParam = |
|
234 |
(SHPStoreParameters) ((FLyrVect) resultMapContext.getLayers() |
|
235 |
.getLayer(0)).getDataStore().getParameters(); |
|
236 |
|
|
237 |
// Compare shp result file |
|
238 |
SHPStoreParameters resultShpParam2 = |
|
239 |
(SHPStoreParameters) ((FLyrVect) resultMapContext.getLayers() |
|
240 |
.getLayer(1)).getDataStore().getParameters(); |
|
241 |
|
|
242 |
File resultShpFile = resultShpParam.getSHPFile(); |
|
243 |
// Check that ThM file is not the very same than source view |
|
244 |
assertFalse( |
|
245 |
"Target shp path == source shp path", |
|
246 |
resultShpFile.getAbsolutePath().equals( |
|
247 |
getShapeFileToUseInTest().getAbsolutePath())); |
|
248 |
|
|
249 |
assertTrue("result shape open in temporal folder", resultShpFile |
|
250 |
.getAbsolutePath().contains(temporalFolder.getAbsolutePath())); |
|
251 |
|
|
252 |
assertEquals(getShapeFileToUseInTest().length(), resultShpFile.length()); |
|
253 |
|
|
254 |
File resultShpFile2 = resultShpParam2.getSHPFile(); |
|
255 |
assertTrue( |
|
256 |
"The first and the second layer use the same file source", |
|
257 |
resultShpFile.getAbsolutePath().equals( |
|
258 |
resultShpFile2.getAbsolutePath())); |
|
259 |
|
|
260 |
assertTrue(resultFile.getName().startsWith(ID)); |
|
261 |
|
|
262 |
// check close |
|
263 |
map.close(); |
|
264 |
|
|
265 |
if (File.separatorChar == '/') { |
|
266 |
// Check it in unix-like systems only |
|
267 |
assertFalse("Not cleaned after close", resultShpFile.exists()); |
|
268 |
} |
|
269 |
|
|
270 |
// Check if manager gets map from installed folder |
|
271 |
List<ThematicMap> maps = manager.getInstalledMaps(); |
|
272 |
assertFalse("No maps installed", maps.isEmpty()); |
|
273 |
|
|
274 |
ThematicMap map1 = null; |
|
275 |
for (ThematicMap tmp : maps) { |
|
276 |
if (ID.equals(tmp.getInformation().getId())) { |
|
277 |
map1 = tmp; |
|
278 |
} |
|
279 |
} |
|
280 |
assertNotNull("Map not loaded as installed", map1); |
|
281 |
} |
|
282 |
|
|
71 | 283 |
} |
Also available in: Unified diff