use of org.molgenis.semanticmapper.mapping.model.MappingProject in project molgenis by molgenis.
the class MappingServiceImplTest method testIncompatibleMetaDataUnknownAttribute.
@Test(expectedExceptions = MolgenisDataException.class, expectedExceptionsMessageRegExp = "Target repository does not contain the following attribute: COUNTRY_1")
public void testIncompatibleMetaDataUnknownAttribute() {
String targetRepositoryName = "targetRepository";
@SuppressWarnings("unchecked") Repository<Entity> targetRepository = Mockito.mock(Repository.class);
EntityType targetRepositoryMetaData = entityTypeFactory.create(targetRepositoryName);
targetRepositoryMetaData.addAttribute(attrMetaFactory.create().setName("ID").setDataType(STRING), ROLE_ID);
targetRepositoryMetaData.addAttribute(attrMetaFactory.create().setName("COUNTRY").setDataType(STRING));
targetRepositoryMetaData.setPackage(package_);
when(dataService.hasRepository(targetRepositoryName)).thenReturn(true);
when(dataService.getRepository(targetRepositoryName)).thenReturn(targetRepository);
when(targetRepository.getEntityType()).thenReturn(targetRepositoryMetaData);
EntityType mappingTargetMetaData = entityTypeFactory.create("mapping_target");
mappingTargetMetaData.addAttribute(attrMetaFactory.create().setName("ID").setDataType(STRING), ROLE_ID);
mappingTargetMetaData.addAttribute(attrMetaFactory.create().setName("COUNTRY_1").setDataType(STRING));
mappingTargetMetaData.setPackage(package_);
MappingTarget mappingTarget = new MappingTarget(mappingTargetMetaData);
MappingProject mappingProject = Mockito.mock(MappingProject.class);
when(mappingProject.getMappingTargets()).thenReturn(newArrayList(mappingTarget));
when(mappingProjectRepo.getMappingProject("TestRun")).thenReturn(mappingProject);
mappingService.applyMappings("TestRun", targetRepositoryName, false, "packageId", "label", progress);
}
use of org.molgenis.semanticmapper.mapping.model.MappingProject in project molgenis by molgenis.
the class MappingServiceImplTest method testAddMappingProject.
@Test
public void testAddMappingProject() {
String projectName = "test_project";
MappingProject mappingProject = mappingService.addMappingProject(projectName, user, hopMetaData.getId());
Mockito.verify(mappingProjectRepo, Mockito.times(1)).add(mappingProject);
assertEquals(mappingProject.getName(), projectName);
assertEquals(mappingProject.getOwner(), user);
List<MappingTarget> mappingTargets = mappingProject.getMappingTargets();
assertEquals(mappingTargets.size(), 1);
assertEquals(mappingTargets.get(0).getTarget(), hopMetaData);
}
use of org.molgenis.semanticmapper.mapping.model.MappingProject in project molgenis by molgenis.
the class MappingServiceImplTest method testGetMappingProject.
@Test
public void testGetMappingProject() {
String projectName = "test_project";
MappingProject actualAddedMappingProject = mappingService.addMappingProject(projectName, user, hopMetaData.getId());
String mappingTargetIdentifier = actualAddedMappingProject.getMappingTarget(hopMetaData.getId()).getIdentifier();
MappingTarget expectedMappingTarget = getManualMappingTarget(mappingTargetIdentifier, emptyList());
String mappingProjectIdentifier = actualAddedMappingProject.getIdentifier();
MappingProject expectedMappingProject = getManualMappingProject(mappingProjectIdentifier, projectName, expectedMappingTarget);
Entity mappingTargetEntity = Mockito.mock(Entity.class);
when(mappingTargetEntity.getString(MappingTargetMetaData.IDENTIFIER)).thenReturn(mappingTargetIdentifier);
when(mappingTargetEntity.getString(MappingTargetMetaData.TARGET)).thenReturn(hopMetaData.getId());
when(mappingTargetEntity.getEntities(MappingTargetMetaData.ENTITY_MAPPINGS)).thenReturn(null);
when(dataService.getEntityType(mappingTargetEntity.getString(MappingTargetMetaData.TARGET))).thenReturn(hopMetaData);
Entity mappingProjectEntity = Mockito.mock(Entity.class);
when(mappingProjectEntity.get(IDENTIFIER)).thenReturn(mappingProjectIdentifier);
when(mappingProjectEntity.get(NAME)).thenReturn(projectName);
when(mappingProjectEntity.get(OWNER)).thenReturn(user);
when(mappingProjectEntity.getEntities(MAPPING_TARGETS)).thenReturn(singletonList(mappingTargetEntity));
when(mappingProjectEntity.get(MAPPING_TARGETS)).thenReturn(singletonList(expectedMappingTarget));
when(dataService.findOneById(MAPPING_PROJECT, mappingProjectIdentifier)).thenReturn(mappingProjectEntity);
when(mappingProjectRepo.getMappingProject(mappingProjectIdentifier)).thenReturn(actualAddedMappingProject);
MappingProject retrievedMappingProject = mappingService.getMappingProject(mappingProjectIdentifier);
assertEquals(retrievedMappingProject, expectedMappingProject);
}
use of org.molgenis.semanticmapper.mapping.model.MappingProject in project molgenis by molgenis.
the class MappingServiceImplTest method testApplyMappingsAdd.
/**
* New entities in the source should be added to the target when a new mapping to the same target is performed.
*/
@Test
@SuppressWarnings("unchecked")
public void testApplyMappingsAdd() {
String entityTypeId = "addEntity";
@SuppressWarnings("unchecked") Repository<Entity> addEntityRepo = Mockito.mock(Repository.class);
when(addEntityRepo.getName()).thenReturn(entityTypeId);
EntityType targetMeta = entityTypeFactory.create(TARGET_HOP_ENTITY).setPackage(package_);
targetMeta.addAttribute(attrMetaFactory.create().setName("identifier"), ROLE_ID);
targetMeta.addAttribute(attrMetaFactory.create().setName("height").setDataType(DECIMAL).setNillable(false));
targetMeta.addAttribute(attrMetaFactory.create().setName("source"));
when(addEntityRepo.getEntityType()).thenReturn(targetMeta);
when(metaDataService.createRepository(argThat(obj -> obj.getId().equals(entityTypeId)))).thenReturn(addEntityRepo);
// add an entity to the source
List<Entity> sourceGeneEntities = newArrayList();
List<Entity> expectedEntities = newArrayList();
createEntities(targetMeta, sourceGeneEntities, expectedEntities);
Mockito.doAnswer(invocationOnMock -> {
@SuppressWarnings("unchecked") Consumer<List<Entity>> consumer = (Consumer<List<Entity>>) invocationOnMock.<Consumer>getArgument(0);
consumer.accept(sourceGeneEntities);
return null;
}).when(geneRepo).forEachBatched(ArgumentMatchers.any(Consumer.class), ArgumentMatchers.eq(MAPPING_BATCH_SIZE));
// make project and apply mappings once
MappingProject project = createMappingProjectWithMappings();
Entity mappedEntity = Mockito.mock(Entity.class);
when(entityManager.create(targetMeta, EntityManager.CreationMode.POPULATE)).thenReturn(mappedEntity);
// apply mapping again
assertEquals(mappingService.applyMappings("TestRun", entityTypeId, true, "packageId", "label", progress), 4);
Mockito.verify(geneRepo).forEachBatched(ArgumentMatchers.any(Consumer.class), ArgumentMatchers.any(Integer.class));
ArgumentCaptor<EntityType> entityTypeCaptor = ArgumentCaptor.forClass(EntityType.class);
Mockito.verify(permissionSystemService).giveUserWriteMetaPermissions(entityTypeCaptor.capture());
assertEquals(entityTypeCaptor.getValue().getId(), entityTypeId);
Mockito.verify(progress).setProgressMax(ArgumentMatchers.anyInt());
Mockito.verify(progress).progress(0, "Checking target repository [addEntity]...");
Mockito.verify(progress).status("Applying mappings to repository [HopEntity]");
Mockito.verify(progress).status("Mapping source [Genes]...");
Mockito.verify(progress).increment(1);
Mockito.verify(progress).status("Mapped 4 [Genes] entities.");
Mockito.verify(progress).status("Done applying mappings to repository [HopEntity]");
Mockito.verifyNoMoreInteractions(progress);
}
use of org.molgenis.semanticmapper.mapping.model.MappingProject in project molgenis by molgenis.
the class MappingServiceImplTest method testIncompatibleMetaDataDifferentType.
@Test(expectedExceptions = MolgenisDataException.class, expectedExceptionsMessageRegExp = "attribute COUNTRY in the mapping target is type INT while attribute " + "COUNTRY in the target repository is type STRING. Please make sure the types are the same")
public void testIncompatibleMetaDataDifferentType() {
String targetRepositoryName = "target_repository";
@SuppressWarnings("unchecked") Repository<Entity> targetRepository = Mockito.mock(Repository.class);
EntityType targetRepositoryMetaData = entityTypeFactory.create(targetRepositoryName);
targetRepositoryMetaData.addAttribute(attrMetaFactory.create().setName("ID").setDataType(STRING), ROLE_ID);
targetRepositoryMetaData.addAttribute(attrMetaFactory.create().setName("COUNTRY").setDataType(STRING));
targetRepositoryMetaData.setPackage(package_);
when(dataService.hasRepository(targetRepositoryName)).thenReturn(true);
when(dataService.getRepository(targetRepositoryName)).thenReturn(targetRepository);
when(targetRepository.getEntityType()).thenReturn(targetRepositoryMetaData);
EntityType mappingTargetMetaData = entityTypeFactory.create("mapping_target");
mappingTargetMetaData.addAttribute(attrMetaFactory.create().setName("ID").setDataType(STRING), ROLE_ID);
mappingTargetMetaData.addAttribute(attrMetaFactory.create().setName("COUNTRY").setDataType(INT));
mappingTargetMetaData.setPackage(package_);
MappingTarget mappingTarget = new MappingTarget(mappingTargetMetaData);
MappingProject mappingProject = Mockito.mock(MappingProject.class);
when(mappingProject.getMappingTargets()).thenReturn(newArrayList(mappingTarget));
when(mappingProjectRepo.getMappingProject("TestRun")).thenReturn(mappingProject);
mappingService.applyMappings("TestRun", targetRepositoryName, false, "packageId", "label", progress);
}
Aggregations