add-email-alias-hosting-asset #70
@ -1,5 +1,6 @@
|
|||||||
package net.hostsharing.hsadminng.hs.hosting.asset;
|
package net.hostsharing.hsadminng.hs.hosting.asset;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import net.hostsharing.hsadminng.context.Context;
|
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.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_WEBSPACE_HOSTING_ASSET;
|
||||||
import static net.hostsharing.hsadminng.hs.office.contact.TestHsOfficeContact.TEST_CONTACT;
|
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.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.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
@ -189,19 +190,21 @@ public class HsHostingAssetControllerRestTest {
|
|||||||
final HsHostingAssetType assetType;
|
final HsHostingAssetType assetType;
|
||||||
final List<HsHostingAssetEntity> givenHostingAssetsOfType;
|
final List<HsHostingAssetEntity> givenHostingAssetsOfType;
|
||||||
final String expectedResponse;
|
final String expectedResponse;
|
||||||
|
final JsonNode expectedResponseJson;
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
ListTestCases(
|
ListTestCases(
|
||||||
final List<HsHostingAssetEntity> givenHostingAssetsOfType,
|
final List<HsHostingAssetEntity> givenHostingAssetsOfType,
|
||||||
final String expectedResponse) {
|
final String expectedResponse) {
|
||||||
this.assetType = HsHostingAssetType.valueOf(name());
|
this.assetType = HsHostingAssetType.valueOf(name());
|
||||||
this.givenHostingAssetsOfType = givenHostingAssetsOfType;
|
this.givenHostingAssetsOfType = givenHostingAssetsOfType;
|
||||||
this.expectedResponse = expectedResponse;
|
this.expectedResponse = expectedResponse;
|
||||||
|
this.expectedResponseJson = new ObjectMapper().readTree(expectedResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
String expectedConfig() {
|
JsonNode expectedConfig(final int n) {
|
||||||
// FIXME: iterate all indexes, not just 0
|
return expectedResponseJson.get(n).path("config");
|
||||||
return new ObjectMapper().readTree(expectedResponse).get(0).path("config").toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +224,7 @@ public class HsHostingAssetControllerRestTest {
|
|||||||
.thenReturn(testCase.givenHostingAssetsOfType);
|
.thenReturn(testCase.givenHostingAssetsOfType);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
mockMvc.perform(MockMvcRequestBuilders
|
final var result = mockMvc.perform(MockMvcRequestBuilders
|
||||||
.get("/api/hs/hosting/assets?type="+testCase.name())
|
.get("/api/hs/hosting/assets?type="+testCase.name())
|
||||||
.header("current-user", "superuser-alex@hostsharing.net")
|
.header("current-user", "superuser-alex@hostsharing.net")
|
||||||
.accept(MediaType.APPLICATION_JSON))
|
.accept(MediaType.APPLICATION_JSON))
|
||||||
@ -229,6 +232,12 @@ public class HsHostingAssetControllerRestTest {
|
|||||||
// then
|
// then
|
||||||
.andExpect(status().is2xxSuccessful())
|
.andExpect(status().is2xxSuccessful())
|
||||||
.andExpect(jsonPath("$", lenientlyEquals(testCase.expectedResponse)))
|
.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