@Test
    public void testCreateUpdateFindDelete() {
        val profile = new DbProfile();
        profile.setId(Pac4jConstants.EMPTY_STRING + DB_ID);
        profile.setLinkedId(DB_LINKED_ID);
        profile.addAttribute(USERNAME, DB_USER);
        val dbProfileService = new DbProfileService(ds);
        dbProfileService.setPasswordEncoder(DbServer.PASSWORD_ENCODER);
        // create
        dbProfileService.create(profile, DB_PASS);
        // check credentials
        val credentials = new UsernamePasswordCredentials(DB_USER, DB_PASS);
        dbProfileService.validate(null, credentials);
        val profile1 = credentials.getUserProfile();
        assertNotNull(profile1);
        // check data
        val results = getData(DB_ID);
        assertEquals(1, results.size());
        val result = results.get(0);
        assertEquals(5, result.size());
        assertEquals(DB_ID, result.get(ID));
        assertEquals(DB_LINKED_ID, result.get(AbstractProfileService.LINKEDID));
        assertNotNull(result.get(AbstractProfileService.SERIALIZED_PROFILE));
        assertTrue(DbServer.PASSWORD_ENCODER.matches(DB_PASS, (String) result.get(PASSWORD)));
        assertEquals(DB_USER, result.get(USERNAME));
        // findById
        val profile2 = dbProfileService.findById(Pac4jConstants.EMPTY_STRING + DB_ID);
        assertEquals(Pac4jConstants.EMPTY_STRING + DB_ID, profile2.getId());
        assertEquals(DB_LINKED_ID, profile2.getLinkedId());
        assertEquals(DB_USER, profile2.getUsername());
        assertEquals(1, profile2.getAttributes().size());
        // update
        profile.addAttribute(USERNAME, DB_USER2);
        dbProfileService.update(profile, null);
        val results2 = getData(DB_ID);
        assertEquals(1, results2.size());
        val result2 = results2.get(0);
        assertEquals(5, result2.size());
        assertEquals(DB_ID, result2.get(ID));
        assertEquals(DB_LINKED_ID, result2.get(AbstractProfileService.LINKEDID));
        assertNotNull(result2.get(AbstractProfileService.SERIALIZED_PROFILE));
        assertTrue(DbServer.PASSWORD_ENCODER.matches(DB_PASS, (String) result2.get(PASSWORD)));
        assertEquals(DB_USER2, result2.get(USERNAME));
        // remove
        dbProfileService.remove(profile);
        val results3 = getData(DB_ID);
        assertEquals(0, results3.size());
    }
Tests the {@link DbProfileService}.

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