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