use of org.junit.Assert.assertNotNull in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleFormAttributeServiceIntegrationTest method testSubDefinitionOverrideValidationUnique.
@Test
public void testSubDefinitionOverrideValidationUnique() {
// Create role with attribute (include the sub-definition)
IdmRoleDto role = createRoleWithAttributes();
IdmRoleFormAttributeFilter filter = new IdmRoleFormAttributeFilter();
filter.setRole(role.getId());
List<IdmRoleFormAttributeDto> list = roleFormAttributeService.find(filter, null).getContent();
Assert.assertEquals(2, list.size());
IdmFormDefinitionDto formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
// Set unique validation on false to IP attribute in the sub-definition
list.stream().filter(roleFormAttributeDto -> {
IdmFormAttributeDto formAttributeDto = DtoUtils.getEmbedded(roleFormAttributeDto, IdmRoleFormAttribute_.formAttribute.getName(), IdmFormAttributeDto.class);
return formAttributeDto.getCode().equals(IP);
}).forEach(roleFormAttributeDto -> {
Assert.assertFalse(roleFormAttributeDto.isUnique());
roleFormAttributeDto.setUnique(true);
roleFormAttributeService.save(roleFormAttributeDto);
});
// Load sub-definition by role
formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
IdmFormAttributeDto ipFormAttribute = formAttributeSubdefinition.getFormAttributes().stream().filter(attributeDto -> {
return attributeDto.getCode().equals(IP);
}).findFirst().orElse(null);
Assert.assertNotNull(ipFormAttribute);
Assert.assertTrue(ipFormAttribute.isUnique());
}
use of org.junit.Assert.assertNotNull in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleFormAttributeServiceIntegrationTest method testSubDefinitionOverrideDefaultValue.
@Test
public void testSubDefinitionOverrideDefaultValue() {
// Create role with attribute (include the sub-definition)
IdmRoleDto role = createRoleWithAttributes();
IdmRoleFormAttributeFilter filter = new IdmRoleFormAttributeFilter();
filter.setRole(role.getId());
List<IdmRoleFormAttributeDto> list = roleFormAttributeService.find(filter, null).getContent();
Assert.assertEquals(2, list.size());
IdmFormDefinitionDto formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
// Set unique defaultValue to IP attribute in the sub-definition
String uniqueDefaultValue = this.getHelper().createName();
list.stream().filter(roleFormAttributeDto -> {
IdmFormAttributeDto formAttributeDto = DtoUtils.getEmbedded(roleFormAttributeDto, IdmRoleFormAttribute_.formAttribute.getName(), IdmFormAttributeDto.class);
return formAttributeDto.getCode().equals(IP);
}).forEach(roleFormAttributeDto -> {
roleFormAttributeDto.setDefaultValue(uniqueDefaultValue);
roleFormAttributeService.save(roleFormAttributeDto);
});
// Load sub-definition by role
formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
IdmFormAttributeDto ipFormAttribute = formAttributeSubdefinition.getFormAttributes().stream().filter(attributeDto -> {
return attributeDto.getCode().equals(IP);
}).findFirst().orElse(null);
Assert.assertNotNull(ipFormAttribute);
Assert.assertEquals(uniqueDefaultValue, ipFormAttribute.getDefaultValue());
}
use of org.junit.Assert.assertNotNull in project CzechIdMng by bcvsolutions.
the class DefaultProvisioningExecutorIntegrationTest method testRetryProvisioning.
@Test
public void testRetryProvisioning() {
testProvisioningExceptionProcessor.setDisabled(false);
try {
SysSystemDto system = getHelper().createTestResourceSystem(true);
SysProvisioningOperationDto provisioningOperation = createProvisioningOperation(system, "firstname");
Map<ProvisioningAttributeDto, Object> accoutObject = provisioningOperation.getProvisioningContext().getAccountObject();
String uid = (String) accoutObject.get(getProvisioningAttribute(TestHelper.ATTRIBUTE_MAPPING_NAME));
ZonedDateTime now = ZonedDateTime.now();
//
// publish event
// 1 - create
provisioningExecutor.execute(provisioningOperation);
// is necessary to get again operation from service
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setSystemEntityUid(provisioningOperation.getSystemEntityUid());
filter.setSystemId(system.getId());
SysProvisioningOperationDto operation = provisioningOperationService.find(filter, null).getContent().get(0);
SysProvisioningBatchDto batch = provisioningBatchService.findBatch(operation.getSystemEntity());
Assert.assertEquals(OperationState.EXCEPTION, operation.getResultState());
Assert.assertEquals(AccResultCode.PROVISIONING_FAILED.name(), operation.getResult().getModel().getStatusEnum());
Assert.assertEquals(1, operation.getCurrentAttempt());
Assert.assertTrue(operation.getMaxAttempts() > 1);
Assert.assertTrue(batch.getNextAttempt().isAfter(now));
SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
Assert.assertTrue(systemEntity.isWish());
Assert.assertNull(getHelper().findResource(uid));
// check failed operation is in archive too
List<SysProvisioningArchiveDto> archived = provisioningArchiveService.find(filter, PageRequest.of(0, 10, new Sort(Direction.DESC, SysProvisioningArchive_.created.getName()))).getContent();
Assert.assertEquals(1, archived.size());
Assert.assertEquals(OperationState.EXCEPTION, archived.get(0).getResultState());
Assert.assertEquals(AccResultCode.PROVISIONING_FAILED.name(), archived.get(0).getResult().getModel().getStatusEnum());
//
batch.setNextAttempt(ZonedDateTime.now());
provisioningBatchService.save(batch);
//
// retry - the same exception expected
RetryProvisioningTaskExecutor retryProvisioningTaskExecutor = new RetryProvisioningTaskExecutor();
Boolean result = longRunningTaskManager.executeSync(retryProvisioningTaskExecutor);
Assert.assertTrue(result);
operation = provisioningOperationService.get(operation.getId());
batch = provisioningBatchService.findBatch(systemEntity.getId());
Assert.assertEquals(2, operation.getCurrentAttempt());
Assert.assertNotNull(batch.getNextAttempt());
Assert.assertTrue(batch.getNextAttempt().isAfter(now));
archived = provisioningArchiveService.find(filter, PageRequest.of(0, 10, new Sort(Direction.DESC, SysProvisioningArchive_.created.getName()))).getContent();
Assert.assertEquals(2, archived.size());
Assert.assertEquals(OperationState.EXCEPTION, archived.get(0).getResultState());
Assert.assertEquals(AccResultCode.PROVISIONING_FAILED.name(), archived.get(0).getResult().getModel().getStatusEnum());
//
batch.setNextAttempt(ZonedDateTime.now());
provisioningBatchService.save(batch);
//
// retry - expected success now
testProvisioningExceptionProcessor.setDisabled(true);
retryProvisioningTaskExecutor = new RetryProvisioningTaskExecutor();
longRunningTaskManager.executeSync(retryProvisioningTaskExecutor);
//
systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
Assert.assertFalse(systemEntity.isWish());
Assert.assertNotNull(getHelper().findResource(uid));
batch = provisioningBatchService.get(batch.getId());
Assert.assertNull(batch.getNextAttempt());
archived = provisioningArchiveService.find(filter, PageRequest.of(0, 10, new Sort(Direction.DESC, SysProvisioningArchive_.created.getName()))).getContent();
Assert.assertEquals(3, archived.size());
Assert.assertTrue(archived.stream().anyMatch(a -> a.getResultState() == OperationState.EXECUTED));
} finally {
testProvisioningExceptionProcessor.setDisabled(true);
}
}
use of org.junit.Assert.assertNotNull in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testChangeInvalidContractPositionAndValidityWithAutomaticRolesAssigned.
@Test
public void testChangeInvalidContractPositionAndValidityWithAutomaticRolesAssigned() {
prepareAutomaticRoles();
//
// prepare identity and contract
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = new IdmIdentityContractDto();
contract.setIdentity(identity.getId());
contract.setWorkPosition(nodeD.getId());
LocalDate validTill = LocalDate.now().plusDays(1);
contract.setValidTill(validTill);
contract = service.save(contract);
//
// test after create
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
IdmIdentityRoleDto automaticRole = identityRoles.stream().filter(ir -> {
return roleA.getId().equals(ir.getRole());
}).findFirst().orElse(null);
Assert.assertNotNull(automaticRole);
Assert.assertEquals(validTill, automaticRole.getValidTill());
UUID automaticRoleId = automaticRole.getId();
//
// change validity of contract to past => LOOKOUT: internal method is used to test only
LocalDate minusDays = LocalDate.now().minusDays(1);
contract.setValidTill(minusDays);
contract = service.saveInternal(contract);
Assert.assertEquals(minusDays, contract.getValidTill());
// assigned roles is still unchanged
identityRoles = identityRoleService.findAllByContract(contract.getId());
automaticRole = identityRoles.stream().filter(ir -> {
return roleA.getId().equals(ir.getRole());
}).findFirst().orElse(null);
Assert.assertNotNull(automaticRole);
Assert.assertEquals(validTill, automaticRole.getValidTill());
//
LocalDate newValidTill = LocalDate.now().plusDays(3);
contract.setValidTill(newValidTill);
contract = service.save(contract);
//
// test after change
identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleA.getId().equals(ir.getRole()) && // prevent drop and create
ir.getId().equals(automaticRoleId) && // validity is changed
newValidTill.equals(ir.getValidTill());
}));
}
use of org.junit.Assert.assertNotNull in project flink by apache.
the class OrcColumnarRowInputFormatTest method innerTestRestore.
private void innerTestRestore(OrcColumnarRowInputFormat<?, FileSourceSplit> format, FileSourceSplit split, int breakCnt, int expectedCnt, long expectedTotalF0) throws IOException {
AtomicInteger cnt = new AtomicInteger(0);
AtomicLong totalF0 = new AtomicLong(0);
Consumer<RowData> consumer = row -> {
Assert.assertFalse(row.isNullAt(0));
Assert.assertFalse(row.isNullAt(1));
totalF0.addAndGet(row.getInt(0));
assertNotNull(row.getString(1).toString());
cnt.incrementAndGet();
};
// ---------- restore reading ---------------
long offset = -1;
long recordSkipCount = -1;
try (BulkFormat.Reader<RowData> reader = createReader(format, split)) {
while (cnt.get() < breakCnt) {
BulkFormat.RecordIterator<RowData> batch = reader.readBatch();
Assert.assertNotNull(batch);
RecordAndPosition<RowData> record;
while ((record = batch.next()) != null && cnt.get() < breakCnt) {
consumer.accept(record.getRecord());
offset = record.getOffset();
recordSkipCount = record.getRecordSkipCount();
}
batch.releaseBatch();
}
}
Utils.forEachRemaining(restoreReader(format, split, offset, recordSkipCount), consumer);
// ---------- end restore reading ---------------
// the results should be the same as:
// forEach(format, split, consumer);
// check that all rows have been read
assertEquals(expectedCnt, cnt.get());
assertEquals(expectedTotalF0, totalF0.get());
}
Aggregations