public void testMapping() throws FailException {
FrameAddressResolver far = new FrameAddressResolver();
Sequence tested = createMappingTestSequence1(far);
List<Record> localCloneQueue = new ArrayList<>();
Record record = new RecordImpl();
record.add(new Field("a", "a1"));
Kernel kernel = new Kernel(tested, far, localCloneQueue);
try {
kernel.process(record);
} catch (FailException | FilterException e) {
fail();
}
// record out test
assertTrue("Check field exist: a", record.has("a"));
assertEquals("Check field value: a", "b2", record.get("a").getValue());
assertTrue("Check field exist: c", record.has("c"));
assertEquals("Check field value: c", "ok", record.get("c").getValue());
assertTrue("Check that another field isn't exist.", record.getFields().size() == 2);
// test clone1:
Record clone1 = localCloneQueue.get(1);
assertTrue("Check field exist: b", clone1.has("b"));
assertEquals("Check field value: b", "b3", clone1.get("b").getValue());
assertTrue("Check field exist: f", clone1.has("f"));
assertEquals("Check field value: f", "ok", clone1.get("f").getValue());
assertTrue("Check field exist: a", clone1.has("a"));
assertEquals("Check field value: a", "error", clone1.get("a").getValue());
assertTrue("Check that another field isn't exist.", clone1.getFields().size() == 3);
// test clone1 parent
Record parent1 = ((MappedRecord)clone1).getParent();
assertTrue("Check field exist: a", parent1.has("a"));
assertEquals("Check field value: a", "a1", parent1.get("a").getValue());
assertTrue("Check that another field isn't exist.", parent1.getFields().size() == 1);
// test clone2:
Record clone2 = localCloneQueue.get(0);
assertTrue("Check field exist: b", clone2.has("b"));
assertEquals("Check field value: b", "error", clone2.get("b").getValue());
assertTrue("Check field exist: c", clone2.has("c"));
assertEquals("Check field value: c", "ok", clone2.get("c").getValue());
assertTrue("Check field exist: a", clone2.has("a"));
assertEquals("Check field value: a", "error", clone2.get("a").getValue());
assertTrue("Check field exist: d", clone2.has("d"));
assertEquals("Check field value: d", "b2", clone2.get("d").getValue());
assertTrue("Check field exist: e", clone2.has("e"));
assertEquals("Check field value: e", "b2", clone2.get("e").getValue());
assertTrue("Check that another field isn't exist.", clone2.getFields().size() == 5);
// test clone2 parent
Record parent2 = ((MappedRecord)clone2).getParent();
assertTrue("Check field exist: b", parent2.has("b"));
assertEquals("Check field value: b", "b1", parent2.get("b").getValue());
assertTrue("Check that another field isn't exist.", parent2.getFields().size() == 1);
// test clone2 parent's parent
Record parent3 = ((MappedRecord)parent2).getParent();
assertTrue("Check field exist: a", parent3.has("a"));
assertEquals("Check field value: a", "a1", parent3.get("a").getValue());
assertTrue("Check that another field isn't exist.", parent3.getFields().size() == 1);
// test clone2 out
try {
kernel.process(clone2);
// Beacause the cloned records
if (clone2 instanceof MappedRecord) {
record = ((MappedRecord) clone2).getAncestor();
}
} catch (FailException | FilterException e) {
fail();
}
assertTrue("Check field exist: a", record.has("a"));
assertEquals("Check field value: a", "b2", record.get("a").getValue());
assertTrue("Check field exist: c", record.has("c"));
assertEquals("Check field value: c", "ok", record.get("c").getValue());
assertTrue("Check that another field isn't exist.", record.getFields().size() == 2);
// test clone1 out
try {
kernel.process(clone1);
// Beacause the cloned records
if (clone1 instanceof MappedRecord) {
record = ((MappedRecord) clone1).getAncestor();
}
} catch (FailException | FilterException e) {
fail();
}
assertTrue("Check field exist: a", record.has("a"));
assertEquals("Check field value: a", "b3", record.get("a").getValue());
assertTrue("Check field exist: c", record.has("c"));
assertEquals("Check field value: c", "ok", record.get("c").getValue());
assertTrue("Check that another field isn't exist.", record.getFields().size() == 2);
// test clone2 cloned record cloned by clone1 record out
Record clone3 = localCloneQueue.get(2);
try {
kernel.process(clone3);
// Beacause the cloned records
if (clone3 instanceof MappedRecord) {
record = ((MappedRecord) clone3).getAncestor();
}
} catch (FailException | FilterException e) {
fail();
}
assertTrue("Check field exist: a", record.has("a"));
assertEquals("Check field value: a", "b3", record.get("a").getValue());
assertTrue("Check field exist: c", record.has("c"));
assertEquals("Check field value: c", "ok", record.get("c").getValue());
assertTrue("Check that another field isn't exist.", record.getFields().size() == 2);
}