Search in sources :

Example 1 with DefaultTrackedEntityInstanceService

use of org.hisp.dhis.trackedentity.DefaultTrackedEntityInstanceService in project dhis2-core by dhis2.

the class TrackerCrudTest method shouldUpdateTrackedEntityWithUpdateStrategy.

@Test
void shouldUpdateTrackedEntityWithUpdateStrategy() {
    List<TrackedEntityInstance> trackedEntityInstanceList = Collections.singletonList(trackedEntityInstance);
    when(importOptions.getImportStrategy()).thenReturn(ImportStrategy.UPDATE);
    ImportSummaries importSummaries = trackedEntityInstanceService.mergeOrDeleteTrackedEntityInstances(trackedEntityInstanceList, importOptions, jobConfiguration);
    assertFalse(importSummaries.getImportSummaries().stream().anyMatch(is -> is.isStatus(ImportStatus.ERROR)));
    verify(defaultTrackedEntityInstanceService, times(1)).getTrackedEntityInstance(trackedEntityInstanceUid, user);
    verify(defaultTrackedEntityInstanceService, times(1)).updateTrackedEntityInstance(any());
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) TrackedEntityAttributeValueService(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService) Mock(org.mockito.Mock) DefaultTrackedEntityInstanceService(org.hisp.dhis.trackedentity.DefaultTrackedEntityInstanceService) ArrayList(java.util.ArrayList) Notifier(org.hisp.dhis.system.notification.Notifier) CALLS_REAL_METHODS(org.mockito.Mockito.CALLS_REAL_METHODS) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) DbmsManager(org.hisp.dhis.dbms.DbmsManager) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) User(org.hisp.dhis.user.User) Mockito.anyString(org.mockito.Mockito.anyString) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) EnrollmentService(org.hisp.dhis.dxf2.events.enrollment.EnrollmentService) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) UserService(org.hisp.dhis.user.UserService) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) IdSchemes(org.hisp.dhis.common.IdSchemes) RelationshipService(org.hisp.dhis.dxf2.events.relationship.RelationshipService) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mockito.times(org.mockito.Mockito.times) AbstractTrackedEntityInstanceService(org.hisp.dhis.dxf2.events.trackedentity.AbstractTrackedEntityInstanceService) SchemaService(org.hisp.dhis.schema.SchemaService) Mockito.when(org.mockito.Mockito.when) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) QueryService(org.hisp.dhis.query.QueryService) Mockito.verify(org.mockito.Mockito.verify) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) NotificationLevel(org.hisp.dhis.system.notification.NotificationLevel) Mockito.anyList(org.mockito.Mockito.anyList) TrackerAccessManager(org.hisp.dhis.trackedentity.TrackerAccessManager) CachingMap(org.hisp.dhis.commons.collection.CachingMap) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) Mockito.any(org.mockito.Mockito.any) Collections(java.util.Collections) IdScheme(org.hisp.dhis.common.IdScheme) Mockito.mock(org.mockito.Mockito.mock) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test)

Example 2 with DefaultTrackedEntityInstanceService

use of org.hisp.dhis.trackedentity.DefaultTrackedEntityInstanceService in project dhis2-core by dhis2.

the class TrackerCrudTest method shouldDeleteTrackedEntityWithDeleteStrategy.

@Test
void shouldDeleteTrackedEntityWithDeleteStrategy() {
    List<TrackedEntityInstance> trackedEntityInstanceList = Collections.singletonList(trackedEntityInstance);
    when(defaultTrackedEntityInstanceService.trackedEntityInstanceExists(trackedEntityInstanceUid)).thenReturn(true);
    when(importOptions.getImportStrategy()).thenReturn(ImportStrategy.DELETE);
    ImportSummaries importSummaries = trackedEntityInstanceService.mergeOrDeleteTrackedEntityInstances(trackedEntityInstanceList, importOptions, jobConfiguration);
    assertFalse(importSummaries.getImportSummaries().stream().anyMatch(is -> is.isStatus(ImportStatus.ERROR)));
    verify(defaultTrackedEntityInstanceService, times(1)).deleteTrackedEntityInstance(any());
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) TrackedEntityAttributeValueService(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService) Mock(org.mockito.Mock) DefaultTrackedEntityInstanceService(org.hisp.dhis.trackedentity.DefaultTrackedEntityInstanceService) ArrayList(java.util.ArrayList) Notifier(org.hisp.dhis.system.notification.Notifier) CALLS_REAL_METHODS(org.mockito.Mockito.CALLS_REAL_METHODS) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) DbmsManager(org.hisp.dhis.dbms.DbmsManager) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) User(org.hisp.dhis.user.User) Mockito.anyString(org.mockito.Mockito.anyString) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) EnrollmentService(org.hisp.dhis.dxf2.events.enrollment.EnrollmentService) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) UserService(org.hisp.dhis.user.UserService) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) IdSchemes(org.hisp.dhis.common.IdSchemes) RelationshipService(org.hisp.dhis.dxf2.events.relationship.RelationshipService) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mockito.times(org.mockito.Mockito.times) AbstractTrackedEntityInstanceService(org.hisp.dhis.dxf2.events.trackedentity.AbstractTrackedEntityInstanceService) SchemaService(org.hisp.dhis.schema.SchemaService) Mockito.when(org.mockito.Mockito.when) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) QueryService(org.hisp.dhis.query.QueryService) Mockito.verify(org.mockito.Mockito.verify) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) NotificationLevel(org.hisp.dhis.system.notification.NotificationLevel) Mockito.anyList(org.mockito.Mockito.anyList) TrackerAccessManager(org.hisp.dhis.trackedentity.TrackerAccessManager) CachingMap(org.hisp.dhis.commons.collection.CachingMap) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) Mockito.any(org.mockito.Mockito.any) Collections(java.util.Collections) IdScheme(org.hisp.dhis.common.IdScheme) Mockito.mock(org.mockito.Mockito.mock) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test)

