Skip to content

Commit

Permalink
test: move TrackedEntitiesExportControllerTest to postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
teleivo committed Jan 15, 2025
1 parent f4e27c2 commit 235b2d3
Show file tree
Hide file tree
Showing 7 changed files with 505 additions and 482 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public class TrackedEntityOperationParams {
/** Tracked entity type to fetch. */
private UID trackedEntityType;

private OrganisationUnitSelectionMode orgUnitMode;
@Builder.Default
private OrganisationUnitSelectionMode orgUnitMode = OrganisationUnitSelectionMode.ACCESSIBLE;

@Getter @Builder.Default
private AssignedUserQueryParam assignedUserQueryParam = AssignedUserQueryParam.ALL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,24 +191,59 @@ public static void assertNotEmpty(Collection<?> actual, String message) {
assertFalse(actual.isEmpty(), message);
}

/**
* Asserts that the given collection is not null and not empty.
*
* @param actual the collection.
* @param messageSupplier fails with this supplied message
*/
public static void assertNotEmpty(Collection<?> actual, Supplier<String> messageSupplier) {
assertNotNull(actual, messageSupplier);
assertFalse(actual.isEmpty(), messageSupplier);
}

/**
* Asserts that the given collection contains the expected number of elements.
*
* @param actual the collection.
*/
public static void assertHasSize(int expected, Collection<?> actual) {
assert expected > 0 : "use assertIsEmpty";

assertNotEmpty(actual);
assertEquals(
assertHasSize(
expected,
actual.size(),
actual,
() ->
String.format(
"expected collection to contain %d elements, it has %d instead: '%s'",
expected, actual.size(), actual));
}

/**
* Asserts that the given collection contains the expected number of elements.
*
* @param actual the collection.
* @param messageSupplier fails with this supplied message
*/
public static void assertHasSize(
int expected, Collection<?> actual, Supplier<String> messageSupplier) {
assert expected > 0 : "use assertIsEmpty";

assertNotEmpty(actual);
assertEquals(expected, actual.size(), messageSupplier);
}

/**
* Asserts that the given collection contains the expected number of elements.
*
* @param actual the collection.
* @param message fails with this message
*/
public static void assertHasSize(int expected, Collection<?> actual, String message) {
assert expected > 0 : "use assertIsEmpty";

assertNotEmpty(actual);
assertEquals(expected, actual.size(), message);
}

/**
* Asserts that the given string starts with the expected prefix.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@
"attribute": {
"id": "j45AR9cBQKc"
},
"value": "programStage qLZC0lvvxQH"
"value": "multi-program-stage-attribute"
}
],
"autoGenerateEvent": true,
Expand Down Expand Up @@ -1126,15 +1126,7 @@
}
],
"validationStrategy": "ON_UPDATE_AND_INSERT",
"featureType": "POINT",
"attributeValues": [
{
"attribute": {
"id": "j45AR9cBQKc"
},
"value": "multi-program-stage-attribute"
}
]
"featureType": "POINT"
},
{
"id": "SKNvpoLioON",
Expand Down Expand Up @@ -1851,6 +1843,29 @@
},
"relationshipEntity": "PROGRAM_STAGE_INSTANCE"
}
},
{
"id": "m1575931405",
"displayFromToName": "Parent Of",
"displayName": "Parent to Child",
"fromConstraint": {
"relationshipEntity": "TRACKED_ENTITY_INSTANCE",
"trackedEntityType": {
"id": "ja8NY4PW7Xm"
}
},
"fromToName": "Child Of",
"name": "Tracked entity to tracked entity",
"sharing": {
"owner": null,
"public": "r-------"
},
"toConstraint": {
"relationshipEntity": "TRACKED_ENTITY_INSTANCE",
"trackedEntityType": {
"id": "ja8NY4PW7Xm"
}
}
}
],
"trackedEntityAttributes": [
Expand Down Expand Up @@ -2230,6 +2245,41 @@
],
"username": "trackeradmin"
},
{
"id": "Z7870757a75",
"access": {
"delete": true,
"externalize": true,
"manage": true,
"read": true,
"update": true,
"write": true
},
"dataViewOrganisationUnits": [
{
"id": "h4w96yEMlzO"
}
],
"displayName": "basicuser",
"email": "basic@dhis2.org",
"firstName": "basic",
"name": "user",
"organisationUnits": [
{
"id": "h4w96yEMlzO"
}
],
"password": "Test123###...",
"passwordLastUpdated": "2020-05-31T08:57:59.060",
"phoneNumber": "+4740332255",
"surname": "basic",
"userRoles": [
{
"id": "UbhT3bXWUyb"
}
],
"username": "basicuser"
},
{
"id": "o1HMTIzBGo7",
"access": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ void shouldReturnEnrollmentsFromSpecifiedProgramWhenRequestingSingleTrackedEntit
trackedEntityService.getTrackedEntity(
UID.of(trackedEntityA), UID.of(programA), TrackedEntityParams.TRUE);

assertContainsOnly(Set.of(enrollmentA), trackedEntity.getEnrollments());
assertContainsOnly(Set.of(enrollmentA), trackedEntity.getEnrollments(), Enrollment::getUid);
}

@Test
Expand All @@ -740,7 +740,9 @@ void shouldReturnAllEnrollmentsWhenRequestingSingleTrackedEntityAndNoProgramSpec
UID.of(trackedEntityA), null, TrackedEntityParams.TRUE);

assertContainsOnly(
Set.of(enrollmentA, enrollmentB, enrollmentProgramB), trackedEntity.getEnrollments());
Set.of(enrollmentA, enrollmentB, enrollmentProgramB),
trackedEntity.getEnrollments(),
Enrollment::getUid);
}

@Test
Expand Down
Loading

0 comments on commit 235b2d3

Please sign in to comment.