diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixBindTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixBindTest.java index a79b1794..db7cbc95 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixBindTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixBindTest.java @@ -622,7 +622,7 @@ public void shouldIterateOverListWithWildcard() { shouldIterateOverList("n?me", 3); } - @Test + @Test // checkstyle-disable-line JavaNCSS @Disabled("See https://github.com/metafacture/metafacture-fix/issues/119") public void shouldPerformComplexOperationWithPathWildcard() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixLookupTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixLookupTest.java index d901f7f6..31501c4f 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixLookupTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixLookupTest.java @@ -91,6 +91,42 @@ public void inlineDotNotationNested() { ); } + @Test + // See https://github.com/metafacture/metafacture-fix/issues/121 + public void shouldLookupArraySubFieldWithAsterisk() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "lookup('animals[].*.Aanimal', '" + TSV_MAP + "', 'sep_char': '\t')" + ), + i -> { + i.startRecord("1"); + i.startEntity("animals[]"); + i.startEntity("1"); + i.literal("name", "Jake"); + i.literal("Aanimal", "Aloha"); + i.endEntity(); + i.startEntity("2"); + i.literal("name", "Blacky"); + i.literal("Aanimal", "Hey"); + i.endEntity(); + i.endEntity(); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + o.get().startEntity("animals[]"); + o.get().startEntity("1"); + o.get().literal("name", "Jake"); + o.get().literal("Aanimal", "Alohaeha"); + o.get().endEntity(); + o.get().startEntity("2"); + o.get().literal("name", "Blacky"); + o.get().literal("Aanimal", "Tach"); + f.apply(2).endEntity(); + o.get().endRecord(); + } + ); + } + @Test public void csv() { assertMap( diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java index 89f8b764..c2cc5732 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java @@ -908,6 +908,101 @@ public void shouldPrependValueInEntireArray() { ); } + @Test + // See https://github.com/metafacture/metafacture-fix/issues/121 + public void shouldPrependValueInNestedArray() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "prepend('nestedTest[].*.test[].*', 'Number ')" + ), + i -> { + i.startRecord("1"); + i.startEntity("nestedTest[]"); + i.startEntity("1"); + i.startEntity("test[]"); + i.literal("1", "One"); + i.literal("2", "Two"); + i.literal("3", "Three"); + i.endEntity(); + i.endEntity(); + i.startEntity("2"); + i.startEntity("test[]"); + i.literal("1", "4"); + i.literal("2", "5"); + i.literal("3", "6"); + i.endEntity(); + i.endEntity(); + i.endEntity(); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + o.get().startEntity("nestedTest[]"); + o.get().startEntity("1"); + o.get().startEntity("test[]"); + o.get().literal("1", "Number One"); + o.get().literal("2", "Number Two"); + o.get().literal("3", "Number Three"); + f.apply(2).endEntity(); + o.get().startEntity("2"); + o.get().startEntity("test[]"); + o.get().literal("1", "Number 4"); + o.get().literal("2", "Number 5"); + o.get().literal("3", "Number 6"); + f.apply(3).endEntity(); + o.get().endRecord(); + } + ); + } + + @Test + // See https://github.com/metafacture/metafacture-fix/issues/121 + // TODO: Fix order (`coll[].*.a` should stay before `coll[].*.b`) + public void shouldPrependValueInArraySubField() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "prepend('coll[].*.a', 'HELLO ')" + ), + i -> { + i.startRecord("1"); + i.startEntity("coll[]"); + i.startEntity("1"); + i.literal("a", "Dog"); + i.literal("b", "Dog"); + i.endEntity(); + i.startEntity("2"); + i.literal("a", "Ape"); + i.literal("b", "Ape"); + i.endEntity(); + i.startEntity("3"); + i.literal("a", "Giraffe"); + i.endEntity(); + i.startEntity("4"); + i.literal("a", "Crocodile"); + i.endEntity(); + i.endEntity(); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + o.get().startEntity("coll[]"); + o.get().startEntity("1"); + o.get().literal("b", "Dog"); + o.get().literal("a", "HELLO Dog"); + o.get().endEntity(); + o.get().startEntity("2"); + o.get().literal("b", "Ape"); + o.get().literal("a", "HELLO Ape"); + o.get().endEntity(); + o.get().startEntity("3"); + o.get().literal("a", "HELLO Giraffe"); + o.get().endEntity(); + o.get().startEntity("4"); + o.get().literal("a", "HELLO Crocodile"); + f.apply(2).endEntity(); + o.get().endRecord(); + } + ); + } + @Test // See https://github.com/metafacture/metafacture-fix/issues/100 public void shouldNotPrependValueToArray() { @@ -975,6 +1070,101 @@ public void shouldReplaceAllRegexesInArray() { ); } + @Test + // See https://github.com/metafacture/metafacture-fix/issues/121 + // TODO: Fix order (`coll[].*.a` should stay before `coll[].*.b`) + public void shouldReplaceAllRegexesInArraySubField() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "replace_all('coll[].*.a', 'o', '__')" + ), + i -> { + i.startRecord("1"); + i.startEntity("coll[]"); + i.startEntity("1"); + i.literal("a", "Dog"); + i.literal("b", "Dog"); + i.endEntity(); + i.startEntity("2"); + i.literal("a", "Ape"); + i.literal("b", "Ape"); + i.endEntity(); + i.startEntity("3"); + i.literal("a", "Giraffe"); + i.endEntity(); + i.startEntity("4"); + i.literal("a", "Crocodile"); + i.endEntity(); + i.endEntity(); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + o.get().startEntity("coll[]"); + o.get().startEntity("1"); + o.get().literal("b", "Dog"); + o.get().literal("a", "D__g"); + o.get().endEntity(); + o.get().startEntity("2"); + o.get().literal("b", "Ape"); + o.get().literal("a", "Ape"); + o.get().endEntity(); + o.get().startEntity("3"); + o.get().literal("a", "Giraffe"); + o.get().endEntity(); + o.get().startEntity("4"); + o.get().literal("a", "Cr__c__dile"); + f.apply(2).endEntity(); + o.get().endRecord(); + } + ); + } + + @Test + // See https://github.com/metafacture/metafacture-fix/issues/121 + public void shouldReplaceAllRegexesInNestedArray() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "replace_all('nestedTest[].*.test[].*', 'o', '__')" + ), + i -> { + i.startRecord("1"); + i.startEntity("nestedTest[]"); + i.startEntity("1"); + i.startEntity("test[]"); + i.literal("1", "One"); + i.literal("2", "Two"); + i.literal("3", "Three"); + i.endEntity(); + i.endEntity(); + i.startEntity("2"); + i.startEntity("test[]"); + i.literal("1", "4"); + i.literal("2", "5"); + i.literal("3", "6"); + i.endEntity(); + i.endEntity(); + i.endEntity(); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + o.get().startEntity("nestedTest[]"); + o.get().startEntity("1"); + o.get().startEntity("test[]"); + o.get().literal("1", "One"); + o.get().literal("2", "Tw__"); + o.get().literal("3", "Three"); + f.apply(2).endEntity(); + o.get().startEntity("2"); + o.get().startEntity("test[]"); + o.get().literal("1", "4"); + o.get().literal("2", "5"); + o.get().literal("3", "6"); + f.apply(3).endEntity(); + o.get().endRecord(); + } + ); + } + @Test public void shouldReverseString() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( @@ -1015,6 +1205,69 @@ public void shouldReverseArray() { ); } + @Test + @Disabled("See https://github.com/metafacture/metafacture-fix/issues/121") + public void shouldReverseArrayOfStringsWithAsterisk() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "reverse('test[].*')" + ), + i -> { + i.startRecord("1"); + i.startEntity("test[]"); + i.literal("1", "One"); + i.literal("2", "Two"); + i.literal("3", "Three"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().startEntity("test[]"); + o.get().literal("1", "enO"); + o.get().literal("2", "owT"); + o.get().literal("3", "eerhT"); + o.get().endEntity(); + o.get().endRecord(); + } + ); + } + + @Test + @Disabled("java.lang.ArrayIndexOutOfBoundsException: 0; see https://github.com/metafacture/metafacture-fix/issues/121") + public void shouldReverseArrayOfHashesWithAsterisk() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "reverse('ANIMALS[].*')" + ), + i -> { + i.startRecord("1"); + i.startEntity("ANIMALS[]"); + i.startEntity("1"); + i.literal("Aanimal", "dog"); + i.literal("name", "Jake"); + i.endEntity(); + i.startEntity("2"); + i.literal("Aanimal", "parrot"); + i.literal("name", "Blacky"); + i.endEntity(); + i.endEntity(); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + o.get().startEntity("ANIMALS[]"); + o.get().startEntity("1"); + o.get().literal("Aanimal", "parrot"); + o.get().literal("name", "Blacky"); + o.get().endEntity(); + o.get().startEntity("2"); + o.get().literal("Aanimal", "dog"); + o.get().literal("name", "Jake"); + f.apply(2).endEntity(); + o.get().endRecord(); + } + ); + } + @Test public void shouldSortField() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( @@ -1164,6 +1417,53 @@ public void shouldSortFieldAndRemoveDuplicates() { ); } + @Test + @Disabled("See https://github.com/metafacture/metafacture-fix/issues/121") + public void shouldSortArrayFieldWithAsterisk() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "sort_field('OTHERS[].*.dnimals[]')" + ), + i -> { + i.startRecord("1"); + i.startEntity("OTHERS[]"); + i.startEntity("1"); + i.literal("name", "Jake"); + i.startEntity("dnimals[]"); + i.literal("1", "dog"); + i.literal("2", "zebra"); + i.literal("3", "cat"); + i.endEntity(); + i.startEntity("dumbers[]"); + i.literal("1", "7"); + i.literal("2", "2"); + i.literal("3", "1"); + i.literal("4", "10"); + i.endEntity(); + i.endEntity(); + i.endEntity(); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + o.get().startEntity("OTHERS[]"); + o.get().startEntity("1"); + o.get().literal("name", "Jake"); + o.get().startEntity("dnimals[]"); + o.get().literal("1", "cat"); + o.get().literal("2", "dog"); + o.get().literal("3", "zebra"); + o.get().endEntity(); + o.get().startEntity("dumbers[]"); + o.get().literal("1", "7"); + o.get().literal("2", "2"); + o.get().literal("3", "1"); + o.get().literal("4", "10"); + f.apply(3).endEntity(); + o.get().endRecord(); + } + ); + } + @Test public void shouldSplitStringField() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( @@ -1247,7 +1547,7 @@ public void shouldSplitHashField() { } @Test - @Disabled("See https://github.com/metafacture/metafacture-fix/issues/100") + @Disabled("See https://github.com/metafacture/metafacture-fix/issues/100 and https://github.com/metafacture/metafacture-fix/issues/121") public void shouldSplitNestedField() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( "split_field('others[].*.tools', '--')" @@ -1296,6 +1596,50 @@ public void shouldSumNumbers() { ); } + @Test + @Disabled("java.lang.IllegalStateException: expected String, got Array; see https://github.com/metafacture/metafacture-fix/issues/121") + public void shouldSumArrayFieldWithAsterisk() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "sum('OTHERS[].*.dumbers[]')" + ), + i -> { + i.startRecord("1"); + i.startEntity("OTHERS[]"); + i.startEntity("1"); + i.literal("name", "Jake"); + i.startEntity("dnimals[]"); + i.literal("1", "dog"); + i.literal("2", "zebra"); + i.literal("3", "cat"); + i.endEntity(); + i.startEntity("dumbers[]"); + i.literal("1", "7"); + i.literal("2", "2"); + i.literal("3", "1"); + i.literal("4", "10"); + i.endEntity(); + i.endEntity(); + i.endEntity(); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + o.get().startEntity("OTHERS[]"); + o.get().startEntity("1"); + o.get().literal("name", "Jake"); + o.get().startEntity("dnimals[]"); + o.get().literal("1", "dog"); + o.get().literal("2", "zebra"); + o.get().literal("3", "cat"); + o.get().endEntity(); + o.get().startEntity("dumbers[]"); + o.get().literal("1", "20"); + f.apply(3).endEntity(); + o.get().endRecord(); + } + ); + } + @Test public void shouldRemoveDuplicateStrings() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java index c2fbeb7c..b5d0b62e 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java @@ -33,7 +33,7 @@ * * @author Fabian Steeg */ -@ExtendWith(MockitoExtension.class) +@ExtendWith(MockitoExtension.class) // checkstyle-disable-line JavaNCSS public class MetafixRecordTest { @Mock @@ -670,6 +670,147 @@ public void appendWithAsteriksWildcardAtTheEnd() { ); } + @Test + // See https://github.com/metafacture/metafacture-fix/issues/121 + public void shouldCopyArrayFieldWithAsterisk() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "set_array('TEST_TWO[]')", + "copy_field('test[].*', 'TEST_TWO[].$append')" + ), + i -> { + i.startRecord("1"); + i.startEntity("test[]"); + i.literal("1", "One"); + i.literal("2", "Two"); + i.literal("3", "Three"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().startEntity("test[]"); + o.get().literal("1", "One"); + o.get().literal("2", "Two"); + o.get().literal("3", "Three"); + o.get().endEntity(); + o.get().startEntity("TEST_TWO[]"); + o.get().literal("1", "One"); + o.get().literal("2", "Two"); + o.get().literal("3", "Three"); + o.get().endEntity(); + o.get().endRecord(); + } + ); + } + + @Test + @Disabled("See https://github.com/metafacture/metafacture-fix/issues/121") + public void shouldCopyNestedArrayFieldWithAsterisk() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "set_array('TEST_4[]')", + "copy_field('nestedTest[].*.test[].*', 'TEST_4[].$append')" + ), + i -> { + i.startRecord("1"); + i.startEntity("nestedTest[]"); + i.startEntity("1"); + i.startEntity("test[]"); + i.literal("1", "One"); + i.literal("2", "Two"); + i.literal("3", "Three"); + i.endEntity(); + i.endEntity(); + i.startEntity("2"); + i.startEntity("test[]"); + i.literal("1", "4"); + i.literal("2", "5"); + i.literal("3", "6"); + i.endEntity(); + i.endEntity(); + i.endEntity(); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + o.get().startEntity("nestedTest[]"); + o.get().startEntity("1"); + o.get().startEntity("test[]"); + o.get().literal("1", "One"); + o.get().literal("2", "Two"); + o.get().literal("3", "Three"); + f.apply(2).endEntity(); + o.get().startEntity("2"); + o.get().startEntity("test[]"); + o.get().literal("1", "4"); + o.get().literal("2", "5"); + o.get().literal("3", "6"); + f.apply(3).endEntity(); + o.get().startEntity("TEST_4[]"); + o.get().literal("1", "One"); + o.get().literal("2", "Two"); + o.get().literal("3", "Three"); + o.get().literal("4", "4"); + o.get().literal("5", "5"); + o.get().literal("6", "6"); + o.get().endEntity(); + o.get().endRecord(); + } + ); + } + + @Test + // See https://github.com/metafacture/metafacture-fix/issues/121 + public void shouldCopyArraySubFieldWithAsterisk() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "set_array('TEST_5[]')", + "copy_field('coll[].*.b', 'TEST_5[].$append')" + ), + i -> { + i.startRecord("1"); + i.startEntity("coll[]"); + i.startEntity("1"); + i.literal("a", "Dog"); + i.literal("b", "Dog"); + i.endEntity(); + i.startEntity("2"); + i.literal("a", "Ape"); + i.literal("b", "Ape"); + i.endEntity(); + i.startEntity("3"); + i.literal("a", "Giraffe"); + i.endEntity(); + i.startEntity("4"); + i.literal("a", "Crocodile"); + i.endEntity(); + i.endEntity(); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + o.get().startEntity("coll[]"); + o.get().startEntity("1"); + o.get().literal("a", "Dog"); + o.get().literal("b", "Dog"); + o.get().endEntity(); + o.get().startEntity("2"); + o.get().literal("a", "Ape"); + o.get().literal("b", "Ape"); + o.get().endEntity(); + o.get().startEntity("3"); + o.get().literal("a", "Giraffe"); + o.get().endEntity(); + o.get().startEntity("4"); + o.get().literal("a", "Crocodile"); + f.apply(2).endEntity(); + o.get().startEntity("TEST_5[]"); + o.get().literal("1", "Dog"); + o.get().literal("2", "Ape"); + o.get().endEntity(); + o.get().endRecord(); + } + ); + } + @Test public void addFieldToFirstObjectInRepeatedFields() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( @@ -922,6 +1063,58 @@ private void assertThrowsOnEmptyRecord(final String index) { }); } + @Test + @Disabled("See https://github.com/metafacture/metafacture-fix/issues/121") + public void shouldAddArraySubFieldWithAsterisk() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "add_field('coll[].*.c', 'test')" + ), + i -> { + i.startRecord("1"); + i.startEntity("coll[]"); + i.startEntity("1"); + i.literal("a", "Dog"); + i.literal("b", "Dog"); + i.endEntity(); + i.startEntity("2"); + i.literal("a", "Ape"); + i.literal("b", "Ape"); + i.endEntity(); + i.startEntity("3"); + i.literal("a", "Giraffe"); + i.endEntity(); + i.startEntity("4"); + i.literal("a", "Crocodile"); + i.endEntity(); + i.endEntity(); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + o.get().startEntity("coll[]"); + o.get().startEntity("1"); + o.get().literal("a", "Dog"); + o.get().literal("b", "Dog"); + o.get().literal("c", "test"); + o.get().endEntity(); + o.get().startEntity("2"); + o.get().literal("a", "Ape"); + o.get().literal("b", "Ape"); + o.get().literal("c", "test"); + o.get().endEntity(); + o.get().startEntity("3"); + o.get().literal("a", "Giraffe"); + o.get().literal("c", "test"); + o.get().endEntity(); + o.get().startEntity("4"); + o.get().literal("a", "Crocodile"); + o.get().literal("c", "test"); + f.apply(3).endEntity(); + o.get().endRecord(); + } + ); + } + @Test public void move() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( @@ -2228,4 +2421,51 @@ public void shouldRenameAllFieldsInHash() { ); } + @Test + @Disabled("java.lang.ArrayIndexOutOfBoundsException: 0; see https://github.com/metafacture/metafacture-fix/issues/121") + public void shouldRenameArrayFieldWithAsterisk() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "rename('OTHERS[].*', 'd', 'XY')" + ), + i -> { + i.startRecord("1"); + i.startEntity("OTHERS[]"); + i.startEntity("1"); + i.literal("name", "Jake"); + i.startEntity("dnimals[]"); + i.literal("1", "dog"); + i.literal("2", "zebra"); + i.literal("3", "cat"); + i.endEntity(); + i.startEntity("dumbers[]"); + i.literal("1", "7"); + i.literal("2", "2"); + i.literal("3", "1"); + i.literal("4", "10"); + i.endEntity(); + i.endEntity(); + i.endEntity(); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + o.get().startEntity("OTHERS[]"); + o.get().startEntity("1"); + o.get().literal("name", "Jake"); + o.get().startEntity("XYnimals[]"); + o.get().literal("1", "dog"); + o.get().literal("2", "zebra"); + o.get().literal("3", "cat"); + o.get().endEntity(); + o.get().startEntity("XYumbers[]"); + o.get().literal("1", "7"); + o.get().literal("2", "2"); + o.get().literal("3", "1"); + o.get().literal("4", "10"); + f.apply(3).endEntity(); + o.get().endRecord(); + } + ); + } + }