@Test
    public void testCreateUpdateFindDelete() {
        val profile = new CouchProfile();
        profile.setId(COUCH_ID);
        profile.setLinkedId(COUCH_LINKED_ID);
        profile.addAttribute(USERNAME, COUCH_USER);
        val couchProfileService = new CouchProfileService(couchDbConnector);
        couchProfileService.setPasswordEncoder(PASSWORD_ENCODER);
        // create
        couchProfileService.create(profile, COUCH_PASS);
        // check credentials
        val credentials = new UsernamePasswordCredentials(COUCH_USER, COUCH_PASS);
        couchProfileService.validate(null, credentials);
        val profile1 = credentials.getUserProfile();
        assertNotNull(profile1);
        // check data
        val results = getData(couchProfileService, COUCH_ID);
        assertEquals(1, results.size());
        val result = results.get(0);
        assertEquals(5, result.size());
        assertEquals(COUCH_ID, result.get(COUCH_ID_FIELD));
        assertEquals(COUCH_LINKED_ID, result.get(AbstractProfileService.LINKEDID));
        assertNotNull(result.get(AbstractProfileService.SERIALIZED_PROFILE));
        assertEquals(COUCH_USER, result.get(USERNAME));
        // findById
        val profile2 = couchProfileService.findById(COUCH_ID);
        assertEquals(COUCH_ID, profile2.getId());
        assertEquals(COUCH_LINKED_ID, profile2.getLinkedId());
        assertEquals(COUCH_USER, profile2.getUsername());
        assertEquals(1, profile2.getAttributes().size());
        // update with password
        profile.addAttribute(USERNAME, COUCH_USER2);
        couchProfileService.update(profile, COUCH_PASS2);
        var results2 = getData(couchProfileService, COUCH_ID);
        assertEquals(1, results2.size());
        var result2 = results2.get(0);
        assertEquals(5, result2.size());
        assertEquals(COUCH_ID, result2.get(COUCH_ID_FIELD));
        assertEquals(COUCH_LINKED_ID, result2.get(AbstractProfileService.LINKEDID));
        assertNotNull(result2.get(AbstractProfileService.SERIALIZED_PROFILE));
        assertEquals(COUCH_USER2, result2.get(USERNAME));
        // check credentials
        val credentials2 = new UsernamePasswordCredentials(COUCH_USER2, COUCH_PASS2);
        couchProfileService.validate(null, credentials2);
        var profile3 = credentials.getUserProfile();
        assertNotNull(profile3);
        // update with no password update
        couchProfileService.update(profile, null);
        results2 = getData(couchProfileService, COUCH_ID);
        assertEquals(1, results2.size());
        result2 = results2.get(0);
        assertEquals(5, result2.size());
        assertEquals(COUCH_USER2, result2.get(USERNAME));
        // check credentials
        couchProfileService.validate(null, credentials2);
        profile3 = credentials.getUserProfile();
        assertNotNull(profile3);
        // remove
        couchProfileService.remove(profile);
        val results3 = getData(couchProfileService, COUCH_ID);
        assertEquals(0, results3.size());
    }
Tests the {@link CouchProfileService}.

@author Elie Roux
@since 2.0.0
pac4j-couch/src/test/java/org/pac4j/couch/profile/service/CouchProfileServiceTests.java