Skip to content

Commit a7f6785

Browse files
committed
Fix #265: split and switch-name-value emit wrong source
1 parent 88483ee commit a7f6785

File tree

4 files changed

+129
-2
lines changed

4 files changed

+129
-2
lines changed

src/main/java/org/culturegraph/mf/metamorph/functions/Split.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void receive(final String name, final String value,
3535
final int entityCount) {
3636
final String[] parts = delimiterPattern.split(value);
3737
for (final String part : parts) {
38-
getNamedValueReceiver().receive(name, part, source, recordCount,
38+
getNamedValueReceiver().receive(name, part, this, recordCount,
3939
entityCount);
4040
}
4141
}

src/main/java/org/culturegraph/mf/metamorph/functions/SwitchNameValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void receive(final String name, final String value,
3030
final NamedValueSource source, final int recordCount,
3131
final int entityCount) {
3232

33-
getNamedValueReceiver().receive(value, name, source, recordCount,
33+
getNamedValueReceiver().receive(value, name, this, recordCount,
3434
entityCount);
3535

3636
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2017 Christoph Böhme
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+
package org.culturegraph.mf.metamorph.functions;
17+
18+
import static org.mockito.Mockito.verify;
19+
20+
import org.culturegraph.mf.framework.StreamReceiver;
21+
import org.culturegraph.mf.metamorph.InlineMorph;
22+
import org.culturegraph.mf.metamorph.Metamorph;
23+
import org.junit.Rule;
24+
import org.junit.Test;
25+
import org.mockito.Mock;
26+
import org.mockito.junit.MockitoJUnit;
27+
import org.mockito.junit.MockitoRule;
28+
29+
/**
30+
* Tests for class {@link Split}.
31+
*
32+
* @author Christoph Böhme
33+
*/
34+
public final class SplitTest {
35+
36+
@Rule
37+
public MockitoRule mockitoRule = MockitoJUnit.rule();
38+
39+
@Mock
40+
private StreamReceiver receiver;
41+
42+
private Metamorph metamorph;
43+
44+
@Test
45+
public void issue265_shouldWorkIfLastFunctionInCombineStatement() {
46+
metamorph = InlineMorph.in(this)
47+
.with("<rules>")
48+
.with(" <combine name='out' value='${v}'>")
49+
.with(" <data source='in' name='v'>")
50+
.with(" <split delimiter=' ' />")
51+
.with(" </data>")
52+
.with(" </combine>")
53+
.with("</rules>")
54+
.createConnectedTo(receiver);
55+
56+
metamorph.startRecord("1");
57+
metamorph.literal("in", "1 2");
58+
metamorph.endRecord();
59+
60+
verify(receiver).literal("out", "1");
61+
verify(receiver).literal("out", "2");
62+
}
63+
64+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2017 Christoph Böhme
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+
package org.culturegraph.mf.metamorph.functions;
17+
18+
import static org.mockito.Mockito.verify;
19+
20+
import org.culturegraph.mf.framework.StreamReceiver;
21+
import org.culturegraph.mf.metamorph.InlineMorph;
22+
import org.culturegraph.mf.metamorph.Metamorph;
23+
import org.junit.Rule;
24+
import org.junit.Test;
25+
import org.mockito.Mock;
26+
import org.mockito.junit.MockitoJUnit;
27+
import org.mockito.junit.MockitoRule;
28+
29+
/**
30+
* Tests for class {@link Split}.
31+
*
32+
* @author Christoph Böhme
33+
*/
34+
public final class SwitchNameValueTest {
35+
36+
@Rule
37+
public MockitoRule mockitoRule = MockitoJUnit.rule();
38+
39+
@Mock
40+
private StreamReceiver receiver;
41+
42+
private Metamorph metamorph;
43+
44+
@Test
45+
public void issue265_shouldWorkIfLastFunctionInCombineStatement() {
46+
metamorph = InlineMorph.in(this)
47+
.with("<rules>")
48+
.with(" <combine name='out' value='val'>")
49+
.with(" <data source='in'>")
50+
.with(" <switch-name-value />")
51+
.with(" </data>")
52+
.with(" </combine>")
53+
.with("</rules>")
54+
.createConnectedTo(receiver);
55+
56+
metamorph.startRecord("1");
57+
metamorph.literal("in", "val");
58+
metamorph.endRecord();
59+
60+
verify(receiver).literal("out", "val");
61+
}
62+
63+
}

0 commit comments

Comments
 (0)