Search in sources :

Example 26 with Tenant

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

the class TenantServiceIT method testUpdateTenant.

@Test
public void testUpdateTenant() throws Exception {
    Tenant tenant = tenantService.createTenant(getCorporateTenant());
    try {
        tenant.setVerifyNewProfiles(true);
        tenant.getAvailableRoles().remove(ADMIN_ROLE);
        tenant.getAvailableRoles().add(USER_ROLE);
        tenant.getAttributeDefinitions().remove(getSubscriptionsAttributeDefinition());
        tenant.getAttributeDefinitions().add(getGenderAttributeDefinition());
        Tenant result = tenantService.updateTenant(tenant);
        assertNotNull(result);
        assertEquals(tenant.isVerifyNewProfiles(), result.isVerifyNewProfiles());
        assertEquals(tenant.getAvailableRoles(), result.getAvailableRoles());
        assertEqualAttributeDefinitions(tenant.getAttributeDefinitions(), result.getAttributeDefinitions());
    } finally {
        tenantService.deleteTenant(CORPORATE_TENANT_NAME);
    }
}
Also used : Tenant(org.craftercms.profile.api.Tenant) Test(org.junit.Test)

Example 27 with Tenant

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

the class TenantServiceIT method getCorporateTenant.

private Tenant getCorporateTenant() {
    Tenant tenant = new Tenant();
    tenant.setName(CORPORATE_TENANT_NAME);
    tenant.setAvailableRoles(CORPORATE_ROLES);
    tenant.setVerifyNewProfiles(false);
    tenant.setAttributeDefinitions(getAttributeDefinitions());
    return tenant;
}
Also used : Tenant(org.craftercms.profile.api.Tenant)

Example 28 with Tenant

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

the class TenantServiceIT method testRemoveAttributeDefinitions.

@Test
@DirtiesContext
public void testRemoveAttributeDefinitions() throws Exception {
    tenantService.createTenant(getCorporateTenant());
    try {
        Collection<String> attributeNames = Arrays.asList(FIRST_NAME_ATTRIBUTE_NAME, LAST_NAME_ATTRIBUTE_NAME);
        Tenant tenant = tenantService.removeAttributeDefinitions(CORPORATE_TENANT_NAME, attributeNames);
        assertNotNull(tenant);
        assertNotNull(tenant.getAttributeDefinitions());
        assertEquals(1, tenant.getAttributeDefinitions().size());
    } finally {
        tenantService.deleteTenant(CORPORATE_TENANT_NAME);
    }
}
Also used : Tenant(org.craftercms.profile.api.Tenant) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 29 with Tenant

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

the class TenantServiceIT method testCreateTenant.

@Test
public void testCreateTenant() throws Exception {
    Tenant tenant = tenantService.createTenant(getCorporateTenant());
    try {
        assertNotNull(tenant);
        assertNotNull(tenant.getId());
        assertEquals(CORPORATE_TENANT_NAME, tenant.getName());
        assertEquals(false, tenant.isVerifyNewProfiles());
        assertEquals(CORPORATE_ROLES, tenant.getAvailableRoles());
        try {
            tenantService.createTenant(getCorporateTenant());
            fail("Exception " + ProfileRestServiceException.class.getName() + " expected");
        } catch (ProfileRestServiceException e) {
            assertEquals(HttpStatus.CONFLICT, e.getStatus());
            assertEquals(ErrorCode.TENANT_EXISTS, e.getErrorCode());
        }
    } finally {
        tenantService.deleteTenant(CORPORATE_TENANT_NAME);
    }
}
Also used : ProfileRestServiceException(org.craftercms.profile.exceptions.ProfileRestServiceException) Tenant(org.craftercms.profile.api.Tenant) Test(org.junit.Test)

Example 30 with Tenant

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

the class TenantServiceImpl method addAttributeDefinitions.

@Override
public Tenant addAttributeDefinitions(final String tenantName, final Collection<AttributeDefinition> attributeDefinitions) throws ProfileException {
    Tenant tenant = updateTenant(tenantName, new UpdateCallback() {

        @Override
        public void doWithTenant(TenantUpdater tenantUpdater) throws ProfileException {
            tenantUpdater.addAttributeDefinitions(attributeDefinitions);
        }
    });
    for (AttributeDefinition definition : tenant.getAttributeDefinitions()) {
        addDefaultValue(tenantName, definition.getName(), definition.getDefaultValue());
    }
    logger.debug(LOG_KEY_ATTRIBUTE_DEFINITIONS_ADDED, attributeDefinitions, tenantName);
    return tenant;
}
Also used : Tenant(org.craftercms.profile.api.Tenant) TenantUpdater(org.craftercms.profile.utils.db.TenantUpdater) AttributeDefinition(org.craftercms.profile.api.AttributeDefinition) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException)

Aggregations

Tenant (org.craftercms.profile.api.Tenant)46 Test (org.junit.Test)21 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)12 AttributeDefinition (org.craftercms.profile.api.AttributeDefinition)8 TenantUpdater (org.craftercms.profile.utils.db.TenantUpdater)8 HashMap (java.util.HashMap)7 ProfileException (org.craftercms.profile.api.exceptions.ProfileException)7 Mockito.anyString (org.mockito.Mockito.anyString)7 MongoDataException (org.craftercms.commons.mongo.MongoDataException)5 Profile (org.craftercms.profile.api.Profile)5 ResourceNotFoundException (org.craftercms.profile.management.exceptions.ResourceNotFoundException)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 HashSet (java.util.HashSet)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 DuplicateKeyException (org.craftercms.commons.mongo.DuplicateKeyException)1 UpdateHelper (org.craftercms.commons.mongo.UpdateHelper)1