UUIDMapper extends KeywordMapper { public UUIDMapper(String field, String column, Boolean validated) { super(field, column, validated, Arrays.asList(String.class, UUID.class)); } UUIDMapper(String field, String column, Boolean validated);   }
@Test public void testConstructorWithoutArgs() { UUIDMapper mapper = uuidMapper().build("field"); assertEquals("Field is not properly set", "field", mapper.field); assertEquals("Column is not set to default value", "field", mapper.column); assertEquals("Mapped columns are not properly set", 1, mapper.mappedColumns.size()); assertTrue("Mapped columns are not properly set", mapper.mappedColumns.contains("field")); }
@Test public void testConstructorWithAllArgs() { UUIDMapper mapper = uuidMapper().validated(true).column("column").build("field"); assertEquals("Field is not properly set", "field", mapper.field); assertEquals("Column is not properly set", "column", mapper.column); assertEquals("Mapped columns are not properly set", 1, mapper.mappedColumns.size()); assertTrue("Mapped columns are not properly set", mapper.mappedColumns.contains("column")); }
@Test public void testJsonSerialization() { UUIDMapperBuilder builder = uuidMapper().column("column"); testJson(builder, "{type:\"uuid\",column:\"column\"}"); }
@Test public void testJsonSerializationDefaults() { UUIDMapperBuilder builder = uuidMapper(); testJson(builder, "{type:\"uuid\"}"); }
@Test public void testValueNull() { UUIDMapper mapper = uuidMapper().build("field"); assertNull("Base value must be null", mapper.base("test", null)); }
@Test public void testValueUUIDRandom() { UUIDMapper mapper = uuidMapper().build("field"); String parsed = mapper.base("test", "550e8400-e29b-41d4-a716-446655440000"); assertEquals("Base value is wrong", "04550e8400e29b41d4a716446655440000", parsed); }
@Test public void testValueUUIDTimeBased() { UUIDMapper mapper = uuidMapper().build("field"); String parsed = mapper.base("test", "c4c61dc4-89d7-11e4-b116-123b93f75cba"); assertEquals("Base value is wrong", "0101e489d7c4c61dc4c4c61dc489d711e4b116123b93f75cba", parsed); }
@Test public void testValueStringRandom() { UUIDMapper mapper = uuidMapper().build("field"); String parsed = mapper.base("test", "550e8400-e29b-41d4-a716-446655440000"); assertEquals("Base value is wrong", "04550e8400e29b41d4a716446655440000", parsed); }
@Test public void testValueStringTimeBased() { UUIDMapper mapper = uuidMapper().build("field"); String parsed = mapper.base("test", "c4c61dc4-89d7-11e4-b116-123b93f75cba"); assertEquals("Base value is wrong", "0101e489d7c4c61dc4c4c61dc489d711e4b116123b93f75cba", parsed); }
@Test(expected = IndexException.class) public void testValueStringInvalid() { UUIDMapper mapper = uuidMapper().build("field"); mapper.base("test", "550e840"); }
@Test(expected = IndexException.class) public void testValueInteger() { UUIDMapper mapper = uuidMapper().build("field"); String parsed = mapper.base("test", 3); assertEquals("Base value is wrong", "3", parsed); }
@Test(expected = IndexException.class) public void testValueLong() { UUIDMapper mapper = uuidMapper().build("field"); String parsed = mapper.base("test", 3l); assertEquals("Base value is wrong", "3", parsed); }
@Test(expected = IndexException.class) public void testValueFloat() { UUIDMapper mapper = uuidMapper().build("field"); String parsed = mapper.base("test", 3.6f); assertEquals("Base value is wrong", "3.6", parsed); }
@Test(expected = IndexException.class) public void testValueDouble() { UUIDMapper mapper = uuidMapper().build("field"); String parsed = mapper.base("test", 3d); assertEquals("Base value is wrong", "3.0", parsed); }
@Test public void testIndexedField() { UUIDMapper mapper = uuidMapper().build("field"); String base = mapper.base("name", "550e8400-e29b-41d4-a716-446655440000"); Field field = mapper.indexedField("name", base) .orElseThrow(() -> new AssertionError("Indexed field is not created")); assertEquals("Field name is wrong", "name", field.name()); assertEquals("Field value is wrong", base, field.stringValue()); assertFalse("Field type is wrong", field.fieldType().stored()); }
@Test public void testSortedField() { UUIDMapper mapper = uuidMapper().build("field"); String base = mapper.base("name", "550e8400-e29b-41d4-a716-446655440000"); Field field = mapper.sortedField("name", base) .orElseThrow(() -> new AssertionError("Sorted field is not created")); assertEquals("Doc values has wrong type", DocValuesType.SORTED_SET, field.fieldType().docValuesType()); }
@Test public void testExtractAnalyzers() { UUIDMapper mapper = uuidMapper().build("field"); String analyzer = mapper.analyzer; assertEquals("Analyzer type is wrong", Mapper.KEYWORD_ANALYZER, analyzer); }
@Test public void testCompareDifferentTypes() { UUIDMapper mapper = uuidMapper().build("field"); UUID uuidTimeBased = UUID.fromString("c4c61dc4-89d7-11e4-b116-123b93f75cba"); UUID uuidRandom = UUID.fromString("c4c61dc4-89d7-41e4-b116-123b93f75cba"); ByteBuffer bb1 = UUIDType.instance.decompose(uuidTimeBased); ByteBuffer bb2 = UUIDType.instance.decompose(uuidRandom); String s1 = mapper.base("uuidTimeBased", uuidTimeBased); String s2 = mapper.base("uuidRandom", uuidRandom); int nativeComparison = flatComparison(UUIDType.instance.compare(bb1, bb2)); int mapperComparison = flatComparison(s1.compareTo(s2)); assertEquals("Native and term comparisons are different", nativeComparison, mapperComparison); }
@Test public void testCompareTimeUUID() { UUIDMapper mapper = uuidMapper().build("field"); UUID uuid1 = UUID.fromString("d9b602c0-89d8-11e4-b116-123b93f75cba"); UUID uuid2 = UUID.fromString("d9b6ff0e-89d8-11e4-b116-123b93f75cba"); ByteBuffer bb1 = UUIDType.instance.decompose(uuid1); ByteBuffer bb2 = UUIDType.instance.decompose(uuid2); String s1 = mapper.base("uuid1", uuid1); String s2 = mapper.base("uuid2", uuid2); int nativeComparison = flatComparison(UUIDType.instance.compare(bb1, bb2)); int mapperComparison = flatComparison(s1.compareTo(s2)); assertEquals("Native and term comparisons are different", nativeComparison, mapperComparison); }
@Test public void testCompareRandomUUID() throws InterruptedException { UUIDMapper mapper = uuidMapper().build("field"); UUID uuid1 = UUID.fromString("5e9384d7-c72b-402a-aa13-2745f9b6b318"); UUID uuid2 = UUID.fromString("eddfdc0d-76ee-4a5c-a155-3e5dd16ce1ae"); ByteBuffer bb1 = UUIDType.instance.decompose(uuid1); ByteBuffer bb2 = UUIDType.instance.decompose(uuid2); String s1 = mapper.base("uuid1", uuid1); String s2 = mapper.base("uuid2", uuid2); int nativeComparison = flatComparison(UUIDType.instance.compare(bb1, bb2)); int mapperComparison = flatComparison(s1.compareTo(s2)); assertEquals("Native and term comparisons are different", nativeComparison, mapperComparison); }
@Test public void testToString() { UUIDMapper mapper = uuidMapper().validated(true).build("field"); assertEquals("Method toString is wrong", "UUIDMapper{field=field, validated=true, column=field}", mapper.toString()); }