Search in sources :

Example 46 with ErrorModel

use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.

the class ConnectedOperations method createDatasetExpectError.

public ErrorModel createDatasetExpectError(DatasetRequestModel datasetRequest, HttpStatus expectedStatus) throws Exception {
    MvcResult result = mvc.perform(post("/api/repository/v1/datasets").contentType(MediaType.APPLICATION_JSON).content(TestUtils.mapToJson(datasetRequest))).andReturn();
    MockHttpServletResponse response = validateJobModelAndWait(result);
    ErrorModel errorModel = handleFailureCase(response, expectedStatus);
    return errorModel;
}
Also used : ErrorModel(bio.terra.model.ErrorModel) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 47 with ErrorModel

use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.

the class ConnectedOperations method checkDeleteResponse.

public void checkDeleteResponse(MockHttpServletResponse response) throws Exception {
    HttpStatus status = HttpStatus.valueOf(response.getStatus());
    if (status.is2xxSuccessful()) {
        DeleteResponseModel responseModel = TestUtils.mapFromJson(response.getContentAsString(), DeleteResponseModel.class);
        assertTrue("Valid delete response object state enumeration", (responseModel.getObjectState() == DeleteResponseModel.ObjectStateEnum.DELETED || responseModel.getObjectState() == DeleteResponseModel.ObjectStateEnum.NOT_FOUND));
    } else {
        ErrorModel errorModel = handleFailureCase(response, HttpStatus.NOT_FOUND);
        assertNotNull("error model returned", errorModel);
    }
}
Also used : HttpStatus(org.springframework.http.HttpStatus) ErrorModel(bio.terra.model.ErrorModel) DeleteResponseModel(bio.terra.model.DeleteResponseModel)

Example 48 with ErrorModel

use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.

the class ApiValidationExceptionHandler method handleMethodArgumentNotValid.

@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
    BindingResult bindingResult = ex.getBindingResult();
    List<String> errorDetails = bindingResult.getFieldErrors().stream().map(this::formatFieldError).collect(toList());
    ErrorModel errorModel = new ErrorModel().message("Validation errors - see error details").errorDetail(errorDetails);
    return new ResponseEntity<>(errorModel, HttpStatus.BAD_REQUEST);
}
Also used : BindingResult(org.springframework.validation.BindingResult) ResponseEntity(org.springframework.http.ResponseEntity) ErrorModel(bio.terra.model.ErrorModel)

Aggregations

ErrorModel (bio.terra.model.ErrorModel)48 Test (org.junit.Test)38 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)38 DatasetRequestModel (bio.terra.model.DatasetRequestModel)21 AssetTableModel (bio.terra.model.AssetTableModel)16 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)16 MvcResult (org.springframework.test.web.servlet.MvcResult)14 TableModel (bio.terra.model.TableModel)13 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)13 ColumnModel (bio.terra.model.ColumnModel)8 IntPartitionOptionsModel (bio.terra.model.IntPartitionOptionsModel)6 AssetModel (bio.terra.model.AssetModel)5 FileModel (bio.terra.model.FileModel)5 DatePartitionOptionsModel (bio.terra.model.DatePartitionOptionsModel)4 IngestRequestModel (bio.terra.model.IngestRequestModel)4 DatasetSummaryModel (bio.terra.model.DatasetSummaryModel)3 DeleteResponseModel (bio.terra.model.DeleteResponseModel)3 FileLoadModel (bio.terra.model.FileLoadModel)3 SnapshotSummaryModel (bio.terra.model.SnapshotSummaryModel)3 Blob (com.google.cloud.storage.Blob)3