Skip to content

Commit

Permalink
chore(tests): Use MockMVC (#3264)
Browse files Browse the repository at this point in the history
---------
Co-authored-by: bonita-ci <[email protected]>
  • Loading branch information
rbioteau authored Nov 26, 2024
1 parent 5d0c685 commit 07bce7b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
**/
package org.bonitasoft.engine.bpm;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

/**
* Interface <code>BaseRestElement</code> identifies a <code>BonitaObject</code> that can be used in the REST API.
*/
@JsonPropertyOrder(alphabetic = true)
public interface BaseRestElement extends BaseElement {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
**/
package org.bonitasoft.web.rest.server.api;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import lombok.extern.slf4j.Slf4j;
import org.bonitasoft.console.common.server.utils.SessionUtil;
import org.bonitasoft.engine.session.APISession;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.server.ResponseStatusException;

/**
Expand All @@ -35,24 +39,11 @@ public APISession getApiSession(HttpSession session) {
return apiSession;
}

protected long getParameterAsLong(String parameterValue, String errorMessage) {
try {
return Long.parseLong(parameterValue);
} catch (NumberFormatException e) {
log.debug(errorMessage, e);
throw new ResponseStatusException(HttpStatus.BAD_REQUEST,
errorMessage);
}
}

protected int getParameterAsInt(String parameterValue, String errorMessage) {
try {
return Integer.parseInt(parameterValue);
} catch (NumberFormatException e) {
log.debug(errorMessage, e);
throw new ResponseStatusException(HttpStatus.BAD_REQUEST,
errorMessage);
}
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "Bad request")
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
public void handleBadRequestError(HttpServletRequest req, MethodArgumentTypeMismatchException ex) {
String error = "[" + req.getPathInfo() + "] " + ex.getName() + ": " + ex.getMessage();
log.debug(error);
}

}

0 comments on commit 07bce7b

Please sign in to comment.