Skip to content

Commit

Permalink
fix: testDeleteProgramWithMapView failed on jenkins (#19709)
Browse files Browse the repository at this point in the history
* fix: FK constraint error when delete Program with MapView

* fix: failed test on jenkins testDeleteProgramWithMapView

* fix: testDeleteProgramWithMapView failed on jenkins

* fix: testDeleteProgramWithMapView failed on jenkins
  • Loading branch information
vietnguyen authored Jan 20, 2025
1 parent 0936fa2 commit f007409
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@
*/
package org.hisp.dhis.program;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.HashSet;
import java.util.List;
import org.hisp.dhis.mapping.MapView;
import org.hisp.dhis.mapping.MappingService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
Expand Down Expand Up @@ -155,20 +153,4 @@ void testProgramHasOrgUnit() {
OrganisationUnit ou = organisationUnitService.getOrganisationUnit(organisationUnitA.getUid());
assertTrue(programService.hasOrgUnit(p, ou));
}

@Test
void testDeleteProgramWithMapView() {
programService.addProgram(programA);
ProgramStage programStageA = createProgramStage('A', programA);
programStageService.saveProgramStage(programStageA);
programA.getProgramStages().add(programStageA);
MapView mapView = createMapView("Test");
mapView.setProgram(programA);
mapView.setProgramStage(programStageA);
mappingService.addMapView(mapView);
assertDoesNotThrow(() -> programService.deleteProgram(programA));
mapView = mappingService.getMapView(mapView.getId());
assertNull(mapView.getProgram());
assertNull(mapView.getProgramStage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static org.hisp.dhis.test.webapi.Assertions.assertWebMessage;
import static org.hisp.dhis.test.webapi.TestUtils.getMatchingGroupFromPattern;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.fasterxml.jackson.core.JsonProcessingException;
Expand All @@ -43,6 +44,7 @@
import org.hisp.dhis.feedback.ErrorCode;
import org.hisp.dhis.http.HttpStatus;
import org.hisp.dhis.jsontree.JsonList;
import org.hisp.dhis.jsontree.JsonMixed;
import org.hisp.dhis.test.webapi.H2ControllerIntegrationTestBase;
import org.hisp.dhis.test.webapi.json.domain.JsonErrorReport;
import org.hisp.dhis.test.webapi.json.domain.JsonObjectReport;
Expand Down Expand Up @@ -364,4 +366,31 @@ void testCopyProgramWithNoPublicSharing() {

assertStatus(HttpStatus.NOT_FOUND, POST("/programs/%s/copy".formatted(PROGRAM_UID)));
}

@Test
void testDeleteWithMapView() {
String mapViewJson =
"""
{
"name": "test mapview",
"id": "mVIVRd23Jm9",
"organisationUnitLevels": [],
"maps": [],
"layer": "event",
"program": {
"id": "PrZMWi7rBga"
},
"programStage": {
"id": "PSzMWi7rBga"
}
}
""";
POST("/mapViews", mapViewJson).content(HttpStatus.CREATED);

assertStatus(HttpStatus.OK, DELETE("/programs/%s".formatted(PROGRAM_UID)));
assertStatus(HttpStatus.NOT_FOUND, GET("/programs/%s".formatted(PROGRAM_UID)));
JsonMixed mapview = GET("/mapViews/mVIVRd23Jm9").content().as(JsonMixed.class);
assertFalse(mapview.has("program"));
assertFalse(mapview.has("programStage"));
}
}

0 comments on commit f007409

Please sign in to comment.