Search in sources :

Example 1 with MappingTarget

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

the class MappingServiceControllerTest method itShouldUpdateExistingAttributeMappingWhenSaving.

@Test
public void itShouldUpdateExistingAttributeMappingWhenSaving() throws Exception {
    when(mappingService.getMappingProject("asdf")).thenReturn(mappingProject);
    Menu menu = mock(Menu.class);
    when(menuReaderService.getMenu()).thenReturn(menu);
    when(menu.findMenuItemPath(ID)).thenReturn("/menu/main/mappingservice");
    mockMvc.perform(post(URI + "/saveattributemapping").param("mappingProjectId", "asdf").param("target", "HOP").param("source", "LifeLines").param("targetAttribute", "age").param("algorithm", "$('length').value()").param("algorithmState", "CURATED")).andExpect(redirectedUrl("/menu/main/mappingservice/mappingproject/asdf"));
    MappingProject expected = new MappingProject("hop hop hop", me);
    expected.setIdentifier("asdf");
    MappingTarget mappingTarget = expected.addTarget(hop);
    EntityMapping entityMapping = mappingTarget.addSource(lifeLines);
    AttributeMapping ageMapping = entityMapping.addAttributeMapping("age");
    ageMapping.setAlgorithm("$('length').value()");
    ageMapping.setAlgorithmState(AttributeMapping.AlgorithmState.CURATED);
    Mockito.verify(mappingService).updateMappingProject(expected);
}
Also used : EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) Menu(org.molgenis.core.ui.menu.Menu) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 2 with MappingTarget

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

the class MappingServiceControllerTest method getFirstAttributeMappingInfo_none.

@Test
public void getFirstAttributeMappingInfo_none() throws Exception {
    when(mappingService.getMappingProject("asdf")).thenReturn(mappingProject);
    Menu menu = mock(Menu.class);
    when(menuReaderService.getMenu()).thenReturn(menu);
    when(menu.findMenuItemPath(ID)).thenReturn("/menu/main/mappingservice");
    mappingProject.getMappingTarget("HOP").getMappingForSource("LifeLines").getAttributeMapping("age").setAlgorithmState(AttributeMapping.AlgorithmState.DISCUSS);
    MappingTarget mappingTarget = mappingProject.getMappingTarget("HOP");
    EntityMapping entityMapping = mappingTarget.getMappingForSource("LifeLines");
    AttributeMapping attributeMapping = entityMapping.addAttributeMapping("dob");
    attributeMapping.setAlgorithm("$('dob').age()");
    attributeMapping.setAlgorithmState(AttributeMapping.AlgorithmState.DISCUSS);
    MvcResult result3 = mockMvc.perform(post(URI + "/firstattributemapping").param("mappingProjectId", "asdf").param("target", "HOP").param("source", "LifeLines").param("skipAlgorithmStates[]", "CURATED", "DISCUSS").accept(MediaType.APPLICATION_JSON)).andReturn();
    String actual3 = result3.getResponse().getContentAsString();
    assertEquals(actual3, "");
}
Also used : EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) Menu(org.molgenis.core.ui.menu.Menu) MvcResult(org.springframework.test.web.servlet.MvcResult) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 3 with MappingTarget

use of org.molgenis.semanticmapper.mapping.model.MappingTarget 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 4 with MappingTarget

use of org.molgenis.semanticmapper.mapping.model.MappingTarget 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 5 with MappingTarget

use of org.molgenis.semanticmapper.mapping.model.MappingTarget 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);
}
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