From 4ffee79da408c9cb19121b4c134e575096f78c68 Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Tue, 3 May 2022 16:51:48 +0200 Subject: [PATCH 1/5] Fix field order in integration test for #113 --- .../input.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldArrayOfObjectsAndListNewArrayOfObjectsAndMoveSubfield/input.json b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldArrayOfObjectsAndListNewArrayOfObjectsAndMoveSubfield/input.json index 847b571a..ee0cd433 100644 --- a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldArrayOfObjectsAndListNewArrayOfObjectsAndMoveSubfield/input.json +++ b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldArrayOfObjectsAndListNewArrayOfObjectsAndMoveSubfield/input.json @@ -25,8 +25,8 @@ { "author": [ { - "@type": "Person", - "name": "Jürgen Böhner" + "name": "Jürgen Böhner", + "@type": "Person" } ] } From 379867032e2a4d5734f4d23a22759ec1b1bc4b21 Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Tue, 3 May 2022 18:08:32 +0200 Subject: [PATCH 2/5] Fix asterisk handling on insert into array (#113, #121, #130, #156) --- .../java/org/metafacture/metafix/FixPath.java | 12 +++---- .../metafix/MetafixMethodTest.java | 3 -- .../metafix/MetafixRecordTest.java | 33 +++++++++++++++++++ .../todo.txt | 1 - .../todo.txt | 2 +- .../todo.txt | 1 - .../todo.txt | 1 - .../todo.txt | 1 - .../todo.txt | 1 - 9 files changed, 38 insertions(+), 17 deletions(-) delete mode 100644 metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/add_fieldAsteriskIntoArrayOfObjects/todo.txt delete mode 100644 metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldArrayOfStringsIntoArrayOfObjectsWithAsteriskWildcard/todo.txt delete mode 100644 metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldAsteriskIntoArrayOfObjects/todo.txt delete mode 100644 metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/move_fieldAsteriskIntoArrayOfObjects/todo.txt delete mode 100644 metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/set_arrayIntoArrayOfObjectsWithAsterisk/todo.txt diff --git a/metafix/src/main/java/org/metafacture/metafix/FixPath.java b/metafix/src/main/java/org/metafacture/metafix/FixPath.java index 2dad76f5..5dee05f5 100644 --- a/metafix/src/main/java/org/metafacture/metafix/FixPath.java +++ b/metafix/src/main/java/org/metafacture/metafix/FixPath.java @@ -250,14 +250,10 @@ private void removeNestedFrom(final Value value) { // basic idea: reuse findIn logic here? setIn(findIn(array), newValue) final String field = path[0]; if (field.equals(ASTERISK)) { - if (path.length == 1) { - for (int i = 0; i < array.size(); ++i) { - mode.apply(array, String.valueOf(i + 1), newValue); - } - } - else { - array.add(Value.newHash(h -> new FixPath(tail(path)).insertInto(h, mode, newValue))); - } + array.forEach(value -> value.matchType() + .ifArray(a -> new FixPath(tail(path)).insertInto(a, mode, newValue)) + .ifHash(h -> new FixPath(tail(path)).insertInto(h, mode, newValue)) + .orElseThrow()); } else { if (path.length == 1) { diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java index eb781aca..01404d0c 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java @@ -2369,7 +2369,6 @@ public void shouldSortFieldAndRemoveDuplicates() { } @Test - @MetafixToDo("See https://github.com/metafacture/metafacture-fix/issues/121") public void shouldSortArrayFieldWithAsterisk() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( "sort_field('OTHERS[].*.dnimals[]')" @@ -2558,7 +2557,6 @@ public void shouldSplitHashField() { } @Test - @MetafixToDo("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', '--')" @@ -2607,7 +2605,6 @@ public void shouldSumNumbers() { } @Test - @MetafixToDo("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[]')" diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java index 6f783b4d..643859a9 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java @@ -1685,6 +1685,39 @@ public void setArrayReplaceExisting() { }); } + @Test + // See https://github.com/metafacture/metafacture-fix/issues/130 + public void setArrayInArrayWithAsterisk() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "set_array('foo[].*.test[]', 'test')"), + i -> { + i.startRecord("1"); + i.startEntity("foo[]"); + i.startEntity("1"); + i.literal("id", "A"); + i.endEntity(); + i.startEntity("2"); + i.literal("id", "B"); + i.endEntity(); + i.endEntity(); + i.endRecord(); + }, (o, f) -> { + o.get().startRecord("1"); + o.get().startEntity("foo[]"); + o.get().startEntity("1"); + o.get().literal("id", "A"); + o.get().startEntity("test[]"); + o.get().literal("1", "test"); + f.apply(2).endEntity(); + o.get().startEntity("2"); + o.get().literal("id", "B"); + o.get().startEntity("test[]"); + o.get().literal("1", "test"); + f.apply(3).endEntity(); + o.get().endRecord(); + }); + } + @Test public void setHash() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( diff --git a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/add_fieldAsteriskIntoArrayOfObjects/todo.txt b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/add_fieldAsteriskIntoArrayOfObjects/todo.txt deleted file mode 100644 index 26adbe67..00000000 --- a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/add_fieldAsteriskIntoArrayOfObjects/todo.txt +++ /dev/null @@ -1 +0,0 @@ -See issue #156 and #121 diff --git a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldArrayOfObjectsAsRepeatedObjectAndThenArrayOfStringsIntoTheArrayOfObjectsWithLastWildcard/todo.txt b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldArrayOfObjectsAsRepeatedObjectAndThenArrayOfStringsIntoTheArrayOfObjectsWithLastWildcard/todo.txt index b19226bb..9b87121b 100644 --- a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldArrayOfObjectsAsRepeatedObjectAndThenArrayOfStringsIntoTheArrayOfObjectsWithLastWildcard/todo.txt +++ b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldArrayOfObjectsAsRepeatedObjectAndThenArrayOfStringsIntoTheArrayOfObjectsWithLastWildcard/todo.txt @@ -1 +1 @@ -See issue #132 may also be related to #113 +See issue #132 diff --git a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldArrayOfStringsIntoArrayOfObjectsWithAsteriskWildcard/todo.txt b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldArrayOfStringsIntoArrayOfObjectsWithAsteriskWildcard/todo.txt deleted file mode 100644 index 0b9661d2..00000000 --- a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldArrayOfStringsIntoArrayOfObjectsWithAsteriskWildcard/todo.txt +++ /dev/null @@ -1 +0,0 @@ -See issue #121 diff --git a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldAsteriskIntoArrayOfObjects/todo.txt b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldAsteriskIntoArrayOfObjects/todo.txt deleted file mode 100644 index 5d692bde..00000000 --- a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldAsteriskIntoArrayOfObjects/todo.txt +++ /dev/null @@ -1 +0,0 @@ -See issue #156 diff --git a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/move_fieldAsteriskIntoArrayOfObjects/todo.txt b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/move_fieldAsteriskIntoArrayOfObjects/todo.txt deleted file mode 100644 index 5d692bde..00000000 --- a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/move_fieldAsteriskIntoArrayOfObjects/todo.txt +++ /dev/null @@ -1 +0,0 @@ -See issue #156 diff --git a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/set_arrayIntoArrayOfObjectsWithAsterisk/todo.txt b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/set_arrayIntoArrayOfObjectsWithAsterisk/todo.txt deleted file mode 100644 index c8097c36..00000000 --- a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/set_arrayIntoArrayOfObjectsWithAsterisk/todo.txt +++ /dev/null @@ -1 +0,0 @@ -See issue #113, #130 and #156 From 03e7360bddb111b71bbfbb166a2626f683defd2f Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Thu, 5 May 2022 10:55:40 +0200 Subject: [PATCH 3/5] Add failing unit test, tweak releated existing test (#113) --- .../metafix/MetafixRecordTest.java | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java index 643859a9..515ffe22 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java @@ -676,7 +676,7 @@ public void appendWithAsteriksWildcardAtTheEnd() { } @Test - // See https://github.com/metafacture/metafacture-fix/pull/142 + @MetafixToDo("See https://github.com/metafacture/metafacture-fix/pull/113") public void shouldCopyArrayFieldWithoutAsterisk() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( "set_array('TEST_TWO[]')", @@ -691,7 +691,7 @@ public void shouldCopyArrayFieldWithoutAsterisk() { i.endEntity(); i.endRecord(); }, - o -> { + (o, f) -> { o.get().startRecord("1"); o.get().startEntity("test[]"); o.get().literal("1", "One"); @@ -699,15 +699,43 @@ public void shouldCopyArrayFieldWithoutAsterisk() { o.get().literal("3", "Three"); o.get().endEntity(); o.get().startEntity("TEST_TWO[]"); + o.get().startEntity("1"); o.get().literal("1", "One"); o.get().literal("2", "Two"); o.get().literal("3", "Three"); - o.get().endEntity(); + f.apply(2).endEntity(); o.get().endRecord(); } ); } + @Test + @MetafixToDo("See https://github.com/metafacture/metafacture-fix/issues/113") + public void copyFieldArrayOfObjectsAndListNewArrayOfObjectsAndMoveSubfield() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "copy_field('author[]','creator[]')", + "do list(path:'creator[]')", + " move_field('name','label')", + "end", + "retain('creator[]')"), + i -> { + i.startRecord("1"); + i.startEntity("author[]"); + i.startEntity("1"); + i.literal("name", "A University"); + i.endEntity(); + i.endEntity(); + i.endRecord(); + }, (o, f) -> { + o.get().startRecord("1"); + o.get().startEntity("creator[]"); + o.get().startEntity("1"); + o.get().literal("label", "A University"); + f.apply(2).endEntity(); + o.get().endRecord(); + }); + } + @Test // See https://github.com/metafacture/metafacture-fix/issues/121 public void shouldCopyArrayFieldWithAsterisk() { From 57ac8421b365290980aa4b347c6ef92aff617909 Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Thu, 5 May 2022 14:58:29 +0200 Subject: [PATCH 4/5] Fix issue in unit test for #121 --- .../test/java/org/metafacture/metafix/MetafixRecordTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java index 515ffe22..7c168c9b 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java @@ -1127,7 +1127,6 @@ private void assertThrowsOnEmptyRecord(final String index) { } @Test - @MetafixToDo("See https://github.com/metafacture/metafacture-fix/issues/121") public void shouldAddArraySubFieldWithAsterisk() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( "add_field('coll[].*.c', 'test')" @@ -1172,7 +1171,7 @@ public void shouldAddArraySubFieldWithAsterisk() { o.get().startEntity("4"); o.get().literal("a", "Crocodile"); o.get().literal("c", "test"); - f.apply(3).endEntity(); + f.apply(2).endEntity(); o.get().endRecord(); } ); From c557c16d0abd85c0f9452165fbeeb6e939e0cd8f Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Thu, 5 May 2022 17:41:25 +0200 Subject: [PATCH 5/5] Reuse former `processRef` in `insertInto` methods (#92, #171, #205) Fix issue with testing non-existing refs, update tests --- .../java/org/metafacture/metafix/FixPath.java | 58 +++++++------------ .../metafix/MetafixMethodTest.java | 57 ++++++++++++++++-- .../metafix/MetafixRecordTest.java | 10 ++-- .../test.fix | 4 +- .../todo.txt | 1 - .../add_fieldSimpleSubsubfield/todo.txt | 1 - .../todo.txt | 1 - .../todo.txt | 1 - .../test.fix | 2 +- .../test.fix | 2 +- 10 files changed, 84 insertions(+), 53 deletions(-) delete mode 100644 metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/add_fieldIntoArrayOfObjectsWithLastWildcard/todo.txt delete mode 100644 metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/add_fieldSimpleSubsubfield/todo.txt delete mode 100644 metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldObjectFromArrayOfObjectsWithFirstWildcard/todo.txt delete mode 100644 metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldObjectFromArrayOfObjectsWithLastWildcard/todo.txt diff --git a/metafix/src/main/java/org/metafacture/metafix/FixPath.java b/metafix/src/main/java/org/metafacture/metafix/FixPath.java index 5dee05f5..60c6a90b 100644 --- a/metafix/src/main/java/org/metafacture/metafix/FixPath.java +++ b/metafix/src/main/java/org/metafacture/metafix/FixPath.java @@ -102,7 +102,7 @@ else if (isReference(currentSegment)) { private Value findInValue(final Value value, final String[] p) { // TODO: move impl into enum elements, here call only value.find - return value == null ? null : value.extractType((m, c) -> m + return p.length == 0 ? value : value == null ? null : value.extractType((m, c) -> m .ifArray(a -> c.accept(new FixPath(p).findIn(a))) .ifHash(h -> c.accept(new FixPath(p).findIn(h))) .orElse(c) @@ -249,20 +249,15 @@ private void removeNestedFrom(final Value value) { /*package-private*/ private Value insertInto(final Array array, final InsertMode mode, final Value newValue) { // basic idea: reuse findIn logic here? setIn(findIn(array), newValue) final String field = path[0]; - if (field.equals(ASTERISK)) { - array.forEach(value -> value.matchType() - .ifArray(a -> new FixPath(tail(path)).insertInto(a, mode, newValue)) - .ifHash(h -> new FixPath(tail(path)).insertInto(h, mode, newValue)) - .orElseThrow()); + if (path.length == 1) { + mode.apply(array, field, newValue); } else { - if (path.length == 1) { - mode.apply(array, field, newValue); + if (ASTERISK.equals(field)) { + array.forEach(value -> insertInto(value, mode, newValue, field, tail(path))); } - else { - if (isReference(field)) { - return processRef(getReferencedValue(array, field), mode, newValue, field, tail(path)); - } + else if (isReference(field)) { + insertInto(getReferencedValue(array, field), mode, newValue, field, tail(path)); } } return new Value(array); @@ -275,45 +270,34 @@ private void removeNestedFrom(final Value value) { mode.apply(hash, field, newValue); } else { - final String[] tail = tail(path); - if (isReference(field)) { - return processRef(hash.get(field), mode, newValue, field, tail); - } if (!hash.containsField(field)) { hash.put(field, Value.newHash()); } - final Value value = hash.get(field); - if (value != null) { - // TODO: move impl into enum elements, here call only value.insert - value.matchType() - .ifArray(a -> new FixPath(tail).insertInto(a, mode, newValue)) - .ifHash(h -> new FixPath(tail).insertInto(h, mode, newValue)) - .orElseThrow(); - } + insertInto(hash.get(field), mode, newValue, field, tail(path)); } return new Value(hash); } - private String[] tail(final String[] fields) { - return Arrays.copyOfRange(fields, 1, fields.length); - } - - private Value processRef(final Value referencedValue, final InsertMode mode, final Value newValue, final String field, + private Value insertInto(final Value value, final InsertMode mode, final Value newValue, final String field, final String[] tail) { - if (referencedValue != null) { + if (value != null) { final FixPath fixPath = new FixPath(tail); - newValue.updatePathAddBase(referencedValue, field); - return referencedValue.extractType((m, c) -> m - .ifArray(a -> c.accept(fixPath.insertInto(referencedValue.asArray(), mode, newValue))) - .ifHash(h -> c.accept(fixPath.insertInto(referencedValue.asHash(), mode, newValue))) + newValue.updatePathAddBase(value, field); + return value.extractType((m, c) -> m + .ifArray(a -> c.accept(fixPath.insertInto(a, mode, newValue))) + .ifHash(h -> c.accept(fixPath.insertInto(h, mode, newValue))) .orElseThrow()); } else { - throw new IllegalArgumentException("Using ref, but can't find: " + field + " in: " + referencedValue); + throw new IllegalArgumentException("Using ref, but can't find: " + field + " in: " + value); } } + private String[] tail(final String[] fields) { + return Arrays.copyOfRange(fields, 1, fields.length); + } + private enum ReservedField { $append, $first, $last; @@ -344,10 +328,10 @@ private Value getReferencedValue(final Array array, final String field) { if (reservedField != null) { switch (reservedField) { case $first: - referencedValue = array.get(0); + referencedValue = getReferencedValue(array, "1"); break; case $last: - referencedValue = array.get(array.size() - 1); + referencedValue = getReferencedValue(array, String.valueOf(array.size())); break; case $append: referencedValue = Value.newHash(); // TODO: append non-hash? diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java index 01404d0c..0b7036e0 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java @@ -1844,10 +1844,34 @@ public void copyFieldToSubfieldOfArrayOfObjectsWithIndexExplicitAppend() { } @Test - @MetafixToDo("See https://github.com/metafacture/metafacture-fix/pull/205") - public void addFieldIntoArrayOfObjectsWithLastWildcardImplicitSkip() { + // We currently fail on unresolved references, see MetafixRecordTests#assertThrowsOnEmptyArray + public void addFieldIntoArrayOfObjectsWithLastWildcardMissingError() { + MetafixTestHelpers.assertProcessException(IllegalArgumentException.class, "Using ref, but can't find: $last in: null", () -> { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "add_field('animals[].$last.key', 'value')" + ), + i -> { + i.startRecord("1"); + i.startEntity("animals[]"); + i.endEntity(); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + o.get().startEntity("animals[]"); + o.get().endEntity(); + o.get().endRecord(); + } + ); + }); + } + + @Test + public void addFieldIntoArrayOfObjectsWithLastWildcardAllEmpty() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "add_field('animals[].$last.key', 'value')" + "if exists('animals[].$last')", + " add_field('animals[].$last.key', 'value')", + "end" ), i -> { i.startRecord("1"); @@ -1865,8 +1889,7 @@ public void addFieldIntoArrayOfObjectsWithLastWildcardImplicitSkip() { } @Test - @MetafixToDo("See https://github.com/metafacture/metafacture-fix/pull/205") - public void addFieldIntoArrayOfObjectsWithLastWildcardExplicitSkip() { + public void addFieldIntoArrayOfObjectsWithLastWildcardLastEmpty() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( "if exists('animals[].$last')", " add_field('animals[].$last.key', 'value')", @@ -1875,12 +1898,36 @@ public void addFieldIntoArrayOfObjectsWithLastWildcardExplicitSkip() { i -> { i.startRecord("1"); i.startEntity("animals[]"); + i.startEntity("1"); + i.literal("name", "Jake"); + i.literal("type", "dog"); + i.endEntity(); + i.startEntity("2"); + i.literal("name", "Blacky"); + i.literal("type", "bird"); + i.endEntity(); + i.endEntity(); + i.endRecord(); + i.startRecord("2"); + i.startEntity("animals[]"); 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("type", "dog"); + o.get().endEntity(); + o.get().startEntity("2"); + o.get().literal("name", "Blacky"); + o.get().literal("type", "bird"); + o.get().literal("key", "value"); + f.apply(2).endEntity(); + o.get().endRecord(); + o.get().startRecord("2"); + o.get().startEntity("animals[]"); o.get().endEntity(); o.get().endRecord(); } diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java index 7c168c9b..3e78836b 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java @@ -1098,26 +1098,28 @@ public void addFieldToObjectByIndexInIndexedArray() { @Test public void addFieldToFirstObjectMissing() { - assertThrowsOnEmptyRecord("$first"); + assertThrowsOnEmptyArray("$first"); } @Test public void addFieldToLastObjectMissing() { - assertThrowsOnEmptyRecord("$last"); + assertThrowsOnEmptyArray("$last"); } @Test public void addFieldToObjectByIndexMissing() { - assertThrowsOnEmptyRecord("2"); + assertThrowsOnEmptyArray("2"); } - private void assertThrowsOnEmptyRecord(final String index) { + private void assertThrowsOnEmptyArray(final String index) { MetafixTestHelpers.assertProcessException(IllegalArgumentException.class, "Using ref, but can't find: " + index + " in: null", () -> { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( "add_field('animals[]." + index + ".kind','nice')" ), i -> { i.startRecord("1"); + i.startEntity("animals[]"); + i.endEntity(); i.endRecord(); }, o -> { diff --git a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/add_fieldIntoArrayOfObjectsWithLastWildcard/test.fix b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/add_fieldIntoArrayOfObjectsWithLastWildcard/test.fix index ca7943f9..44cfd14c 100644 --- a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/add_fieldIntoArrayOfObjectsWithLastWildcard/test.fix +++ b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/add_fieldIntoArrayOfObjectsWithLastWildcard/test.fix @@ -1 +1,3 @@ -add_field("animals[].$last.key", "value") +if exists("animals[].$last") + add_field("animals[].$last.key", "value") +end diff --git a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/add_fieldIntoArrayOfObjectsWithLastWildcard/todo.txt b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/add_fieldIntoArrayOfObjectsWithLastWildcard/todo.txt deleted file mode 100644 index 0d3f4274..00000000 --- a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/add_fieldIntoArrayOfObjectsWithLastWildcard/todo.txt +++ /dev/null @@ -1 +0,0 @@ -See PR #205. diff --git a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/add_fieldSimpleSubsubfield/todo.txt b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/add_fieldSimpleSubsubfield/todo.txt deleted file mode 100644 index 289b8cb3..00000000 --- a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/add_fieldSimpleSubsubfield/todo.txt +++ /dev/null @@ -1 +0,0 @@ -See issue #171 diff --git a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldObjectFromArrayOfObjectsWithFirstWildcard/todo.txt b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldObjectFromArrayOfObjectsWithFirstWildcard/todo.txt deleted file mode 100644 index 2f4b8670..00000000 --- a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldObjectFromArrayOfObjectsWithFirstWildcard/todo.txt +++ /dev/null @@ -1 +0,0 @@ -See issue #92 diff --git a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldObjectFromArrayOfObjectsWithLastWildcard/todo.txt b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldObjectFromArrayOfObjectsWithLastWildcard/todo.txt deleted file mode 100644 index 2f4b8670..00000000 --- a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldObjectFromArrayOfObjectsWithLastWildcard/todo.txt +++ /dev/null @@ -1 +0,0 @@ -See issue #92 diff --git a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldPrependObjectToArrayOfObjects/test.fix b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldPrependObjectToArrayOfObjects/test.fix index dc7b29ca..cf2c5df0 100644 --- a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldPrependObjectToArrayOfObjects/test.fix +++ b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/copy_fieldPrependObjectToArrayOfObjects/test.fix @@ -1 +1 @@ -copy_field("test_2", "test[].$append") +copy_field("test_2", "test[].$prepend") diff --git a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/move_fieldPrependObjectToArrayOfObjects/test.fix b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/move_fieldPrependObjectToArrayOfObjects/test.fix index dc7b29ca..cf2c5df0 100644 --- a/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/move_fieldPrependObjectToArrayOfObjects/test.fix +++ b/metafix/src/test/resources/org/metafacture/metafix/integration/record/fromJson/toJson/move_fieldPrependObjectToArrayOfObjects/test.fix @@ -1 +1 @@ -copy_field("test_2", "test[].$append") +copy_field("test_2", "test[].$prepend")