|
75 | 75 | import org.hisp.dhis.user.UserGroup; |
76 | 76 | import org.junit.jupiter.api.DisplayName; |
77 | 77 | import org.junit.jupiter.api.Test; |
| 78 | +import org.junit.jupiter.params.ParameterizedTest; |
| 79 | +import org.junit.jupiter.params.provider.ValueSource; |
78 | 80 | import org.springframework.http.MediaType; |
79 | 81 | import org.springframework.transaction.annotation.Transactional; |
80 | 82 |
|
@@ -105,6 +107,28 @@ void testGetObject() { |
105 | 107 | assertEquals(id, userById.getId()); |
106 | 108 | } |
107 | 109 |
|
| 110 | + @ParameterizedTest |
| 111 | + @ValueSource(strings = {":all", "*", ":simple", "href", "id,href", "id,name,href"}) |
| 112 | + @DisplayName("Single object GET returns href when requested directly or via an expanding preset") |
| 113 | + void testGetObjectWithHref(String fields) { |
| 114 | + String id = GET("/users/").content().getList("users", JsonUser.class).get(0).getId(); |
| 115 | + JsonUser user = |
| 116 | + GET("/users/{id}?fields={fields}", id, fields).content(HttpStatus.OK).as(JsonUser.class); |
| 117 | + String href = user.getString("href").string(); |
| 118 | + assertNotNull(href); |
| 119 | + assertTrue(href.endsWith("/users/" + id)); |
| 120 | + } |
| 121 | + |
| 122 | + @ParameterizedTest |
| 123 | + @ValueSource(strings = {":owner", ":identifiable", ":nameable", ":persisted", "id,name"}) |
| 124 | + @DisplayName("Single object GET omits href for presets that do not expand to it") |
| 125 | + void testGetObjectWithoutHref(String fields) { |
| 126 | + String id = GET("/users/").content().getList("users", JsonUser.class).get(0).getId(); |
| 127 | + JsonUser user = |
| 128 | + GET("/users/{id}?fields={fields}", id, fields).content(HttpStatus.OK).as(JsonUser.class); |
| 129 | + assertFalse(user.has("href")); |
| 130 | + } |
| 131 | + |
108 | 132 | @Test |
109 | 133 | void testGetObjectProperty() { |
110 | 134 | // response will look like: { "surname": <name> } |
|
0 commit comments