Skip to content

Commit faede4b

Browse files
committed
Add unit tests for list_as() Fix bind. (#268)
1 parent 269d207 commit faede4b

File tree

1 file changed

+125
-2
lines changed

1 file changed

+125
-2
lines changed

metafix/src/test/java/org/metafacture/metafix/MetafixBindTest.java

Lines changed: 125 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,36 +745,159 @@ public void shouldPerformComplexOperationWithPathWildcard() {
745745
}
746746

747747
@Test
748-
public void shouldDoListAs() {
748+
public void shouldDoListAsWithSingleList() {
749749
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
750750
"set_array('sourceOrga[]')",
751-
"do list_as(orgId: 'ccm:university[]', orgName: 'ccm:university_DISPLAYNAME[]')",
751+
"do list_as(orgId: 'ccm:university[]')",
752+
" copy_field(orgId, 'sourceOrga[].$append.id')",
753+
"end"
754+
),
755+
i -> {
756+
i.startRecord("1");
757+
i.startEntity("ccm:university[]");
758+
i.literal("1", "https://ror.org/0304hq317");
759+
i.literal("2", "https://ror.org/014nnvj65");
760+
i.endEntity();
761+
i.endRecord();
762+
},
763+
(o, f) -> {
764+
o.get().startRecord("1");
765+
o.get().startEntity("ccm:university[]");
766+
o.get().literal("1", "https://ror.org/0304hq317");
767+
o.get().literal("2", "https://ror.org/014nnvj65");
768+
o.get().endEntity();
769+
o.get().startEntity("sourceOrga[]");
770+
o.get().startEntity("1");
771+
o.get().literal("id", "https://ror.org/0304hq317");
772+
o.get().endEntity();
773+
o.get().startEntity("2");
774+
o.get().literal("id", "https://ror.org/014nnvj65");
775+
f.apply(2).endEntity();
776+
o.get().endRecord();
777+
}
778+
);
779+
}
780+
781+
@Test
782+
public void shouldDoListAsWithMultipleLists() {
783+
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
784+
"set_array('sourceOrga[]')",
785+
"do list_as(orgId: 'ccm:university[]', orgName: 'ccm:university_DISPLAYNAME[]', orgLoc: 'ccm:university_LOCATION[]')",
752786
" copy_field(orgId, 'sourceOrga[].$append.id')",
753787
" copy_field(orgName, 'sourceOrga[].$last.name')",
788+
" copy_field(orgLoc, 'sourceOrga[].$last.location')",
754789
"end"
755790
),
756791
i -> {
757792
i.startRecord("1");
758793
i.startEntity("ccm:university[]");
759794
i.literal("1", "https://ror.org/0304hq317");
795+
i.literal("2", "https://ror.org/014nnvj65");
760796
i.endEntity();
761797
i.startEntity("ccm:university_DISPLAYNAME[]");
762798
i.literal("1", "Gottfried Wilhelm Leibniz Universität Hannover");
799+
i.literal("2", "Technische Hochschule Köln");
800+
i.endEntity();
801+
i.startEntity("ccm:university_LOCATION[]");
802+
i.literal("1", "Hannover");
803+
i.literal("2", "Köln");
763804
i.endEntity();
764805
i.endRecord();
765806
},
766807
(o, f) -> {
767808
o.get().startRecord("1");
768809
o.get().startEntity("ccm:university[]");
769810
o.get().literal("1", "https://ror.org/0304hq317");
811+
o.get().literal("2", "https://ror.org/014nnvj65");
770812
o.get().endEntity();
771813
o.get().startEntity("ccm:university_DISPLAYNAME[]");
772814
o.get().literal("1", "Gottfried Wilhelm Leibniz Universität Hannover");
815+
o.get().literal("2", "Technische Hochschule Köln");
816+
o.get().endEntity();
817+
o.get().startEntity("ccm:university_LOCATION[]");
818+
o.get().literal("1", "Hannover");
819+
o.get().literal("2", "Köln");
773820
o.get().endEntity();
774821
o.get().startEntity("sourceOrga[]");
775822
o.get().startEntity("1");
776823
o.get().literal("id", "https://ror.org/0304hq317");
777824
o.get().literal("name", "Gottfried Wilhelm Leibniz Universität Hannover");
825+
o.get().literal("location", "Hannover");
826+
o.get().endEntity();
827+
o.get().startEntity("2");
828+
o.get().literal("id", "https://ror.org/014nnvj65");
829+
o.get().literal("name", "Technische Hochschule Köln");
830+
o.get().literal("location", "Köln");
831+
f.apply(2).endEntity();
832+
o.get().endRecord();
833+
}
834+
);
835+
}
836+
837+
@Test // checkstyle-disable-line JavaNCSS
838+
public void shouldDoListAsWithMultipleListsOfDifferentSizes() {
839+
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
840+
"set_array('sourceOrga[]')",
841+
"do list_as(orgId: 'ccm:university[]', orgName: 'ccm:university_DISPLAYNAME[]', orgLoc: 'ccm:university_LOCATION[]')",
842+
" set_hash('sourceOrga[].$append')",
843+
" copy_field(orgId, 'sourceOrga[].$last.id')",
844+
" copy_field(orgName, 'sourceOrga[].$last.name')",
845+
" copy_field(orgLoc, 'sourceOrga[].$last.location')",
846+
"end"
847+
),
848+
i -> {
849+
i.startRecord("1");
850+
i.startEntity("ccm:university[]");
851+
i.literal("1", "https://ror.org/0304hq317");
852+
i.literal("2", "https://ror.org/014nnvj65");
853+
i.endEntity();
854+
i.startEntity("ccm:university_DISPLAYNAME[]");
855+
i.literal("1", "Gottfried Wilhelm Leibniz Universität Hannover");
856+
i.literal("2", "Technische Hochschule Köln");
857+
i.literal("3", "Universität zu Köln");
858+
i.literal("4", "Stadtbibliothek Köln");
859+
i.endEntity();
860+
i.startEntity("ccm:university_LOCATION[]");
861+
i.literal("1", "Hannover");
862+
i.literal("2", "Köln");
863+
i.literal("3", "Köln");
864+
i.endEntity();
865+
i.endRecord();
866+
},
867+
(o, f) -> {
868+
o.get().startRecord("1");
869+
o.get().startEntity("ccm:university[]");
870+
o.get().literal("1", "https://ror.org/0304hq317");
871+
o.get().literal("2", "https://ror.org/014nnvj65");
872+
o.get().endEntity();
873+
o.get().startEntity("ccm:university_DISPLAYNAME[]");
874+
o.get().literal("1", "Gottfried Wilhelm Leibniz Universität Hannover");
875+
o.get().literal("2", "Technische Hochschule Köln");
876+
o.get().literal("3", "Universität zu Köln");
877+
o.get().literal("4", "Stadtbibliothek Köln");
878+
o.get().endEntity();
879+
o.get().startEntity("ccm:university_LOCATION[]");
880+
o.get().literal("1", "Hannover");
881+
o.get().literal("2", "Köln");
882+
o.get().literal("3", "Köln");
883+
o.get().endEntity();
884+
o.get().startEntity("sourceOrga[]");
885+
o.get().startEntity("1");
886+
o.get().literal("id", "https://ror.org/0304hq317");
887+
o.get().literal("name", "Gottfried Wilhelm Leibniz Universität Hannover");
888+
o.get().literal("location", "Hannover");
889+
o.get().endEntity();
890+
o.get().startEntity("2");
891+
o.get().literal("id", "https://ror.org/014nnvj65");
892+
o.get().literal("name", "Technische Hochschule Köln");
893+
o.get().literal("location", "Köln");
894+
o.get().endEntity();
895+
o.get().startEntity("3");
896+
o.get().literal("name", "Universität zu Köln");
897+
o.get().literal("location", "Köln");
898+
o.get().endEntity();
899+
o.get().startEntity("4");
900+
o.get().literal("name", "Stadtbibliothek Köln");
778901
f.apply(2).endEntity();
779902
o.get().endRecord();
780903
}

0 commit comments

Comments
 (0)