Search in sources :

Example 11 with IdmIdentity

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));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 12 with IdmIdentity

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());
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 13 with IdmIdentity

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);
}
Also used : IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity)

Example 14 with IdmIdentity

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());
}
Also used : ArrayList(java.util.ArrayList) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Ignore(org.junit.Ignore) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 15 with IdmIdentity

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());
}
Also used : Serializable(java.io.Serializable) ZonedDateTime(java.time.ZonedDateTime) HashMap(java.util.HashMap) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Aggregations

IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)58 Test (org.junit.Test)44 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)28 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)20 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)18 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)13 Transactional (org.springframework.transaction.annotation.Transactional)11 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)9 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)9 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)7 DataFilter (eu.bcvsolutions.idm.core.api.dto.filter.DataFilter)6 List (java.util.List)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 IdmIdentityContract (eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)5 Assert (org.junit.Assert)5 IdmAuthorityChange (eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange)4 UUID (java.util.UUID)4 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)3 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)3