use of org.junit.Assert.assertNotNull in project CzechIdMng by bcvsolutions.
the class DefaultAuthorizationManagerIntegrationTest method testCacheAfterContractIsChanged.
@Test
@Transactional
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testCacheAfterContractIsChanged() {
// create and login identity
IdmIdentityDto identity = getHelper().createIdentity();
UUID mockIdentity = UUID.randomUUID();
// prepare role
IdmRoleDto role = getHelper().createRole();
getHelper().createBasePolicy(role.getId(), IdmBasePermission.AUTOCOMPLETE, IdmBasePermission.READ);
getHelper().createIdentityRole(identity, role);
//
Assert.assertNull(cacheManager.getValue(AuthorizationManager.AUTHORIZATION_POLICY_CACHE_NAME, identity.getId()));
Assert.assertNull(cacheManager.getValue(AuthorizationManager.PERMISSION_CACHE_NAME, identity.getId()));
Assert.assertNull(cacheManager.getValue(AuthorizationManager.AUTHORIZATION_POLICY_CACHE_NAME, mockIdentity));
Assert.assertNull(cacheManager.getValue(AuthorizationManager.PERMISSION_CACHE_NAME, mockIdentity));
//
cacheManager.cacheValue(AuthorizationManager.AUTHORIZATION_POLICY_CACHE_NAME, mockIdentity, new HashMap<>());
cacheManager.cacheValue(AuthorizationManager.PERMISSION_CACHE_NAME, mockIdentity, new HashMap<>());
Assert.assertNotNull(cacheManager.getValue(AuthorizationManager.AUTHORIZATION_POLICY_CACHE_NAME, mockIdentity));
Assert.assertNotNull(cacheManager.getValue(AuthorizationManager.PERMISSION_CACHE_NAME, mockIdentity));
//
// without login
Set<String> permissions = manager.getPermissions(role);
Assert.assertTrue(permissions.isEmpty());
//
try {
getHelper().login(identity);
//
// new entity is not supported with cache, but permissions are evaluated
permissions = manager.getPermissions(new IdmRoleDto());
Assert.assertEquals(2, permissions.size());
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.AUTOCOMPLETE.getName())));
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.getName())));
Assert.assertNull(cacheManager.getValue(AuthorizationManager.PERMISSION_CACHE_NAME, identity.getId()));
//
// load from db
permissions = manager.getPermissions(role);
Assert.assertEquals(2, permissions.size());
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.AUTOCOMPLETE.getName())));
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.getName())));
Assert.assertNotNull(cacheManager.getValue(AuthorizationManager.AUTHORIZATION_POLICY_CACHE_NAME, identity.getId()));
Assert.assertNotNull(cacheManager.getValue(AuthorizationManager.PERMISSION_CACHE_NAME, identity.getId()));
// load from cache
permissions = manager.getPermissions(role);
Assert.assertEquals(2, permissions.size());
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.AUTOCOMPLETE.getName())));
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.getName())));
Assert.assertNotNull(cacheManager.getValue(AuthorizationManager.AUTHORIZATION_POLICY_CACHE_NAME, identity.getId()));
Assert.assertNotNull(cacheManager.getValue(AuthorizationManager.PERMISSION_CACHE_NAME, identity.getId()));
// check cache content - one
ValueWrapper cacheValue = cacheManager.getValue(AuthorizationManager.AUTHORIZATION_POLICY_CACHE_NAME, identity.getId());
List<UUID> cachedPolicies = (List) ((Map) cacheValue.get()).get(role.getClass());
Assert.assertEquals(1, cachedPolicies.size());
Assert.assertEquals(BasePermissionEvaluator.class.getCanonicalName(), ((IdmAuthorizationPolicyDto) cacheManager.getValue(AuthorizationManager.AUTHORIZATION_POLICY_DEFINITION_CACHE_NAME, cachedPolicies.get(0)).get()).getEvaluatorType());
cacheValue = cacheManager.getValue(AuthorizationManager.PERMISSION_CACHE_NAME, identity.getId());
permissions = (Set) ((Map) cacheValue.get()).get(role.getId());
Assert.assertEquals(2, permissions.size());
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.AUTOCOMPLETE.getName())));
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.getName())));
//
// change contract => evict cache of logged identity
getHelper().createContract(identity);
//
// check cache is evicted only for logged identity
Assert.assertNotNull(cacheManager.getValue(AuthorizationManager.AUTHORIZATION_POLICY_CACHE_NAME, identity.getId()));
Assert.assertNull(cacheManager.getValue(AuthorizationManager.PERMISSION_CACHE_NAME, identity.getId()));
Assert.assertNotNull(cacheManager.getValue(AuthorizationManager.AUTHORIZATION_POLICY_CACHE_NAME, mockIdentity));
Assert.assertNotNull(cacheManager.getValue(AuthorizationManager.PERMISSION_CACHE_NAME, mockIdentity));
} finally {
logout();
}
}
use of org.junit.Assert.assertNotNull in project CzechIdMng by bcvsolutions.
the class DefaultVsRequestServiceIntegrationTest method checkMultivalueInWishObjectTest.
@Test
public void checkMultivalueInWishObjectTest() {
String ldapGroupsName = "ldapGroups";
String changed = "changed";
List<String> attributes = new ArrayList<>(Lists.newArrayList(BasicVirtualConfiguration.DEFAULT_ATTRIBUTES));
attributes.add(ldapGroupsName);
// Create virtual system with extra attribute (ldapGroups)
SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, attributes);
// Search attribute definition for ldapGroups and set him to multivalue
String virtualSystemKey = MessageFormat.format("{0}:systemId={1}", system.getConnectorKey().getFullName(), system.getId().toString());
String type = VsAccount.class.getName();
IdmFormDefinitionDto definition = this.formService.getDefinition(type, virtualSystemKey);
IdmFormAttributeDto ldapGroupsFormAttr = formAttributeService.findAttribute(VsAccount.class.getName(), definition.getCode(), ldapGroupsName);
Assert.assertNotNull("Ldap attribute muste exist!", ldapGroupsFormAttr);
ldapGroupsFormAttr.setMultiple(true);
// Change the name of this attribute. We want to check that logic no depends on the attribute name.
ldapGroupsFormAttr.setName(helper.createName());
formService.saveAttribute(ldapGroupsFormAttr);
// Generate schema for system (we need propagate multivalue setting)
SysSchemaObjectClassDto schema = systemService.generateSchema(system).get(0);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
List<SysSchemaAttributeDto> schemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
SysSystemMappingFilter systemMappingFilter = new SysSystemMappingFilter();
systemMappingFilter.setSystemId(system.getId());
systemMappingFilter.setObjectClassId(schema.getId());
SysSystemMappingDto mapping = systemMappingService.find(systemMappingFilter, null).getContent().get(0);
for (SysSchemaAttributeDto schemaAttr : schemaAttributes) {
if (ldapGroupsName.equals(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setUid(false);
attributeMapping.setEntityAttribute(false);
attributeMapping.setExtendedAttribute(true);
attributeMapping.setIdmPropertyName(ldapGroupsName);
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setSystemMapping(mapping.getId());
systemAttributeMappingService.save(attributeMapping);
}
}
IdmIdentityDto userOne = helper.createIdentity(USER_ONE_NAME);
List<Serializable> initList = ImmutableList.of("TEST1", "TEST2", "TEST3");
formService.saveValues(userOne, ldapGroupsName, initList);
this.assignRoleSystem(system, userOne, ROLE_ONE_NAME);
// Find created requests
VsRequestFilter requestFilter = new VsRequestFilter();
requestFilter.setSystemId(system.getId());
requestFilter.setUid(USER_ONE_NAME);
List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
Assert.assertEquals(1, requests.size());
VsRequestDto createRequest = requests.get(0);
Assert.assertEquals(USER_ONE_NAME, createRequest.getUid());
Assert.assertEquals(VsOperationType.CREATE, createRequest.getOperationType());
Assert.assertEquals(VsRequestState.IN_PROGRESS, createRequest.getState());
VsConnectorObjectDto wish = requestService.getWishConnectorObject(createRequest);
boolean findAttributeWithouChange = wish.getAttributes().stream().filter(attribute -> !attribute.isChanged()).findFirst().isPresent();
Assert.assertTrue(!findAttributeWithouChange);
// Check on exist ldapGroups attribute with three values
SysAttributeDifferenceDto ldapGroupAttribute = wish.getAttributes().stream().filter(attribute -> ldapGroupsName.equals(attribute.getName())).findFirst().get();
Assert.assertTrue(ldapGroupAttribute.isMultivalue());
Assert.assertEquals(3, ldapGroupAttribute.getValues().size());
// Change multivalue attribute
List<Serializable> changeList = ImmutableList.of("TEST1", changed, "TEST3");
formService.saveValues(userOne, ldapGroupsName, changeList);
// Invoke provisioning
identityService.save(userOne);
requests = requestService.find(requestFilter, null).getContent();
Assert.assertEquals(2, requests.size());
VsRequestDto changeRequest = requests.stream().filter(req -> VsOperationType.UPDATE == req.getOperationType()).findFirst().get();
wish = requestService.getWishConnectorObject(changeRequest);
ldapGroupAttribute = wish.getAttributes().stream().filter(attribute -> ldapGroupsName.equals(attribute.getName())).findFirst().get();
Assert.assertTrue(ldapGroupAttribute.isMultivalue());
// Wish must contains three values (all add) ... because previous create
// request is not realize yet. Wish show changes versus reals state in
// VsAccount.
Assert.assertEquals(3, ldapGroupAttribute.getValues().size());
// We realize the create request
super.logout();
loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
requestService.realize(createRequest);
// Refresh wish
wish = requestService.getWishConnectorObject(changeRequest);
ldapGroupAttribute = wish.getAttributes().stream().filter(attribute -> ldapGroupsName.equals(attribute.getName())).findFirst().get();
Assert.assertTrue(ldapGroupAttribute.isMultivalue());
// Wish must contains four values ... two without change, one delete and
// one add value
Assert.assertEquals(4, ldapGroupAttribute.getValues().size());
// Find unchanged value
boolean findCorrectTest1Value = ldapGroupAttribute.getValues().stream().filter(value -> value.getValue().equals(initList.get(0)) && value.getOldValue().equals(initList.get(0)) && value.getChange() == null).findFirst().isPresent();
Assert.assertTrue(findCorrectTest1Value);
// Find deleted value
boolean findCorrectDeletedTest2Value = ldapGroupAttribute.getValues().stream().filter(value -> value.getValue().equals(initList.get(1)) && value.getOldValue().equals(initList.get(1)) && SysValueChangeType.REMOVED == value.getChange()).findFirst().isPresent();
Assert.assertTrue(findCorrectDeletedTest2Value);
// Find added value
boolean findCorrectCreatedChangedValue = ldapGroupAttribute.getValues().stream().filter(value -> value.getValue().equals(changed) && value.getOldValue() == null && SysValueChangeType.ADDED == value.getChange()).findFirst().isPresent();
Assert.assertTrue(findCorrectCreatedChangedValue);
}
use of org.junit.Assert.assertNotNull in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method testCreateIdentityWithAutomaticRoleByEavAttribute.
@Test
public void testCreateIdentityWithAutomaticRoleByEavAttribute() {
String username = getHelper().createName();
SysSystemDto system = initData(username, "mockIdentity@idm.eu");
Assert.assertNotNull(system);
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
config.setCreateDefaultContract(true);
config.setStartAutoRoleRec(true);
syncConfigService.save(config);
//
// create form definition, roles, automatic role etc.
IdmRoleDto role = getHelper().createRole();
IdmRoleDto subRole = getHelper().createRole();
getHelper().createRoleComposition(role, subRole);
// sync supports default definition only
IdmFormAttributeDto formAttribute = new IdmFormAttributeDto(getHelper().createName());
IdmFormAttributeDto formAttributeIdentity = formService.saveAttribute(IdmIdentityDto.class, formAttribute);
//
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, formAttributeIdentity.getId(), "mockIdentity@idm.eu");
//
// create mapping to eav attribute - leader = eav
SysSystemMappingDto syncSystemMapping = systemMappingService.get(config.getSystemMapping());
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemMappingId(syncSystemMapping.getId());
SysSystemAttributeMappingDto lastnameAttributeMapping = schemaAttributeMappingService.findBySystemMappingAndName(syncSystemMapping.getId(), ATTRIBUTE_EMAIL);
lastnameAttributeMapping.setEntityAttribute(false);
lastnameAttributeMapping.setExtendedAttribute(true);
lastnameAttributeMapping.setIdmPropertyName(formAttributeIdentity.getCode());
schemaAttributeMappingService.save(lastnameAttributeMapping);
//
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1, OperationResultType.SUCCESS);
Assert.assertFalse(log.isRunning());
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
identityFilter.setUsername(username);
identityFilter.setAddEavMetadata(Boolean.TRUE);
List<IdmIdentityDto> identities = identityService.find(identityFilter, null).getContent();
Assert.assertEquals(1, identities.size());
Assert.assertEquals("mockIdentity@idm.eu", identities.get(0).getEavs().stream().filter(fi -> fi.getFormDefinition().isMain()).findFirst().get().getValues().stream().filter(v -> v.getFormAttribute().equals(formAttributeIdentity.getId())).findFirst().get().getShortTextValue());
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(identities.get(0).getId());
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(identityRoleFilter, null).getContent();
Assert.assertEquals(2, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(role.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(subRole.getId())));
// Delete log
syncLogService.delete(log);
syncConfigService.delete(config);
}
use of org.junit.Assert.assertNotNull in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method testCreateSliceWithEAVs.
@Test
public void testCreateSliceWithEAVs() {
IdmIdentityDto identity = helper.createIdentity();
String contractCode = "contract-one";
IdmContractSliceDto slice = helper.createContractSlice(identity, null, null, null, null);
slice.setContractCode(contractCode);
slice = contractSliceService.save(slice);
// Init form definition for identity-contract
IdmFormDefinitionDto definition = this.initIdentityContractFormDefinition();
// Create slice with EAV values
IdmFormInstanceDto formInstanceDto = formService.getFormInstance(slice, definition);
Assert.assertNotNull(formInstanceDto);
Assert.assertNotNull(formInstanceDto.getFormDefinition());
Assert.assertEquals(0, formInstanceDto.getValues().size());
IdmFormAttributeDto attribute = formInstanceDto.getMappedAttributeByCode(NUMBER_OF_FINGERS);
formService.saveValues(slice, attribute, Lists.newArrayList(BigDecimal.TEN));
// We need to save slice for invoke save slice to the contract
slice = contractSliceService.save(slice);
formInstanceDto = formService.getFormInstance(slice, definition);
Assert.assertNotNull(formInstanceDto);
Assert.assertNotNull(formInstanceDto.getFormDefinition());
Assert.assertEquals(1, formInstanceDto.getValues().size());
Assert.assertEquals(BigDecimal.TEN.longValue(), ((BigDecimal) formInstanceDto.getValues().get(0).getValue()).longValue());
IdmContractSliceFilter filter = new IdmContractSliceFilter();
filter.setIdentity(identity.getId());
List<IdmContractSliceDto> results = contractSliceService.find(filter, null).getContent();
assertEquals(1, results.size());
IdmContractSliceDto createdSlice = results.get(0);
assertTrue(createdSlice.isValid());
assertEquals(null, createdSlice.getValidTill());
// Check created contract by that slice
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setIdentity(identity.getId());
List<IdmIdentityContractDto> resultsContract = //
contractService.find(filter, null).getContent().stream().filter(//
c -> contractService.get(c.getId()).getControlledBySlices()).collect(Collectors.toList());
//
assertEquals(1, resultsContract.size());
IdmIdentityContractDto contract = resultsContract.get(0);
assertEquals(slice.getContractValidFrom(), contract.getValidFrom());
assertEquals(slice.getContractValidTill(), contract.getValidTill());
assertTrue(contract.isValidNowOrInFuture());
IdmFormInstanceDto contractFormInstanceDto = formService.getFormInstance(contract);
Assert.assertNotNull(contractFormInstanceDto);
Assert.assertNotNull(contractFormInstanceDto.getFormDefinition());
Assert.assertEquals(1, contractFormInstanceDto.getValues().size());
Assert.assertEquals(BigDecimal.TEN.longValue(), ((BigDecimal) contractFormInstanceDto.getValues().get(0).getValue()).longValue());
}
use of org.junit.Assert.assertNotNull in project eclipse.jdt.ls by eclipse.
the class CodeActionResolveHandlerTest method testResolveCodeAction_AnnotationQuickFixes.
// See https://github.com/redhat-developer/vscode-java/issues/1992
@Test
public void testResolveCodeAction_AnnotationQuickFixes() throws Exception {
when(preferenceManager.getClientPreferences().isResolveCodeActionSupported()).thenReturn(true);
importProjects("maven/salut4");
IProject proj = WorkspaceHelper.getProject("salut4");
IJavaProject javaProject = JavaCore.create(proj);
assertTrue(javaProject.exists());
IType type = javaProject.findType("org.sample.MyTest");
ICompilationUnit unit = type.getCompilationUnit();
assertFalse(unit.getSource().contains("import org.junit.jupiter.api.Test"));
CodeActionParams params = new CodeActionParams();
params.setTextDocument(new TextDocumentIdentifier(JDTUtils.toURI(unit)));
Position position = new Position(3, 4);
final Range range = new Range(position, position);
params.setRange(range);
CodeActionContext context = new CodeActionContext(Arrays.asList(getDiagnostic(Integer.toString(IProblem.UndefinedType), range)), Collections.singletonList(CodeActionKind.QuickFix));
params.setContext(context);
List<Either<Command, CodeAction>> quickfixActions = server.codeAction(params).join();
assertNotNull(quickfixActions);
assertFalse("No quickfix actions were found", quickfixActions.isEmpty());
Optional<Either<Command, CodeAction>> importTest = quickfixActions.stream().filter(codeAction -> {
return "Import 'Test' (org.junit.jupiter.api)".equals(codeAction.getRight().getTitle());
}).findFirst();
CodeAction codeAction = importTest.get().getRight();
assertEquals(1, codeAction.getDiagnostics().size());
CodeAction resolvedCodeAction = server.resolveCodeAction(codeAction).join();
Assert.assertNotNull("Should resolve the edit property in the resolveCodeAction request", resolvedCodeAction.getEdit());
String actual = AbstractQuickFixTest.evaluateWorkspaceEdit(resolvedCodeAction.getEdit());
assertTrue(actual.contains("import org.junit.jupiter.api.Test"));
}
Aggregations