use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testCRUDContractWithAutomaticRolesAsync.
@Test
public void testCRUDContractWithAutomaticRolesAsync() {
prepareAutomaticRoles();
//
try {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
TransactionContextHolder.setContext(TransactionContextHolder.createEmptyContext());
UUID transactionId = TransactionContextHolder.getContext().getTransactionId();
//
// prepare identity and contract
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contractToCreate = service.getPrimeContract(identity.getId());
contractToCreate.setIdentity(identity.getId());
contractToCreate.setValidFrom(LocalDate.now().minusDays(1));
contractToCreate.setValidTill(LocalDate.now().plusMonths(1));
contractToCreate.setWorkPosition(nodeD.getId());
contractToCreate.setMain(true);
contractToCreate.setDescription("test-node-d");
service.save(contractToCreate);
//
IdmIdentityContractDto contract = service.getPrimeContract(identity.getId());
//
// test after create
Assert.assertEquals(nodeD.getId(), contract.getWorkPosition());
Assert.assertEquals("test-node-d", contract.getDescription());
Assert.assertEquals(transactionId, contract.getTransactionId());
//
getHelper().waitForResult(res -> {
return identityRoleService.findAllByContract(contract.getId()).isEmpty();
}, 500, Integer.MAX_VALUE);
getHelper().waitForResult(res -> {
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setRunning(Boolean.TRUE);
//
return taskManager.findLongRunningTasks(filter, null).getTotalElements() != 0;
});
//
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertEquals(3, identityRoles.size());
Assert.assertTrue(identityRoles.stream().allMatch(ir -> contract.getValidFrom().equals(ir.getValidFrom())));
Assert.assertTrue(identityRoles.stream().allMatch(ir -> contract.getValidTill().equals(ir.getValidTill())));
Assert.assertTrue(identityRoles.stream().allMatch(ir -> ir.getTransactionId().equals(transactionId)));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleA.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleB.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleC.getId().equals(ir.getRole());
}));
//
// find by transactionId
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setTransactionId(transactionId);
identityRoles = identityRoleService.find(filter, null).getContent();
Assert.assertEquals(3, identityRoles.size());
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleA.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleB.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleC.getId().equals(ir.getRole());
}));
//
service.delete(contract);
} finally {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
}
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testAssignAutomaticRoleToExistIdentitySync.
@Test
public void testAssignAutomaticRoleToExistIdentitySync() {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
//
IdmIdentityDto identityOne = getHelper().createIdentityOnly();
IdmIdentityDto identityTwo = getHelper().createIdentityOnly();
IdmIdentityDto identityThree = getHelper().createIdentityOnly();
IdmTreeNodeDto treeNode = getHelper().createTreeNode();
IdmIdentityContractDto contractOne = getHelper().createContract(identityOne, treeNode);
IdmIdentityContractDto contractTwo = getHelper().createContract(identityTwo, treeNode);
IdmIdentityContractDto contractThree = getHelper().createContract(identityThree, treeNode);
IdmRoleDto role = getHelper().createRole();
IdmRoleTreeNodeDto automaticRole = getHelper().createAutomaticRole(role, treeNode);
//
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findByAutomaticRole(automaticRole.getId(), null).getContent();
Assert.assertEquals(3, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getIdentityContract().equals(contractOne.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getIdentityContract().equals(contractTwo.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getIdentityContract().equals(contractThree.getId())));
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityRoleServiceIntegrationTest method testReferentialIntegrityDirectRole.
@Test
@Transactional
public void testReferentialIntegrityDirectRole() {
IdmIdentityContractDto contract = getHelper().getPrimeContract(getHelper().createIdentity().getId());
IdmRoleDto directRoleOne = getHelper().createRole();
IdmRoleDto subRoleOne = getHelper().createRole();
IdmRoleDto directRoleTwo = getHelper().createRole();
//
IdmIdentityRoleDto directIdentityRoleOne = new IdmIdentityRoleDto();
directIdentityRoleOne.setIdentityContract(contract.getId());
directIdentityRoleOne.setRole(directRoleOne.getId());
directIdentityRoleOne = service.save(directIdentityRoleOne);
//
IdmIdentityRoleDto subIdentityRoleOne = new IdmIdentityRoleDto();
subIdentityRoleOne.setIdentityContract(contract.getId());
subIdentityRoleOne.setRole(subRoleOne.getId());
subIdentityRoleOne.setDirectRole(directIdentityRoleOne.getId());
subIdentityRoleOne = service.save(subIdentityRoleOne);
//
IdmIdentityRoleDto otherIdentityRoleOne = new IdmIdentityRoleDto();
otherIdentityRoleOne.setIdentityContract(contract.getId());
otherIdentityRoleOne.setRole(directRoleTwo.getId());
otherIdentityRoleOne = service.save(otherIdentityRoleOne);
//
// check after create
List<IdmIdentityRoleDto> assignedRoles = service.findAllByContract(contract.getId());
Assert.assertEquals(3, assignedRoles.size());
//
// delete direct role
service.delete(directIdentityRoleOne);
assignedRoles = service.findAllByContract(contract.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(directRoleTwo.getId())));
}
use of org.junit.Assert.assertTrue in project flow by vaadin.
the class BootstrapHandlerTest method no_body_size_or_page_configurator_adds_margin_and_full_size_for_body.
// 3749
@Test
public void no_body_size_or_page_configurator_adds_margin_and_full_size_for_body() throws InvalidRouteConfigurationException {
initUI(testUI, createVaadinRequest(), Collections.singleton(RootNavigationTarget.class));
Document page = pageBuilder.getBootstrapPage(new BootstrapContext(request, null, session, testUI, this::contextRootRelativePath));
Elements allElements = page.head().getAllElements();
Optional<Element> styleTag = allElements.stream().filter(element -> element.tagName().equals("style")).findFirst();
Assert.assertTrue("Expected a style element in head.", styleTag.isPresent());
Assert.assertTrue("The first style tag should start with body style containing default body size and margin", styleTag.get().toString().startsWith("<style type=\"text/css\">body {height:100vh;width:100%;margin:0;}"));
}
use of org.junit.Assert.assertTrue in project flow by vaadin.
the class BootstrapHandlerTest method getBootstrapPage_removesExportScript.
@Test
public void getBootstrapPage_removesExportScript() throws ServiceException {
initUI(testUI);
BootstrapContext bootstrapContext = new BootstrapContext(request, null, session, testUI, this::contextRootRelativePath);
Document page = pageBuilder.getBootstrapPage(bootstrapContext);
Elements scripts = page.head().getElementsByTag("script");
Assert.assertTrue(scripts.stream().filter(el -> el.attr("src").equals("./VAADIN/build/vaadin-bundle-1111.cache.js")).findFirst().isPresent());
Assert.assertFalse(scripts.stream().filter(el -> el.attr("src").equals("./VAADIN/build/vaadin-export-2222.cache.js")).findFirst().isPresent());
}
Aggregations