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