Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Reenable disabled tests and clean up #19443

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private RuntimeException cancellationException(boolean failedPostCondition) {
if (skipRecording && cause instanceof RuntimeException rex) throw rex;
CancellationException ex =
failedPostCondition
? new CancellationException("Non-null post-condition failed")
? new CancellationException("Non-null post-condition failed: " + cause.getMessage())
: new CancellationException();
ex.initCause(cause);
return ex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ public ImportReport importMetadata(
handleDeprecationIfEventReport(bundleParams);

progress.startingStage("Creating bundle");
log.info("OBP: " + bundleParams);
ObjectBundle bundle =
progress.nonNullStagePostCondition(
progress.runStage(() -> objectBundleService.create(bundleParams)));

log.info("OB after nonnull stage: " + (bundle != null));
progress.startingStage("Running postCreateBundle");
progress.runStage(() -> postCreateBundle(bundle, bundleParams));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@
Preheat preheat = preheatService.preheat(preheatParams);

ObjectBundle bundle = new ObjectBundle(params, preheat, params.getObjects());
log.info("OB state 1: " + (bundle != null));
Fixed Show fixed Hide fixed
bundle.setObjectBundleStatus(ObjectBundleStatus.CREATED);
log.info("OB state 2: " + (bundle != null));
Fixed Show fixed Hide fixed
bundle.setObjectReferences(preheatService.collectObjectReferences(params.getObjects()));
log.info("OB state 3: " + (bundle != null));
Fixed Show fixed Hide fixed

return bundle;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ public String extractUid() {
return uid;
}

return extractString("response.importSummaries.reference[0]");
uid = extractString("response.importSummaries.reference[0]");
if (!StringUtils.isEmpty(uid)) {
return uid;
}

return extractString("response.typeReports[0].objectReports[0].uid");
}

/** Extracts uids from import summaries. Use when more than one object was created. */
Expand Down
6 changes: 6 additions & 0 deletions dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/ApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.hisp.dhis.helpers.extensions.MetadataSetupExtension;
import org.hisp.dhis.test.e2e.actions.LoginActions;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;

Expand All @@ -51,4 +52,9 @@ public void afterAll() {
new LoginActions().loginAsDefaultUser();
new TestCleanUp().deleteCreatedEntities();
}

@AfterEach
public void cleanup() {
new TestCleanUp().deleteCreatedEntities();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@
import com.google.gson.JsonObject;
import io.restassured.response.ValidatableResponse;
import org.hisp.dhis.ApiTest;
import org.hisp.dhis.helpers.TestCleanUp;
import org.hisp.dhis.test.e2e.actions.LoginActions;
import org.hisp.dhis.test.e2e.actions.RestApiActions;
import org.hisp.dhis.test.e2e.actions.UserActions;
import org.hisp.dhis.test.e2e.actions.metadata.MetadataActions;
import org.hisp.dhis.test.e2e.dto.ApiResponse;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -84,8 +85,12 @@ public void setup() {
setupMetadata();
}

@AfterEach
public void cleanup() {
new TestCleanUp().deleteCreatedEntities();
}

@Test
@Disabled("Started failing in GitHub (Not Jenkins) for no obvious reason")
@DisplayName(
"Valid CategoryOption merge completes successfully with all source CategoryOption refs replaced with target CategoryOption")
void validDataElementMergeTest() {
Expand Down Expand Up @@ -153,11 +158,10 @@ void validDataElementMergeTest() {
}

private void setupMetadata() {
metadataActions.post(metadata()).validateStatus(200);
metadataActions.importMetadata(metadata()).validateStatus(200);
}

@Test
@Disabled("Started failing in GitHub (Not Jenkins) for no obvious reason")
@DisplayName("CategoryOption merge fails when user has not got the required authority")
void testDataElementMergeNoRequiredAuth() {
userActions.addUserFull("basic", "User", "basicUser", "Test1234!", "NO_AUTH");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,23 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.hisp.dhis.ApiTest;
import org.hisp.dhis.helpers.TestCleanUp;
import org.hisp.dhis.test.e2e.actions.LoginActions;
import org.hisp.dhis.test.e2e.actions.RestApiActions;
import org.hisp.dhis.test.e2e.actions.UserActions;
import org.hisp.dhis.test.e2e.actions.metadata.MetadataActions;
import org.hisp.dhis.test.e2e.dto.ApiResponse;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

class DataElementMergeTest extends ApiTest {

private RestApiActions dataElementApiActions;
private RestApiActions datasetApiActions;
private MetadataActions metadataApiActions;
private MetadataActions metadataActions;
private RestApiActions minMaxActions;
private UserActions userActions;
private LoginActions loginActions;
Expand All @@ -66,7 +67,7 @@ public void before() {
loginActions = new LoginActions();
dataElementApiActions = new RestApiActions("dataElements");
datasetApiActions = new RestApiActions("dataSets");
metadataApiActions = new MetadataActions();
metadataActions = new MetadataActions();
minMaxActions = new RestApiActions("minMaxDataElements");
loginActions.loginAsSuperUser();

Expand All @@ -86,6 +87,11 @@ public void setup() {
loginActions.loginAsSuperUser();
}

@AfterEach
public void cleanup() {
new TestCleanUp().deleteCreatedEntities();
}

@Test
@DisplayName(
"Valid DataElement merge completes successfully with all source DataElement refs replaced with target DataElement")
Expand Down Expand Up @@ -124,8 +130,6 @@ void validDataElementMergeTest() {
}

@Test
@Disabled(
"setup started failing on GitHub only 409 response, reason not known, e2e all passing locally")
@DisplayName("DataElement merge fails when min max DE DB unique key constraint met")
void dbConstraintMinMaxTest() {
// given
Expand Down Expand Up @@ -295,14 +299,14 @@ void testDataElementMergeNoRequiredAuth() {
}

private String setupDataElement(String uniqueChar, String valueType, String domainType) {
return dataElementApiActions
.post(createDataElement("source 1" + uniqueChar, valueType, domainType))
.validateStatus(201)
return metadataActions
.importMetadata(createDataElement("source 1" + uniqueChar, valueType, domainType))
.validateStatus(200)
.extractUid();
}

private void setupDataSet(String sourceUid1, String sourceUid2, String targetUid) {
datasetApiActions.post(createDataset(sourceUid1, sourceUid2, targetUid)).extractUid();
metadataActions.importMetadata(createDataset(sourceUid1, sourceUid2, targetUid)).extractUid();
}

private JsonObject getMergeBody(
Expand All @@ -320,16 +324,25 @@ private JsonObject getMergeBody(

private void setupProgramStageDataElements(
String sourceUid1, String sourceUid2, String targetUid) {
metadataApiActions
metadataActions
.importMetadata(programWithStageAndDataElements(sourceUid1, sourceUid2, targetUid))
.validateStatus(200);
}

private void setupMinMaxDataElements(String sourceUid1, String sourceUid2, String targetUid) {
metadataApiActions.importMetadata(metadata()).validateStatus(200);
minMaxActions.post(minMaxDataElements("OrgUnit0Z91", sourceUid1, "CatOptComZ3"));
minMaxActions.post(minMaxDataElements("OrgUnit0Z91", sourceUid2, "CatOptComZ3"));
minMaxActions.post(minMaxDataElements("OrgUnit0Z91", targetUid, "CatOptComZ3"));
metadataActions.importMetadata(metadata()).validateStatus(200);
String mmde1 =
minMaxActions
.post(minMaxDataElements("OrgUnit0Z91", sourceUid1, "CatOptComZ3"))
.getAsString();
String mmde2 =
minMaxActions
.post(minMaxDataElements("OrgUnit0Z91", sourceUid2, "CatOptComZ3"))
.getAsString();
String mmde3 =
minMaxActions
.post(minMaxDataElements("OrgUnit0Z91", targetUid, "CatOptComZ3"))
.getAsString();
}

private String programWithStageAndDataElements(
Expand Down Expand Up @@ -485,38 +498,46 @@ private String minMaxDataElements(String orgUnit, String de, String coc) {
private String createDataElement(String name, String valueType, String domainType) {
return """
{
"aggregationType": "DEFAULT",
"domainType": "%s",
"name": "%s",
"shortName": "%s",
"displayName": "%s",
"valueType": "%s"
}
"dataElements":[
{
"aggregationType": "DEFAULT",
"domainType": "%s",
"name": "%s",
"shortName": "%s",
"displayName": "%s",
"valueType": "%s"
}
]
}
"""
.formatted(domainType, name, name, name, valueType);
}

private String createDataset(String dataEl1, String dataEl2, String dataEl3) {
return """
{
"name": "ds1",
"shortName": "ds1",
"periodType": "Daily",
"dataSetElements": [
{
"dataElement": {
"id": "%s"
}
},
{
"dataElement": {
"id": "%s"
}
},
"dataSets": [
{
"dataElement": {
"id": "%s"
"name": "ds1",
"shortName": "ds1",
"periodType": "Daily",
"dataSetElements": [
{
"dataElement": {
"id": "%s"
}
},
{
"dataElement": {
"id": "%s"
}
},
{
"dataElement": {
"id": "%s"
}
}
]
}
]
}
Expand Down
Loading
Loading