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);
}
}
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;
}
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);
}
}
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);
}
}
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;
}
Aggregations