TSK-1407: adopted RestDocumentation tests to use taskana-common-test aswell
This commit is contained in:
parent
980d4490dc
commit
121a9c103f
|
|
@ -72,6 +72,14 @@
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</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 -->
|
<!-- TEST DEPENDENCIES -->
|
||||||
|
|
|
||||||
|
|
@ -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;
|
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.test.web.servlet.MockMvc;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
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.RestHelper;
|
||||||
import pro.taskana.common.test.rest.TaskanaSpringBootTest;
|
import pro.taskana.common.test.rest.TaskanaSpringBootTest;
|
||||||
import pro.taskana.doc.api.BaseRestDocumentation.ResultHandlerConfiguration;
|
|
||||||
|
|
||||||
/** Base class for Rest Documentation tests. */
|
/** Base class for Rest Documentation tests. */
|
||||||
@TaskanaSpringBootTest
|
@TaskanaSpringBootTest
|
||||||
|
|
@ -1,10 +1,5 @@
|
||||||
package pro.taskana.doc.api;
|
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.fieldWithPath;
|
||||||
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
|
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
|
||||||
import static org.springframework.restdocs.payload.PayloadDocumentation.subsectionWithPath;
|
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 java.util.HashMap;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
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.MockMvcRestDocumentation;
|
||||||
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders;
|
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders;
|
||||||
import org.springframework.restdocs.payload.FieldDescriptor;
|
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.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. */
|
/** Generate documentation for the history event controller. */
|
||||||
@SpringBootTest(
|
public class TaskHistoryEventControllerRestDocumentation extends BaseRestDocumentation {
|
||||||
classes = TaskHistoryRestConfiguration.class,
|
|
||||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
|
||||||
@ExtendWith({RestDocumentationExtension.class, SpringExtension.class})
|
|
||||||
public class TaskHistoryEventControllerRestDocumentation {
|
|
||||||
|
|
||||||
@LocalServerPort int port;
|
|
||||||
|
|
||||||
private MockMvc mockMvc;
|
|
||||||
|
|
||||||
private final HashMap<String, String> taskHistoryEventFieldDescriptionsMap = new HashMap<>();
|
private final HashMap<String, String> taskHistoryEventFieldDescriptionsMap = new HashMap<>();
|
||||||
|
|
||||||
private FieldDescriptor[] allTaskHistoryEventFieldDescriptors;
|
private FieldDescriptor[] allTaskHistoryEventFieldDescriptors;
|
||||||
|
|
||||||
private FieldDescriptor[] taskHistoryEventFieldDescriptors;
|
private FieldDescriptor[] taskHistoryEventFieldDescriptors;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp(
|
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();
|
|
||||||
|
|
||||||
taskHistoryEventFieldDescriptionsMap.put("taskHistoryId", "Unique ID");
|
taskHistoryEventFieldDescriptionsMap.put("taskHistoryId", "Unique ID");
|
||||||
taskHistoryEventFieldDescriptionsMap.put("businessProcessId", "The id of the business process");
|
taskHistoryEventFieldDescriptionsMap.put("businessProcessId", "The id of the business process");
|
||||||
taskHistoryEventFieldDescriptionsMap.put(
|
taskHistoryEventFieldDescriptionsMap.put(
|
||||||
|
|
@ -160,7 +125,7 @@ public class TaskHistoryEventControllerRestDocumentation {
|
||||||
RestDocumentationRequestBuilders.get(
|
RestDocumentationRequestBuilders.get(
|
||||||
"http://127.0.0.1:" + port + "/api/v1/task-history-event?page=1&page-size=3")
|
"http://127.0.0.1:" + port + "/api/v1/task-history-event?page=1&page-size=3")
|
||||||
.accept("application/hal+json")
|
.accept("application/hal+json")
|
||||||
.header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x"))
|
.header("Authorization", TEAMLEAD_1_CREDENTIALS))
|
||||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||||
.andDo(
|
.andDo(
|
||||||
MockMvcRestDocumentation.document(
|
MockMvcRestDocumentation.document(
|
||||||
|
|
@ -177,7 +142,7 @@ public class TaskHistoryEventControllerRestDocumentation {
|
||||||
+ port
|
+ port
|
||||||
+ "/api/v1/task-history-event/HEI:000000000000000000000000000000000000")
|
+ "/api/v1/task-history-event/HEI:000000000000000000000000000000000000")
|
||||||
.accept("application/hal+json")
|
.accept("application/hal+json")
|
||||||
.header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x"))
|
.header("Authorization", TEAMLEAD_1_CREDENTIALS))
|
||||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||||
.andDo(
|
.andDo(
|
||||||
MockMvcRestDocumentation.document(
|
MockMvcRestDocumentation.document(
|
||||||
|
|
|
||||||
|
|
@ -4,36 +4,27 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.simplehistory.rest.models.TaskHistoryEventRepresentationModel;
|
||||||
import pro.taskana.spi.history.api.events.task.TaskHistoryCustomField;
|
import pro.taskana.spi.history.api.events.task.TaskHistoryCustomField;
|
||||||
import pro.taskana.spi.history.api.events.task.TaskHistoryEvent;
|
import pro.taskana.spi.history.api.events.task.TaskHistoryEvent;
|
||||||
|
|
||||||
/** Test for {@link TaskHistoryEventRepresentationModelAssembler}. */
|
/** Test for {@link TaskHistoryEventRepresentationModelAssembler}. */
|
||||||
@ExtendWith(SpringExtension.class)
|
@TaskanaSpringBootTest
|
||||||
@SpringBootTest(
|
|
||||||
classes = {TaskHistoryRestConfiguration.class},
|
|
||||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
|
||||||
class TaskHistoryEventRepresentationModelAssemblerTest {
|
class TaskHistoryEventRepresentationModelAssemblerTest {
|
||||||
|
|
||||||
private final TaskHistoryEventRepresentationModelAssembler
|
private final TaskHistoryEventRepresentationModelAssembler assembler;
|
||||||
taskHistoryEventRepresentationModelAssembler;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
TaskHistoryEventRepresentationModelAssemblerTest(
|
TaskHistoryEventRepresentationModelAssemblerTest(
|
||||||
TaskHistoryEventRepresentationModelAssembler taskHistoryEventRepresentationModelAssembler) {
|
TaskHistoryEventRepresentationModelAssembler assembler) {
|
||||||
this.taskHistoryEventRepresentationModelAssembler =
|
this.assembler = assembler;
|
||||||
taskHistoryEventRepresentationModelAssembler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void taskHistoryEventModelToResource() {
|
void taskHistoryEventModelToResource() {
|
||||||
|
|
||||||
TaskHistoryEvent historyEvent = new TaskHistoryEvent();
|
TaskHistoryEvent historyEvent = new TaskHistoryEvent();
|
||||||
|
|
||||||
historyEvent.setEventType("TASK_CREATED");
|
historyEvent.setEventType("TASK_CREATED");
|
||||||
|
|
@ -57,7 +48,7 @@ class TaskHistoryEventRepresentationModelAssemblerTest {
|
||||||
historyEvent.setCustomAttribute(TaskHistoryCustomField.CUSTOM_4, "custom4");
|
historyEvent.setCustomAttribute(TaskHistoryCustomField.CUSTOM_4, "custom4");
|
||||||
|
|
||||||
TaskHistoryEventRepresentationModel taskHistoryEventRepresentationModel =
|
TaskHistoryEventRepresentationModel taskHistoryEventRepresentationModel =
|
||||||
taskHistoryEventRepresentationModelAssembler.toModel(historyEvent);
|
assembler.toModel(historyEvent);
|
||||||
|
|
||||||
testEquality(historyEvent, taskHistoryEventRepresentationModel);
|
testEquality(historyEvent, taskHistoryEventRepresentationModel);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import org.springframework.restdocs.payload.FieldDescriptor;
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||||
|
|
||||||
import pro.taskana.common.rest.Mapping;
|
import pro.taskana.common.rest.Mapping;
|
||||||
|
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
|
||||||
|
|
||||||
/** Generate Rest Docu for AbstractPagingController. */
|
/** Generate Rest Docu for AbstractPagingController. */
|
||||||
class AbstractPagingControllerRestDocumentation extends BaseRestDocumentation {
|
class AbstractPagingControllerRestDocumentation extends BaseRestDocumentation {
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import org.springframework.test.web.servlet.MvcResult;
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||||
|
|
||||||
import pro.taskana.common.rest.Mapping;
|
import pro.taskana.common.rest.Mapping;
|
||||||
|
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
|
||||||
|
|
||||||
/** Generate REST Dokumentation for ClassificationController. */
|
/** Generate REST Dokumentation for ClassificationController. */
|
||||||
class ClassificationControllerRestDocumentation extends BaseRestDocumentation {
|
class ClassificationControllerRestDocumentation extends BaseRestDocumentation {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import org.springframework.restdocs.payload.FieldDescriptor;
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||||
|
|
||||||
import pro.taskana.common.rest.Mapping;
|
import pro.taskana.common.rest.Mapping;
|
||||||
|
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
|
||||||
|
|
||||||
/** Test ClassificationDefinitionControlller. */
|
/** Test ClassificationDefinitionControlller. */
|
||||||
class ClassificationDefinitionControllerRestDocumentation extends BaseRestDocumentation {
|
class ClassificationDefinitionControllerRestDocumentation extends BaseRestDocumentation {
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import org.springframework.restdocs.payload.FieldDescriptor;
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||||
|
|
||||||
import pro.taskana.common.rest.Mapping;
|
import pro.taskana.common.rest.Mapping;
|
||||||
|
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
|
||||||
|
|
||||||
/** Generate common REST Documentation. */
|
/** Generate common REST Documentation. */
|
||||||
class CommonRestDocumentation extends BaseRestDocumentation {
|
class CommonRestDocumentation extends BaseRestDocumentation {
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import org.springframework.restdocs.payload.FieldDescriptor;
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||||
|
|
||||||
import pro.taskana.common.rest.Mapping;
|
import pro.taskana.common.rest.Mapping;
|
||||||
|
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
|
||||||
|
|
||||||
/** Generate REST docu for the monitor controller. */
|
/** Generate REST docu for the monitor controller. */
|
||||||
class MonitorControllerRestDocumentation extends BaseRestDocumentation {
|
class MonitorControllerRestDocumentation extends BaseRestDocumentation {
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||||
|
|
||||||
import pro.taskana.common.rest.Mapping;
|
import pro.taskana.common.rest.Mapping;
|
||||||
import pro.taskana.common.rest.models.TaskanaPagedModelKeys;
|
import pro.taskana.common.rest.models.TaskanaPagedModelKeys;
|
||||||
|
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
|
||||||
|
|
||||||
class TaskCommentControllerRestDocumentation extends BaseRestDocumentation {
|
class TaskCommentControllerRestDocumentation extends BaseRestDocumentation {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import org.springframework.test.web.servlet.MvcResult;
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||||
|
|
||||||
import pro.taskana.common.rest.Mapping;
|
import pro.taskana.common.rest.Mapping;
|
||||||
|
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
|
||||||
|
|
||||||
/** Generate REST Documentation for the TaskController. */
|
/** Generate REST Documentation for the TaskController. */
|
||||||
class TaskControllerRestDocumentation extends BaseRestDocumentation {
|
class TaskControllerRestDocumentation extends BaseRestDocumentation {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import org.springframework.restdocs.payload.FieldDescriptor;
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||||
|
|
||||||
import pro.taskana.common.rest.Mapping;
|
import pro.taskana.common.rest.Mapping;
|
||||||
|
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
|
||||||
|
|
||||||
/** Generate REST Docu for the TaskanaEngineController. */
|
/** Generate REST Docu for the TaskanaEngineController. */
|
||||||
class TaskanaEngineControllerRestDocumentation extends BaseRestDocumentation {
|
class TaskanaEngineControllerRestDocumentation extends BaseRestDocumentation {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||||
|
|
||||||
import pro.taskana.common.rest.Mapping;
|
import pro.taskana.common.rest.Mapping;
|
||||||
|
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
|
||||||
|
|
||||||
/** Generate REST Docu for the WorkbasketAccessItemController. */
|
/** Generate REST Docu for the WorkbasketAccessItemController. */
|
||||||
class WorkbasketAccessItemControllerRestDocumentation extends BaseRestDocumentation {
|
class WorkbasketAccessItemControllerRestDocumentation extends BaseRestDocumentation {
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||||
|
|
||||||
import pro.taskana.common.rest.Mapping;
|
import pro.taskana.common.rest.Mapping;
|
||||||
import pro.taskana.common.rest.models.TaskanaPagedModelKeys;
|
import pro.taskana.common.rest.models.TaskanaPagedModelKeys;
|
||||||
|
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
|
||||||
|
|
||||||
/** Generate REST Documentatioon for the WorkbasketController. */
|
/** Generate REST Documentatioon for the WorkbasketController. */
|
||||||
class WorkbasketControllerRestDocumentation extends BaseRestDocumentation {
|
class WorkbasketControllerRestDocumentation extends BaseRestDocumentation {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import org.springframework.restdocs.payload.FieldDescriptor;
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||||
|
|
||||||
import pro.taskana.common.rest.Mapping;
|
import pro.taskana.common.rest.Mapping;
|
||||||
|
import pro.taskana.common.test.doc.api.BaseRestDocumentation;
|
||||||
|
|
||||||
/** Generate Rest Documentation for Workbasket Definitions. */
|
/** Generate Rest Documentation for Workbasket Definitions. */
|
||||||
class WorkbasketDefinitionControllerRestDocumentation extends BaseRestDocumentation {
|
class WorkbasketDefinitionControllerRestDocumentation extends BaseRestDocumentation {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue