Skip to content
This repository has been archived by the owner on Jan 27, 2025. It is now read-only.

Commit

Permalink
Add unit tests for new integration test from cb4f27e (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg committed Apr 1, 2022
1 parent cb4f27e commit 1d495ab
Showing 1 changed file with 111 additions and 0 deletions.
111 changes: 111 additions & 0 deletions metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,117 @@ public void shouldNotInsertOptionalRepeatedHashSubFieldWithAsteriskInReplaceAll(
);
}

@Test
public void replaceAllInOptionalSubfieldInArrayOfObjectsWithAsterisk() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"replace_all('RSWK[].*.subjectGenre', '[.]$', '')"
),
i -> {
i.startRecord("1");
i.startEntity("RSWK[]");
i.startEntity("1");
i.literal("subjectTopicName", "Nonprofit organizations");
i.endEntity();
i.startEntity("2");
i.literal("subjectTopicName", "Nonprofit organizations");
i.literal("subjectGenre", "Case studies.");
i.endEntity();
i.endEntity();
i.endRecord();
},
(o, f) -> {
o.get().startRecord("1");
o.get().startEntity("RSWK[]");
o.get().startEntity("1");
o.get().literal("subjectTopicName", "Nonprofit organizations");
o.get().endEntity();
o.get().startEntity("2");
o.get().literal("subjectTopicName", "Nonprofit organizations");
o.get().literal("subjectGenre", "Case studies");
f.apply(2).endEntity();
o.get().endRecord();
}
);
}

@Test
public void inDoBindCopyFieldWithVarInSourceAndTarget() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"set_array('RSWK[]')",
"do list(path: '650??', 'var': '$i')",
" copy_field('$i.a', 'RSWK[].$append.subjectTopicName')",
" copy_field('$i.v', 'RSWK[].$last.subjectGenre')",
"end",
"retain('RSWK[]')"
),
i -> {
i.startRecord("1");
i.startEntity("650 ");
i.literal("a", "Nonprofit organizations");
i.literal("x", "Management.");
i.endEntity();
i.startEntity("650 ");
i.literal("a", "Nonprofit organizations");
i.literal("x", "Management");
i.literal("v", "Case studies.");
i.endEntity();
i.endRecord();
},
(o, f) -> {
o.get().startRecord("1");
o.get().startEntity("RSWK[]");
o.get().startEntity("1");
o.get().literal("subjectTopicName", "Nonprofit organizations");
o.get().endEntity();
o.get().startEntity("2");
o.get().literal("subjectTopicName", "Nonprofit organizations");
o.get().literal("subjectGenre", "Case studies.");
f.apply(2).endEntity();
o.get().endRecord();
}
);
}

@Test
@MetafixToDo("See https://github.com/metafacture/metafacture-fix/pull/170")
public void replaceAllWithWildcardAfterCopyFieldWithVarInSourceAndTarget() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"set_array('RSWK[]')",
"do list(path: '650??', 'var': '$i')",
" copy_field('$i.a', 'RSWK[].$append.subjectTopicName')",
" copy_field('$i.v', 'RSWK[].$last.subjectGenre')",
"end",
"replace_all('RSWK[].*.subjectGenre', '[.]$', '')",
"retain('RSWK[]')"
),
i -> {
i.startRecord("1");
i.startEntity("650 ");
i.literal("a", "Nonprofit organizations");
i.literal("x", "Management.");
i.endEntity();
i.startEntity("650 ");
i.literal("a", "Nonprofit organizations");
i.literal("x", "Management");
i.literal("v", "Case studies.");
i.endEntity();
i.endRecord();
},
(o, f) -> {
o.get().startRecord("1");
o.get().startEntity("RSWK[]");
o.get().startEntity("1");
o.get().literal("subjectTopicName", "Nonprofit organizations");
o.get().endEntity();
o.get().startEntity("2");
o.get().literal("subjectTopicName", "Nonprofit organizations");
o.get().literal("subjectGenre", "Case studies");
f.apply(2).endEntity();
o.get().endRecord();
}
);
}

@Test
@MetafixToDo("See https://github.com/metafacture/metafacture-fix/pull/170")
public void copyFieldToSubfieldOfArrayOfObjectsWithIndexImplicitAppend() {
Expand Down

0 comments on commit 1d495ab

Please sign in to comment.