Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_elseNested: Entity with more than one subfield results in multiple entities #338

Closed
dr0i opened this issue Oct 29, 2020 · 1 comment · Fixed by #342
Closed

_elseNested: Entity with more than one subfield results in multiple entities #338

dr0i opened this issue Oct 29, 2020 · 1 comment · Fixed by #342
Assignees
Labels

Comments

@dr0i
Copy link
Member

dr0i commented Oct 29, 2020

Reported by @hagbeck:

I've observed another effect.

<marc:datafield tag="856" ind1="4" ind2="0">
   <marc:subfield code="u">http://www.video2brain.com/</mx:subfield>
   <marc:subfield code="x">Agentur</mx:subfield>
</marc:datafield>

results in multiple entities like

<marc:datafield tag="856" ind1="4" ind2="0">
        <marc:subfield code="u">http://www.video2brain.com/</marc:subfield>
</marc:datafield>
<marc:datafield tag="856" ind1="4" ind2="0">
        <marc:subfield code="x">Agentur</marc:subfield>
</marc:datafield>

using the '_elseNested' morph.

Originates from #107.

@dr0i dr0i added the Bug label Oct 29, 2020
@blackwinter
Copy link
Member

Fortunately, we have a test for this. Unfortunately, the test is insufficient. All (?) tests should verifyNoMoreInteractions:

diff --git metamorph/src/test/java/org/metafacture/metamorph/TestMetamorphBasics.java metamorph/src/test/java/org/metafacture/metamorph/TestMetamorphBasics.java
index a564bed8..29fc828c 100644
--- metamorph/src/test/java/org/metafacture/metamorph/TestMetamorphBasics.java
+++ metamorph/src/test/java/org/metafacture/metamorph/TestMetamorphBasics.java
@@ -19,6 +19,7 @@
 import static org.mockito.Mockito.inOrder;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
 
 import org.junit.Rule;
 import org.junit.Test;
@@ -156,6 +157,8 @@ public void shouldHandleUnmatchedLiteralsAndEntitiesInElseNestedSource() {
         ordered.verify(receiver).literal("Hawaii", "Aloha");
         ordered.verify(receiver).endEntity();
         ordered.verify(receiver).endRecord();
+        ordered.verifyNoMoreInteractions();
+        verifyNoMoreInteractions(receiver);
     }
 
     @Test
> Task :metamorph:test

org.metafacture.metamorph.TestMetamorphBasics > shouldHandleUnmatchedLiteralsAndEntitiesInElseNestedSource FAILED
    org.mockito.exceptions.verification.NoInteractionsWanted at TestMetamorphBasics.java:161

168 tests completed, 1 failed, 1 skipped

[...]

BUILD FAILED in 5s
126 actionable tasks: 2 executed, 124 up-to-date
diff --git metamorph/src/test/java/org/metafacture/metamorph/TestMetamorphBasics.java metamorph/src/test/java/org/metafacture/metamorph/TestMetamorphBasics.java
index 29fc828c..1cf6700d 100644
--- metamorph/src/test/java/org/metafacture/metamorph/TestMetamorphBasics.java
+++ metamorph/src/test/java/org/metafacture/metamorph/TestMetamorphBasics.java
@@ -151,6 +151,8 @@ public void shouldHandleUnmatchedLiteralsAndEntitiesInElseNestedSource() {
         ordered.verify(receiver).literal("Shikotan", "Aekap");
         ordered.verify(receiver).startEntity("Germany");
         ordered.verify(receiver).literal("Langeoog", "Moin");
+        ordered.verify(receiver).endEntity();
+        ordered.verify(receiver).startEntity("Germany");
         ordered.verify(receiver).literal("Baltrum", "Moin Moin");
         ordered.verify(receiver).endEntity();
         ordered.verify(receiver).startEntity("USA");
BUILD SUCCESSFUL in 5s
131 actionable tasks: 2 executed, 129 up-to-date

blackwinter added a commit that referenced this issue Nov 2, 2020
…ccurred at all.

* Changed `shouldHandleUnmatchedLiteralsAndEntitiesInElseNestedSource` to match actual behaviour (see #338).
blackwinter added a commit that referenced this issue Nov 2, 2020
…ccurred at all.

* Changed `shouldHandleUnmatchedLiteralsAndEntitiesInElseNestedSource` to match actual behaviour (see #338).
@blackwinter blackwinter self-assigned this Nov 5, 2020
blackwinter added a commit that referenced this issue Nov 5, 2020
* Fixes #338 (see test `shouldHandleUnmatchedLiteralsAndEntitiesInElseNestedSource`; e4c6fe5).
* Doesn't work with partially handled entities (see test `shouldHandlePartiallyUnmatchedLiteralsAndEntitiesInElseNestedSource`).
  * It should either coordinate with `Entity` w.r.t. starting/ending entities.
  * Or separate pass-through entities from explicitly specified entities.
dr0i added a commit that referenced this issue Nov 10, 2020
This reimplemets commit f009e28:

 "Data which is handled by metamorph rules will NOT be passed through
 (hence the aptly named "_else"). If you want to use data in the morph
 AND pass it through, you have to add an explicit rule for this, as usual."

This behaviour is not the default, though.
It can be achieved by this morph rule:

<entity name='$name' sameEntity='true' reset='true' flushWith='$name' flushIncomplete='true'>"

where $name is the name of the entity you want to treat.

See #338.
@dr0i dr0i closed this as completed in 6f871cc Apr 19, 2021
blackwinter added a commit that referenced this issue Sep 14, 2021
…ested`).

Keep track of nested entities and open/close them in the appropriate order.

Fixes #378.

Related to #107, #338.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants