Search in sources :

Example 1 with Tenant

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

the class TenantServiceImplTest method testAddAvailableRoles.

@Test
public void testAddAvailableRoles() throws Exception {
    Tenant expected = getTenant1();
    expected.getAvailableRoles().add(ROLE2);
    List<String> rolesToAdd = Collections.singletonList(ROLE2);
    Map<String, Object> expectedPushParams = new HashMap<>();
    expectedPushParams.put("availableRoles", Collections.singletonMap("$each", rolesToAdd));
    Tenant actual = tenantService.addRoles(TENANT1_NAME, rolesToAdd);
    assertEqualTenants(expected, actual);
    verify(tenantRepository).findByName(TENANT1_NAME);
    verify(tenantRepository).update(TENANT1_ID.toString(), "{$push: #}", false, false, expectedPushParams);
}
Also used : Tenant(org.craftercms.profile.api.Tenant) HashMap(java.util.HashMap) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 2 with Tenant

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

the class TenantServiceImplTest method testAddAttributeDefinitions.

@Test
public void testAddAttributeDefinitions() throws Exception {
    AttributeDefinition def = getAttribute2Definition();
    List<AttributeDefinition> defsToAdd = Collections.singletonList(def);
    Tenant expected = getTenant1();
    expected.getAttributeDefinitions().add(def);
    Map<String, Object> expectedPushParams = new HashMap<>();
    expectedPushParams.put("attributeDefinitions", Collections.singletonMap("$each", defsToAdd));
    Tenant actual = tenantService.addAttributeDefinitions(TENANT1_NAME, defsToAdd);
    assertEqualTenants(expected, actual);
    verify(profileRepository).updateAllWithDefaultValue(TENANT1_NAME, ATTRIB2_NAME, DEFAULT_ATTRIB_VALUE);
    verify(tenantRepository).findByName(TENANT1_NAME);
    verify(tenantRepository).update(TENANT1_ID.toString(), "{$push: #}", false, false, expectedPushParams);
}
Also used : Tenant(org.craftercms.profile.api.Tenant) HashMap(java.util.HashMap) AttributeDefinition(org.craftercms.profile.api.AttributeDefinition) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 3 with Tenant

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

the class TenantServiceImplTest method testUpdateAttributeDefinitions.

@Test
public void testUpdateAttributeDefinitions() throws Exception {
    AttributeDefinition def = getAttribute2Definition();
    def.setName(ATTRIB1_NAME);
    Tenant expected = getTenant1();
    expected.getAttributeDefinitions().clear();
    expected.getAttributeDefinitions().add(def);
    Map<String, Object> expectedSetParams = new HashMap<>();
    expectedSetParams.put("attributeDefinitions.0", def);
    Tenant actual = tenantService.updateAttributeDefinitions(TENANT1_NAME, Collections.singletonList(def));
    assertEqualTenants(expected, actual);
    verify(tenantRepository).findByName(TENANT1_NAME);
    verify(tenantRepository).update(TENANT1_ID.toString(), "{$set: #}", false, false, expectedSetParams);
}
Also used : Tenant(org.craftercms.profile.api.Tenant) HashMap(java.util.HashMap) AttributeDefinition(org.craftercms.profile.api.AttributeDefinition) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 4 with Tenant

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

the class TenantServiceImplTest method getTenant1.

private Tenant getTenant1() {
    Tenant tenant = new Tenant();
    tenant.setId(TENANT1_ID);
    tenant.setName(TENANT1_NAME);
    tenant.setVerifyNewProfiles(true);
    tenant.setAvailableRoles(SetUtils.asSet(ROLE1));
    tenant.setAttributeDefinitions(new ArrayList<>(Collections.singletonList(getAttribute1Definition())));
    return tenant;
}
Also used : Tenant(org.craftercms.profile.api.Tenant)

Example 5 with Tenant

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

the class TenantServiceImplTest method testRemoveAvailableRoles.

@Test
public void testRemoveAvailableRoles() throws Exception {
    Tenant expected = getTenant1();
    expected.getAvailableRoles().remove(ROLE1);
    List<String> rolesToRemove = Collections.singletonList(ROLE1);
    Map<String, Object> expectedPullParams = new HashMap<>();
    expectedPullParams.put("availableRoles", Collections.singletonMap("$in", rolesToRemove));
    Tenant actual = tenantService.removeRoles(TENANT1_NAME, rolesToRemove);
    assertEqualTenants(expected, actual);
    verify(profileRepository).removeRoleFromAll(TENANT1_NAME, ROLE1);
    verify(tenantRepository).findByName(TENANT1_NAME);
    verify(tenantRepository).update(TENANT1_ID.toString(), "{$pull: #}", false, false, expectedPullParams);
}
Also used : Tenant(org.craftercms.profile.api.Tenant) HashMap(java.util.HashMap) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

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