diff --git a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/AbstractPagingControllerRestDocumentation.java b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/AbstractPagingControllerRestDocumentation.java index 1fb00dcfd..fa2e3254e 100644 --- a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/AbstractPagingControllerRestDocumentation.java +++ b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/AbstractPagingControllerRestDocumentation.java @@ -1,52 +1,22 @@ 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; -import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import java.util.HashMap; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.restdocs.JUnitRestDocumentation; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; import org.springframework.restdocs.payload.FieldDescriptor; -import org.springframework.test.context.junit4.SpringRunner; -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.rest.RestConfiguration; /** * Generate Rest Docu for AbstractPagingController. */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = RestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT) -public class AbstractPagingControllerRestDocumentation { - - @Rule - public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(); - @LocalServerPort - int port; - @Autowired - private WebApplicationContext context; - - private MockMvc mockMvc; +public class AbstractPagingControllerRestDocumentation extends BaseRestDocumentation { private HashMap pagingFieldDescriptionsMap = new HashMap(); @@ -54,17 +24,6 @@ public class AbstractPagingControllerRestDocumentation { @Before public void setUp() { - document("{methodName}", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint())); - - this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context) - .apply(springSecurity()) - .apply(documentationConfiguration(this.restDocumentation) - .operationPreprocessors() - .withResponseDefaults(prettyPrint()) - .withRequestDefaults(prettyPrint())) - .build(); pagingFieldDescriptionsMap.put("page", "Contains metainfo if there are multiple pages, else it is null"); pagingFieldDescriptionsMap.put("page.size", "Number of items per page"); diff --git a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/BaseRestDocumentation.java b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/BaseRestDocumentation.java new file mode 100644 index 000000000..0068d7b8a --- /dev/null +++ b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/BaseRestDocumentation.java @@ -0,0 +1,56 @@ +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.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.restdocs.JUnitRestDocumentation; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import pro.taskana.rest.RestConfiguration; + +/** + * Base class for Rest Documentation tests. + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = RestConfiguration.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public abstract class BaseRestDocumentation { + + @Rule + public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(); + @LocalServerPort + protected int port; + @Autowired + protected WebApplicationContext context; + + protected MockMvc mockMvc; + + @Before + public void setUpMockMvc() { + document("{methodName}", + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint())); + + this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context) + .apply(springSecurity()) + .apply(documentationConfiguration(this.restDocumentation) + .operationPreprocessors() + .withResponseDefaults(prettyPrint()) + .withRequestDefaults(prettyPrint())) + .build(); + + } + +} diff --git a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/ClassificationControllerRestDocumentation.java b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/ClassificationControllerRestDocumentation.java index 13d190807..05a4e997d 100644 --- a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/ClassificationControllerRestDocumentation.java +++ b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/ClassificationControllerRestDocumentation.java @@ -1,16 +1,10 @@ package pro.taskana.doc.api; import static org.junit.Assert.assertEquals; -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.requestFields; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; import static org.springframework.restdocs.payload.PayloadDocumentation.subsectionWithPath; -import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -19,43 +13,17 @@ import java.net.URL; import java.util.HashMap; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.restdocs.JUnitRestDocumentation; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; import org.springframework.restdocs.payload.FieldDescriptor; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; 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.rest.RestConfiguration; /** * Generate REST Dokumentation for ClassificationController. */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = RestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT) -public class ClassificationControllerRestDocumentation { - - @LocalServerPort - int port; - - @Rule - public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(); - - @Autowired - private WebApplicationContext context; - - private MockMvc mockMvc; +public class ClassificationControllerRestDocumentation extends BaseRestDocumentation { private HashMap classificationFieldDescriptionsMap = new HashMap(); @@ -66,17 +34,6 @@ public class ClassificationControllerRestDocumentation { @Before public void setUp() { - document("{methodName}", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint())); - - this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context) - .apply(springSecurity()) - .apply(documentationConfiguration(this.restDocumentation) - .operationPreprocessors() - .withResponseDefaults(prettyPrint()) - .withRequestDefaults(prettyPrint())) - .build(); classificationFieldDescriptionsMap.put("classificationId", "Unique Id"); classificationFieldDescriptionsMap.put("key", diff --git a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/ClassificationDefinitionControllerRestDocumentation.java b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/ClassificationDefinitionControllerRestDocumentation.java index 1096fb7f9..183672dd8 100644 --- a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/ClassificationDefinitionControllerRestDocumentation.java +++ b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/ClassificationDefinitionControllerRestDocumentation.java @@ -1,70 +1,28 @@ 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.responseFields; import static org.springframework.restdocs.payload.PayloadDocumentation.subsectionWithPath; import static org.springframework.restdocs.request.RequestDocumentation.partWithName; import static org.springframework.restdocs.request.RequestDocumentation.requestParts; -import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.restdocs.JUnitRestDocumentation; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; import org.springframework.restdocs.payload.FieldDescriptor; -import org.springframework.test.context.junit4.SpringRunner; -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.rest.RestConfiguration; /** * Test ClassificationDefinitionControlller. */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = RestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT) -public class ClassificationDefinitionControllerRestDocumentation { - - @LocalServerPort - int port; - - @Rule - public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(); - - @Autowired - private WebApplicationContext context; - - private MockMvc mockMvc; +public class ClassificationDefinitionControllerRestDocumentation extends BaseRestDocumentation { private FieldDescriptor[] classificationDefinitionsFieldDescriptors; @Before public void setUp() { - document("{methodName}", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint())); - - this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context) - .apply(springSecurity()) - .apply(documentationConfiguration(this.restDocumentation) - .operationPreprocessors() - .withResponseDefaults(prettyPrint()) - .withRequestDefaults(prettyPrint())) - .build(); classificationDefinitionsFieldDescriptors = new FieldDescriptor[] { subsectionWithPath("[]").description("An array of <>") diff --git a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/CommonRestDocumentation.java b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/CommonRestDocumentation.java index 2036d8efd..179c56087 100644 --- a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/CommonRestDocumentation.java +++ b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/CommonRestDocumentation.java @@ -1,54 +1,22 @@ 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.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import java.util.HashMap; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.restdocs.JUnitRestDocumentation; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; import org.springframework.restdocs.payload.FieldDescriptor; -import org.springframework.test.context.junit4.SpringRunner; -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.rest.RestConfiguration; /** * Generate common REST Documentation. * */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = RestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT) -public class CommonRestDocumentation { - - @LocalServerPort - int port; - - @Rule - public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(); - - @Autowired - private WebApplicationContext context; - - private MockMvc mockMvc; +public class CommonRestDocumentation extends BaseRestDocumentation { private HashMap selfLinkFieldDescriptionsMap = new HashMap(); @@ -56,17 +24,6 @@ public class CommonRestDocumentation { @Before public void setUp() { - document("{methodName}", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint())); - - this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context) - .apply(springSecurity()) - .apply(documentationConfiguration(this.restDocumentation) - .operationPreprocessors() - .withResponseDefaults(prettyPrint()) - .withRequestDefaults(prettyPrint())) - .build(); selfLinkFieldDescriptionsMap.put("_links", "Links section"); selfLinkFieldDescriptionsMap.put("_links.self", "Link to self"); diff --git a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/MonitorControllerRestDocumentation.java b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/MonitorControllerRestDocumentation.java index cfd6b3c57..0b8c1b577 100644 --- a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/MonitorControllerRestDocumentation.java +++ b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/MonitorControllerRestDocumentation.java @@ -1,67 +1,26 @@ 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; -import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.restdocs.JUnitRestDocumentation; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; import org.springframework.restdocs.payload.FieldDescriptor; -import org.springframework.test.context.junit4.SpringRunner; -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.rest.RestConfiguration; /** * Generate REST docu for the monitor controller. * */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = RestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT) -public class MonitorControllerRestDocumentation { - - @Rule - public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(); - @LocalServerPort - int port; - @Autowired - private WebApplicationContext context; - - private MockMvc mockMvc; +public class MonitorControllerRestDocumentation extends BaseRestDocumentation { private FieldDescriptor[] taskReportFieldDescriptors; @Before public void setUp() { - document("{methodName}", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint())); - - this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context) - .apply(springSecurity()) - .apply(documentationConfiguration(this.restDocumentation) - .operationPreprocessors() - .withResponseDefaults(prettyPrint()) - .withRequestDefaults(prettyPrint())) - .build(); taskReportFieldDescriptors = new FieldDescriptor[] { fieldWithPath("meta").description("Object holding metainfo on the report"), @@ -73,10 +32,13 @@ public class MonitorControllerRestDocumentation { fieldWithPath("rows").description("Array holding the rows of the report."), fieldWithPath("rows[].cells").description("Array holding all the cell values of the given row"), fieldWithPath("rows[].total").description("Sum of all values of the given row"), - fieldWithPath("rows[].depth").description("Depth of the row. If the depth is > 0, then this row is a sub-row of a prior row"), + fieldWithPath("rows[].depth").description( + "Depth of the row. If the depth is > 0, then this row is a sub-row of a prior row"), fieldWithPath("rows[].desc").description("Array containing description of the row."), - fieldWithPath("rows[].display").description("Boolean identifying if the given row should be initially displayed or not."), - subsectionWithPath("sumRow").description("Array holding the sums in the columns over all rows. Structure same as 'rows'"), + fieldWithPath("rows[].display").description( + "Boolean identifying if the given row should be initially displayed or not."), + subsectionWithPath("sumRow").description( + "Array holding the sums in the columns over all rows. Structure same as 'rows'"), fieldWithPath("_links.self.href").ignored() }; } diff --git a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/TaskControllerRestDocumentation.java b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/TaskControllerRestDocumentation.java index fb246934e..28d2bce55 100644 --- a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/TaskControllerRestDocumentation.java +++ b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/TaskControllerRestDocumentation.java @@ -1,16 +1,10 @@ package pro.taskana.doc.api; import static org.junit.Assert.assertEquals; -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.requestFields; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; import static org.springframework.restdocs.payload.PayloadDocumentation.subsectionWithPath; -import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -19,43 +13,17 @@ import java.net.URL; import java.util.HashMap; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.restdocs.JUnitRestDocumentation; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; import org.springframework.restdocs.payload.FieldDescriptor; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; 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.rest.RestConfiguration; /** * Generate REST Documentation for the TaskController. */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = RestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT) -public class TaskControllerRestDocumentation { - - @LocalServerPort - int port; - - @Rule - public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(); - - @Autowired - private WebApplicationContext context; - - private MockMvc mockMvc; +public class TaskControllerRestDocumentation extends BaseRestDocumentation { private HashMap taskFieldDescriptionsMap = new HashMap(); @@ -66,17 +34,6 @@ public class TaskControllerRestDocumentation { @Before public void setUp() { - document("{methodName}", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint())); - - this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context) - .apply(springSecurity()) - .apply(documentationConfiguration(this.restDocumentation) - .operationPreprocessors() - .withResponseDefaults(prettyPrint()) - .withRequestDefaults(prettyPrint())) - .build(); taskFieldDescriptionsMap.put("taskId", "Unique ID"); taskFieldDescriptionsMap.put("externalId", @@ -437,7 +394,7 @@ public class TaskControllerRestDocumentation { String newId = content.substring(content.indexOf("TKI:"), content.indexOf("TKI:") + 40); this.mockMvc.perform(RestDocumentationRequestBuilders - .post("http://127.0.0.1:" + port + "/api/v1/tasks/" + newId + "/claim") + .post("http://127.0.0.1:" + port + "/api/v1/tasks/" + newId + "/claim") .accept("application/hal+json") .header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x") .content("{}")) diff --git a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/TaskanaEngineControllerRestDocumentation.java b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/TaskanaEngineControllerRestDocumentation.java index dc810468e..e4a1ed800 100644 --- a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/TaskanaEngineControllerRestDocumentation.java +++ b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/TaskanaEngineControllerRestDocumentation.java @@ -1,52 +1,20 @@ 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.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.restdocs.JUnitRestDocumentation; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; import org.springframework.restdocs.payload.FieldDescriptor; -import org.springframework.test.context.junit4.SpringRunner; -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.rest.RestConfiguration; /** * Generate REST Docu for the TaskanaEngineController. * */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = RestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT) -public class TaskanaEngineControllerRestDocumentation { - - @LocalServerPort - int port; - - @Rule - public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(); - - @Autowired - private WebApplicationContext context; - - private MockMvc mockMvc; +public class TaskanaEngineControllerRestDocumentation extends BaseRestDocumentation { private FieldDescriptor[] allDomainsFieldDescriptors; private FieldDescriptor[] allClassificationCategoriesFieldDescriptors; @@ -55,17 +23,6 @@ public class TaskanaEngineControllerRestDocumentation { @Before public void setUp() { - document("{methodName}", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint())); - - this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context) - .apply(springSecurity()) - .apply(documentationConfiguration(this.restDocumentation) - .operationPreprocessors() - .withResponseDefaults(prettyPrint()) - .withRequestDefaults(prettyPrint())) - .build(); allDomainsFieldDescriptors = new FieldDescriptor[] { fieldWithPath("[]").description("An array with the domain-names as strings") diff --git a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/WorkbasketAccessItemControllerRestDocumentation.java b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/WorkbasketAccessItemControllerRestDocumentation.java index 14574cfb8..d85d332d7 100644 --- a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/WorkbasketAccessItemControllerRestDocumentation.java +++ b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/WorkbasketAccessItemControllerRestDocumentation.java @@ -1,72 +1,30 @@ 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.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import java.util.HashMap; import org.junit.Before; import org.junit.FixMethodOrder; -import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.restdocs.JUnitRestDocumentation; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; import org.springframework.restdocs.payload.FieldDescriptor; -import org.springframework.test.context.junit4.SpringRunner; -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.rest.RestConfiguration; /** * Generate REST Docu for the WorkbasketAccessItemController. */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = RestConfiguration.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class WorkbasketAccessItemControllerRestDocumentation { - - @LocalServerPort - int port; - - @Rule - public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(); - - @Autowired - private WebApplicationContext context; - - private MockMvc mockMvc; +public class WorkbasketAccessItemControllerRestDocumentation extends BaseRestDocumentation { private HashMap accessItemFieldDescriptionsMap = new HashMap(); private FieldDescriptor[] accessItemFieldDescriptors; @Before public void setUp() { - document("{methodName}", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint())); - - this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context) - .apply(springSecurity()) - .apply(documentationConfiguration(this.restDocumentation) - .operationPreprocessors() - .withResponseDefaults(prettyPrint()) - .withRequestDefaults(prettyPrint())) - .build(); accessItemFieldDescriptionsMap.put("accessItems.accessItemId", "Unique ID"); accessItemFieldDescriptionsMap.put("accessItems.workbasketId", "The workbasket id"); diff --git a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/WorkbasketControllerRestDocumentation.java b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/WorkbasketControllerRestDocumentation.java index f91fb7198..c1633880f 100644 --- a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/WorkbasketControllerRestDocumentation.java +++ b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/WorkbasketControllerRestDocumentation.java @@ -1,16 +1,10 @@ package pro.taskana.doc.api; import static org.junit.Assert.assertEquals; -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.requestFields; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; import static org.springframework.restdocs.payload.PayloadDocumentation.subsectionWithPath; -import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -19,42 +13,16 @@ import java.net.URL; import java.util.HashMap; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.restdocs.JUnitRestDocumentation; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; import org.springframework.restdocs.payload.FieldDescriptor; -import org.springframework.test.context.junit4.SpringRunner; -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.rest.RestConfiguration; /** * Generate REST Documentatioon for the WorkbasketController. */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = RestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT) -public class WorkbasketControllerRestDocumentation { - - @LocalServerPort - int port; - - @Rule - public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(); - - @Autowired - private WebApplicationContext context; - - private MockMvc mockMvc; +public class WorkbasketControllerRestDocumentation extends BaseRestDocumentation { // HashMaps to store the field descriptions centrally for multiple uses private HashMap workbasketFieldDescriptionsMap = new HashMap(); @@ -70,17 +38,6 @@ public class WorkbasketControllerRestDocumentation { @Before public void setUp() { - document("{methodName}", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint())); - - this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context) - .apply(springSecurity()) - .apply(documentationConfiguration(this.restDocumentation) - .operationPreprocessors() - .withResponseDefaults(prettyPrint()) - .withRequestDefaults(prettyPrint())) - .build(); workbasketFieldDescriptionsMap.put("workbasketId", "Unique ID"); workbasketFieldDescriptionsMap.put("key", ""); diff --git a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/WorkbasketDefinitionControllerRestDocumentation.java b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/WorkbasketDefinitionControllerRestDocumentation.java index 0e2e50653..34ad4cdd4 100644 --- a/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/WorkbasketDefinitionControllerRestDocumentation.java +++ b/rest/taskana-rest-spring-test/src/test/java/pro/taskana/doc/api/WorkbasketDefinitionControllerRestDocumentation.java @@ -1,70 +1,28 @@ 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.responseFields; import static org.springframework.restdocs.payload.PayloadDocumentation.subsectionWithPath; import static org.springframework.restdocs.request.RequestDocumentation.partWithName; import static org.springframework.restdocs.request.RequestDocumentation.requestParts; -import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.restdocs.JUnitRestDocumentation; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; import org.springframework.restdocs.payload.FieldDescriptor; -import org.springframework.test.context.junit4.SpringRunner; -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.rest.RestConfiguration; /** * Generate Rest Documentation for Workbasket Definitions. */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = RestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT) -public class WorkbasketDefinitionControllerRestDocumentation { - - @LocalServerPort - int port; - - @Rule - public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(); - - @Autowired - private WebApplicationContext context; - - private MockMvc mockMvc; +public class WorkbasketDefinitionControllerRestDocumentation extends BaseRestDocumentation { private FieldDescriptor[] workbasketDefinitionsFieldDescriptors; @Before public void setUp() { - document("{methodName}", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint())); - - this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context) - .apply(springSecurity()) - .apply(documentationConfiguration(this.restDocumentation) - .operationPreprocessors() - .withResponseDefaults(prettyPrint()) - .withRequestDefaults(prettyPrint())) - .build(); workbasketDefinitionsFieldDescriptors = new FieldDescriptor[] { subsectionWithPath("[]").description("An array of <>")