Search in sources :

Example 61 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceIT method testDisableProfile.

@Test
public void testDisableProfile() throws Exception {
    Profile profile = profileService.createProfile(DEFAULT_TENANT, AVASQUEZ_USERNAME, AVASQUEZ_PASSWORD1, AVASQUEZ_EMAIL1, true, AVASQUEZ_ROLES1, null, VERIFICATION_URL);
    try {
        assertNotNull(profile);
        assertTrue(profile.isEnabled());
        Profile updatedProfile = profileService.disableProfile(profile.getId().toString());
        assertNotNull(updatedProfile);
        assertEquals(profile.getId(), updatedProfile.getId());
        assertEquals(profile.getUsername(), updatedProfile.getUsername());
        assertNull(updatedProfile.getPassword());
        assertEquals(profile.getEmail(), updatedProfile.getEmail());
        assertEquals(profile.isVerified(), updatedProfile.isVerified());
        assertFalse(updatedProfile.isEnabled());
        assertEquals(profile.getCreatedOn(), updatedProfile.getCreatedOn());
        assertTrue(profile.getLastModified().before(updatedProfile.getLastModified()));
        assertEquals(profile.getTenant(), updatedProfile.getTenant());
        assertEquals(profile.getRoles(), updatedProfile.getRoles());
        assertEquals(profile.getAttributes(), updatedProfile.getAttributes());
    } finally {
        profileService.deleteProfile(profile.getId().toString());
    }
}
Also used : Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 62 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceIT method testUpdateProfile.

@Test
public void testUpdateProfile() throws Exception {
    Profile profile = profileService.createProfile(DEFAULT_TENANT, AVASQUEZ_USERNAME, AVASQUEZ_PASSWORD1, AVASQUEZ_EMAIL1, true, AVASQUEZ_ROLES1, null, VERIFICATION_URL);
    try {
        assertNotNull(profile);
        Map<String, Object> attributes = new LinkedHashMap<>(2);
        attributes.put("firstName", AVASQUEZ_FIRST_NAME);
        attributes.put("lastName", AVASQUEZ_LAST_NAME);
        Profile updatedProfile = profileService.updateProfile(profile.getId().toString(), AVASQUEZ_USERNAME, AVASQUEZ_PASSWORD2, AVASQUEZ_EMAIL2, false, AVASQUEZ_ROLES2, attributes);
        assertNotNull(updatedProfile);
        assertEquals(profile.getId(), updatedProfile.getId());
        assertEquals(profile.getUsername(), updatedProfile.getUsername());
        assertNull(updatedProfile.getPassword());
        assertEquals(AVASQUEZ_EMAIL2, updatedProfile.getEmail());
        assertEquals(profile.isVerified(), updatedProfile.isVerified());
        assertFalse(updatedProfile.isEnabled());
        assertEquals(profile.getCreatedOn(), updatedProfile.getCreatedOn());
        assertTrue(profile.getLastModified().before(updatedProfile.getLastModified()));
        assertEquals(profile.getTenant(), updatedProfile.getTenant());
        assertEquals(AVASQUEZ_ROLES2, updatedProfile.getRoles());
        assertEquals(attributes, updatedProfile.getAttributes());
    } finally {
        profileService.deleteProfile(profile.getId().toString());
    }
}
Also used : Profile(org.craftercms.profile.api.Profile) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 63 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceIT method testGetProfileByIds.

@Test
public void testGetProfileByIds() throws Exception {
    ObjectId adminProfileId = profileService.getProfileByUsername(DEFAULT_TENANT, ADMIN_USERNAME).getId();
    ObjectId jdoeProfileId = profileService.getProfileByUsername(DEFAULT_TENANT, JDOE_USERNAME).getId();
    List<Profile> profiles = profileService.getProfilesByIds(Arrays.asList(adminProfileId.toString(), jdoeProfileId.toString()), null, null);
    assertNotNull(profiles);
    assertEquals(2, profiles.size());
    assertAdminProfile(profiles.get(0));
    assertJdoeProfile(profiles.get(1));
    // With sort
    profiles = profileService.getProfilesByIds(Arrays.asList(adminProfileId.toString(), jdoeProfileId.toString()), "username", SortOrder.DESC);
    assertNotNull(profiles);
    assertEquals(2, profiles.size());
    assertJdoeProfile(profiles.get(0));
    assertAdminProfile(profiles.get(1));
}
Also used : ObjectId(org.bson.types.ObjectId) Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 64 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceIT method testGetProfileByTicket.

@Test(expected = ProfileRestServiceException.class)
public void testGetProfileByTicket() throws Exception {
    Ticket ticket = authenticationService.authenticate(DEFAULT_TENANT, ADMIN_USERNAME, ADMIN_PASSWORD);
    assertNotNull(ticket);
    Profile profile = profileService.getProfileByTicket(ticket.getId());
    assertAdminProfile(profile);
    authenticationService.invalidateTicket(ticket.getId());
    // Try with invalid ticket
    profileService.getProfileByTicket("507c7f79bcf86cd7994f6c0e");
}
Also used : Ticket(org.craftercms.profile.api.Ticket) Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 65 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceIT method testDeleteVerificationToken.

@Test
public void testDeleteVerificationToken() throws Exception {
    Profile profile = profileService.getProfileByUsername(DEFAULT_TENANT, ADMIN_USERNAME);
    String profileId = profile.getId().toString();
    VerificationToken token = profileService.createVerificationToken(profileId);
    assertNotNull(token);
    profileService.deleteVerificationToken(token.getId());
    token = profileService.getVerificationToken(token.getId());
    assertNull(token);
}
Also used : VerificationToken(org.craftercms.profile.api.VerificationToken) Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Aggregations

Profile (org.craftercms.profile.api.Profile)111 Test (org.junit.Test)54 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)19 MongoDataException (org.craftercms.commons.mongo.MongoDataException)15 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)15 LinkedHashMap (java.util.LinkedHashMap)13 VerificationToken (org.craftercms.profile.api.VerificationToken)13 DefaultAuthentication (org.craftercms.security.authentication.impl.DefaultAuthentication)12 Date (java.util.Date)11 Map (java.util.Map)11 ObjectId (org.bson.types.ObjectId)10 RequestContext (org.craftercms.commons.http.RequestContext)9 Authentication (org.craftercms.security.authentication.Authentication)9 ArgumentMatcher (org.mockito.ArgumentMatcher)9 Mockito.anyString (org.mockito.Mockito.anyString)9 RequestSecurityProcessorChain (org.craftercms.security.processors.RequestSecurityProcessorChain)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 Tenant (org.craftercms.profile.api.Tenant)6 HashMap (java.util.HashMap)4