Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import org.springframework.security.core.AuthenticationException;
import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.multipart.support.MissingServletRequestPartException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.servlet.resource.NoResourceFoundException;
Expand Down Expand Up @@ -58,6 +60,11 @@ public ResponseEntity<ErrorMessage> handleMessageNotReadableException(RuntimeExc
return new ResponseEntity<>(new ErrorMessage(e, HttpStatus.BAD_REQUEST), HttpStatus.BAD_REQUEST);
}

@ExceptionHandler({MissingServletRequestParameterException.class, MissingServletRequestPartException.class})
public ResponseEntity<ErrorMessage> handleMissingServletRequestParameter(Exception e) {
return new ResponseEntity<>(new ErrorMessage(e, HttpStatus.BAD_REQUEST), HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(RuntimeException.class)
public ResponseEntity<ErrorMessage> handleRuntimeException(RuntimeException e) {
return new ResponseEntity<>(new ErrorMessage(e, HttpStatus.BAD_REQUEST), HttpStatus.BAD_REQUEST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,6 @@ public void should_fail_create_attachment_without_files() throws IOException {
requestEntity,
String.class);

assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public void should_fail_upload_component_without_file() throws IOException {
requestEntity,
String.class);

assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}

@Test
Expand All @@ -475,7 +475,7 @@ public void should_fail_upload_release_without_file() throws IOException {
requestEntity,
String.class);

assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}

@Test
Expand All @@ -494,7 +494,7 @@ public void should_fail_upload_attachment_without_file() throws IOException {
requestEntity,
String.class);

assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}

@Test
Expand Down Expand Up @@ -651,8 +651,8 @@ public void should_verify_error_response_structure() throws IOException {
String.class);

// Verify error response
assertEquals("HTTP status should be INTERNAL_SERVER_ERROR",
HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertEquals("HTTP status should be BAD_REQUEST",
HttpStatus.BAD_REQUEST, response.getStatusCode());

// Verify error response body
String responseBody = response.getBody();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ public void should_fail_merge_vendors_with_missing_parameters() throws IOExcepti
requestEntity,
String.class);

assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}

// ========== EXCEPTION COVERAGE TESTS ==========
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,12 @@ public void should_document_create_attachment() throws Exception {
this.mockMvc.perform(builder).andExpect(status().isOk()).andDo(this.documentationHandler.document());
}

@Test
public void should_return_400_when_sha1_parameter_is_missing() throws Exception {
mockMvc.perform(get("/api/attachments")
.header("Authorization", TestHelper.generateAuthHeader(testUserId, testUserPassword))
.accept(MediaTypes.HAL_JSON))
.andExpect(status().isBadRequest());
}

}