use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerUnitTest method testIsDuplicate.
@Test
public void testIsDuplicate() {
ZonedDateTime created = ZonedDateTime.now();
UUID ownerId = UUID.randomUUID();
//
IdmEntityEventDto eventOne = new IdmEntityEventDto(UUID.randomUUID());
eventOne.setCreated(created.minusNanos(11));
eventOne.setPriority(PriorityType.HIGH);
eventOne.setOwnerId(ownerId);
eventOne.setParentEventType("one");
eventOne.setEventType("type");
//
IdmEntityEventDto eventTwo = new IdmEntityEventDto(UUID.randomUUID());
eventTwo.setCreated(created.minusNanos(21));
eventTwo.setPriority(PriorityType.HIGH);
eventTwo.setOwnerId(ownerId);
eventTwo.setEventType("type");
eventTwo.setParentEventType("one");
//
Assert.assertTrue(manager.isDuplicate(eventOne, eventTwo));
//
eventTwo.setParentEventType("two");
//
Assert.assertFalse(manager.isDuplicate(eventOne, eventTwo));
//
eventTwo.setParentEventType("one");
eventTwo.setEventType("type2");
//
Assert.assertFalse(manager.isDuplicate(eventOne, eventTwo));
//
eventTwo.setEventType("type");
eventOne.getProperties().put("one", "one");
//
Assert.assertFalse(manager.isDuplicate(eventOne, eventTwo));
//
eventTwo.getProperties().put("one", "one");
//
Assert.assertTrue(manager.isDuplicate(eventOne, eventTwo));
//
eventTwo.getProperties().put("one", "one2");
//
Assert.assertFalse(manager.isDuplicate(eventOne, eventTwo));
//
eventTwo.getProperties().put("one", "one");
//
Assert.assertTrue(manager.isDuplicate(eventOne, eventTwo));
//
IdmIdentityDto originalSourceOne = new IdmIdentityDto(UUID.randomUUID());
eventOne.setOriginalSource(originalSourceOne);
//
Assert.assertFalse(manager.isDuplicate(eventOne, eventTwo));
//
eventOne.setOriginalSource(null);
eventTwo.setOriginalSource(originalSourceOne);
//
Assert.assertFalse(manager.isDuplicate(eventOne, eventTwo));
Assert.assertFalse(manager.isDuplicate(eventTwo, eventOne));
//
eventOne.setOriginalSource(new IdmIdentity(originalSourceOne.getId()));
eventTwo.setOriginalSource(originalSourceOne);
//
Assert.assertFalse(manager.isDuplicate(eventOne, eventTwo));
//
eventOne.setOriginalSource(new IdmIdentity(originalSourceOne.getId()));
eventTwo.setOriginalSource(new IdmIdentity(UUID.randomUUID()));
//
Assert.assertFalse(manager.isDuplicate(eventOne, eventTwo));
//
eventOne.setOriginalSource(new IdmIdentity(originalSourceOne.getId()));
eventTwo.setOriginalSource(new IdmIdentity(originalSourceOne.getId()));
//
Assert.assertFalse(manager.isDuplicate(eventOne, eventTwo));
//
eventOne.setOriginalSource(originalSourceOne);
eventTwo.setOriginalSource(new IdmIdentity(originalSourceOne.getId()));
//
Assert.assertFalse(manager.isDuplicate(eventOne, eventTwo));
//
eventOne.setOriginalSource(originalSourceOne);
eventTwo.setOriginalSource(originalSourceOne);
//
Assert.assertTrue(manager.isDuplicate(eventOne, eventTwo));
//
IdmIdentityDto originalSourceTwo = new IdmIdentityDto(originalSourceOne.getId());
eventTwo.setOriginalSource(originalSourceTwo);
//
Assert.assertTrue(manager.isDuplicate(eventOne, eventTwo));
//
IdmIdentityDto embedded = new IdmIdentityDto(UUID.randomUUID());
originalSourceOne.getEmbedded().put("embedded", embedded);
//
Assert.assertTrue(manager.isDuplicate(eventOne, eventTwo));
Assert.assertEquals(embedded, originalSourceOne.getEmbedded().get("embedded"));
//
originalSourceTwo.setFirstName("hoho");
//
Assert.assertFalse(manager.isDuplicate(eventOne, eventTwo));
//
originalSourceOne.setFirstName("hoho");
//
Assert.assertTrue(manager.isDuplicate(eventOne, eventTwo));
//
// audit fields are ignored
originalSourceOne.setModified(ZonedDateTime.now());
//
Assert.assertTrue(manager.isDuplicate(eventOne, eventTwo));
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class UuidFilterBuilderIntegrationTest method testFindIdentityByUuid.
@Test
public void testFindIdentityByUuid() {
// prepare data
IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto identityTwo = getHelper().createIdentity((GuardedString) null);
IdmRoleDto roleOne = getHelper().createRole();
UuidFilter<IdmIdentity> identityFilter = new FindableUuidFilter<>(repository);
//
DataFilter dataFilter = new DataFilter(IdmIdentityDto.class);
dataFilter.setId(identityOne.getId());
List<IdmIdentity> identities = identityFilter.find(dataFilter, null).getContent();
//
assertEquals(1, identities.size());
assertEquals(identityOne.getId(), identities.get(0).getId());
//
dataFilter.setId(identityTwo.getId());
identities = identityFilter.find(dataFilter, null).getContent();
assertEquals(1, identities.size());
assertEquals(identityTwo.getId(), identities.get(0).getId());
//
dataFilter.setId(roleOne.getId());
assertEquals(0, identityFilter.find(dataFilter, null).getTotalElements());
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class DefaultAuditStressTest method createTestIdentity.
/**
* Create test identity
*
* @return
*/
private IdmIdentity createTestIdentity() {
IdmIdentity newIdentity = new IdmIdentity();
newIdentity.setUsername(TEST_IDENTITY);
newIdentity.setFirstName(TEST_IDENTITY);
newIdentity.setLastName(TEST_IDENTITY);
return this.identityRepository.save(newIdentity);
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class DefaultAuditStressTest method createAndUpdateIdentitySimple.
@Test
@Ignore
public void createAndUpdateIdentitySimple() {
List<Result> averageList = new ArrayList<Result>();
// create identity
IdmIdentity identity = this.createTestIdentity();
LOG.info("Start update identity");
long startTime = System.currentTimeMillis();
long startTimeAverage = System.currentTimeMillis();
for (long index = 0; index < MAX_UPDATE; index++) {
// create one update
identity = updatetestIdenityComplex(identity, index);
// and set average for PRINT_PROGRESS
if (index % PRINT_PROGRESS == 0) {
if (index == 0) {
continue;
}
Result resultAverage = new Result(index);
resultAverage.setDuration(startTimeAverage, System.currentTimeMillis());
Double percent = (Double.valueOf(index) / Double.valueOf(MAX_UPDATE)) * 100d;
double average = resultAverage.duration / index;
LOG.info("Status [{}](%), index [{}] average time for save one entity is [{}]ms", String.valueOf(percent), index, String.valueOf(average));
averageList.add(resultAverage);
startTimeAverage = System.currentTimeMillis();
}
}
long finishTime = System.currentTimeMillis();
LOG.info("Finish update identity");
int auditSize = auditService.findRevisions(IdmIdentity.class, identity.getId()).size();
LOG.info("Time of execute [{}]", finishTime - startTime);
LOG.info("Average time for one entity update [{}]", (finishTime - startTime) / MAX_UPDATE);
LOG.info("Audit counts [{}]", auditSize);
LOG.info("1. record [{}]", averageList.get(0).toString());
LOG.info("100 000. record [{}]", averageList.get(100).toString());
LOG.info("200 000. record [{}]", averageList.get(200).toString());
LOG.info("300 000. record [{}]", averageList.get(300).toString());
LOG.info("400 000. record [{}]", averageList.get(400).toString());
LOG.info("500 000. record [{}]", averageList.get(500).toString());
LOG.info("600 000. record [{}]", averageList.get(600).toString());
LOG.info("700 000. record [{}]", averageList.get(700).toString());
LOG.info("800 000. record [{}]", averageList.get(800).toString());
LOG.info("900 000. record [{}]", averageList.get(900).toString());
LOG.info("1 000 000. record [{}]", averageList.get(999).toString());
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerUnitTest method testSetAdditionalPrioritiesForEvent.
@Test
public void testSetAdditionalPrioritiesForEvent() {
when(eventConfiguration.getAsynchronousInstanceId()).thenReturn("mockInstance");
//
ZonedDateTime executeDate = ZonedDateTime.now();
IdmIdentity identity = new IdmIdentity(UUID.randomUUID());
when(lookupService.getOwnerId(any())).thenReturn(identity.getId());
Map<String, Serializable> props = new HashMap<>();
props.put(EntityEvent.EVENT_PROPERTY_EXECUTE_DATE, executeDate);
props.put(EntityEvent.EVENT_PROPERTY_PRIORITY, PriorityType.HIGH);
//
IdmEntityEventDto entityEvent = manager.prepareEvent(identity, new CoreEvent<>(CoreEventType.CREATE, identity, props));
//
Assert.assertEquals("mockInstance", entityEvent.getInstanceId());
Assert.assertEquals(executeDate, entityEvent.getExecuteDate());
Assert.assertEquals(PriorityType.HIGH, entityEvent.getPriority());
}
Aggregations