Search in sources :

Example 6 with MappingTarget

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);
}
Also used : MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) Test(org.testng.annotations.Test)

Example 7 with MappingTarget

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);
}
Also used : MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) DynamicEntity(org.molgenis.data.support.DynamicEntity) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) Test(org.testng.annotations.Test)

Example 8 with MappingTarget

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);
}
Also used : EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) Test(org.testng.annotations.Test)

Example 9 with MappingTarget

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);
}
Also used : EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) Test(org.testng.annotations.Test)

Example 10 with MappingTarget

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);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) Test(org.testng.annotations.Test)

Aggregations

MappingTarget (org.molgenis.semanticmapper.mapping.model.MappingTarget)22 Test (org.testng.annotations.Test)16 EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)12 MappingProject (org.molgenis.semanticmapper.mapping.model.MappingProject)12 DynamicEntity (org.molgenis.data.support.DynamicEntity)7 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)5 Menu (org.molgenis.core.ui.menu.Menu)4 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)4 Entity (org.molgenis.data.Entity)3 EntityType (org.molgenis.data.meta.model.EntityType)3 User (org.molgenis.data.security.auth.User)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 DefaultPackage (org.molgenis.data.meta.DefaultPackage)1 Attribute (org.molgenis.data.meta.model.Attribute)1 Package (org.molgenis.data.meta.model.Package)1 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1 Transactional (org.springframework.transaction.annotation.Transactional)1