use of org.molgenis.semanticmapper.mapping.model.MappingTarget in project molgenis by molgenis.
the class MappingServiceControllerTest method itShouldCreateNewAttributeMappingWhenSavingIfNonePresent.
@Test
public void itShouldCreateNewAttributeMappingWhenSavingIfNonePresent() 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");
heightAttr = attrMetaFactory.create().setName("height").setDataType(INT);
hop.addAttribute(heightAttr);
mockMvc.perform(post(URI + "/saveattributemapping").param("mappingProjectId", "asdf").param("target", "HOP").param("source", "LifeLines").param("targetAttribute", "height").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("$('dob').age()");
AttributeMapping heightMapping = entityMapping.addAttributeMapping("height");
heightMapping.setAlgorithm("$('length').value()");
heightMapping.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 beforeTest.
@BeforeMethod
public void beforeTest() {
me = mock(User.class);
when(me.getUsername()).thenReturn("fdlk");
TestingAuthenticationToken authentication = new TestingAuthenticationToken("fdlk", null);
authentication.setAuthenticated(true);
SecurityContextHolder.getContext().setAuthentication(authentication);
hop = entityTypeFactory.create("HOP");
ageAttr = attrMetaFactory.create().setName("age").setDataType(INT);
hop.addAttribute(ageAttr);
dobAttr = attrMetaFactory.create().setName("dob").setDataType(DATE);
hop.addAttribute(dobAttr);
hop.setAbstract(true);
lifeLines = entityTypeFactory.create("LifeLines");
mappingProject = new MappingProject("hop hop hop", me);
mappingProject.setIdentifier("asdf");
MappingTarget mappingTarget = mappingProject.addTarget(hop);
EntityMapping entityMapping = mappingTarget.addSource(lifeLines);
AttributeMapping attributeMapping = entityMapping.addAttributeMapping("age");
attributeMapping.setAlgorithm("$('dob').age()");
when(dataService.getMeta()).thenReturn(metaDataService);
mockMvc = MockMvcBuilders.standaloneSetup(controller).setMessageConverters(gsonHttpMessageConverter, new StringHttpMessageConverter()).build();
}
use of org.molgenis.semanticmapper.mapping.model.MappingTarget in project molgenis by molgenis.
the class MappingServiceControllerTest method itShouldRemoveEmptyAttributeMappingsWhenSaving.
@Test
public void itShouldRemoveEmptyAttributeMappingsWhenSaving() 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", "").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);
mappingTarget.addSource(lifeLines);
Mockito.verify(mappingService).updateMappingProject(expected);
}
use of org.molgenis.semanticmapper.mapping.model.MappingTarget in project molgenis by molgenis.
the class MappingServiceImplTest method createMappingProjectWithMappings.
private MappingProject createMappingProjectWithMappings() {
MappingProject mappingProject = mappingService.addMappingProject("TestRun", user, hopMetaData.getId());
MappingTarget target = mappingProject.getMappingTarget(hopMetaData.getId());
when(mappingProjectRepo.getMappingProject("TestRun")).thenReturn(mappingProject);
EntityMapping mapping = target.addSource(geneMetaData);
AttributeMapping idMapping = mapping.addAttributeMapping("identifier");
idMapping.setAlgorithm("$('id').value()");
AttributeMapping attrMapping = mapping.addAttributeMapping("height");
attrMapping.setAlgorithm("$('length').value()");
return mappingProject;
}
use of org.molgenis.semanticmapper.mapping.model.MappingTarget in project molgenis by molgenis.
the class MappingServiceImplTest method createMetaWithNullParameters.
@Test
public void createMetaWithNullParameters() {
MappingTarget mappingTarget = Mockito.mock(MappingTarget.class);
when(mappingTarget.getTarget()).thenReturn(hopMetaData);
EntityType targetMetadata = mappingService.createTargetMetadata(mappingTarget, "target id", null, null, null);
assertEquals(targetMetadata.getId(), "target id");
assertEquals(targetMetadata.getLabel(), "target id");
assertEquals(targetMetadata.getPackage().getId(), "base");
Assert.assertNull(targetMetadata.getAttribute(SOURCE));
}
Aggregations