Search in sources :

Example 6 with EntityMapping

use of org.molgenis.semanticmapper.mapping.model.EntityMapping in project molgenis by molgenis.

the class MappingTargetRepositoryImplTest method beforeMethod.

@BeforeMethod
public void beforeMethod() {
    // POJOs
    EntityType sourceEntityType = entityTypeFactory.create("source");
    targetEntityType = entityTypeFactory.create("target");
    Attribute targetAttribute = attrMetaFactory.create().setName("targetAttribute");
    targetEntityType.addAttribute(targetAttribute);
    entityMappings = singletonList(new EntityMapping("entityMappingID", sourceEntityType, targetEntityType, emptyList()));
    mappingTargets = singletonList(new MappingTarget("mappingTargetID", targetEntityType, entityMappings));
    // Entities
    Entity entityMappingEntity = new DynamicEntity(entityMappingMeta);
    entityMappingEntity.set(EntityMappingMetaData.IDENTIFIER, "entityMappingID");
    entityMappingEntity.set(EntityMappingMetaData.SOURCE_ENTITY_TYPE, "source");
    entityMappingEntity.set(EntityMappingMetaData.TARGET_ENTITY_TYPE, "target");
    entityMappingEntity.set(EntityMappingMetaData.ATTRIBUTE_MAPPINGS, emptyList());
    Entity mappingTargetEntity = new DynamicEntity(mappingTargetMeta);
    mappingTargetEntity.set(IDENTIFIER, "mappingTargetID");
    mappingTargetEntity.set(TARGET, "target");
    entityMappingEntities = singletonList(entityMappingEntity);
    mappingTargetEntity.set(ENTITY_MAPPINGS, entityMappingEntities);
    mappingTargetEntities = singletonList(mappingTargetEntity);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) DynamicEntity(org.molgenis.data.support.DynamicEntity) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with EntityMapping

use of org.molgenis.semanticmapper.mapping.model.EntityMapping in project molgenis by molgenis.

the class MappingServiceImplTest method testMaxProgressOneSourceMultipleBatches.

@Test
public void testMaxProgressOneSourceMultipleBatches() {
    MappingTarget mappingTarget = Mockito.mock(MappingTarget.class);
    EntityMapping entityMapping = getMockEntityMapping("a", (3 * MAPPING_BATCH_SIZE) + 1);
    List<EntityMapping> mappings = singletonList(entityMapping);
    when(mappingTarget.getEntityMappings()).thenReturn(mappings);
    assertEquals(mappingService.calculateMaxProgress(mappingTarget), 4);
}
Also used : EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) Test(org.testng.annotations.Test)

Example 8 with EntityMapping

use of org.molgenis.semanticmapper.mapping.model.EntityMapping in project molgenis by molgenis.

the class MappingServiceImplTest method testApplyMappingsToRepoAdd.

