TSK-1407: adopted RestDocumentation tests to use taskana-common-test aswell

This commit is contained in:
Mustapha Zorgati 2020-10-11 18:23:46 +02:00
parent 980d4490dc
commit 121a9c103f
15 changed files with 32 additions and 57 deletions

View File

@ -72,6 +72,14 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
</dependency>
<!-- TEST DEPENDENCIES -->

View File

@ -1,4 +1,4 @@
package pro.taskana.doc.api;
package pro.taskana.common.test.doc.api;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
@ -13,9 +13,9 @@ import org.springframework.context.annotation.Import;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.context.WebApplicationContext;
import pro.taskana.common.test.doc.api.BaseRestDocumentation.ResultHandlerConfiguration;
import pro.taskana.common.test.rest.RestHelper;
import pro.taskana.common.test.rest.TaskanaSpringBootTest;
import pro.taskana.doc.api.BaseRestDocumentation.ResultHandlerConfiguration;
/** Base class for Rest Documentation tests. */
@TaskanaSpringBootTest

View File

@ -1,10 +1,5 @@
package pro.taskana.doc.api;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.restdocs.payload.PayloadDocumentation.subsectionWithPath;
@ -12,54 +7,24 @@ import static org.springframework.restdocs.payload.PayloadDocumentation.subsecti
import java.util.HashMap;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.restdocs.RestDocumentationContextProvider;
import org.springframework.restdocs.RestDocumentationExtension;
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders;
import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import pro.taskana.simplehistory.rest.TaskHistoryRestConfiguration;
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
/** Generate documentation for the history event controller. */
@SpringBootTest(
classes = TaskHistoryRestConfiguration.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ExtendWith({RestDocumentationExtension.class, SpringExtension.class})
public class TaskHistoryEventControllerRestDocumentation {
public class TaskHistoryEventControllerRestDocumentation extends BaseRestDocumentation {
@LocalServerPort int port;
private MockMvc mockMvc;
private final HashMap<String, String> taskHistoryEventFieldDescriptionsMap = new HashMap<>();
private FieldDescriptor[] allTaskHistoryEventFieldDescriptors;
private FieldDescriptor[] taskHistoryEventFieldDescriptors;
@BeforeEach
public void setUp(
WebApplicationContext webApplicationContext,
RestDocumentationContextProvider restDocumentationContextProvider) {
document("{methodName}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()));
this.mockMvc =
MockMvcBuilders.webAppContextSetup(webApplicationContext)
.apply(
documentationConfiguration(restDocumentationContextProvider)
.operationPreprocessors()
.withResponseDefaults(prettyPrint())
.withRequestDefaults(prettyPrint()))
.build();
public void setUp() {
taskHistoryEventFieldDescriptionsMap.put("taskHistoryId", "Unique ID");
taskHistoryEventFieldDescriptionsMap.put("businessProcessId", "The id of the business process");
taskHistoryEventFieldDescriptionsMap.put(
@ -160,7 +125,7 @@ public class TaskHistoryEventControllerRestDocumentation {
RestDocumentationRequestBuilders.get(
"http://127.0.0.1:" + port + "/api/v1/task-history-event?page=1&page-size=3")
.accept("application/hal+json")
.header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x"))
.header("Authorization", TEAMLEAD_1_CREDENTIALS))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(
MockMvcRestDocumentation.document(
@ -177,7 +142,7 @@ public class TaskHistoryEventControllerRestDocumentation {
+ port
+ "/api/v1/task-history-event/HEI:000000000000000000000000000000000000")
.accept("application/hal+json")
.header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x"))
.header("Authorization", TEAMLEAD_1_CREDENTIALS))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(
MockMvcRestDocumentation.document(

View File

@ -4,36 +4,27 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.time.Instant;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import pro.taskana.simplehistory.rest.TaskHistoryRestConfiguration;
import pro.taskana.common.test.rest.TaskanaSpringBootTest;
import pro.taskana.simplehistory.rest.models.TaskHistoryEventRepresentationModel;
import pro.taskana.spi.history.api.events.task.TaskHistoryCustomField;
import pro.taskana.spi.history.api.events.task.TaskHistoryEvent;
/** Test for {@link TaskHistoryEventRepresentationModelAssembler}. */
@ExtendWith(SpringExtension.class)
@SpringBootTest(
classes = {TaskHistoryRestConfiguration.class},
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TaskanaSpringBootTest
class TaskHistoryEventRepresentationModelAssemblerTest {
private final TaskHistoryEventRepresentationModelAssembler
taskHistoryEventRepresentationModelAssembler;
private final TaskHistoryEventRepresentationModelAssembler assembler;
@Autowired
TaskHistoryEventRepresentationModelAssemblerTest(
TaskHistoryEventRepresentationModelAssembler taskHistoryEventRepresentationModelAssembler) {
this.taskHistoryEventRepresentationModelAssembler =
taskHistoryEventRepresentationModelAssembler;
TaskHistoryEventRepresentationModelAssembler assembler) {
this.assembler = assembler;
}
@Test
void taskHistoryEventModelToResource() {
TaskHistoryEvent historyEvent = new TaskHistoryEvent();
historyEvent.setEventType("TASK_CREATED");
@ -57,7 +48,7 @@ class TaskHistoryEventRepresentationModelAssemblerTest {
historyEvent.setCustomAttribute(TaskHistoryCustomField.CUSTOM_4, "custom4");
TaskHistoryEventRepresentationModel taskHistoryEventRepresentationModel =
taskHistoryEventRepresentationModelAssembler.toModel(historyEvent);
assembler.toModel(historyEvent);
testEquality(historyEvent, taskHistoryEventRepresentationModel);
}

View File

@ -13,6 +13,7 @@ import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import pro.taskana.common.rest.Mapping;
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
/** Generate Rest Docu for AbstractPagingController. */
class AbstractPagingControllerRestDocumentation extends BaseRestDocumentation {

View File

@ -21,6 +21,7 @@ import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import pro.taskana.common.rest.Mapping;
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
/** Generate REST Dokumentation for ClassificationController. */
class ClassificationControllerRestDocumentation extends BaseRestDocumentation {

View File

@ -16,6 +16,7 @@ import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import pro.taskana.common.rest.Mapping;
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
/** Test ClassificationDefinitionControlller. */
class ClassificationDefinitionControllerRestDocumentation extends BaseRestDocumentation {

View File

@ -12,6 +12,7 @@ import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import pro.taskana.common.rest.Mapping;
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
/** Generate common REST Documentation. */
class CommonRestDocumentation extends BaseRestDocumentation {

View File

@ -12,6 +12,7 @@ import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import pro.taskana.common.rest.Mapping;
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
/** Generate REST docu for the monitor controller. */
class MonitorControllerRestDocumentation extends BaseRestDocumentation {

View File

@ -23,6 +23,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import pro.taskana.common.rest.Mapping;
import pro.taskana.common.rest.models.TaskanaPagedModelKeys;
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
class TaskCommentControllerRestDocumentation extends BaseRestDocumentation {

View File

@ -21,6 +21,7 @@ import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import pro.taskana.common.rest.Mapping;
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
/** Generate REST Documentation for the TaskController. */
class TaskControllerRestDocumentation extends BaseRestDocumentation {

View File

@ -11,6 +11,7 @@ import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import pro.taskana.common.rest.Mapping;
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
/** Generate REST Docu for the TaskanaEngineController. */
class TaskanaEngineControllerRestDocumentation extends BaseRestDocumentation {

View File

@ -13,6 +13,7 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import pro.taskana.common.rest.Mapping;
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
/** Generate REST Docu for the WorkbasketAccessItemController. */
class WorkbasketAccessItemControllerRestDocumentation extends BaseRestDocumentation {

View File

@ -22,6 +22,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import pro.taskana.common.rest.Mapping;
import pro.taskana.common.rest.models.TaskanaPagedModelKeys;
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
/** Generate REST Documentatioon for the WorkbasketController. */
class WorkbasketControllerRestDocumentation extends BaseRestDocumentation {

View File

@ -16,6 +16,7 @@ import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import pro.taskana.common.rest.Mapping;
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
/** Generate Rest Documentation for Workbasket Definitions. */
class WorkbasketDefinitionControllerRestDocumentation extends BaseRestDocumentation {