cleanup
This commit is contained in:
parent
cb84efe63d
commit
5d63544a15
@ -3,14 +3,12 @@ package net.hostsharing.hsadminng.hs.hspackage;
|
|||||||
import io.restassured.RestAssured;
|
import io.restassured.RestAssured;
|
||||||
import io.restassured.http.ContentType;
|
import io.restassured.http.ContentType;
|
||||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||||
import net.hostsharing.hsadminng.config.JsonObjectMapperConfiguration;
|
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
|
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -24,8 +22,6 @@ import static org.hamcrest.Matchers.is;
|
|||||||
webEnvironment = WebEnvironment.RANDOM_PORT,
|
webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||||
classes = HsadminNgApplication.class
|
classes = HsadminNgApplication.class
|
||||||
)
|
)
|
||||||
// classes = { PackageController.class, JsonObjectMapperConfiguration.class },
|
|
||||||
@Import(JsonObjectMapperConfiguration.class)
|
|
||||||
@Transactional
|
@Transactional
|
||||||
class PackageControllerAcceptanceTest {
|
class PackageControllerAcceptanceTest {
|
||||||
|
|
||||||
@ -36,7 +32,7 @@ class PackageControllerAcceptanceTest {
|
|||||||
class ListPackages {
|
class ListPackages {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void withoutNameParameter() throws Exception {
|
void withoutNameParameter() {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
RestAssured
|
RestAssured
|
||||||
.given()
|
.given()
|
||||||
@ -57,7 +53,7 @@ class PackageControllerAcceptanceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void withNameParameter() throws Exception {
|
void withNameParameter() {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
RestAssured
|
RestAssured
|
||||||
.given()
|
.given()
|
||||||
@ -78,7 +74,7 @@ class PackageControllerAcceptanceTest {
|
|||||||
class UpdatePackage {
|
class UpdatePackage {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void withDescriptionUpdatesDescription() throws Exception {
|
void withDescriptionUpdatesDescription() {
|
||||||
|
|
||||||
assumeThat(getDescriptionOfPackage("aaa00"))
|
assumeThat(getDescriptionOfPackage("aaa00"))
|
||||||
.isEqualTo("Here can add your own description of package aaa00.");
|
.isEqualTo("Here can add your own description of package aaa00.");
|
||||||
@ -109,7 +105,7 @@ class PackageControllerAcceptanceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void withNullDescriptionUpdatesDescriptionToNull() throws Exception {
|
void withNullDescriptionUpdatesDescriptionToNull() {
|
||||||
|
|
||||||
assumeThat(getDescriptionOfPackage("aaa01"))
|
assumeThat(getDescriptionOfPackage("aaa01"))
|
||||||
.isEqualTo("Here can add your own description of package aaa01.");
|
.isEqualTo("Here can add your own description of package aaa01.");
|
||||||
@ -137,7 +133,7 @@ class PackageControllerAcceptanceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void withoutDescriptionDoesNothing() throws Exception {
|
void withoutDescriptionDoesNothing() {
|
||||||
|
|
||||||
assumeThat(getDescriptionOfPackage("aaa02"))
|
assumeThat(getDescriptionOfPackage("aaa02"))
|
||||||
.isEqualTo("Here can add your own description of package aaa02.");
|
.isEqualTo("Here can add your own description of package aaa02.");
|
||||||
|
@ -34,22 +34,6 @@ class PackageControllerRestTest {
|
|||||||
@MockBean
|
@MockBean
|
||||||
PackageRepository packageRepositoryMock;
|
PackageRepository packageRepositoryMock;
|
||||||
|
|
||||||
// @Autowired
|
|
||||||
// ObjectMapper objectMapper;
|
|
||||||
//
|
|
||||||
// @Autowired
|
|
||||||
// private Jackson2ObjectMapperBuilder jacksonObjectMapper;
|
|
||||||
//
|
|
||||||
// @Autowired
|
|
||||||
// private PackageController restController;
|
|
||||||
|
|
||||||
// @Before
|
|
||||||
// public void init(){
|
|
||||||
//
|
|
||||||
// objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
|
|
||||||
// objectMapper.registerModule(new JsonNullableModule());
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
class ListPackages {
|
class ListPackages {
|
||||||
|
|
||||||
@ -61,7 +45,7 @@ class PackageControllerRestTest {
|
|||||||
when(packageRepositoryMock.findAllByOptionalNameLike(null)).thenReturn(givenPacs);
|
when(packageRepositoryMock.findAllByOptionalNameLike(null)).thenReturn(givenPacs);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
final var pacs = mockMvc.perform(MockMvcRequestBuilders
|
mockMvc.perform(MockMvcRequestBuilders
|
||||||
.get("/api/packages")
|
.get("/api/packages")
|
||||||
.header("current-user", "mike@hostsharing.net")
|
.header("current-user", "mike@hostsharing.net")
|
||||||
.header("assumed-roles", "customer#xxx.admin")
|
.header("assumed-roles", "customer#xxx.admin")
|
||||||
@ -86,7 +70,7 @@ class PackageControllerRestTest {
|
|||||||
when(packageRepositoryMock.findAllByOptionalNameLike("xxx01")).thenReturn(givenPacs);
|
when(packageRepositoryMock.findAllByOptionalNameLike("xxx01")).thenReturn(givenPacs);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
final var pacs = mockMvc.perform(MockMvcRequestBuilders
|
mockMvc.perform(MockMvcRequestBuilders
|
||||||
.get("/api/packages?name=xxx01")
|
.get("/api/packages?name=xxx01")
|
||||||
.header("current-user", "mike@hostsharing.net")
|
.header("current-user", "mike@hostsharing.net")
|
||||||
.header("assumed-roles", "customer#xxx.admin")
|
.header("assumed-roles", "customer#xxx.admin")
|
||||||
@ -114,7 +98,7 @@ class PackageControllerRestTest {
|
|||||||
when(packageRepositoryMock.save(any())).thenAnswer(invocation -> invocation.getArgument(0));
|
when(packageRepositoryMock.save(any())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
final var pacs = mockMvc.perform(MockMvcRequestBuilders
|
mockMvc.perform(MockMvcRequestBuilders
|
||||||
.patch("/api/packages/" + givenPac.getUuid().toString())
|
.patch("/api/packages/" + givenPac.getUuid().toString())
|
||||||
.header("current-user", "mike@hostsharing.net")
|
.header("current-user", "mike@hostsharing.net")
|
||||||
.header("assumed-roles", "customer#xxx.admin")
|
.header("assumed-roles", "customer#xxx.admin")
|
||||||
@ -146,7 +130,7 @@ class PackageControllerRestTest {
|
|||||||
when(packageRepositoryMock.save(any())).thenAnswer(invocation -> invocation.getArgument(0));
|
when(packageRepositoryMock.save(any())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
final var pacs = mockMvc.perform(MockMvcRequestBuilders
|
mockMvc.perform(MockMvcRequestBuilders
|
||||||
.patch("/api/packages/" + givenPac.getUuid().toString())
|
.patch("/api/packages/" + givenPac.getUuid().toString())
|
||||||
.header("current-user", "mike@hostsharing.net")
|
.header("current-user", "mike@hostsharing.net")
|
||||||
.header("assumed-roles", "customer#xxx.admin")
|
.header("assumed-roles", "customer#xxx.admin")
|
||||||
@ -161,8 +145,8 @@ class PackageControllerRestTest {
|
|||||||
verify(contextMock).setCurrentUser("mike@hostsharing.net");
|
verify(contextMock).setCurrentUser("mike@hostsharing.net");
|
||||||
verify(contextMock).assumeRoles("customer#xxx.admin");
|
verify(contextMock).assumeRoles("customer#xxx.admin");
|
||||||
verify(packageRepositoryMock).save(argThat(entity ->
|
verify(packageRepositoryMock).save(argThat(entity ->
|
||||||
entity.getDescription() == givenPac.getDescription() &&
|
givenPac.getDescription().equals(entity.getDescription()) &&
|
||||||
entity.getUuid().equals(givenPac.getUuid())));
|
givenPac.getUuid().equals(entity.getUuid())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user