@Test
    public void testCreateUpdateFindDelete() {
        val objectId = new ObjectId();
        val profile = new MongoProfile();
        profile.setId(MONGO_ID);
        profile.setLinkedId(MONGO_LINKEDID);
        profile.addAttribute(USERNAME, MONGO_USER);
        profile.addAttribute(FIRSTNAME, objectId);
        val mongoProfileService = new MongoProfileService(getClient());
        mongoProfileService.setPasswordEncoder(MongoServer.PASSWORD_ENCODER);
        // create
        mongoProfileService.create(profile, MONGO_PASS);
        // check credentials
        val credentials = new UsernamePasswordCredentials(MONGO_USER, MONGO_PASS);
        mongoProfileService.validate(null, credentials);
        val profile1 = credentials.getUserProfile();
        assertNotNull(profile1);
        // check data
        val results = getData(mongoProfileService, MONGO_ID);
        assertEquals(1, results.size());
        val result = results.get(0);
        assertEquals(6, result.size());
        assertEquals(MONGO_ID, result.get(ID));
        assertEquals(MONGO_LINKEDID, result.get(AbstractProfileService.LINKEDID));
        assertNotNull(result.get(AbstractProfileService.SERIALIZED_PROFILE));
        assertTrue(MongoServer.PASSWORD_ENCODER.matches(MONGO_PASS, (String) result.get(PASSWORD)));
        assertEquals(MONGO_USER, result.get(USERNAME));
        // findById
        val profile2 = mongoProfileService.findByLinkedId(MONGO_LINKEDID);
        assertEquals(MONGO_ID, profile2.getId());
        assertEquals(MONGO_LINKEDID, profile2.getLinkedId());
        assertEquals(MONGO_USER, profile2.getUsername());
        assertEquals(objectId, profile2.getAttribute(FIRSTNAME));
        assertEquals(2, profile2.getAttributes().size());
        // update
        profile.setLinkedId(MONGO_LINKEDID2);
        mongoProfileService.update(profile, MONGO_PASS2);
        val results2 = getData(mongoProfileService, MONGO_ID);
        assertEquals(1, results2.size());
        val result2 = results2.get(0);
        assertEquals(6, result2.size());
        assertEquals(MONGO_ID, result2.get(ID));
        assertEquals(MONGO_LINKEDID2, result2.get(AbstractProfileService.LINKEDID));
        assertNotNull(result2.get(AbstractProfileService.SERIALIZED_PROFILE));
        assertTrue(MongoServer.PASSWORD_ENCODER.matches(MONGO_PASS2, (String) result2.get(PASSWORD)));
        assertEquals(MONGO_USER, result2.get(USERNAME));
        // remove
        mongoProfileService.remove(profile);
        val results3 = getData(mongoProfileService, MONGO_ID);
        assertEquals(0, results3.size());
    }
Tests the {@link MongoProfileService}.

@author Jerome Leleu
@since 1.8.0
pac4j-mongo/src/test/java/org/pac4j/mongo/profile/service/MongoProfileServiceIT.java