strictly verify config props of all returned elements
This commit is contained in:
parent
274b74514c
commit
28400d1933
@ -1,5 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.asset;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.SneakyThrows;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
@ -32,7 +33,7 @@ import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_M
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_WEBSPACE_HOSTING_ASSET;
|
||||
import static net.hostsharing.hsadminng.hs.office.contact.TestHsOfficeContact.TEST_CONTACT;
|
||||
import static net.hostsharing.hsadminng.rbac.test.JsonMatcher.lenientlyEquals;
|
||||
import static net.hostsharing.hsadminng.rbac.test.JsonMatcher.strictlyEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
@ -189,19 +190,21 @@ public class HsHostingAssetControllerRestTest {
|
||||
final HsHostingAssetType assetType;
|
||||
final List<HsHostingAssetEntity> givenHostingAssetsOfType;
|
||||
final String expectedResponse;
|
||||
final JsonNode expectedResponseJson;
|
||||
|
||||
@SneakyThrows
|
||||
ListTestCases(
|
||||
final List<HsHostingAssetEntity> givenHostingAssetsOfType,
|
||||
final String expectedResponse) {
|
||||
this.assetType = HsHostingAssetType.valueOf(name());
|
||||
this.givenHostingAssetsOfType = givenHostingAssetsOfType;
|
||||
this.expectedResponse = expectedResponse;
|
||||
this.expectedResponseJson = new ObjectMapper().readTree(expectedResponse);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
String expectedConfig() {
|
||||
// FIXME: iterate all indexes, not just 0
|
||||
return new ObjectMapper().readTree(expectedResponse).get(0).path("config").toString();
|
||||
JsonNode expectedConfig(final int n) {
|
||||
return expectedResponseJson.get(n).path("config");
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,7 +224,7 @@ public class HsHostingAssetControllerRestTest {
|
||||
.thenReturn(testCase.givenHostingAssetsOfType);
|
||||
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
final var result = mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/hosting/assets?type="+testCase.name())
|
||||
.header("current-user", "superuser-alex@hostsharing.net")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
@ -229,6 +232,12 @@ public class HsHostingAssetControllerRestTest {
|
||||
// then
|
||||
.andExpect(status().is2xxSuccessful())
|
||||
.andExpect(jsonPath("$", lenientlyEquals(testCase.expectedResponse)))
|
||||
.andExpect(jsonPath("[0].config", strictlyEquals(testCase.expectedConfig())));
|
||||
.andReturn();
|
||||
|
||||
// and the config properties do match not just leniently but even strictly
|
||||
final var resultBody = new ObjectMapper().readTree(result.getResponse().getContentAsString());
|
||||
for (int n = 0; n < resultBody.size(); ++n) {
|
||||
assertThat(resultBody.get(n).path("config")).isEqualTo(testCase.expectedConfig(n));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user