-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #178: Reset conditions if sameEntity is true
If a collector has an `sameEntity="true"` set, it is reset whenever the current entity changes. As described in issue #178 the current implementation fails to reset the condition during these reset operations. This commit fixes this. Additionally, the test cases for the if-condition have been moved into a separate xml-file as quite a number of tests have accumulated so that it makes sense to keep them in there on test file.
- Loading branch information
Showing
4 changed files
with
281 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
279 changes: 279 additions & 0 deletions
279
src/test/java/org/culturegraph/mf/morph/collectors/If.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,279 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<metamorph-test version="1.0" | ||
xmlns="http://www.culturegraph.org/metamorph-test" xmlns:cgxml="http://www.culturegraph.org/cgxml"> | ||
|
||
<test-case name="should only fire if condition is met"> | ||
<input type="text/x-cg+xml"> | ||
<cgxml:cgxml version="1.0"> | ||
<cgxml:records> | ||
<cgxml:record id="1"> | ||
<cgxml:literal name="data1" value="a" /> | ||
<cgxml:literal name="data2" value="b" /> | ||
<cgxml:literal name="data3" value="c" /> | ||
</cgxml:record> | ||
<cgxml:record id="2"> | ||
<cgxml:literal name="data1" value="a" /> | ||
<cgxml:literal name="data2" value="b" /> | ||
<cgxml:literal name="data4" value="c" /> | ||
</cgxml:record> | ||
</cgxml:records> | ||
</cgxml:cgxml> | ||
</input> | ||
|
||
<transformation type="text/x-metamorph+xml"> | ||
<metamorph version="1" xmlns="http://www.culturegraph.org/metamorph"> | ||
<rules> | ||
<combine name="combined" value="${data1}-${data2}"> | ||
<if> | ||
<data source="data3" /> | ||
</if> | ||
<data source="data1" /> | ||
<data source="data2" /> | ||
</combine> | ||
</rules> | ||
</metamorph> | ||
</transformation> | ||
|
||
<result type="text/x-cg+xml"> | ||
<cgxml:cgxml version="1.0"> | ||
<cgxml:records> | ||
<cgxml:record id="1"> | ||
<cgxml:literal name="combined" value="a-b" /> | ||
</cgxml:record> | ||
<cgxml:record id="2"> | ||
</cgxml:record> | ||
</cgxml:records> | ||
</cgxml:cgxml> | ||
</result> | ||
</test-case> | ||
|
||
<test-case name="should allow to use same source in body and condition"> | ||
<input type="text/x-cg+xml"> | ||
<cgxml:cgxml version="1.0"> | ||
<cgxml:records> | ||
<cgxml:record id="1"> | ||
<cgxml:literal name="data1" value="a" /> | ||
<cgxml:literal name="data2" value="b" /> | ||
</cgxml:record> | ||
<cgxml:record id="2"> | ||
<cgxml:literal name="data1" value="a" /> | ||
<cgxml:literal name="data2" value="c" /> | ||
</cgxml:record> | ||
</cgxml:records> | ||
</cgxml:cgxml> | ||
</input> | ||
|
||
<transformation type="text/x-metamorph+xml"> | ||
<metamorph version="1" xmlns="http://www.culturegraph.org/metamorph"> | ||
<rules> | ||
<combine name="combined" value="${data1}-${data2}"> | ||
<if> | ||
<data source="data2"> | ||
<equals string="b" /> | ||
</data> | ||
</if> | ||
<data source="data1" /> | ||
<data source="data2" /> | ||
</combine> | ||
</rules> | ||
</metamorph> | ||
</transformation> | ||
|
||
<result type="text/x-cg+xml"> | ||
<cgxml:cgxml version="1.0"> | ||
<cgxml:records> | ||
<cgxml:record id="1"> | ||
<cgxml:literal name="combined" value="a-b" /> | ||
</cgxml:record> | ||
<cgxml:record id="2"> | ||
</cgxml:record> | ||
</cgxml:records> | ||
</cgxml:cgxml> | ||
</result> | ||
</test-case> | ||
|
||
<test-case name="should allow quantors in if statements"> | ||
<input type="text/x-cg+xml"> | ||
<cgxml:cgxml version="1.0"> | ||
<cgxml:records> | ||
<cgxml:record id="1"> | ||
<cgxml:literal name="data1" value="a" /> | ||
<cgxml:literal name="data2" value="b" /> | ||
<cgxml:literal name="data3" value="c" /> | ||
</cgxml:record> | ||
<cgxml:record id="2"> | ||
<cgxml:literal name="data1" value="a" /> | ||
<cgxml:literal name="data2" value="d" /> | ||
<cgxml:literal name="data4" value="c" /> | ||
</cgxml:record> | ||
<cgxml:record id="3"> | ||
<cgxml:literal name="data1" value="a" /> | ||
<cgxml:literal name="data2" value="b" /> | ||
<cgxml:literal name="data5" value="c" /> | ||
</cgxml:record> | ||
</cgxml:records> | ||
</cgxml:cgxml> | ||
</input> | ||
|
||
<transformation type="text/x-metamorph+xml"> | ||
<metamorph version="1" xmlns="http://www.culturegraph.org/metamorph"> | ||
<rules> | ||
<combine name="combined" value="${data1}-${data2}"> | ||
<if> | ||
<any> | ||
<data source="data3" /> | ||
<data source="data4" /> | ||
</any> | ||
</if> | ||
<data source="data1" /> | ||
<data source="data2" /> | ||
</combine> | ||
</rules> | ||
</metamorph> | ||
</transformation> | ||
|
||
<result type="text/x-cg+xml"> | ||
<cgxml:cgxml version="1.0"> | ||
<cgxml:records> | ||
<cgxml:record id="1"> | ||
<cgxml:literal name="combined" value="a-b" /> | ||
</cgxml:record> | ||
<cgxml:record id="2"> | ||
<cgxml:literal name="combined" value="a-d" /> | ||
</cgxml:record> | ||
<cgxml:record id="3"> | ||
</cgxml:record> | ||
</cgxml:records> | ||
</cgxml:cgxml> | ||
</result> | ||
</test-case> | ||
|
||
<test-case name="should reset condition with collector"> | ||
<input type="text/x-cg+xml"> | ||
<cgxml:cgxml version="1.0"> | ||
<cgxml:records> | ||
<cgxml:record id="1"> | ||
<cgxml:entity name="entity"> | ||
<cgxml:literal name="data1" value="output" /> | ||
<cgxml:literal name="data2" value="X" /> | ||
</cgxml:entity> | ||
<cgxml:entity name="entity"> | ||
<cgxml:literal name="data1" value="no-output" /> | ||
<cgxml:literal name="data3" value="X" /> | ||
</cgxml:entity> | ||
</cgxml:record> | ||
</cgxml:records> | ||
</cgxml:cgxml> | ||
</input> | ||
|
||
<transformation type="text/x-metamorph+xml"> | ||
<metamorph version="1" xmlns="http://www.culturegraph.org/metamorph"> | ||
<rules> | ||
<combine name="result" value="${VAL}" reset="true"> | ||
<if> | ||
<data source="entity.data2" /> | ||
</if> | ||
<data source="entity.data1" name="VAL" /> | ||
</combine> | ||
</rules> | ||
</metamorph> | ||
</transformation> | ||
|
||
<result type="text/x-cg+xml"> | ||
<cgxml:cgxml version="1.0"> | ||
<cgxml:records> | ||
<cgxml:record id="1"> | ||
<cgxml:literal name="result" value="output" /> | ||
</cgxml:record> | ||
</cgxml:records> | ||
</cgxml:cgxml> | ||
</result> | ||
</test-case> | ||
|
||
<test-case name="should reset condition with collector on flushWith"> | ||
<input type="text/x-cg+xml"> | ||
<cgxml:cgxml version="1.0"> | ||
<cgxml:records> | ||
<cgxml:record id="1"> | ||
<cgxml:entity name="entity"> | ||
<cgxml:literal name="data1" value="output" /> | ||
<cgxml:literal name="data2" value="X" /> | ||
</cgxml:entity> | ||
<cgxml:entity name="entity"> | ||
<cgxml:literal name="data1" value="no-output" /> | ||
<cgxml:literal name="data3" value="X" /> | ||
</cgxml:entity> | ||
</cgxml:record> | ||
</cgxml:records> | ||
</cgxml:cgxml> | ||
</input> | ||
|
||
<transformation type="text/x-metamorph+xml"> | ||
<metamorph version="1" xmlns="http://www.culturegraph.org/metamorph"> | ||
<rules> | ||
<combine name="result" value="${VAL1}${VAL2}" reset="true" flushWith="entity"> | ||
<if> | ||
<data source="entity.data2" /> | ||
</if> | ||
<data source="entity.data1" name="VAL1" /> | ||
<data source="entity.data4" name="VAL2" /> | ||
</combine> | ||
</rules> | ||
</metamorph> | ||
</transformation> | ||
|
||
<result type="text/x-cg+xml"> | ||
<cgxml:cgxml version="1.0"> | ||
<cgxml:records> | ||
<cgxml:record id="1"> | ||
<cgxml:literal name="result" value="output" /> | ||
</cgxml:record> | ||
</cgxml:records> | ||
</cgxml:cgxml> | ||
</result> | ||
</test-case> | ||
|
||
<test-case name="should reset condition with collector on same entity"> | ||
<input type="text/x-cg+xml"> | ||
<cgxml:cgxml version="1.0"> | ||
<cgxml:records> | ||
<cgxml:record id="1"> | ||
<cgxml:entity name="entity"> | ||
<cgxml:literal name="data1" value="output" /> | ||
<cgxml:literal name="data2" value="X" /> | ||
</cgxml:entity> | ||
<cgxml:entity name="entity"> | ||
<cgxml:literal name="data1" value="no-output" /> | ||
<cgxml:literal name="data3" value="X" /> | ||
<cgxml:literal name="data4" value="extra-output" /> | ||
</cgxml:entity> | ||
</cgxml:record> | ||
</cgxml:records> | ||
</cgxml:cgxml> | ||
</input> | ||
|
||
<transformation type="text/x-metamorph+xml"> | ||
<metamorph version="1" xmlns="http://www.culturegraph.org/metamorph"> | ||
<rules> | ||
<combine name="result" value="${VAL1}+${VAL2}" sameEntity="true"> | ||
<if> | ||
<data source="entity.data2" /> | ||
</if> | ||
<data source="entity.data1" name="VAL1" /> | ||
<data source="entity.data4" name="VAL2" /> | ||
</combine> | ||
</rules> | ||
</metamorph> | ||
</transformation> | ||
|
||
<result type="text/x-cg+xml"> | ||
<cgxml:cgxml version="1.0"> | ||
<cgxml:records> | ||
<cgxml:record id="1"> | ||
</cgxml:record> | ||
</cgxml:records> | ||
</cgxml:cgxml> | ||
</result> | ||
</test-case> | ||
|
||
</metamorph-test> |
Oops, something went wrong.