Search in sources :

Example 1 with FieldMapping

use of org.molgenis.data.elasticsearch.generator.model.FieldMapping in project molgenis by molgenis.

the class MappingGeneratorTest method testCreateMappingProviderNested.

@Test(dataProvider = "createMappingProviderNested")
public void testCreateMappingProviderNested(AttributeType attributeType) {
    String refAttrIdentifier = "refAttr";
    EntityType refEntityType = createEntityType(refAttrIdentifier, AttributeType.LONG);
    String attrIdentifier = "attr";
    EntityType entityType = createEntityType(attrIdentifier, attributeType, refEntityType);
    Mapping mapping = mappingGenerator.createMapping(entityType);
    FieldMapping fieldMapping = FieldMapping.builder().setName(attrIdentifier).setType(MappingType.NESTED).setNestedFieldMappings(singletonList(FieldMapping.builder().setName(refAttrIdentifier).setType(MappingType.LONG).build())).build();
    Mapping expectedMapping = createMapping(fieldMapping);
    assertEquals(mapping, expectedMapping);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) Mapping(org.molgenis.data.elasticsearch.generator.model.Mapping) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 2 with FieldMapping

use of org.molgenis.data.elasticsearch.generator.model.FieldMapping in project molgenis by molgenis.

the class MappingGeneratorTest method testCreateMappingProviderDepth.

@Test(dataProvider = "createMappingProviderDepth")
public void testCreateMappingProviderDepth(EntityType entityType, FieldMapping fieldMapping) {
    Mapping mapping = mappingGenerator.createMapping(entityType);
    Mapping expectedMapping = createMapping(fieldMapping);
    assertEquals(mapping, expectedMapping);
}
Also used : Mapping(org.molgenis.data.elasticsearch.generator.model.Mapping) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 3 with FieldMapping

use of org.molgenis.data.elasticsearch.generator.model.FieldMapping in project molgenis by molgenis.

the class MappingGenerator method createFieldMapping.

private FieldMapping createFieldMapping(Attribute attribute, int depth, int maxDepth) {
    String fieldName = documentIdGenerator.generateId(attribute);
    MappingType mappingType = toMappingType(attribute, depth, maxDepth);
    List<FieldMapping> nestedFieldMappings = mappingType == MappingType.NESTED ? createFieldMappings(attribute.getRefEntity(), depth + 1, maxDepth) : null;
    return FieldMapping.create(fieldName, mappingType, nestedFieldMappings);
}
Also used : MappingType(org.molgenis.data.elasticsearch.generator.model.MappingType) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping)

Example 4 with FieldMapping

use of org.molgenis.data.elasticsearch.generator.model.FieldMapping in project molgenis by molgenis.

the class MappingContentBuilderTest method testCreateMappingNested.

@Test
public void testCreateMappingNested() throws IOException {
    FieldMapping nestedFieldMapping = FieldMapping.builder().setName("nestedField").setType(MappingType.BOOLEAN).build();
    Mapping mapping = createMapping(FieldMapping.builder().setName("field").setType(MappingType.NESTED).setNestedFieldMappings(singletonList(nestedFieldMapping)).build());
    XContentBuilder xContentBuilder = mappingContentBuilder.createMapping(mapping);
    assertEquals(xContentBuilder.string(), JSON_NESTED);
}
Also used : FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) Mapping(org.molgenis.data.elasticsearch.generator.model.Mapping) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.testng.annotations.Test)

Example 5 with FieldMapping

use of org.molgenis.data.elasticsearch.generator.model.FieldMapping in project molgenis by molgenis.

the class MappingGeneratorTest method testCreateMapping.

@Test(dataProvider = "createMappingProvider")
public void testCreateMapping(AttributeType attributeType, MappingType mappingType) {
    String attrIdentifier = "attr";
    EntityType entityType = createEntityType(attrIdentifier, attributeType);
    Mapping mapping = mappingGenerator.createMapping(entityType);
    FieldMapping fieldMapping = FieldMapping.builder().setName(attrIdentifier).setType(mappingType).build();
    Mapping expectedMapping = createMapping(fieldMapping);
    assertEquals(mapping, expectedMapping);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) Mapping(org.molgenis.data.elasticsearch.generator.model.Mapping) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Aggregations

FieldMapping (org.molgenis.data.elasticsearch.generator.model.FieldMapping)6 Mapping (org.molgenis.data.elasticsearch.generator.model.Mapping)4 Test (org.testng.annotations.Test)4 EntityType (org.molgenis.data.meta.model.EntityType)3 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)3 ArrayList (java.util.ArrayList)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 MappingType (org.molgenis.data.elasticsearch.generator.model.MappingType)1 DataProvider (org.testng.annotations.DataProvider)1