use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleServiceIntegrationTest method testGetRolesByIds.
@Test
public void testGetRolesByIds() {
IdmRoleDto roleOne = getHelper().createRole();
IdmRoleDto roleTwo = getHelper().createRole();
//
List<IdmRoleDto> roles = roleService.getRolesByIds(StringUtils.join(Lists.newArrayList(roleOne.getId(), roleTwo.getId()), ','));
//
Assert.assertEquals(2, roles.size());
Assert.assertTrue(roles.stream().anyMatch(r -> r.getId().equals(roleOne.getId())));
Assert.assertTrue(roles.stream().anyMatch(r -> r.getId().equals(roleTwo.getId())));
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleServiceIntegrationTest method typeFilterTest.
@Test
public void typeFilterTest() {
IdmRoleDto role = getHelper().createRole();
// other
IdmRoleDto roleTwo = getHelper().createRole();
RoleType type = RoleType.SYSTEM;
role.setRoleType(type);
IdmRoleDto roleOne = roleService.save(role);
IdmRoleFilter filter = new IdmRoleFilter();
filter.setRoleType(type);
Page<IdmRoleDto> result = roleService.find(filter, null);
Assert.assertTrue(result.stream().anyMatch(r -> r.getId().equals(roleOne.getId())));
Assert.assertTrue(result.stream().allMatch(r -> !r.getId().equals(roleTwo.getId())));
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultIdmScriptServiceIntegrationTest method testDeployScriptFromAttachement.
@Test
public void testDeployScriptFromAttachement() throws IOException {
String scriptCode = getHelper().createName();
String scriptOne = "<script> <code>" + scriptCode + "</code> <name>Test script 1</name> <body> <![CDATA[ String s; ]]> </body> <type>groovy</type> <category>DEFAULT</category> <parameters>test1</parameters> <services> <service> <name>treeNodeService</name> <className>eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmTreeNodeService</className> </service> <service> <name>identityService</name> <className>eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmIdentityService</className> </service> </services><allowClasses> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmTreeNode</className> </allowClass> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmIdentity</className> </allowClass> </allowClasses> </script>";
// create attachment
IdmAttachmentDto attachment = new IdmAttachmentDto();
attachment.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
attachment.setName("scriptOne.xml");
attachment.setMimetype(MediaType.TEXT_XML_VALUE);
attachment.setInputData(IOUtils.toInputStream(scriptOne));
// owner and version is resolved after attachment is saved
attachment = attachmentManager.saveAttachment(null, attachment);
// deploy
List<IdmScriptDto> results = scriptService.deploy(attachment);
//
Assert.assertEquals(1, results.size());
Assert.assertEquals(scriptCode, results.get(0).getCode());
//
// test authorities
IdmScriptAuthorityFilter authorityFilter = new IdmScriptAuthorityFilter();
authorityFilter.setScriptId(results.get(0).getId());
List<IdmScriptAuthorityDto> authorities = scriptAuthorityService.find(authorityFilter, null).getContent();
Assert.assertEquals(4, authorities.size());
Assert.assertTrue(authorities.stream().allMatch(a -> StringUtils.isNotEmpty(a.getClassName())));
Assert.assertTrue(authorities.stream().anyMatch(a -> "treeNodeService".equals(a.getService())));
Assert.assertTrue(authorities.stream().anyMatch(a -> "identityService".equals(a.getService())));
Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmTreeNode")));
Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmIdentity")));
//
// deploy from archive
IdmScriptDto scriptOneDto = scriptService.getByCode(scriptCode);
String scriptCodeTwo = getHelper().createName();
String scriptOneUpdateName = getHelper().createName();
scriptOne = "<script> <code>" + scriptCode + "</code> <name>" + scriptOneUpdateName + "</name> <body> <![CDATA[ String s; ]]> </body> <type>groovy</type> <category>DEFAULT</category> <parameters>test1</parameters> <services> <service> <name>treeNodeService</name> <className>eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmTreeNodeService</className> </service> </services><allowClasses> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmTreeNode</className> </allowClass> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmIdentity</className> </allowClass> </allowClasses> </script>";
// create attachment
String scriptTwo = "<script> <code>" + scriptCodeTwo + "</code> <name>Test script 2</name> <body> <![CDATA[ String s; ]]> </body> <type>groovy</type> <category>DEFAULT</category> <parameters>test1</parameters> <services> <service> <name>treeNodeService</name> <className>eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmTreeNodeService</className> </service> <service> <name>identityService</name> <className>eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmIdentityService</className> </service> </services><allowClasses> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmTreeNode</className> </allowClass> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmIdentity</className> </allowClass> </allowClasses> </script>";
IdmAttachmentDto attachmentOne = new IdmAttachmentDto();
attachmentOne.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
attachmentOne.setName("scriptOne.xml");
attachmentOne.setMimetype(MediaType.TEXT_XML_VALUE);
attachmentOne.setInputData(IOUtils.toInputStream(scriptOne));
attachmentOne = attachmentManager.saveAttachment(null, attachmentOne);
IdmAttachmentDto attachmentTwo = new IdmAttachmentDto();
attachmentTwo.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
attachmentTwo.setName("scriptTwo.xml");
attachmentTwo.setMimetype(MediaType.TEXT_XML_VALUE);
attachmentTwo.setInputData(IOUtils.toInputStream(scriptTwo));
attachmentTwo = attachmentManager.saveAttachment(null, attachmentTwo);
// zip
File zipFolder = attachmentManager.createTempDirectory(null).toFile();
File targetFileOne = new File(zipFolder.toString(), String.format("%s.xml", attachmentOne.getName()));
Files.copy(attachmentManager.getAttachmentData(attachmentOne.getId()), targetFileOne.toPath(), StandardCopyOption.REPLACE_EXISTING);
File targetFileTwo = new File(zipFolder.toString(), String.format("%s.xml", attachmentTwo.getName()));
Files.copy(attachmentManager.getAttachmentData(attachmentTwo.getId()), targetFileTwo.toPath(), StandardCopyOption.REPLACE_EXISTING);
// compress
File zipFile = attachmentManager.createTempFile();
ZipUtils.compress(zipFolder, zipFile.getPath());
IdmAttachmentDto attachmentZip = new IdmAttachmentDto();
attachmentZip.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
attachmentZip.setInputData(new FileInputStream(zipFile));
attachmentZip.setEncoding(AttachableEntity.DEFAULT_ENCODING);
// zip ~ octet stream
attachmentZip.setMimetype(AttachableEntity.DEFAULT_MIMETYPE);
attachmentZip.setName("backup.zip");
attachmentZip = attachmentManager.saveAttachment(null, attachmentZip);
// deploy
results = scriptService.deploy(attachmentZip);
//
Assert.assertEquals(2, results.size());
Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(scriptOneDto.getId())));
Assert.assertTrue(results.stream().anyMatch(s -> s.getCode().equals(scriptCode) && s.getName().equals(scriptOneUpdateName)));
Assert.assertTrue(results.stream().anyMatch(s -> s.getCode().equals(scriptCodeTwo)));
//
// test authorities
authorityFilter = new IdmScriptAuthorityFilter();
authorityFilter.setScriptId(scriptOneDto.getId());
authorities = scriptAuthorityService.find(authorityFilter, null).getContent();
Assert.assertEquals(3, authorities.size());
Assert.assertTrue(authorities.stream().allMatch(a -> StringUtils.isNotEmpty(a.getClassName())));
Assert.assertTrue(authorities.stream().anyMatch(a -> "treeNodeService".equals(a.getService())));
Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmTreeNode")));
Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmIdentity")));
//
authorityFilter = new IdmScriptAuthorityFilter();
authorityFilter.setScriptId(scriptService.getByCode(scriptCodeTwo).getId());
authorities = scriptAuthorityService.find(authorityFilter, null).getContent();
Assert.assertEquals(4, authorities.size());
Assert.assertTrue(authorities.stream().allMatch(a -> StringUtils.isNotEmpty(a.getClassName())));
Assert.assertTrue(authorities.stream().anyMatch(a -> "treeNodeService".equals(a.getService())));
Assert.assertTrue(authorities.stream().anyMatch(a -> "identityService".equals(a.getService())));
Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmTreeNode")));
Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmIdentity")));
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningArchiveServiceIntegrationTest method differenceObjectMultipleTest.
@Test
public void differenceObjectMultipleTest() {
String attrName = getHelper().createName();
IcAttributeImpl icAttributeOne = new IcAttributeImpl(attrName, Lists.newArrayList("TESTExisting", "TESTRemoved"));
IcConnectorObject connObjectOld = new IcConnectorObjectImpl(getHelper().createName(), new IcObjectClassImpl("__mock__"), ImmutableList.of(icAttributeOne));
IcAttributeImpl icAttributeTwo = new IcAttributeImpl(attrName, Lists.newArrayList("TESTExisting", "TESTNew"));
IcConnectorObject connObjectNew = new IcConnectorObjectImpl(getHelper().createName(), new IcObjectClassImpl("__mock__"), ImmutableList.of(icAttributeTwo));
List<SysAttributeDifferenceDto> diffs = service.evaluateProvisioningDifferences(connObjectOld, connObjectNew);
List<SysAttributeDifferenceValueDto> values = diffs.get(0).getValues();
Assert.assertEquals(1, diffs.size());
Assert.assertTrue(diffs.get(0).isMultivalue());
Assert.assertTrue(diffs.get(0).isChanged());
Assert.assertNotNull(values);
Assert.assertEquals(3, values.size());
SysAttributeDifferenceValueDto value;
value = values.stream().filter(item -> item.getChange() == null).findFirst().orElse(null);
Assert.assertNotNull(value);
Assert.assertEquals("TESTExisting", value.getValue());
Assert.assertEquals("TESTExisting", value.getOldValue());
value = values.stream().filter(item -> item.getChange() == SysValueChangeType.ADDED).findFirst().orElse(null);
Assert.assertNotNull(value);
Assert.assertEquals("TESTNew", value.getValue());
Assert.assertEquals(null, value.getOldValue());
value = values.stream().filter(item -> item.getChange() == SysValueChangeType.REMOVED).findFirst().orElse(null);
Assert.assertNotNull(value);
Assert.assertEquals("TESTRemoved", value.getValue());
Assert.assertEquals("TESTRemoved", value.getOldValue());
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testRemoveLastRuleRecount.
@Test
public void testRemoveLastRuleRecount() {
// start transaction
TransactionContextHolder.setContext(TransactionContextHolder.createEmptyContext());
UUID transactionId = TransactionContextHolder.getContext().getTransactionId();
//
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmRoleDto role = getHelper().createRole();
//
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
//
IdmAutomaticRoleAttributeRuleDto automaticRoleRule = getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.username.getName(), null, identity.getUsername());
this.recalculateSync(automaticRole.getId());
//
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, identityRoles.size());
Assert.assertEquals(transactionId, identityRoles.get(0).getTransactionId());
//
automaticRoleAttributeRuleService.delete(automaticRoleRule);
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(identityRoles.isEmpty());
//
this.recalculateSync(automaticRole.getId());
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(identityRoles.isEmpty());
//
// check all LRT ended successfully
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setTransactionId(transactionId);
List<IdmLongRunningTaskDto> lrts = longRunningTaskManager.findLongRunningTasks(filter, null).getContent();
Assert.assertFalse(lrts.isEmpty());
Assert.assertTrue(lrts.stream().allMatch(lrt -> lrt.getResultState() == OperationState.EXECUTED));
}
Aggregations