Skip to content

Commit 822f058

Browse files
author
Robin Duda
committed
Updated test cases for changes.
1 parent 8d2c4d8 commit 822f058

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

src/test/java/TestParser.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,51 @@
77
import org.junit.Test;
88
import org.junit.runner.RunWith;
99

10-
import java.io.IOException;
10+
import java.io.*;
1111
import java.nio.file.Files;
1212
import java.nio.file.Paths;
1313

14-
import static com.codingchili.Model.FileParser.ITEMS;
15-
1614
/**
1715
* @author Robin Duda
1816
*/
1917
@RunWith(VertxUnitRunner.class)
2018
public class TestParser {
21-
private static final int ROW_OFFSET = 5;
19+
public static final String TEST_XLSX_FILE = "src/test/java/test.xlsx";
20+
public static final String TEST_XLS_FILE = "src/test/java/test.xls";
21+
public static final String TEST_INVALID_FILE = "src/test/java/test_invalid.xlsx";
22+
public static final int ROW_OFFSET = 5;
2223
private static final String XLSX = ".xlsx";
2324

2425
@Test
2526
public void failParseInvalid() throws Exception {
2627
try {
27-
new FileParser(new byte[2048], 5, XLSX);
28+
new FileParser(new File(TEST_INVALID_FILE), 5, XLSX);
2829
throw new Exception("Should fail for invalid bytes.");
2930
} catch (ParserException ignored) {
3031
}
3132
}
3233

3334
@Test
3435
public void testParseOOXML(TestContext context) throws IOException, ParserException {
35-
testParseFile(context, "src/test/java/test.xlsx");
36+
testParseFile(context, TEST_XLSX_FILE);
3637
}
3738

3839
@Test
3940
public void testParse2007(TestContext context) throws IOException, ParserException {
40-
testParseFile(context, "src/test/java/test.xls");
41+
testParseFile(context, TEST_XLS_FILE);
4142
}
4243

4344
private void testParseFile(TestContext context, String fileName) throws IOException, ParserException {
44-
FileParser parser = new FileParser(Files.readAllBytes(Paths.get(fileName)), ROW_OFFSET, fileName);
45-
JsonArray list = parser.toImportable("index", "mapping", false).getJsonArray(ITEMS);
45+
FileParser parser = new FileParser(
46+
Paths.get(fileName).toFile(),
47+
ROW_OFFSET,
48+
fileName
49+
);
50+
51+
parser.assertFileParsable();
52+
53+
JsonArray list = new JsonArray();
54+
parser.parseRowRange(0, parser.getNumberOfElements(), list::add);
4655

4756
context.assertEquals(2, list.size());
4857

src/test/java/TestWriter.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import com.codingchili.Model.Configuration;
2-
import com.codingchili.Model.ElasticWriter;
1+
import com.codingchili.Model.*;
32
import io.vertx.core.Vertx;
43
import io.vertx.core.json.JsonArray;
54
import io.vertx.core.json.JsonObject;
@@ -13,6 +12,11 @@
1312
import org.junit.Test;
1413
import org.junit.runner.RunWith;
1514

15+
import java.io.ByteArrayInputStream;
16+
import java.io.IOException;
17+
import java.nio.file.Files;
18+
import java.nio.file.Paths;
19+
1620
/**
1721
* @author Robin Duda
1822
*/
@@ -23,6 +27,7 @@ public class TestWriter {
2327
@Before
2428
public void setUp(TestContext context) {
2529
vertx = Vertx.vertx();
30+
ImportEventCodec.registerOn(vertx);
2631
vertx.deployVerticle(new ElasticWriter(), context.asyncAssertSuccess());
2732
}
2833

@@ -35,7 +40,7 @@ public void tearDown(TestContext context) {
3540
}
3641

3742
@Test
38-
public void shouldWriteToElasticPort(TestContext context) {
43+
public void shouldWriteToElasticPort(TestContext context) throws IOException {
3944
Async async = context.async();
4045

4146
vertx.createHttpServer().requestHandler(request -> {
@@ -46,10 +51,16 @@ public void shouldWriteToElasticPort(TestContext context) {
4651
});
4752
}).listen(Configuration.getElasticPort());
4853

49-
vertx.eventBus().send(Configuration.INDEXING_ELASTICSEARCH, new JsonObject()
50-
.put("items", new JsonArray().add(new JsonObject().put("test", true)))
51-
.put("index", "test-index")
52-
.put("clear", false));
54+
FileParser fileParser = new FileParser(
55+
Paths.get(TestParser.TEST_XLS_FILE).toFile(),
56+
TestParser.ROW_OFFSET,
57+
"testFileName.xls");
58+
59+
vertx.eventBus().send(Configuration.INDEXING_ELASTICSEARCH, new ImportEvent()
60+
.setParser(fileParser)
61+
.setIndex("text-index")
62+
.setClearExisting(false)
63+
.setMapping("test-mapping"));
5364
}
5465

5566
}

src/test/java/invalid.xlsx

Whitespace-only changes.

0 commit comments

Comments
 (0)