Mercurial > lada > lada-server
comparison src/test/java/de/intevation/lada/importer/TestLAFImporter.java @ 311:eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
!! Currently the tests are ignored when running with maven.
!! Some system properties are still missing in maven (coming soon ;))
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 20 Aug 2013 16:19:20 +0200 |
parents | |
children | 79cbc672d8e4 |
comparison
equal
deleted
inserted
replaced
310:821557a17e5e | 311:eeb5d3a5e194 |
---|---|
1 package de.intevation.lada.importer; | |
2 | |
3 | |
4 import static org.junit.Assert.assertEquals; | |
5 import static org.junit.Assert.assertNotNull; | |
6 import static org.junit.Assert.fail; | |
7 | |
8 import java.io.IOException; | |
9 import java.nio.ByteBuffer; | |
10 import java.nio.charset.Charset; | |
11 import java.nio.file.Files; | |
12 import java.nio.file.Paths; | |
13 import java.util.List; | |
14 | |
15 import org.junit.Before; | |
16 import org.junit.Ignore; | |
17 import org.junit.Test; | |
18 | |
19 import de.intevation.lada.data.importer.EntryFormat; | |
20 import de.intevation.lada.data.importer.LAFFormat; | |
21 import de.intevation.lada.data.importer.LAFParser; | |
22 import de.intevation.lada.data.importer.LAFParserException; | |
23 | |
24 | |
25 public class TestLAFImporter | |
26 { | |
27 | |
28 private static final String PROBE_HEADER_FAIL = | |
29 "%OBE%\n"; | |
30 private String singleProbe; | |
31 private String incompleteProbe; | |
32 | |
33 @Before | |
34 @Ignore | |
35 public void loadLafFiles() { | |
36 String single = System.getProperty("de_intevation_lada_test_singleprobe"); | |
37 String incomplete = | |
38 System.getProperty("de_intevation_lada_test_incompleteprobe"); | |
39 try { | |
40 byte[] encodedSingle = Files.readAllBytes(Paths.get(single)); | |
41 byte[] encodedIncomplete = | |
42 Files.readAllBytes(Paths.get(incomplete)); | |
43 Charset encoding = Charset.defaultCharset(); | |
44 singleProbe = | |
45 encoding.decode(ByteBuffer.wrap(encodedSingle)).toString(); | |
46 incompleteProbe = | |
47 encoding.decode(ByteBuffer.wrap(encodedIncomplete)).toString(); | |
48 } | |
49 catch (IOException ioe) { | |
50 singleProbe = ""; | |
51 incompleteProbe = ""; | |
52 } | |
53 } | |
54 | |
55 @Test(expected = IOException.class) | |
56 @Ignore | |
57 public void testConfigFileNotFound() { | |
58 LAFFormat format = new LAFFormat(); | |
59 boolean success = format.readConfigFile("/file/not/found"); | |
60 } | |
61 | |
62 @Test | |
63 @Ignore | |
64 public void testConfigFileLoading() { | |
65 String fileName = System.getProperty("de_intevation_lada_import"); | |
66 LAFFormat format = new LAFFormat(); | |
67 boolean success = format.readConfigFile(fileName); | |
68 assertEquals(true, success); | |
69 List<EntryFormat> probeFormat = format.getFormat("probe"); | |
70 assertNotNull("No probe format available", probeFormat); | |
71 assertEquals( | |
72 "Not enough configuration elements for probe.", | |
73 32, | |
74 probeFormat.size()); | |
75 List<EntryFormat> messungFormat = format.getFormat("messung"); | |
76 assertNotNull("No messung format available", messungFormat); | |
77 assertEquals( | |
78 "Not enough configuration elements for messung.", | |
79 10, | |
80 messungFormat.size()); | |
81 List<EntryFormat> ortFormat = format.getFormat("ort"); | |
82 assertNotNull("No ort format available", ortFormat); | |
83 assertEquals( | |
84 "Not enough configuration elements for ort.", | |
85 20, | |
86 ortFormat.size()); | |
87 } | |
88 | |
89 @Test(expected = LAFParserException.class) | |
90 @Ignore | |
91 public void testProbeHeaderFail() { | |
92 LAFParser parser = new LAFParser(); | |
93 parser.setDryRun(true); | |
94 try { | |
95 parser.parse(PROBE_HEADER_FAIL); | |
96 } | |
97 catch (LAFParserException e) { | |
98 assertEquals( | |
99 "Exception cause not expected: " + e.getMessage(), | |
100 "No %PROBE% at the begining.", e.getMessage()); | |
101 } | |
102 } | |
103 | |
104 @Test | |
105 @Ignore | |
106 public void testIncompleteProbe() { | |
107 LAFParser parser = new LAFParser(); | |
108 parser.setDryRun(true); | |
109 try { | |
110 parser.parse(incompleteProbe); | |
111 } | |
112 catch (LAFParserException e) { | |
113 e.printStackTrace(); | |
114 } | |
115 } | |
116 | |
117 @Test | |
118 @Ignore | |
119 public void testCompleteParser() { | |
120 LAFParser parser = new LAFParser(); | |
121 //parser.setDryRun(true); | |
122 try { | |
123 parser.parse(singleProbe); | |
124 } | |
125 catch (LAFParserException e) { | |
126 e.printStackTrace(); | |
127 } | |
128 } | |
129 | |
130 @Test | |
131 @Ignore | |
132 public void testMessungParser() { | |
133 fail("Not yet implemented"); | |
134 } | |
135 | |
136 @Test | |
137 @Ignore | |
138 public void testOrtParser() { | |
139 fail("Not yet implemented"); | |
140 } | |
141 } |