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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations