diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/sync/CompleteDataSetRegistrationSynchronization.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/sync/CompleteDataSetRegistrationSynchronization.java index 2cad9c1f6b3e..8ff122d906f4 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/sync/CompleteDataSetRegistrationSynchronization.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/sync/CompleteDataSetRegistrationSynchronization.java @@ -102,16 +102,14 @@ public SynchronizationResult synchronizeData(JobProgress progress) { this::createContext); if (context.getObjectsToSynchronize() == 0) { - settingsService.put( - "keyLastCompleteDataSetRegistrationSyncSuccess", context.getStartTime().toString()); + settingsService.put("keyLastCompleteDataSetRegistrationSyncSuccess", context.getStartTime()); String msg = "Skipping completeness synchronization, no new or updated data"; progress.completedProcess(msg); return SynchronizationResult.success(msg); } if (runSync(context, progress)) { - settingsService.put( - "keyLastCompleteDataSetRegistrationSyncSuccess", context.getStartTime().toString()); + settingsService.put("keyLastCompleteDataSetRegistrationSyncSuccess", context.getStartTime()); String msg = "Complete data set registration synchronization is done."; progress.completedProcess(msg); return SynchronizationResult.success(msg); diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/sync/CompleteDataSetRegistrationSyncTest.java b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/sync/CompleteDataSetRegistrationSyncTest.java new file mode 100644 index 000000000000..d5fa6491aafc --- /dev/null +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/sync/CompleteDataSetRegistrationSyncTest.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2004-2026, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.dxf2.sync; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.Serializable; +import java.util.Map; +import org.hisp.dhis.dataset.CompleteDataSetRegistrationService; +import org.hisp.dhis.dxf2.dataset.CompleteDataSetRegistrationExchangeService; +import org.hisp.dhis.scheduling.JobProgress; +import org.hisp.dhis.setting.Settings; +import org.hisp.dhis.setting.SystemSettings; +import org.hisp.dhis.setting.SystemSettingsService; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +/** + * Tests {@link CompleteDataSetRegistrationSynchronization}. + * + *
Regression test for {@code BadRequestException: Not a valid value for setting
+ * keyLastCompleteDataSetRegistrationSyncSuccess} thrown during sync process. The value handed to
+ * {@link SystemSettingsService#put} must be a persistable setting value, i.e. round-trip through
+ * {@link Settings#valueOf} into a value the settings validation accepts.
+ */
+@ExtendWith(MockitoExtension.class)
+class CompleteDataSetRegistrationSyncTest {
+
+ private static final String SYNC_SUCCESS_KEY = "keyLastCompleteDataSetRegistrationSyncSuccess";
+
+ @Mock private SystemSettingsService settingsService;
+ @Mock private RestTemplate restTemplate;
+ @Mock private CompleteDataSetRegistrationService completeDataSetRegistrationService;
+
+ @Mock
+ private CompleteDataSetRegistrationExchangeService completeDataSetRegistrationExchangeService;
+
+ @Captor private ArgumentCaptor