@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 findUserByToken() {
    MolgenisToken molgenisToken = new MolgenisToken();
    molgenisToken.setToken("token");
    MolgenisUser user = new MolgenisUser();
    user.setUsername("admin");
    molgenisToken.setMolgenisUser(user);

    when(dataService.findOne(
            MolgenisToken.ENTITY_NAME,
            new QueryImpl().eq(MolgenisToken.TOKEN, "token"),
            MolgenisToken.class))
        .thenReturn(molgenisToken);

    UserDetails userDetails =
        new User("admin", "admin", Arrays.asList(new SimpleGrantedAuthority("admin")));
    when(userDetailsService.loadUserByUsername("admin")).thenReturn(userDetails);

    assertEquals(tokenService.findUserByToken("token"), userDetails);
  }