Example 3 with DefaultTrackedEntityInstanceService

use of org.hisp.dhis.trackedentity.DefaultTrackedEntityInstanceService in project dhis2-core by dhis2.

the class TrackerCrudTest method shouldAddTrackedEntityWithCreateStrategy.

@Test
void shouldAddTrackedEntityWithCreateStrategy() {
    List<TrackedEntityInstance> trackedEntityInstanceList = Collections.singletonList(trackedEntityInstance);
    when(importOptions.getImportStrategy()).thenReturn(ImportStrategy.CREATE);
    ImportSummaries importSummaries = trackedEntityInstanceService.mergeOrDeleteTrackedEntityInstances(trackedEntityInstanceList, importOptions, jobConfiguration);
    assertFalse(importSummaries.getImportSummaries().stream().anyMatch(is -> is.isStatus(ImportStatus.ERROR)));
    verify(defaultTrackedEntityInstanceService, times(1)).addTrackedEntityInstance(any());
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) TrackedEntityAttributeValueService(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService) Mock(org.mockito.Mock) DefaultTrackedEntityInstanceService(org.hisp.dhis.trackedentity.DefaultTrackedEntityInstanceService) ArrayList(java.util.ArrayList) Notifier(org.hisp.dhis.system.notification.Notifier) CALLS_REAL_METHODS(org.mockito.Mockito.CALLS_REAL_METHODS) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) DbmsManager(org.hisp.dhis.dbms.DbmsManager) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) User(org.hisp.dhis.user.User) Mockito.anyString(org.mockito.Mockito.anyString) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) EnrollmentService(org.hisp.dhis.dxf2.events.enrollment.EnrollmentService) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) UserService(org.hisp.dhis.user.UserService) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) IdSchemes(org.hisp.dhis.common.IdSchemes) RelationshipService(org.hisp.dhis.dxf2.events.relationship.RelationshipService) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mockito.times(org.mockito.Mockito.times) AbstractTrackedEntityInstanceService(org.hisp.dhis.dxf2.events.trackedentity.AbstractTrackedEntityInstanceService) SchemaService(org.hisp.dhis.schema.SchemaService) Mockito.when(org.mockito.Mockito.when) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) QueryService(org.hisp.dhis.query.QueryService) Mockito.verify(org.mockito.Mockito.verify) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) NotificationLevel(org.hisp.dhis.system.notification.NotificationLevel) Mockito.anyList(org.mockito.Mockito.anyList) TrackerAccessManager(org.hisp.dhis.trackedentity.TrackerAccessManager) CachingMap(org.hisp.dhis.commons.collection.CachingMap) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) Mockito.any(org.mockito.Mockito.any) Collections(java.util.Collections) IdScheme(org.hisp.dhis.common.IdScheme) Mockito.mock(org.mockito.Mockito.mock) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 List (java.util.List)3 IdScheme (org.hisp.dhis.common.IdScheme)3 IdSchemes (org.hisp.dhis.common.IdSchemes)3 IdentifiableObjectManager (org.hisp.dhis.common.IdentifiableObjectManager)3 CachingMap (org.hisp.dhis.commons.collection.CachingMap)3 DbmsManager (org.hisp.dhis.dbms.DbmsManager)3 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)3 EnrollmentService (org.hisp.dhis.dxf2.events.enrollment.EnrollmentService)3 RelationshipService (org.hisp.dhis.dxf2.events.relationship.RelationshipService)3 AbstractTrackedEntityInstanceService (org.hisp.dhis.dxf2.events.trackedentity.AbstractTrackedEntityInstanceService)3 TrackedEntityInstance (org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)3 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)3 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)3 ImportStrategy (org.hisp.dhis.importexport.ImportStrategy)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 QueryService (org.hisp.dhis.query.QueryService)3 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)3 SchemaService (org.hisp.dhis.schema.SchemaService)3