Skip to content

Commit 78c33a0

Browse files
committed
Updated test cases to use StreamValidator.
See issue #15.
1 parent 61b3225 commit 78c33a0

File tree

3 files changed

+76
-58
lines changed

3 files changed

+76
-58
lines changed

src/test/java/org/culturegraph/mf/stream/pipe/StreamBufferTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.culturegraph.mf.framework.StreamReceiver;
2222
import org.culturegraph.mf.stream.sink.EventList;
2323
import org.culturegraph.mf.stream.sink.StreamValidator;
24-
import org.junit.Ignore;
2524
import org.junit.Test;
2625

2726

src/test/java/org/culturegraph/mf/stream/pipe/StreamLoggerTest.java

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,52 @@
1515
*/
1616
package org.culturegraph.mf.stream.pipe;
1717

18-
import org.culturegraph.mf.stream.pipe.StreamLogger;
19-
import org.junit.Ignore;
20-
import org.junit.Test;
18+
import static org.junit.Assert.fail;
19+
20+
import org.culturegraph.mf.exceptions.FormatException;
21+
import org.culturegraph.mf.framework.StreamReceiver;
22+
import org.culturegraph.mf.stream.sink.EventList;
23+
import org.culturegraph.mf.stream.sink.StreamValidator;
24+
import org.junit.Test;
2125

2226

2327
/**
2428
* Tests if {@link StreamLogger} is correctly piping all events.
2529
*
26-
* @author Markus Michael Geipel
30+
* @author Markus Michael Geipel, Christoph Böhme
2731
*/
2832

2933
public final class StreamLoggerTest {
3034

3135
@Test
32-
@Ignore
3336
public void testCorrectPipeFunction() {
34-
// final ResourceOpener opener = new ResourceOpener();
35-
// final PicaDecoder picaDecoder = new PicaDecoder();
36-
// final StringWriter referenceWriter = new StringWriter();
37-
//
38-
// opener.setReceiver(new LineReader())
39-
// .setReceiver(picaDecoder)
40-
// .setReceiver(new StreamWriter(referenceWriter));
41-
//
42-
// opener.process(DataFilePath.PND_PICA);
43-
// opener.closeStream();
44-
//
45-
// final StringWriter finalWriter = new StringWriter();
46-
//
47-
// picaDecoder.setReceiver(new StreamLogger("test-logger"))
48-
// .setReceiver(new StreamWriter(finalWriter));
49-
//
50-
// opener.process(DataFilePath.PND_PICA);
51-
// opener.closeStream();
52-
//
53-
// Assert.assertEquals(referenceWriter.toString(), finalWriter.toString());
54-
//
55-
}
37+
final EventList list = new EventList();
38+
execTestEvents(list);
39+
40+
final StreamValidator validator = new StreamValidator(list.getEvents());
41+
final StreamLogger logger = new StreamLogger("test-logger");
42+
logger.setReceiver(validator);
43+
44+
try {
45+
execTestEvents(logger);
46+
logger.closeStream();
47+
} catch (FormatException e) {
48+
fail("Logger did not forward data as expected: " + e);
49+
}
50+
51+
}
52+
53+
private void execTestEvents(final StreamReceiver receiver) {
54+
receiver.startRecord("1");
55+
receiver.literal("l1", "value1");
56+
receiver.literal("l1", "value2");
57+
receiver.startEntity("e1");
58+
receiver.literal("l2", "value3");
59+
receiver.endEntity();
60+
receiver.endRecord();
61+
receiver.startRecord("2");
62+
receiver.literal("l3", "value4");
63+
receiver.endRecord();
64+
}
65+
5666
}

src/test/java/org/culturegraph/mf/stream/pipe/StreamTeeTest.java

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,53 @@
1515
*/
1616
package org.culturegraph.mf.stream.pipe;
1717

18-
import org.culturegraph.mf.framework.Tee;
19-
import org.junit.Ignore;
20-
import org.junit.Test;
18+
import static org.junit.Assert.fail;
19+
20+
import org.culturegraph.mf.exceptions.FormatException;
21+
import org.culturegraph.mf.framework.StreamReceiver;
22+
import org.culturegraph.mf.stream.sink.EventList;
23+
import org.culturegraph.mf.stream.sink.StreamValidator;
24+
import org.junit.Test;
2125

2226

2327
/**
24-
* Tests if {@link Tee} is correctly piping all events.
28+
* Tests if {@link StreamTee} is correctly piping all events.
2529
*
2630
* @author Markus Michael Geipel
2731
*
2832
*/
2933
public final class StreamTeeTest {
3034

3135
@Test
32-
@Ignore
33-
public void testCorrectTeeFunction() {
34-
// final ResourceOpener opener = new ResourceOpener();
35-
// final PicaDecoder picaDecoder = new PicaDecoder();
36-
//
37-
// final StringWriter referenceWriter = new StringWriter();
38-
//
39-
// opener.setReceiver(new LineReader())
40-
// .setReceiver(picaDecoder)
41-
// .setReceiver(new StreamWriter(referenceWriter));
42-
//
43-
// opener.process(DataFilePath.PND_PICA);
44-
// opener.closeStream();
45-
//
46-
// final StringWriter finalWriter1 = new StringWriter();
47-
// final StringWriter finalWriter2 = new StringWriter();
48-
//
49-
// picaDecoder.setReceiver(new StreamTee())
50-
// .setReceivers(new StreamWriter(finalWriter1), new StreamWriter(finalWriter2));
51-
//
52-
// opener.process(DataFilePath.PND_PICA);
53-
// opener.closeStream();
54-
//
55-
// Assert.assertEquals(referenceWriter.toString(), finalWriter1.toString());
56-
// Assert.assertEquals(referenceWriter.toString(), finalWriter2.toString());
57-
}
36+
public void testCorrectTeeFunction() {
37+
final EventList list = new EventList();
38+
execTestEvents(list);
39+
40+
final StreamValidator validator1 = new StreamValidator(list.getEvents());
41+
final StreamValidator validator2 = new StreamValidator(list.getEvents());
42+
final StreamTee tee = new StreamTee();
43+
tee.addReceiver(validator1)
44+
.addReceiver(validator2);
45+
46+
try {
47+
execTestEvents(tee);
48+
tee.closeStream();
49+
} catch (FormatException e) {
50+
fail("Tee did not forward data as expected: " + e);
51+
}
52+
}
53+
54+
private void execTestEvents(final StreamReceiver receiver) {
55+
receiver.startRecord("1");
56+
receiver.literal("l1", "value1");
57+
receiver.literal("l1", "value2");
58+
receiver.startEntity("e1");
59+
receiver.literal("l2", "value3");
60+
receiver.endEntity();
61+
receiver.endRecord();
62+
receiver.startRecord("2");
63+
receiver.literal("l3", "value4");
64+
receiver.endRecord();
65+
}
66+
5867
}

0 commit comments

Comments
 (0)