@Test
@SuppressWarnings("unchecked")
public void testApplyMappingsToRepoAdd() {
    Repository<Entity> targetRepo = Mockito.mock(Repository.class);
    Repository<Entity> sourceRepo = Mockito.mock(Repository.class);
    EntityMapping sourceMapping = Mockito.mock(EntityMapping.class);
    when(sourceMapping.getLabel()).thenReturn("sourceMappingLabel");
    when(sourceMapping.getName()).thenReturn("sourceMappingID");
    EntityType sourceEntityType = Mockito.mock(EntityType.class);
    when(sourceEntityType.getLabel()).thenReturn("test");
    when(sourceRepo.getEntityType()).thenReturn(sourceEntityType);
    when(dataService.getRepository("sourceMappingID")).thenReturn(sourceRepo);
    when(targetRepo.count()).thenReturn(0L);
    EntityType targetEntityType = Mockito.mock(EntityType.class);
    when(targetEntityType.getId()).thenReturn("targetEntityType");
    when(targetEntityType.getAtomicAttributes()).thenReturn(newArrayList());
    Attribute targetID = Mockito.mock(Attribute.class);
    when(targetID.getName()).thenReturn("targetID");
    when(targetEntityType.getIdAttribute()).thenReturn(targetID);
    when(targetRepo.getEntityType()).thenReturn(targetEntityType);
    List<Entity> batch = Lists.newArrayList(Mockito.mock(Entity.class));
    Mockito.doAnswer(invocationOnMock -> {
        Consumer<List<Entity>> consumer = (Consumer<List<Entity>>) invocationOnMock.<Consumer>getArgument(0);
        consumer.accept(batch);
        consumer.accept(batch);
        consumer.accept(batch);
        return null;
    }).when(sourceRepo).forEachBatched(ArgumentMatchers.any(Consumer.class), ArgumentMatchers.eq(MAPPING_BATCH_SIZE));
    mappingService.applyMappingToRepo(sourceMapping, targetRepo, progress);
    Mockito.verify(targetRepo, Mockito.times(3)).add(ArgumentMatchers.any(Stream.class));
    Mockito.verify(progress, Mockito.times(3)).increment(1);
    Mockito.verify(progress).status("Mapping source [sourceMappingLabel]...");
    Mockito.verify(progress).status("Mapped 3 [sourceMappingLabel] entities.");
    Mockito.verifyNoMoreInteractions(progress);
}
Also used : EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) DynamicEntity(org.molgenis.data.support.DynamicEntity) Consumer(java.util.function.Consumer) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Stream(java.util.stream.Stream) Test(org.testng.annotations.Test)

Example 9 with EntityMapping

use of org.molgenis.semanticmapper.mapping.model.EntityMapping in project molgenis by molgenis.

the class MappingServiceImplTest method testApplyMappingToEntity.

@Test
public void testApplyMappingToEntity() {
    EntityMapping entityMapping = Mockito.mock(EntityMapping.class);
    Entity sourceEntity = Mockito.mock(Entity.class);
    EntityType targetMetaData = Mockito.mock(EntityType.class);
    Entity mappedEntity = Mockito.mock(Entity.class);
    when(entityManager.create(targetMetaData, EntityManager.CreationMode.POPULATE)).thenReturn(mappedEntity);
    assertEquals(mappingService.applyMappingToEntity(entityMapping, sourceEntity, targetMetaData), mappedEntity);
}
Also used : EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test)

Example 10 with EntityMapping

use of org.molgenis.semanticmapper.mapping.model.EntityMapping in project molgenis by molgenis.

the class MappingServiceImplTest method testMaxProgressOneSourceMultipleBatchesSelfReferencing.

@Test
public void testMaxProgressOneSourceMultipleBatchesSelfReferencing() {
    MappingTarget mappingTarget = Mockito.mock(MappingTarget.class);
    EntityMapping entityMapping = getMockEntityMapping("a", (3 * MAPPING_BATCH_SIZE) + 1);
    when(mappingTarget.hasSelfReferences()).thenReturn(true);
    List<EntityMapping> mappings = singletonList(entityMapping);
    when(mappingTarget.getEntityMappings()).thenReturn(mappings);
    assertEquals(mappingService.calculateMaxProgress(mappingTarget), 8);
}
Also used : EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) Test(org.testng.annotations.Test)

Aggregations

EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)22 Test (org.testng.annotations.Test)16 MappingTarget (org.molgenis.semanticmapper.mapping.model.MappingTarget)12 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)8 EntityType (org.molgenis.data.meta.model.EntityType)8 DynamicEntity (org.molgenis.data.support.DynamicEntity)8 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)8 MappingProject (org.molgenis.semanticmapper.mapping.model.MappingProject)7 Attribute (org.molgenis.data.meta.model.Attribute)6 Entity (org.molgenis.data.Entity)5 User (org.molgenis.data.security.auth.User)4 Menu (org.molgenis.core.ui.menu.Menu)3 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 Relation (org.molgenis.data.semantic.Relation)2 OntologyTerm (org.molgenis.ontology.core.model.OntologyTerm)2