use of org.molgenis.semanticmapper.mapping.model.MappingTarget 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.MappingTarget 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.MappingTarget 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);
}
use of org.molgenis.semanticmapper.mapping.model.MappingTarget in project molgenis by molgenis.
the class MappingServiceImplTest method testMaxProgressOneSourceOneBatch.
@Test
public void testMaxProgressOneSourceOneBatch() {
MappingTarget mappingTarget = Mockito.mock(MappingTarget.class);
EntityMapping entityMapping = getMockEntityMapping("a", MAPPING_BATCH_SIZE - 1);
List<EntityMapping> mappings = singletonList(entityMapping);
when(mappingTarget.getEntityMappings()).thenReturn(mappings);
assertEquals(mappingService.calculateMaxProgress(mappingTarget), 1);
}
use of org.molgenis.semanticmapper.mapping.model.MappingTarget 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