TSK-1647: minor improvements and fixes

This commit is contained in:
Mustapha Zorgati 2021-08-02 06:06:07 +02:00
parent 9c8870ad60
commit 6da07b069a
29 changed files with 196 additions and 101 deletions

View File

@ -1,7 +1,8 @@
package pro.taskana.common.api.exceptions;
/**
* This exception is thrown in ConnectionManagementMode AUTOCOMMIT when an attempt to commit fails.
* This exception is thrown when using TASKANA with the AUTOCOMMIT ConnectionManagementMode and an
* attempt to commit fails.
*/
public class AutocommitFailedException extends TaskanaRuntimeException {
@ -10,4 +11,9 @@ public class AutocommitFailedException extends TaskanaRuntimeException {
public AutocommitFailedException(Throwable cause) {
super("Autocommit failed", ErrorCode.of(ERROR_KEY), cause);
}
@Override
public String toString() {
return "AutocommitFailedException{}";
}
}

View File

@ -1,5 +1,7 @@
package pro.taskana.common.api.exceptions;
import pro.taskana.common.internal.util.MapCreator;
/**
* This exception is thrown when an attempt is made to update an object that has already been
* updated by another user.
@ -7,10 +9,23 @@ package pro.taskana.common.api.exceptions;
public class ConcurrencyException extends TaskanaException {
public static final String ERROR_KEY = "ENTITY_NOT_UP_TO_DATE";
private final String entityId;
public ConcurrencyException() {
public ConcurrencyException(String entityId) {
super(
"The current entity cannot be updated since it has been modified while editing.",
ErrorCode.of(ERROR_KEY));
String.format(
"The entity with id '%s' cannot be updated since it has been modified while editing.",
entityId),
ErrorCode.of(ERROR_KEY, MapCreator.of("entityId", entityId)));
this.entityId = entityId;
}
public String getEntityId() {
return entityId;
}
@Override
public String toString() {
return "ConcurrencyException{}";
}
}

View File

@ -1,8 +1,9 @@
package pro.taskana.common.api.exceptions;
/**
* This exception is thrown when ConnectionManagementMode is CONNECTION_MANAGED_EXTERNALLY and an
* attempt is made to call an API method before the setConnection() method has been called.
* This exception is thrown when using TASKANA with the CONNECTION_MANAGED_EXTERNALLY
* ConnectionManagementMode and an attempt is made to call an API method before the
* TaskananEngine#setConnection() method has been called.
*/
public class ConnectionNotSetException extends TaskanaRuntimeException {
@ -11,4 +12,9 @@ public class ConnectionNotSetException extends TaskanaRuntimeException {
public ConnectionNotSetException() {
super("Connection not set", ErrorCode.of(ERROR_KEY));
}
@Override
public String toString() {
return "ConnectionNotSetException{}";
}
}

View File

@ -18,4 +18,9 @@ public class DomainNotFoundException extends NotFoundException {
public String getDomain() {
return domain;
}
@Override
public String toString() {
return "DomainNotFoundException [domain=" + domain + "]";
}
}

View File

@ -3,11 +3,18 @@ package pro.taskana.common.api.exceptions;
/** This exception is thrown when a method is called with an invalid argument. */
public class InvalidArgumentException extends TaskanaException {
public static final String ERROR_KEY = "INVALID_ARGUMENT";
public InvalidArgumentException(String msg) {
this(msg, null);
}
public InvalidArgumentException(String msg, Throwable cause) {
super(msg, ErrorCode.of("INVALID_ARGUMENT"), cause);
super(msg, ErrorCode.of(ERROR_KEY), cause);
}
@Override
public String toString() {
return "InvalidArgumentException{}";
}
}

View File

@ -33,4 +33,13 @@ public class MismatchedRoleException extends NotAuthorizedException {
public String getCurrentUserId() {
return currentUserId;
}
@Override
public String toString() {
return "MismatchedRoleException [currentUserId="
+ currentUserId
+ ", roles="
+ Arrays.toString(roles)
+ "]";
}
}

View File

@ -2,7 +2,13 @@ package pro.taskana.common.api.exceptions;
/** This exception is thrown when a user is not authorized. */
public class NotAuthorizedException extends TaskanaException {
protected NotAuthorizedException(String msg, ErrorCode errorCode) {
super(msg, errorCode);
}
@Override
public String toString() {
return "NotAuthorizedException{}";
}
}

View File

@ -6,4 +6,9 @@ public class NotFoundException extends TaskanaException {
protected NotFoundException(String message, ErrorCode errorCode) {
super(message, errorCode);
}
@Override
public String toString() {
return "NotFoundException{}";
}
}

View File

@ -12,4 +12,9 @@ public class SystemException extends TaskanaRuntimeException {
public SystemException(String msg, Throwable cause) {
super(msg, ErrorCode.of(ERROR_KEY), cause);
}
@Override
public String toString() {
return "SystemException{}";
}
}

View File

@ -17,4 +17,9 @@ public class TaskanaException extends Exception {
public ErrorCode getErrorCode() {
return errorCode;
}
@Override
public String toString() {
return "TaskanaException [errorCode=" + errorCode + "]";
}
}

View File

@ -20,4 +20,9 @@ public class UnsupportedDatabaseException extends TaskanaRuntimeException {
public String getDatabaseProductName() {
return databaseProductName;
}
@Override
public String toString() {
return "UnsupportedDatabaseException [databaseProductName=" + databaseProductName + "]";
}
}

View File

@ -22,4 +22,9 @@ public class WrongCustomHolidayFormatException extends TaskanaException {
public String getCustomHoliday() {
return customHoliday;
}
@Override
public String toString() {
return "WrongCustomHolidayFormatException [customHoliday=" + customHoliday + "]";
}
}

View File

@ -20,7 +20,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.util.UriComponentsBuilder;
import pro.taskana.common.rest.models.PageMetadata;
@ -271,11 +271,12 @@ class TaskHistoryEventControllerIntTest {
TASK_HISTORY_EVENT_PAGED_REPRESENTATION_MODEL_TYPE);
assertThatThrownBy(httpCall)
.isInstanceOf(HttpServerErrorException.class)
.isInstanceOf(HttpClientErrorException.class)
.hasMessageContaining(
"Unkown request parameters found: [anotherIllegalParam, illegalParam]")
.extracting(ex -> ((HttpServerErrorException) ex).getStatusCode())
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
"Unknown request parameters found: [anotherIllegalParam, illegalParam]")
.extracting(HttpClientErrorException.class::cast)
.extracting(HttpStatusCodeException::getStatusCode)
.isEqualTo(HttpStatus.BAD_REQUEST);
}
// endregion

