public void testVariantScansWithKeysUUID() throws Exception {
doTestVariantScansWithKeys(idGenerator.newRecordId());
}
private void doTestVariantScansWithKeys(RecordId master) throws Exception {
final RecordId variant = idGenerator.newRecordId(master, ImmutableMap.of("key1", "value1", "key2", "value2"));
final RecordId variantWithOtherValues =
idGenerator.newRecordId(master, ImmutableMap.of("key1", "other-value-1", "key2", "other-value-2"));
final RecordId extendedVariant =
idGenerator.newRecordId(master, ImmutableMap.of("key1", "value1", "key2", "value2", "key3", "value3"));
repository.recordBuilder()
.id(master)
.recordType(recordType1.getName())
.field(fieldType1.getName(), "foo")
.create();
repository.recordBuilder()
.id(variant)
.recordType(recordType1.getName())
.field(fieldType1.getName(), "foo")
.create();
repository.recordBuilder()
.id(extendedVariant)
.recordType(recordType1.getName())
.field(fieldType1.getName(), "foo")
.create();
repository.recordBuilder()
.id(variantWithOtherValues)
.recordType(recordType1.getName())
.field(fieldType1.getName(), "foo")
.create();
{
// master scan
final RecordScan scan = new RecordScan();
scan.setRecordFilter(new RecordVariantFilter(master, new HashMap<String, String>()));
RecordScanner scanner = repository.getScanner(scan);
assertEquals(master, scanner.next().getId());
assertNull(scanner.next());
scanner.close();
}
{
// variant scan
final HashMap<String, String> variantProperties = new HashMap<String, String>();
variantProperties.put("foo", null);
variantProperties.put("bar", null);
final RecordScan scan = new RecordScan();
scan.setRecordFilter(new RecordVariantFilter(variant.getMaster(), variantProperties));
RecordScanner scanner = repository.getScanner(scan);
assertNull(scanner.next()); // it doesn't match anything
scanner.close();
}
{
// variant scan for something completely different
final HashMap<String, String> variantProperties = new HashMap<String, String>();
variantProperties.put("key1", null);
variantProperties.put("key2", null);
final RecordScan scan = new RecordScan();
scan.setRecordFilter(new RecordVariantFilter(variant.getMaster(), variantProperties));
RecordScanner scanner = repository.getScanner(scan);
assertEquals(variant, scanner.next().getId());
assertEquals(variantWithOtherValues, scanner.next().getId());
assertNull(scanner.next()); // it doesn't match the extendedVariant!
scanner.close();
}
{
// extended variant scan
final HashMap<String, String> variantProperties = new HashMap<String, String>();
variantProperties.put("key1", null);
variantProperties.put("key2", null);
variantProperties.put("key3", null);
final RecordScan scan = new RecordScan();
scan.setRecordFilter(
new RecordVariantFilter(extendedVariant.getMaster(), variantProperties));
RecordScanner scanner = repository.getScanner(scan);
assertEquals(extendedVariant, scanner.next().getId());
assertNull(scanner.next());
scanner.close();
}