@Test
 public void testAddWithIdentifier() {
   MappingProject mappingProject = new MappingProject("My first mapping project", owner);
   mappingProject.setIdentifier("mappingProjectID");
   try {
     mappingProjectRepositoryImpl.add(mappingProject);
   } catch (MolgenisDataException mde) {
     assertEquals(mde.getMessage(), "MappingProject already exists");
   }
 }
  @BeforeMethod
  public void beforeMethod() {
    owner = new MolgenisUser();
    owner.setUsername("flup");
    owner.setPassword("geheim");
    owner.setId("12345");
    owner.setActive(true);
    owner.setEmail("*****@*****.**");
    owner.setFirstName("Flup");
    owner.setLastName("de Flap");

    DefaultEntityMetaData target1 = new DefaultEntityMetaData("target1");
    target1.addAttribute("id", ROLE_ID);
    DefaultEntityMetaData target2 = new DefaultEntityMetaData("target2");
    target2.addAttribute("id", ROLE_ID);

    mappingProject = new MappingProject("My first mapping project", owner);
    mappingTarget1 = mappingProject.addTarget(target1);
    mappingTarget2 = mappingProject.addTarget(target2);

    Entity mappingTargetEntity = new MapEntity(MappingTargetRepositoryImpl.META_DATA);
    mappingTargetEntity.set(MappingTargetMetaData.TARGET, "target1");
    mappingTargetEntity.set(MappingTargetMetaData.IDENTIFIER, "mappingTargetID1");
    Entity mappingTargetEntity2 = new MapEntity(MappingTargetRepositoryImpl.META_DATA);
    mappingTargetEntity2.set(MappingTargetMetaData.TARGET, "target2");
    mappingTargetEntity2.set(MappingTargetMetaData.IDENTIFIER, "mappingTargetID2");
    mappingTargetEntities = asList(mappingTargetEntity, mappingTargetEntity2);

    mappingProjectEntity = new MapEntity(META_DATA);
    mappingProjectEntity.set(IDENTIFIER, "mappingProjectID");
    mappingProjectEntity.set(MAPPINGTARGETS, mappingTargetEntities);
    mappingProjectEntity.set(OWNER, owner);
    mappingProjectEntity.set(NAME, "My first mapping project");
  }
 @Test
 public void testUpdateUnknown() {
   mappingProject.setIdentifier("mappingProjectID");
   when(dataService.findOne(ENTITY_NAME, "mappingProjectID")).thenReturn(null);
   try {
     mappingProjectRepositoryImpl.update(mappingProject);
     fail("Expected exception");
   } catch (MolgenisDataException expected) {
     assertEquals(expected.getMessage(), "MappingProject does not exist");
   }
 }
 @Test
 public void testFindAll() {
   Query q = new QueryImpl();
   q.eq(OWNER, "flup");
   when(dataService.findAll(ENTITY_NAME)).thenReturn(Stream.of(mappingProjectEntity));
   when(userService.getUser("flup")).thenReturn(owner);
   when(mappingTargetRepository.toMappingTargets(mappingTargetEntities))
       .thenReturn(asList(mappingTarget1, mappingTarget2));
   List<MappingProject> result = mappingProjectRepositoryImpl.getAllMappingProjects();
   mappingProject.setIdentifier("mappingProjectID");
   assertEquals(result, asList(mappingProject));
 }