Skip to content
This repository was archived by the owner on May 16, 2025. It is now read-only.

Commit f925b09

Browse files
committed
Adjust FindFixPaths.java and add test #347
1 parent a082cd5 commit f925b09

File tree

2 files changed

+129
-6
lines changed

2 files changed

+129
-6
lines changed

metafix/src/main/java/org/metafacture/metafix/FindFixPaths.java

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,63 @@
4343
@FluxCommand("find-fix-paths")
4444

4545
public class FindFixPaths extends DefaultStreamPipe<ObjectReceiver<String>> {
46+
final Metafix fix;
47+
String objectPattern;
48+
4649
public FindFixPaths(final String objectPattern) {
47-
final Metafix fix;
50+
this.objectPattern = objectPattern;
4851
try {
49-
fix = new Metafix("nothing()");
50-
fix.setRepeatedFieldsToEntities(true);
51-
}
52-
catch (final IOException e) {
52+
this.fix = new Metafix("nothing()");
53+
this.fix.setRepeatedFieldsToEntities(true);
54+
} catch (final IOException e) {
5355
throw new MetafactureException(e);
5456
}
57+
}
58+
59+
@Override
60+
protected void onSetReceiver() {
5561
final TripleFilter tripleFilter = new TripleFilter();
5662
tripleFilter.setObjectPattern(objectPattern);
5763
fix
5864
.setReceiver(new StreamFlattener())
5965
.setReceiver(new StreamToTriples())
6066
.setReceiver(tripleFilter)
61-
.setReceiver(new ObjectTemplate<>("${p}\t ${o}"))
67+
.setReceiver(new ObjectTemplate<>("${p}\\t|\\t${o}"))
6268
.setReceiver(getReceiver());
6369
}
70+
71+
@Override
72+
public void startRecord(final String identifier) {
73+
fix.startRecord(identifier);
74+
}
75+
76+
@Override
77+
public void endRecord() {
78+
fix.endRecord();
79+
}
80+
81+
@Override
82+
public void startEntity(final String name) {
83+
fix.startEntity(name);
84+
}
85+
86+
@Override
87+
public void endEntity() {
88+
fix.endEntity();
89+
}
90+
91+
@Override
92+
public void literal(final String name, final String value) {
93+
fix.literal(name, value);
94+
}
95+
96+
@Override
97+
protected void onCloseStream() {
98+
fix.closeStream();
99+
}
100+
101+
@Override
102+
protected void onResetStream() {
103+
fix.resetStream();
104+
}
64105
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2023 Fabian Steeg, hbz
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.metafacture.metafix;
18+
19+
import org.metafacture.framework.ObjectReceiver;
20+
21+
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.extension.ExtendWith;
23+
import org.mockito.InOrder;
24+
import org.mockito.Mock;
25+
import org.mockito.Mockito;
26+
import org.mockito.exceptions.base.MockitoAssertionError;
27+
import org.mockito.junit.jupiter.MockitoExtension;
28+
29+
/**
30+
* Tests for class {@link FindFixPaths}.
31+
*
32+
* @author Fabian Steeg
33+
*
34+
*/
35+
@ExtendWith(MockitoExtension.class)
36+
public final class FindFixPathsTest {
37+
38+
private final FindFixPaths finder = new FindFixPaths(".*ETL.*");
39+
40+
@Mock
41+
private ObjectReceiver<String> receiver;
42+
43+
public FindFixPathsTest() {
44+
}
45+
46+
@Test
47+
public void testShouldFindPaths() {
48+
verify(
49+
"a\\t|\\tAn ETL test",
50+
"c.2\\t|\\tETL what?");
51+
}
52+
53+
private void processRecord() {
54+
finder.setReceiver(receiver);
55+
finder.startRecord("");
56+
finder.literal("a", "An ETL test");
57+
finder.literal("b", "");
58+
finder.literal("b", "Dummi");
59+
finder.literal("b", "Dog");
60+
finder.literal("c", "");
61+
finder.literal("c", "ETL what?");
62+
finder.endRecord();
63+
finder.closeStream();
64+
}
65+
66+
private void verify(final String... result) throws MockitoAssertionError {
67+
processRecord();
68+
try {
69+
final InOrder ordered = Mockito.inOrder(receiver);
70+
for (final String r : result) {
71+
ordered.verify(receiver).process(r);
72+
}
73+
ordered.verify(receiver, Mockito.times(2)).closeStream();
74+
ordered.verifyNoMoreInteractions();
75+
Mockito.verifyNoMoreInteractions(receiver);
76+
} catch (final MockitoAssertionError e) {
77+
System.out.println(Mockito.mockingDetails(receiver).printInvocations());
78+
throw e;
79+
}
80+
}
81+
82+
}

0 commit comments

Comments
 (0)