View File

@ -515,7 +515,7 @@ public class ClassificationServiceImpl implements ClassificationService {
Classification oldClassification =
this.getClassification(classificationImpl.getKey(), classificationImpl.getDomain());
if (!oldClassification.getModified().equals(classificationImpl.getModified())) {
throw new ConcurrencyException();
throw new ConcurrencyException(classificationImpl.getId());
}
return oldClassification;
}

View File

@ -13,7 +13,7 @@ public class InvalidOwnerException extends TaskanaException {
public InvalidOwnerException(String currentUserId, String taskId) {
super(
String.format("User '%s' is not owner of Task '%s'.", currentUserId, taskId),
String.format("User '%s' is not owner of Task '%s'", currentUserId, taskId),
ErrorCode.of(ERROR_KEY, MapCreator.of("taskId", taskId, "currentUserId", currentUserId)));
this.taskId = taskId;
this.currentUserId = currentUserId;

View File

@ -193,7 +193,7 @@ class TaskCommentServiceImpl {
TaskComment oldTaskComment, TaskComment taskCommentImplToUpdate) throws ConcurrencyException {
if (!oldTaskComment.getModified().equals(taskCommentImplToUpdate.getModified())) {
throw new ConcurrencyException();
throw new ConcurrencyException(taskCommentImplToUpdate.getId());
}
}

View File

@ -1062,7 +1062,7 @@ public class TaskServiceImpl implements TaskService {
&& !oldTaskImpl.getClaimed().equals(newTaskImpl.getClaimed())
|| oldTaskImpl.getState() != null
&& !oldTaskImpl.getState().equals(newTaskImpl.getState())) {
throw new ConcurrencyException();
throw new ConcurrencyException(newTaskImpl.getId());
}
newTaskImpl.setModified(Instant.now());
}

View File

@ -167,11 +167,9 @@ public interface WorkbasketService {
* @throws NotAuthorizedException if the current user is not member of role {@linkplain
* pro.taskana.common.api.TaskanaRole#BUSINESS_ADMIN} or {@linkplain
* pro.taskana.common.api.TaskanaRole#ADMIN}
* @throws WorkbasketNotFoundException if the {@linkplain Workbasket} cannot be found for the
* given {@linkplain Workbasket#getId() id}.
*/
List<WorkbasketAccessItem> getWorkbasketAccessItems(String workbasketId)
throws NotAuthorizedException, WorkbasketNotFoundException;
throws NotAuthorizedException;
/**
* Setting up the new WorkbasketAccessItems for a Workbasket. Already stored values will be

View File

@ -458,7 +458,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
@Override
public List<WorkbasketAccessItem> getWorkbasketAccessItems(String workbasketId)
throws NotAuthorizedException, WorkbasketNotFoundException {
throws NotAuthorizedException {
taskanaEngine.getEngine().checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
List<WorkbasketAccessItem> result = new ArrayList<>();
try {
@ -950,7 +950,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
Workbasket oldWorkbasket, WorkbasketImpl workbasketImplToUpdate) throws ConcurrencyException {
if (!oldWorkbasket.getModified().equals(workbasketImplToUpdate.getModified())) {
throw new ConcurrencyException();
throw new ConcurrencyException(workbasketImplToUpdate.getId());
}
}

View File

@ -127,8 +127,9 @@ class UpdateTaskAccTest extends AbstractAccTest {
@Test
void should_ThrowException_When_TaskHasAlreadyBeenUpdated() throws Exception {
Task task = taskService.getTask("TKI:000000000000000000000000000000000000");
final Task task2 = taskService.getTask("TKI:000000000000000000000000000000000000");
String taskId = "TKI:000000000000000000000000000000000000";
Task task = taskService.getTask(taskId);
final Task task2 = taskService.getTask(taskId);
task.setCustomAttribute(CUSTOM_1, "willi");
Thread.sleep(10);
@ -138,7 +139,8 @@ class UpdateTaskAccTest extends AbstractAccTest {
assertThatThrownBy(() -> taskService.updateTask(task2))
.isInstanceOf(ConcurrencyException.class)
.hasMessage(
"The current entity cannot be updated since it has been modified while editing.");
"The entity with id '%s' cannot be updated since it has been modified while editing.",
taskId);
}
@WithAccessId(user = "admin")
@ -346,6 +348,4 @@ class UpdateTaskAccTest extends AbstractAccTest {
assertThat(retrievedUpdatedTask).extracting(TaskSummary::getReceived).isEqualTo(retrievedTime);
}
}

View File

@ -10,6 +10,7 @@ import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.beans.BeanInstantiationException;
import org.springframework.beans.TypeMismatchException;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
@ -110,6 +111,16 @@ public class TaskanaRestExceptionHandler extends ResponseEntityExceptionHandler
return buildResponse(ErrorCode.of(ERROR_KEY_PAYLOAD), ex, req, HttpStatus.PAYLOAD_TOO_LARGE);
}
@ExceptionHandler(BeanInstantiationException.class)
protected ResponseEntity<Object> handleBeanInstantiationException(
BeanInstantiationException ex, WebRequest req) {
if (ex.getCause() instanceof InvalidArgumentException) {
InvalidArgumentException cause = (InvalidArgumentException) ex.getCause();
return buildResponse(cause.getErrorCode(), ex, req, HttpStatus.BAD_REQUEST);
}
return buildResponse(null, ex, req, HttpStatus.INTERNAL_SERVER_ERROR);
}
@ExceptionHandler({
InvalidTaskStateException.class,
InvalidCallbackStateException.class,
@ -122,6 +133,13 @@ public class TaskanaRestExceptionHandler extends ResponseEntityExceptionHandler
return buildResponse(ex.getErrorCode(), ex, req, HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(IllegalArgumentException.class)
protected ResponseEntity<Object> handleIllegalArgumentException(
IllegalArgumentException ex, WebRequest req) {
return buildResponse(
ErrorCode.of(InvalidArgumentException.ERROR_KEY), ex, req, HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(TaskanaRuntimeException.class)
protected ResponseEntity<Object> handleInternalServerExceptions(
TaskanaRuntimeException ex, WebRequest req) {
@ -148,7 +166,7 @@ public class TaskanaRestExceptionHandler extends ResponseEntityExceptionHandler
.toArray(MalformedQueryParameter[]::new);
// if we have no wrong query parameter then this BindException is representing something else.
// Therefore we only create an ErrorCode when we have found a wrong query parameter.
// Therefore, we only create an ErrorCode when we have found a wrong query parameter.
ErrorCode errorCode =
wrongQueryParameters.length != 0
? ErrorCode.of(

View File

@ -30,7 +30,7 @@ public class QueryParamsValidator {
providedParams.removeIf(allowedParams::contains);
if (!providedParams.isEmpty()) {
throw new IllegalArgumentException("Unkown request parameters found: " + providedParams);
throw new IllegalArgumentException("Unknown request parameters found: " + providedParams);
}
}
}

View File

@ -1307,37 +1307,37 @@ public class TaskQueryFilterParameter implements QueryParameter<TaskQuery, Void>
private void validateFilterParameters() throws InvalidArgumentException {
if (planned != null && (plannedFrom != null || plannedUntil != null)) {
throw new IllegalArgumentException(
throw new InvalidArgumentException(
"It is prohibited to use the param 'planned' in combination "
+ "with the params 'planned-from' and / or 'planned-until'");
}
if (received != null && (receivedFrom != null || receivedUntil != null)) {
throw new IllegalArgumentException(
throw new InvalidArgumentException(
"It is prohibited to use the param 'received' in combination "
+ "with the params 'received-from' and / or 'received-until'");
}
if (due != null && (dueFrom != null || dueUntil != null)) {
throw new IllegalArgumentException(
throw new InvalidArgumentException(
"It is prohibited to use the param 'due' in combination with the params "
+ "'due-from' and / or 'due-until'");
}
if (created != null && (createdFrom != null || createdUntil != null)) {
throw new IllegalArgumentException(
throw new InvalidArgumentException(
"It is prohibited to use the param 'created' in combination with the params "
+ "'created-from' and / or 'created-until'");
}
if (completed != null && (completedFrom != null || completedUntil != null)) {
throw new IllegalArgumentException(
throw new InvalidArgumentException(
"It is prohibited to use the param 'completed' in combination with the params "
+ "'completed-from' and / or 'completed-until'");
}
if (wildcardSearchFields == null ^ wildcardSearchValue == null) {
throw new IllegalArgumentException(
throw new InvalidArgumentException(
"The params 'wildcard-search-field' and 'wildcard-search-value' must be used together");
}

View File

@ -129,8 +129,10 @@ public class TaskRepresentationModelAssembler
task.setDescription(repModel.getDescription());
task.setPriority(repModel.getPriority());
task.setState(repModel.getState());
task.setClassificationSummary(
classificationAssembler.toEntityModel(repModel.getClassificationSummary()));
if (repModel.getClassificationSummary() != null) {
task.setClassificationSummary(
classificationAssembler.toEntityModel(repModel.getClassificationSummary()));
}
if (repModel.getWorkbasketSummary() != null) {
task.setWorkbasketSummary(workbasketAssembler.toEntityModel(repModel.getWorkbasketSummary()));
}

View File

@ -16,7 +16,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.HttpStatusCodeException;
import pro.taskana.classification.rest.models.ClassificationRepresentationModel;
@ -353,7 +352,8 @@ class ClassificationControllerIntTest {
assertThatThrownBy(httpCall)
.isInstanceOf(HttpClientErrorException.class)
.extracting(ex -> ((HttpClientErrorException) ex).getStatusCode())
.extracting(HttpClientErrorException.class::cast)
.extracting(HttpStatusCodeException::getStatusCode)
.isEqualTo(HttpStatus.BAD_REQUEST);
}
@ -448,10 +448,11 @@ class ClassificationControllerIntTest {
ClassificationSummaryPagedRepresentationModel.class));
assertThatThrownBy(httpCall)
.isInstanceOf(HttpServerErrorException.class)
.isInstanceOf(HttpClientErrorException.class)
.hasMessageContaining(
"Unkown request parameters found: [anotherIllegalParam, illegalParam]")
.extracting(ex -> ((HttpServerErrorException) ex).getStatusCode())
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
"Unknown request parameters found: [anotherIllegalParam, illegalParam]")
.extracting(HttpClientErrorException.class::cast)
.extracting(HttpStatusCodeException::getStatusCode)
.isEqualTo(HttpStatus.BAD_REQUEST);
}
}

View File

@ -12,6 +12,7 @@ import pro.taskana.common.api.exceptions.AutocommitFailedException;
import pro.taskana.common.api.exceptions.ConcurrencyException;
import pro.taskana.common.api.exceptions.ConnectionNotSetException;
import pro.taskana.common.api.exceptions.DomainNotFoundException;
import pro.taskana.common.api.exceptions.InvalidArgumentException;
import pro.taskana.common.api.exceptions.MismatchedRoleException;
import pro.taskana.common.api.exceptions.SystemException;
import pro.taskana.common.api.exceptions.UnsupportedDatabaseException;
@ -58,6 +59,7 @@ class ExceptionErrorKeyTest {
assertThat(UnsupportedDatabaseException.ERROR_KEY).isEqualTo("DATABASE_UNSUPPORTED");
assertThat(WrongCustomHolidayFormatException.ERROR_KEY)
.isEqualTo("CUSTOM_HOLIDAY_WRONG_FORMAT");
assertThat(InvalidArgumentException.ERROR_KEY).isEqualTo("INVALID_ARGUMENT");
}
@Test

View File

@ -30,7 +30,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.HttpStatusCodeException;
import pro.taskana.classification.rest.models.ClassificationSummaryRepresentationModel;
import pro.taskana.common.rest.RestEndpoints;
@ -188,13 +188,13 @@ class TaskControllerIntTest {
HttpEntity<Object> auth = new HttpEntity<>(RestHelper.generateHeadersForUser("teamlead-1"));
ThrowingCallable httpCall =
() -> {
TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE);
};
() -> TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE);
assertThatThrownBy(httpCall)
.isInstanceOf(HttpServerErrorException.class)
.hasMessageContaining("500");
.isInstanceOf(HttpClientErrorException.class)
.extracting(HttpClientErrorException.class::cast)
.extracting(HttpStatusCodeException::getStatusCode)
.isEqualTo(HttpStatus.BAD_REQUEST);
}
@Test
@ -296,27 +296,25 @@ class TaskControllerIntTest {
HttpEntity<Object> auth = new HttpEntity<>(RestHelper.generateHeadersForUser("teamlead-1"));
ThrowingCallable httpCall =
() -> {
TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE);
};
() -> TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE);
assertThatThrownBy(httpCall)
.isInstanceOf(HttpServerErrorException.class)
.extracting(ex -> ((HttpServerErrorException) ex).getStatusCode())
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
.isInstanceOf(HttpClientErrorException.class)
.extracting(HttpClientErrorException.class::cast)
.extracting(HttpStatusCodeException::getStatusCode)
.isEqualTo(HttpStatus.BAD_REQUEST);
String url2 =
restHelper.toUrl(RestEndpoints.URL_TASKS)
+ "?wildcard-search-fields=NAME,CUSTOM_3,CUSTOM_4";
ThrowingCallable httpCall2 =
() -> {
TEMPLATE.exchange(url2, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE);
};
() -> TEMPLATE.exchange(url2, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE);
assertThatThrownBy(httpCall2)
.isInstanceOf(HttpServerErrorException.class)
.extracting(ex -> ((HttpServerErrorException) ex).getStatusCode())
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
.isInstanceOf(HttpClientErrorException.class)
.extracting(HttpClientErrorException.class::cast)
.extracting(HttpStatusCodeException::getStatusCode)
.isEqualTo(HttpStatus.BAD_REQUEST);
}
@Test
@ -378,9 +376,10 @@ class TaskControllerIntTest {
};
assertThatThrownBy(httpCall)
.isInstanceOf(HttpServerErrorException.class)
.extracting(ex -> ((HttpServerErrorException) ex).getStatusCode())
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
.isInstanceOf(HttpClientErrorException.class)
.extracting(HttpClientErrorException.class::cast)
.extracting(HttpStatusCodeException::getStatusCode)
.isEqualTo(HttpStatus.BAD_REQUEST);
}
@Test
@ -419,13 +418,13 @@ class TaskControllerIntTest {
HttpEntity<String> auth = new HttpEntity<>(RestHelper.generateHeadersForUser("user-1-2"));
ThrowingCallable httpCall =
() -> {
TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE);
};
() -> TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE);
assertThatThrownBy(httpCall)
.isInstanceOf(HttpServerErrorException.class)
.hasMessageContaining("500");
.isInstanceOf(HttpClientErrorException.class)
.extracting(HttpClientErrorException.class::cast)
.extracting(HttpStatusCodeException::getStatusCode)
.isEqualTo(HttpStatus.BAD_REQUEST);
}
@Test
@ -691,7 +690,7 @@ class TaskControllerIntTest {
out.write(taskToCreateJson);
out.flush();
out.close();
assertThat(con.getResponseCode()).isEqualTo(500);
assertThat(con.getResponseCode()).isEqualTo(400);
con.disconnect();
final String taskToCreateJson2 =
@ -711,7 +710,7 @@ class TaskControllerIntTest {
out.write(taskToCreateJson2);
out.flush();
out.close();
assertThat(con.getResponseCode()).isEqualTo(500);
assertThat(con.getResponseCode()).isEqualTo(400);
con.disconnect();
}
@ -818,9 +817,7 @@ class TaskControllerIntTest {
restHelper.toUrl(
RestEndpoints.URL_TASKS_ID_CLAIM, "TKI:000000000000000000000000000000000026");
ThrowingCallable httpCall =
() -> {
TEMPLATE.exchange(url2, HttpMethod.DELETE, auth, TASK_MODEL_TYPE);
};
() -> TEMPLATE.exchange(url2, HttpMethod.DELETE, auth, TASK_MODEL_TYPE);
assertThatThrownBy(httpCall)
.extracting(ex -> ((HttpClientErrorException) ex).getStatusCode())
@ -915,16 +912,15 @@ class TaskControllerIntTest {
HttpEntity<Object> auth = new HttpEntity<>(RestHelper.generateHeadersForUser("teamlead-1"));
ThrowingCallable httpCall =
() -> {
TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE);
};
() -> TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE);
assertThatThrownBy(httpCall)
.isInstanceOf(HttpServerErrorException.class)
.isInstanceOf(HttpClientErrorException.class)
.hasMessageContaining(
"Unkown request parameters found: [anotherIllegalParam, illegalParam]")
.extracting(ex -> ((HttpServerErrorException) ex).getStatusCode())
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
"Unknown request parameters found: [anotherIllegalParam, illegalParam]")
.extracting(HttpClientErrorException.class::cast)
.extracting(HttpStatusCodeException::getStatusCode)
.isEqualTo(HttpStatus.BAD_REQUEST);
}
@TestFactory

View File

@ -21,7 +21,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.HttpStatusCodeException;
import pro.taskana.common.rest.RestEndpoints;
import pro.taskana.common.test.rest.RestHelper;
@ -131,16 +131,16 @@ class WorkbasketAccessItemControllerIntTest {
HttpEntity<Object> auth = new HttpEntity<>(RestHelper.generateHeadersForUser("teamlead-1"));
ThrowingCallable httpCall =
() -> {
TEMPLATE.exchange(
url, HttpMethod.GET, auth, WORKBASKET_ACCESS_ITEM_PAGED_REPRESENTATION_MODEL_TYPE);
};
() ->
TEMPLATE.exchange(
url, HttpMethod.GET, auth, WORKBASKET_ACCESS_ITEM_PAGED_REPRESENTATION_MODEL_TYPE);
assertThatThrownBy(httpCall)
.isInstanceOf(HttpServerErrorException.class)
.isInstanceOf(HttpClientErrorException.class)
.hasMessageContaining(
"Unkown request parameters found: [anotherIllegalParam, illegalParam]")
.extracting(ex -> ((HttpServerErrorException) ex).getStatusCode())
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
"Unknown request parameters found: [anotherIllegalParam, illegalParam]")
.extracting(HttpClientErrorException.class::cast)
.extracting(HttpStatusCodeException::getStatusCode)
.isEqualTo(HttpStatus.BAD_REQUEST);
}
@TestFactory
@ -161,10 +161,9 @@ class WorkbasketAccessItemControllerIntTest {
new HttpEntity<>(RestHelper.generateHeadersForUser("teamlead-1"));
ThrowingCallable httpCall =
() -> {
TEMPLATE.exchange(
url, HttpMethod.DELETE, auth, ParameterizedTypeReference.forType(Void.class));
};
() ->
TEMPLATE.exchange(
url, HttpMethod.DELETE, auth, ParameterizedTypeReference.forType(Void.class));
assertThatThrownBy(httpCall)
.isInstanceOf(HttpClientErrorException.class)
.extracting(ex -> ((HttpClientErrorException) ex).getStatusCode())

View File

@ -18,7 +18,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.HttpStatusCodeException;
import pro.taskana.common.rest.RestEndpoints;
import pro.taskana.common.test.rest.RestHelper;
@ -298,15 +298,14 @@ class WorkbasketControllerIntTest {
HttpEntity<Object> auth = new HttpEntity<>(RestHelper.generateHeadersForUser("teamlead-1"));
ThrowingCallable httpCall =
() -> {
TEMPLATE.exchange(url, HttpMethod.GET, auth, WORKBASKET_SUMMARY_PAGE_MODEL_TYPE);
};
() -> TEMPLATE.exchange(url, HttpMethod.GET, auth, WORKBASKET_SUMMARY_PAGE_MODEL_TYPE);
assertThatThrownBy(httpCall)
.isInstanceOf(HttpServerErrorException.class)
.isInstanceOf(HttpStatusCodeException.class)
.hasMessageContaining(
"Unkown request parameters found: [anotherIllegalParam, illegalParam]")
.extracting(ex -> ((HttpServerErrorException) ex).getStatusCode())
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
"Unknown request parameters found: [anotherIllegalParam, illegalParam]")
.extracting(HttpStatusCodeException.class::cast)
.extracting(HttpStatusCodeException::getStatusCode)
.isEqualTo(HttpStatus.BAD_REQUEST);
}
}