Search in sources :

Example 26 with JobConfiguration

use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.

the class TrackerTrigramIndexingJobTest method testRunJobWithTwoIndexableAttributesInJobParameters.

@Test
public void testRunJobWithTwoIndexableAttributesInJobParameters() {
    Set<TrackedEntityAttribute> indexableAttributes = new HashSet<>();
    TrackedEntityAttribute tea1 = new TrackedEntityAttribute();
    tea1.setUid("tea1");
    TrackedEntityAttribute tea2 = new TrackedEntityAttribute();
    tea2.setUid("tea2");
    TrackedEntityAttribute tea3 = new TrackedEntityAttribute();
    tea3.setUid("tea3");
    indexableAttributes.add(tea1);
    indexableAttributes.add(tea2);
    indexableAttributes.add(tea3);
    when(trackedEntityAttributeService.getAllTrigramIndexableTrackedEntityAttributes()).thenReturn(indexableAttributes);
    doNothing().when(trackedEntityAttributeTableManager).createTrigramIndex(any());
    JobConfiguration jobConfiguration = new JobConfiguration();
    TrackerTrigramIndexJobParameters jp = new TrackerTrigramIndexJobParameters();
    jp.setAttributes(Stream.of("tea2", "tea3").collect(Collectors.toSet()));
    jobConfiguration.setJobParameters(jp);
    job.execute(jobConfiguration, NoopJobProgress.INSTANCE);
    verify(trackedEntityAttributeTableManager, times(2)).createTrigramIndex(any());
}
Also used : TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackerTrigramIndexJobParameters(org.hisp.dhis.scheduling.parameters.TrackerTrigramIndexJobParameters) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 27 with JobConfiguration

use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.

the class AccountExpiryAlertJobTest method testDisabledJobDoesNotExecute.

@Test
void testDisabledJobDoesNotExecute() {
    when(settingManager.getBoolSetting(SettingKey.ACCOUNT_EXPIRY_ALERT)).thenReturn(false);
    job.execute(new JobConfiguration(), NoopJobProgress.INSTANCE);
    verify(userService, never()).getExpiringUserAccounts(anyInt());
}
Also used : JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test)

Example 28 with JobConfiguration

use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.

the class AccountExpiryAlertJobTest method testEnabledJobSendsEmail.

@Test
void testEnabledJobSendsEmail() {
    when(userService.getExpiringUserAccounts(anyInt())).thenReturn(singletonList(new UserAccountExpiryInfo("username", "email@example.com", Date.valueOf("2021-08-23"))));
    job.execute(new JobConfiguration(), NoopJobProgress.INSTANCE);
    ArgumentCaptor<String> subject = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> text = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> recipient = ArgumentCaptor.forClass(String.class);
    verify(messageSender).sendMessage(subject.capture(), text.capture(), recipient.capture());
    assertEquals("Account Expiry Alert", subject.getValue());
    assertEquals("Dear username, your account is about to expire on 2021-08-23. If your use of the account needs to continue, get in touch with your system administrator.", text.getValue());
    assertEquals("email@example.com", recipient.getValue());
}
Also used : UserAccountExpiryInfo(org.hisp.dhis.user.UserAccountExpiryInfo) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test)

Example 29 with JobConfiguration

use of org.hisp.dhis.scheduling.JobConfiguration 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 30 with JobConfiguration

use of org.hisp.dhis.scheduling.JobConfiguration 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

JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)55 Test (org.junit.jupiter.api.Test)23 ErrorReport (org.hisp.dhis.feedback.ErrorReport)10 List (java.util.List)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 ArrayList (java.util.ArrayList)5 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 InputStream (java.io.InputStream)4 IdScheme (org.hisp.dhis.common.IdScheme)4 CachingMap (org.hisp.dhis.commons.collection.CachingMap)4 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)4 ImportStrategy (org.hisp.dhis.importexport.ImportStrategy)4 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 IdSchemes (org.hisp.dhis.common.IdSchemes)3 IdentifiableObjectManager (org.hisp.dhis.common.IdentifiableObjectManager)3 TrackerTrigramIndexJobParameters (org.hisp.dhis.scheduling.parameters.TrackerTrigramIndexJobParameters)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3