assertEquals(3, countResults(repository.getScanner(scan)));
}
@Test
public void testFilterList() throws Exception {
FieldType f1 = typeManager.createFieldType("STRING", new QName("FilterList", "field1"), Scope.NON_VERSIONED);
FieldType f2 = typeManager.createFieldType("STRING", new QName("FilterList", "field2"), Scope.NON_VERSIONED);
RecordType rt = typeManager.recordTypeBuilder().defaultNamespace("FilterList").name("rt")
.fieldEntry().use(f1).add().fieldEntry().use(f2).add().create();
repository.recordBuilder()
.recordType(rt.getName())
.field(f1.getName(), "A")
.field(f2.getName(), "B")
.create();
repository.recordBuilder()
.recordType(rt.getName())
.field(f1.getName(), "A")
.field(f2.getName(), "C")
.create();
repository.recordBuilder()
.recordType(rt.getName())
.field(f1.getName(), "D")
.field(f2.getName(), "B")
.create();
repository.recordBuilder()
.recordType(rt.getName())
.field(f1.getName(), "F")
.create();
// Test f1=A and f2=B
RecordScan scan = new RecordScan();
RecordFilterList filterList = new RecordFilterList();
filterList.addFilter(new FieldValueFilter(f1.getName(), "A"));
filterList.addFilter(new FieldValueFilter(f2.getName(), "B"));
scan.setRecordFilter(filterList);
assertEquals(1, countResults(repository.getScanner(scan)));
// Test f1=A or f2=B
scan = new RecordScan();
filterList = new RecordFilterList(RecordFilterList.Operator.MUST_PASS_ONE);
filterList.addFilter(new FieldValueFilter(f1.getName(), "A"));
filterList.addFilter(new FieldValueFilter(f2.getName(), "B"));
scan.setRecordFilter(filterList);
assertEquals(3, countResults(repository.getScanner(scan)));
// Test f1=A and (f2=B or f2=C)
scan = new RecordScan();
RecordFilterList filterList2 = new RecordFilterList(RecordFilterList.Operator.MUST_PASS_ONE);
filterList2.addFilter(new FieldValueFilter(f2.getName(), "B"));
filterList2.addFilter(new FieldValueFilter(f2.getName(), "C"));
filterList = new RecordFilterList();
filterList.addFilter(new FieldValueFilter(f1.getName(), "A"));
filterList.addFilter(filterList2);
scan.setRecordFilter(filterList);
assertEquals(2, countResults(repository.getScanner(scan)));
// Test f1=F and f2=Z
scan = new RecordScan();
filterList = new RecordFilterList();
filterList.addFilter(new FieldValueFilter(f1.getName(), "F"));
filterList.addFilter(new FieldValueFilter(f2.getName(), "Z"));
scan.setRecordFilter(filterList);
assertEquals(0, countResults(repository.getScanner(scan)));
// Test f1=F and (f2=Z with filterIfMissing=false)
scan = new RecordScan();
filterList = new RecordFilterList();
filterList.addFilter(new FieldValueFilter(f1.getName(), "F"));
FieldValueFilter fvf = new FieldValueFilter(f2.getName(), "Z");
fvf.setFilterIfMissing(false);
filterList.addFilter(fvf);
scan.setRecordFilter(filterList);
assertEquals(1, countResults(repository.getScanner(scan)));
}