Search in sources :

Example 16 with Tenant

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

the class TenantControllerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    Tenant tenant1 = getTenant(TENANT_ID1, TENANT_NAME1, SUPERADMIN_ROLE, TENANT_ADMIN_ROLE, PROFILE_ADMIN_ROLE);
    Tenant tenant2 = getTenant(TENANT_ID2, TENANT_NAME2, TENANT_ADMIN_ROLE, PROFILE_ADMIN_ROLE);
    Tenant tenant3 = getTenant(TENANT_ID3, TENANT_NAME3, PROFILE_ADMIN_ROLE);
    when(tenantService.getAllTenants()).thenReturn(Arrays.asList(tenant1, tenant2));
    when(tenantService.getTenant(TENANT_NAME1)).thenReturn(tenant1);
    when(tenantService.getTenant(TENANT_NAME2)).thenReturn(tenant2);
    when(tenantService.createTenant(tenant3)).thenReturn(tenant3);
    SubjectResolver<Profile> subjectResolver = new CurrentUserSubjectResolver();
    TenantPermissionResolver permissionResolver = new TenantPermissionResolver();
    PermissionEvaluatorImpl<Profile, String> permissionEvaluator = new PermissionEvaluatorImpl<>();
    permissionEvaluator.setSubjectResolver(subjectResolver);
    permissionEvaluator.setPermissionResolver(permissionResolver);
    controller = new TenantController();
    controller.setTenantService(tenantService);
    controller.setTenantPermissionEvaluator(permissionEvaluator);
    setCurrentRequestContext();
}
Also used : CurrentUserSubjectResolver(org.craftercms.profile.management.security.permissions.CurrentUserSubjectResolver) Tenant(org.craftercms.profile.api.Tenant) TenantPermissionResolver(org.craftercms.profile.management.security.permissions.TenantPermissionResolver) PermissionEvaluatorImpl(org.craftercms.commons.security.permissions.impl.PermissionEvaluatorImpl) Profile(org.craftercms.profile.api.Profile) Before(org.junit.Before)

Example 17 with Tenant

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

the class TenantControllerTest method testCreateTenant.

@Test
public void testCreateTenant() throws Exception {
    setCurrentUser(getProfile(TENANT_NAME1, SUPERADMIN_ROLE));
    Tenant tenant = getTenant(TENANT_ID3, TENANT_NAME3, PROFILE_ADMIN_ROLE);
    Map<String, String> model = controller.createTenant(tenant);
    assertNotNull(model);
    assertEquals(1, model.size());
    assertEquals(String.format(MSG_TENANT_CREATED_FORMAT, TENANT_NAME3), model.get(MODEL_MESSAGE));
    verify(tenantService).createTenant(tenant);
}
Also used : Tenant(org.craftercms.profile.api.Tenant) Test(org.junit.Test)

Example 18 with Tenant

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

the class TenantControllerTest method testGetTenant.

@Test
public void testGetTenant() throws Exception {
    setCurrentUser(getProfile(TENANT_NAME1, PROFILE_ADMIN_ROLE));
    Tenant tenant = controller.getTenant(TENANT_NAME1);
    assertNotNull(tenant);
    assertEquals(TENANT_NAME1, tenant.getName());
}
Also used : Tenant(org.craftercms.profile.api.Tenant) Test(org.junit.Test)

Example 19 with Tenant

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

the class TenantControllerTest method getTenant.

private Tenant getTenant(ObjectId id, String name, String... availableRoles) {
    Tenant tenant = new Tenant();
    tenant.setId(id);
    tenant.setName(name);
    tenant.setAvailableRoles(SetUtils.asSet(availableRoles));
    return tenant;
}
Also used : Tenant(org.craftercms.profile.api.Tenant)

Example 20 with Tenant

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

the class TenantServiceImpl method verifyNewProfiles.

@Override
public Tenant verifyNewProfiles(String tenantName, final boolean verify) throws ProfileException {
    Tenant tenant = updateTenant(tenantName, new UpdateCallback() {

        @Override
        public void doWithTenant(TenantUpdater tenantUpdater) throws ProfileException {
            tenantUpdater.setVerifyNewProfiles(verify);
        }
    });
    logger.debug(LOG_KEY_VERIFY_NEW_PROFILES_FLAG_SET, tenantName, verify);
    return tenant;
}
Also used : Tenant(org.craftercms.profile.api.Tenant) TenantUpdater(org.craftercms.profile.utils.db.TenantUpdater) 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