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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations