TSK-854: enabled checkstyle javadoc integrity check + fixed issues
This commit is contained in:
parent
7df168d870
commit
7b7ae169b7
|
@ -53,6 +53,27 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
this.taskMapper = taskMapper;
|
||||
}
|
||||
|
||||
private static void validateServiceLevel(String serviceLevel) throws InvalidArgumentException {
|
||||
try {
|
||||
Duration.parse(serviceLevel);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new InvalidArgumentException("Invalid service level " + serviceLevel
|
||||
+ ". The formats accepted are based on the ISO-8601 duration format PnDTnHnMn.nS with days considered to be exactly 24 hours. "
|
||||
+ "For example: \"P2D\" represents a period of \"two days.\" ",
|
||||
e.getCause());
|
||||
}
|
||||
// check that the duration is based on format PnD, i.e. it must start with a P, end with a D
|
||||
String serviceLevelLower = serviceLevel.toLowerCase();
|
||||
if (!('p' == serviceLevelLower.charAt(0))
|
||||
|| !('d' == serviceLevelLower.charAt(serviceLevel.length() - 1))) {
|
||||
|
||||
throw new InvalidArgumentException(
|
||||
"Invalid service level " + serviceLevel + ". Taskana only supports service levels that"
|
||||
+ " contain a number of whole days specified according to the format 'PnD' where n is the number of days");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Classification createClassification(Classification classification)
|
||||
throws ClassificationAlreadyExistException, NotAuthorizedException,
|
||||
|
@ -196,7 +217,9 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
/**
|
||||
* Fill missing values and validate classification before saving the classification.
|
||||
*
|
||||
* @param classification
|
||||
* @param classification the classification which will be verified.
|
||||
*
|
||||
* @throws InvalidArgumentException if the given classification has no key.
|
||||
*/
|
||||
private void initDefaultClassificationValues(ClassificationImpl classification) throws InvalidArgumentException {
|
||||
Instant now = Instant.now();
|
||||
|
@ -253,27 +276,6 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
}
|
||||
}
|
||||
|
||||
private static void validateServiceLevel(String serviceLevel) throws InvalidArgumentException {
|
||||
try {
|
||||
Duration.parse(serviceLevel);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new InvalidArgumentException("Invalid service level " + serviceLevel
|
||||
+ ". The formats accepted are based on the ISO-8601 duration format PnDTnHnMn.nS with days considered to be exactly 24 hours. "
|
||||
+ "For example: \"P2D\" represents a period of \"two days.\" ",
|
||||
e.getCause());
|
||||
}
|
||||
// check that the duration is based on format PnD, i.e. it must start with a P, end with a D
|
||||
String serviceLevelLower = serviceLevel.toLowerCase();
|
||||
if (!('p' == serviceLevelLower.charAt(0))
|
||||
|| !('d' == serviceLevelLower.charAt(serviceLevel.length() - 1))) {
|
||||
|
||||
throw new InvalidArgumentException(
|
||||
"Invalid service level " + serviceLevel + ". Taskana only supports service levels that"
|
||||
+ " contain a number of whole days specified according to the format 'PnD' where n is the number of days");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Classification getClassification(String id) throws ClassificationNotFoundException {
|
||||
if (id == null) {
|
||||
|
@ -343,8 +345,8 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
}
|
||||
} catch (Exception ex) {
|
||||
LOGGER.warn(
|
||||
"Classification-Service throwed Exception while calling mapper and searching for classification. EX={}",
|
||||
ex);
|
||||
"Classification-Service threw Exception while calling mapper and searching for classification. EX={}",
|
||||
ex, ex);
|
||||
}
|
||||
return isExisting;
|
||||
}
|
||||
|
@ -433,6 +435,9 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
*
|
||||
* @param classificationImpl the classification
|
||||
* @return the old classification
|
||||
*
|
||||
* @throws ConcurrencyException if the classification has been modified by some other process.
|
||||
* @throws ClassificationNotFoundException if the given classification does not exist.
|
||||
*/
|
||||
private Classification getExistingClassificationAndVerifyTimestampHasNotChanged(
|
||||
ClassificationImpl classificationImpl)
|
||||
|
@ -472,6 +477,8 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
*
|
||||
* @param classificationImpl the new classification
|
||||
* @param oldClassification the old classification
|
||||
*
|
||||
* @throws ClassificationNotFoundException if the given classification does not exist.
|
||||
*/
|
||||
private void checkExistenceOfParentClassification(Classification oldClassification,
|
||||
ClassificationImpl classificationImpl)
|
||||
|
|
|
@ -391,7 +391,7 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
|||
/**
|
||||
* creates the MyBatis transaction factory.
|
||||
*
|
||||
* @param useManagedTransactions
|
||||
* @param useManagedTransactions true, if managed transations should be used. Otherwise false.
|
||||
*/
|
||||
private void createTransactionFactory(boolean useManagedTransactions) {
|
||||
if (useManagedTransactions) {
|
||||
|
|
|
@ -28,6 +28,7 @@ public class DBCleaner {
|
|||
/**
|
||||
* Clears the db.
|
||||
*
|
||||
* @param dataSource the datasource
|
||||
* @param dropTables
|
||||
* if true drop tables, else clean tables
|
||||
*/
|
||||
|
@ -51,7 +52,7 @@ public class DBCleaner {
|
|||
LOGGER.debug(outWriter.toString());
|
||||
String errorMsg = errorWriter.toString().trim();
|
||||
|
||||
if (!errorMsg.isEmpty() && errorMsg.indexOf("SQLCODE=-204, SQLSTATE=42704") == -1) {
|
||||
if (!errorMsg.isEmpty() && !errorMsg.contains("SQLCODE=-204, SQLSTATE=42704")) {
|
||||
LOGGER.error(errorWriter.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,21 +26,10 @@ import pro.taskana.configuration.TaskanaEngineConfiguration;
|
|||
*/
|
||||
public class TaskanaEngineConfigurationTest {
|
||||
|
||||
private static DataSource dataSource = null;
|
||||
private static String schemaName = null;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaEngineConfigurationTest.class);
|
||||
private static final int POOL_TIME_TO_WAIT = 50;
|
||||
|
||||
@Test
|
||||
public void testCreateTaskanaEngine() throws SQLException {
|
||||
DataSource ds = getDataSource();
|
||||
TaskanaEngineConfiguration taskEngineConfiguration = new TaskanaEngineConfiguration(ds, false,
|
||||
TaskanaEngineConfigurationTest.getSchemaName());
|
||||
|
||||
TaskanaEngine te = taskEngineConfiguration.buildTaskanaEngine();
|
||||
|
||||
Assert.assertNotNull(te);
|
||||
}
|
||||
private static DataSource dataSource = null;
|
||||
private static String schemaName = null;
|
||||
|
||||
/**
|
||||
* returns the Datasource used for Junit test. If the file {user.home}/taskanaUnitTest.properties is present, the
|
||||
|
@ -69,7 +58,7 @@ public class TaskanaEngineConfigurationTest {
|
|||
/**
|
||||
* create Default Datasource for in-memory database.
|
||||
*
|
||||
* @return
|
||||
* @return the default datasource.
|
||||
*/
|
||||
private static DataSource createDefaultDataSource() {
|
||||
// JdbcDataSource ds = new JdbcDataSource();
|
||||
|
@ -81,10 +70,10 @@ public class TaskanaEngineConfigurationTest {
|
|||
String jdbcUrl = "jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0";
|
||||
String dbUserName = "sa";
|
||||
String dbPassword = "sa";
|
||||
DataSource ds = new PooledDataSource(Thread.currentThread().getContextClassLoader(), jdbcDriver,
|
||||
PooledDataSource ds = new PooledDataSource(Thread.currentThread().getContextClassLoader(), jdbcDriver,
|
||||
jdbcUrl, dbUserName, dbPassword);
|
||||
((PooledDataSource) ds).setPoolTimeToWait(POOL_TIME_TO_WAIT);
|
||||
((PooledDataSource) ds).forceCloseAll(); // otherwise the MyBatis pool is not initialized correctly
|
||||
ds.setPoolTimeToWait(POOL_TIME_TO_WAIT);
|
||||
ds.forceCloseAll(); // otherwise the MyBatis pool is not initialized correctly
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
@ -116,11 +105,11 @@ public class TaskanaEngineConfigurationTest {
|
|||
/**
|
||||
* create data source from properties file.
|
||||
*
|
||||
* @param propertiesFileName
|
||||
* @return
|
||||
* @param propertiesFileName the name of the property file
|
||||
* @return the parsed datasource.
|
||||
*/
|
||||
public static DataSource createDataSourceFromProperties(String propertiesFileName) {
|
||||
DataSource ds = null;
|
||||
DataSource ds;
|
||||
try (InputStream input = new FileInputStream(propertiesFileName)) {
|
||||
Properties prop = new Properties();
|
||||
prop.load(input);
|
||||
|
@ -157,10 +146,6 @@ public class TaskanaEngineConfigurationTest {
|
|||
ds = createDefaultDataSource();
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
LOGGER.warn("createDataSourceFromProperties caught Exception " + e);
|
||||
LOGGER.warn("Using default Datasource for Test");
|
||||
ds = createDefaultDataSource();
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("createDataSourceFromProperties caught Exception " + e);
|
||||
LOGGER.warn("Using default Datasource for Test");
|
||||
|
@ -200,4 +185,15 @@ public class TaskanaEngineConfigurationTest {
|
|||
return schemaName;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTaskanaEngine() throws SQLException {
|
||||
DataSource ds = getDataSource();
|
||||
TaskanaEngineConfiguration taskEngineConfiguration = new TaskanaEngineConfiguration(ds, false,
|
||||
TaskanaEngineConfigurationTest.getSchemaName());
|
||||
|
||||
TaskanaEngine te = taskEngineConfiguration.buildTaskanaEngine();
|
||||
|
||||
Assert.assertNotNull(te);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE module PUBLIC
|
||||
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
|
||||
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
|
||||
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
|
||||
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
|
||||
|
||||
<!--
|
||||
|
||||
|
@ -19,116 +19,119 @@
|
|||
-->
|
||||
|
||||
<module name="Checker">
|
||||
<!-- Checks whether files end with a new line. -->
|
||||
<!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
|
||||
<module name="NewlineAtEndOfFile">
|
||||
<!-- Checks whether files end with a new line. -->
|
||||
<!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
|
||||
<module name="NewlineAtEndOfFile">
|
||||
<property name="lineSeparator" value="lf_cr_crlf"/>
|
||||
</module>
|
||||
|
||||
<!-- Checks that property files contain the same keys. -->
|
||||
<!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
|
||||
<module name="Translation"/>
|
||||
<!-- Checks that property files contain the same keys. -->
|
||||
<!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
|
||||
<module name="Translation"/>
|
||||
|
||||
<module name="FileLength"/>
|
||||
<module name="FileLength"/>
|
||||
|
||||
<module name="FileTabCharacter">
|
||||
<property name="eachLine" value="true"/>
|
||||
</module>
|
||||
<module name="FileTabCharacter">
|
||||
<property name="eachLine" value="true"/>
|
||||
</module>
|
||||
|
||||
<module name="RegexpSingleline">
|
||||
<!-- \s matches whitespace character, $ matches end of line. -->
|
||||
<property name="format" value="\s+$"/>
|
||||
<property name="message" value="Line has trailing spaces."/>
|
||||
</module>
|
||||
<module name="RegexpSingleline">
|
||||
<!-- \s matches whitespace character, $ matches end of line. -->
|
||||
<property name="format" value="\s+$"/>
|
||||
<property name="message" value="Line has trailing spaces."/>
|
||||
</module>
|
||||
|
||||
<module name="TreeWalker">
|
||||
<module name="TreeWalker">
|
||||
|
||||
<property name="cacheFile" value="${checkstyle.cache.file}"/>
|
||||
<property name="cacheFile" value="${checkstyle.cache.file}"/>
|
||||
<module name="AvoidStarImport"/>
|
||||
|
||||
<!-- required for SuppressWarningsFilter (and other Suppress* rules not used here) -->
|
||||
<!-- see http://checkstyle.sourceforge.net/config_annotation.html#SuppressWarningsHolder -->
|
||||
<module name="SuppressWarningsHolder"/>
|
||||
<!-- required for SuppressWarningsFilter (and other Suppress* rules not used here) -->
|
||||
<!-- see http://checkstyle.sourceforge.net/config_annotation.html#SuppressWarningsHolder -->
|
||||
<module name="SuppressWarningsHolder"/>
|
||||
|
||||
<!-- Checks for Javadoc comments. -->
|
||||
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
|
||||
<module name="JavadocType"/>
|
||||
<module name="JavadocStyle"/>
|
||||
<!-- Checks for Javadoc comments. -->
|
||||
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
|
||||
<module name="JavadocMethod">
|
||||
<property name="allowMissingJavadoc" value="true"/>
|
||||
</module>
|
||||
<module name="JavadocType"/>
|
||||
<module name="JavadocStyle"/>
|
||||
|
||||
<!-- Checks for Naming Conventions. -->
|
||||
<!-- See http://checkstyle.sf.net/config_naming.html -->
|
||||
<module name="ConstantName"/>
|
||||
<module name="LocalFinalVariableName"/>
|
||||
<module name="LocalVariableName"/>
|
||||
<module name="MemberName"/>
|
||||
<!-- Removed because of _ not allowed in test method names -->
|
||||
<!-- <module name="MethodName"/> -->
|
||||
<module name="PackageName"/>
|
||||
<module name="ParameterName"/>
|
||||
<module name="StaticVariableName"/>
|
||||
<module name="TypeName"/>
|
||||
|
||||
<!-- Checks for Naming Conventions. -->
|
||||
<!-- See http://checkstyle.sf.net/config_naming.html -->
|
||||
<module name="ConstantName"/>
|
||||
<module name="LocalFinalVariableName"/>
|
||||
<module name="LocalVariableName"/>
|
||||
<module name="MemberName"/>
|
||||
<!-- Removed because of _ not allowed in test method names -->
|
||||
<!-- <module name="MethodName"/> -->
|
||||
<module name="PackageName"/>
|
||||
<module name="ParameterName"/>
|
||||
<module name="StaticVariableName"/>
|
||||
<module name="TypeName"/>
|
||||
<!-- Checks for imports -->
|
||||
<!-- See http://checkstyle.sf.net/config_import.html -->
|
||||
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
|
||||
<module name="RedundantImport"/>
|
||||
<module name="UnusedImports"/>
|
||||
|
||||
<!-- Checks for imports -->
|
||||
<!-- See http://checkstyle.sf.net/config_import.html -->
|
||||
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
|
||||
<module name="RedundantImport"/>
|
||||
<module name="UnusedImports"/>
|
||||
<!-- Checks for whitespace -->
|
||||
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
|
||||
<module name="EmptyForIteratorPad"/>
|
||||
<module name="MethodParamPad"/>
|
||||
<module name="NoWhitespaceAfter"/>
|
||||
<module name="NoWhitespaceBefore"/>
|
||||
<module name="OperatorWrap"/>
|
||||
<module name="ParenPad"/>
|
||||
<module name="TypecastParenPad"/>
|
||||
<module name="WhitespaceAfter"/>
|
||||
<module name="WhitespaceAround"/>
|
||||
|
||||
<!-- Checks for whitespace -->
|
||||
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
|
||||
<module name="EmptyForIteratorPad"/>
|
||||
<module name="MethodParamPad"/>
|
||||
<module name="NoWhitespaceAfter"/>
|
||||
<module name="NoWhitespaceBefore"/>
|
||||
<module name="OperatorWrap"/>
|
||||
<module name="ParenPad"/>
|
||||
<module name="TypecastParenPad"/>
|
||||
<module name="WhitespaceAfter"/>
|
||||
<module name="WhitespaceAround"/>
|
||||
<!-- Modifier Checks -->
|
||||
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
|
||||
<module name="ModifierOrder"/>
|
||||
<module name="RedundantModifier"/>
|
||||
|
||||
<!-- Modifier Checks -->
|
||||
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
|
||||
<module name="ModifierOrder"/>
|
||||
<module name="RedundantModifier"/>
|
||||
<!-- Checks for blocks. You know, those {}'s -->
|
||||
<!-- See http://checkstyle.sf.net/config_blocks.html -->
|
||||
<module name="AvoidNestedBlocks"/>
|
||||
<module name="EmptyBlock"/>
|
||||
<module name="LeftCurly"/>
|
||||
<module name="NeedBraces"/>
|
||||
<module name="RightCurly"/>
|
||||
|
||||
<!-- Checks for blocks. You know, those {}'s -->
|
||||
<!-- See http://checkstyle.sf.net/config_blocks.html -->
|
||||
<module name="AvoidNestedBlocks"/>
|
||||
<module name="EmptyBlock"/>
|
||||
<module name="LeftCurly"/>
|
||||
<module name="NeedBraces"/>
|
||||
<module name="RightCurly"/>
|
||||
<!-- Checks for common coding problems -->
|
||||
<!-- See http://checkstyle.sf.net/config_coding.html -->
|
||||
<module name="EmptyStatement"/>
|
||||
<module name="EqualsHashCode"/>
|
||||
<module name="IllegalInstantiation"/>
|
||||
<module name="InnerAssignment"/>
|
||||
<module name="MissingSwitchDefault"/>
|
||||
<module name="SimplifyBooleanExpression"/>
|
||||
<module name="SimplifyBooleanReturn"/>
|
||||
|
||||
<!-- Checks for common coding problems -->
|
||||
<!-- See http://checkstyle.sf.net/config_coding.html -->
|
||||
<module name="EmptyStatement"/>
|
||||
<module name="EqualsHashCode"/>
|
||||
<module name="IllegalInstantiation"/>
|
||||
<module name="InnerAssignment"/>
|
||||
<module name="MissingSwitchDefault"/>
|
||||
<module name="SimplifyBooleanExpression"/>
|
||||
<module name="SimplifyBooleanReturn"/>
|
||||
<!-- Checks for class design -->
|
||||
<!-- See http://checkstyle.sf.net/config_design.html -->
|
||||
<module name="FinalClass"/>
|
||||
<module name="HideUtilityClassConstructor"/>
|
||||
<module name="InterfaceIsType"/>
|
||||
|
||||
<!-- Checks for class design -->
|
||||
<!-- See http://checkstyle.sf.net/config_design.html -->
|
||||
<module name="FinalClass"/>
|
||||
<module name="HideUtilityClassConstructor"/>
|
||||
<module name="InterfaceIsType"/>
|
||||
<!-- Miscellaneous other checks. -->
|
||||
<!-- See http://checkstyle.sf.net/config_misc.html -->
|
||||
<module name="ArrayTypeStyle"/>
|
||||
<module name="TodoComment"/>
|
||||
<module name="UpperEll"/>
|
||||
|
||||
<!-- Miscellaneous other checks. -->
|
||||
<!-- See http://checkstyle.sf.net/config_misc.html -->
|
||||
<module name="ArrayTypeStyle"/>
|
||||
<module name="TodoComment"/>
|
||||
<module name="UpperEll"/>
|
||||
</module>
|
||||
|
||||
</module>
|
||||
<!-- Support @SuppressWarnings (added in Checkstyle 5.7) -->
|
||||
<!-- see http://checkstyle.sourceforge.net/config.html#SuppressWarningsFilter -->
|
||||
<module name="SuppressWarningsFilter"/>
|
||||
|
||||
<!-- Support @SuppressWarnings (added in Checkstyle 5.7) -->
|
||||
<!-- see http://checkstyle.sourceforge.net/config.html#SuppressWarningsFilter -->
|
||||
<module name="SuppressWarningsFilter"/>
|
||||
|
||||
<!-- Checks properties file for a duplicated properties. -->
|
||||
<!-- See http://checkstyle.sourceforge.net/config_misc.html#UniqueProperties -->
|
||||
<module name="UniqueProperties"/>
|
||||
<!-- Checks properties file for a duplicated properties. -->
|
||||
<!-- See http://checkstyle.sourceforge.net/config_misc.html#UniqueProperties -->
|
||||
<module name="UniqueProperties"/>
|
||||
|
||||
</module>
|
||||
|
|
|
@ -1,5 +1,17 @@
|
|||
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;
|
||||
|
@ -17,17 +29,8 @@ 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;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.subsectionWithPath;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
|
||||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import pro.taskana.rest.RestConfiguration;
|
||||
|
||||
/**
|
||||
* Generate Rest Docu for AbstractPagingController.
|
||||
|
@ -36,12 +39,10 @@ import java.util.HashMap;
|
|||
@SpringBootTest(classes = RestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
public class AbstractPagingControllerRestDocumentation {
|
||||
|
||||
@LocalServerPort
|
||||
int port;
|
||||
|
||||
@Rule
|
||||
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation();
|
||||
|
||||
@LocalServerPort
|
||||
int port;
|
||||
@Autowired
|
||||
private WebApplicationContext context;
|
||||
|
||||
|
@ -54,16 +55,16 @@ public class AbstractPagingControllerRestDocumentation {
|
|||
@Before
|
||||
public void setUp() {
|
||||
document("{methodName}",
|
||||
preprocessRequest(prettyPrint()),
|
||||
preprocessResponse(prettyPrint()));
|
||||
preprocessRequest(prettyPrint()),
|
||||
preprocessResponse(prettyPrint()));
|
||||
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(springSecurity())
|
||||
.apply(documentationConfiguration(this.restDocumentation)
|
||||
.operationPreprocessors()
|
||||
.withResponseDefaults(prettyPrint())
|
||||
.withRequestDefaults(prettyPrint()))
|
||||
.build();
|
||||
.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");
|
||||
|
@ -76,30 +77,29 @@ public class AbstractPagingControllerRestDocumentation {
|
|||
pagingFieldDescriptionsMap.put("_links.next.href", "Link to next page");
|
||||
|
||||
pagingFieldDescriptors = new FieldDescriptor[] {
|
||||
|
||||
subsectionWithPath("_embedded.classificationSummaryResourceList").ignored(),
|
||||
fieldWithPath("_links").ignored(),
|
||||
fieldWithPath("_links.self").ignored(),
|
||||
fieldWithPath("_links.self.href").ignored(),
|
||||
fieldWithPath("page").description(pagingFieldDescriptionsMap.get("page")),
|
||||
fieldWithPath("page.size").description(pagingFieldDescriptionsMap.get("page.size")),
|
||||
fieldWithPath("page.totalElements").description(pagingFieldDescriptionsMap.get("page.totalElements")),
|
||||
fieldWithPath("page.totalPages").description(pagingFieldDescriptionsMap.get("page.totalPages")),
|
||||
fieldWithPath("page.number").description(pagingFieldDescriptionsMap.get("page.number")),
|
||||
fieldWithPath("_links.first.href").description(pagingFieldDescriptionsMap.get("_links.first.href")),
|
||||
fieldWithPath("_links.last.href").description(pagingFieldDescriptionsMap.get("_links.last.href")),
|
||||
fieldWithPath("_links.prev.href").description(pagingFieldDescriptionsMap.get("_links.prev.href")),
|
||||
fieldWithPath("_links.next.href").description(pagingFieldDescriptionsMap.get("_links.next.href"))
|
||||
subsectionWithPath("_embedded.classificationSummaryResourceList").ignored(),
|
||||
fieldWithPath("_links").ignored(),
|
||||
fieldWithPath("_links.self").ignored(),
|
||||
fieldWithPath("_links.self.href").ignored(),
|
||||
fieldWithPath("page").description(pagingFieldDescriptionsMap.get("page")),
|
||||
fieldWithPath("page.size").description(pagingFieldDescriptionsMap.get("page.size")),
|
||||
fieldWithPath("page.totalElements").description(pagingFieldDescriptionsMap.get("page.totalElements")),
|
||||
fieldWithPath("page.totalPages").description(pagingFieldDescriptionsMap.get("page.totalPages")),
|
||||
fieldWithPath("page.number").description(pagingFieldDescriptionsMap.get("page.number")),
|
||||
fieldWithPath("_links.first.href").description(pagingFieldDescriptionsMap.get("_links.first.href")),
|
||||
fieldWithPath("_links.last.href").description(pagingFieldDescriptionsMap.get("_links.last.href")),
|
||||
fieldWithPath("_links.prev.href").description(pagingFieldDescriptionsMap.get("_links.prev.href")),
|
||||
fieldWithPath("_links.next.href").description(pagingFieldDescriptionsMap.get("_links.next.href"))
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void commonSummaryResourceFieldsDocTest() throws Exception {
|
||||
this.mockMvc.perform(RestDocumentationRequestBuilders
|
||||
.get("http://127.0.0.1:" + port + "/v1/classifications?page=2&page-size=5")
|
||||
.header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x"))
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andDo(MockMvcRestDocumentation.document("CommonSummaryResourceFields",
|
||||
.get("http://127.0.0.1:" + port + "/v1/classifications?page=2&page-size=5")
|
||||
.header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x"))
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andDo(MockMvcRestDocumentation.document("CommonSummaryResourceFields",
|
||||
responseFields(pagingFieldDescriptors)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,9 +76,7 @@ public abstract class AbstractPagingController {
|
|||
return pageMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is deprecated please remove it after updating taskana-simple-history reference to it.
|
||||
*/
|
||||
// This method is deprecated please remove it after updating taskana-simple-history reference to it.
|
||||
@Deprecated
|
||||
protected PageMetadata initPageMetadata(String pagesizeParam, String pageParam, long totalElements)
|
||||
throws InvalidArgumentException {
|
||||
|
|
|
@ -7,7 +7,10 @@ import javax.sql.DataSource;
|
|||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.*;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.http.converter.json.SpringHandlerInstantiator;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
|
|
Loading…
Reference in New Issue