org.springframework.http.HttpStatus.BAD_REQUEST

Here are the examples of the java api org.springframework.http.HttpStatus.BAD_REQUEST taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1225 Examples 7

19 Source : YamiAuth2Exception.java
with GNU Affero General Public License v3.0
from zycSummer

public int getHttpErrorCode() {
    // 400 not 401
    return HttpStatus.BAD_REQUEST.value();
}

19 Source : DefaultExceptionHandlerConfig.java
with GNU Affero General Public License v3.0
from zycSummer

@ExceptionHandler(MethodArgumentNotValidException.clreplaced)
public ResponseEnreplacedy<String> methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) {
    e.printStackTrace();
    return ResponseEnreplacedy.status(HttpStatus.BAD_REQUEST).body(e.getBindingResult().getFieldErrors().get(0).getDefaultMessage());
}

19 Source : ResponseEntityPro.java
with Apache License 2.0
from yujunhao8831

public static <T> ResponseEnreplacedy<T> badRequest(final T body, final String filterFields) {
    if (null == filterFields || WILDCARD_ALL.equals(filterFields)) {
        return badRequest(body);
    }
    return status(HttpStatus.BAD_REQUEST, body, filterFields);
}

19 Source : ResponseEntityPro.java
with Apache License 2.0
from yujunhao8831

public static ResponseEnreplacedy<String> badRequest() {
    return status(HttpStatus.BAD_REQUEST, HttpStatus.BAD_REQUEST.getReasonPhrase());
}

19 Source : ResponseEntityPro.java
with Apache License 2.0
from yujunhao8831

public static <T> ResponseEnreplacedy<T> badRequest(final T body) {
    return status(HttpStatus.BAD_REQUEST, body);
}

19 Source : SampleJerseyApplicationTests.java
with Apache License 2.0
from yuanmabiji

@Test
public void validation() {
    ResponseEnreplacedy<String> enreplacedy = this.restTemplate.getForEnreplacedy("/reverse", String.clreplaced);
    replacedertThat(enreplacedy.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
}

19 Source : ExampleWebExceptionHandler.java
with Apache License 2.0
from yuanmabiji

@Override
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
    exchange.getResponse().setStatusCode(HttpStatus.BAD_REQUEST);
    return exchange.getResponse().setComplete();
}

19 Source : AbstractWebEndpointIntegrationTests.java
with Apache License 2.0
from yuanmabiji

@Test
public void readOperationWithMappingFailureProducesBadRequestResponse() {
    load(QueryEndpointConfiguration.clreplaced, (client) -> {
        WebTestClient.BodyContentSpec body = client.get().uri("/query?two=two").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isBadRequest().expectBody();
        validateErrorBody(body, HttpStatus.BAD_REQUEST, "/endpoints/query", "Missing parameters: one");
    });
}

19 Source : AbstractWebEndpointIntegrationTests.java
with Apache License 2.0
from yuanmabiji

@Test
public void readOperationWithMissingRequiredParametersReturnsBadRequestResponse() {
    load(RequiredParameterEndpointConfiguration.clreplaced, (client) -> {
        WebTestClient.BodyContentSpec body = client.get().uri("/requiredparameters").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isBadRequest().expectBody();
        validateErrorBody(body, HttpStatus.BAD_REQUEST, "/endpoints/requiredparameters", "Missing parameters: foo");
    });
}

19 Source : AppResponseEntityExceptionHandler.java
with MIT License
from Yirendai

@ExceptionHandler(value = { BadRequestException.clreplaced })
protected // 
ResponseEnreplacedy<Object> handleBadRequestException(// 
final BadRequestException ex, final WebRequest request) {
    log.error("{}", ex.getMessage());
    final HttpStatus status = HttpStatus.BAD_REQUEST;
    final ErrorMessage errorMessage = new ErrorMessage(ex.getErrorCode(), ex.getMessage(), ex.getData());
    return new ResponseEnreplacedy<Object>(errorMessage, status);
}

19 Source : WebLogObjectPrinterUnitTest.java
with Apache License 2.0
from xm-online

@Test
public void testPrintRestResult() {
    replacedertEquals(STATUS_OK + ", body=null", WebLogObjectPrinter.printRestResult(joinPoint, null).toString());
    replacedertEquals(STATUS_OK + ", body=value1", WebLogObjectPrinter.printRestResult(joinPoint, "value1").toString());
    replacedertEquals(STATUS_OK + ", body=#hidden#", WebLogObjectPrinter.printRestResult(joinPoint, "value1", false).toString());
    replacedertEquals(STATUS_OK + ", body=value1", WebLogObjectPrinter.printRestResult(joinPoint, "value1", true).toString());
    replacedertEquals(STATUS_OK + ", body=[<ArrayList> size = 5]", WebLogObjectPrinter.printRestResult(joinPoint, Arrays.asList(1, 2, 3, 4, 5)).toString());
    replacedertEquals(STATUS_OK + ", body=#hidden#", WebLogObjectPrinter.printRestResult(joinPoint, Arrays.asList(1, 2, 3, 4, 5), false).toString());
    when(responseEnreplacedy.getStatusCode()).thenReturn(HttpStatus.OK);
    when(responseEnreplacedy.getBody()).thenReturn(null);
    replacedertEquals(STATUS_200_OK + ", body=null", WebLogObjectPrinter.printRestResult(joinPoint, responseEnreplacedy).toString());
    when(responseEnreplacedy.getBody()).thenReturn("value1");
    replacedertEquals(STATUS_200_OK + ", body=value1", WebLogObjectPrinter.printRestResult(joinPoint, responseEnreplacedy).toString());
    when(responseEnreplacedy.getBody()).thenReturn(Arrays.asList(1, 2, 3, 4, 5));
    replacedertEquals(STATUS_200_OK + ", body=[<ArrayList> size = 5]", WebLogObjectPrinter.printRestResult(joinPoint, responseEnreplacedy).toString());
    when(responseEnreplacedy.getBody()).thenReturn(null);
    replacedertEquals(STATUS_200_OK + ", body=#hidden#", WebLogObjectPrinter.printRestResult(joinPoint, responseEnreplacedy, false).toString());
    when(responseEnreplacedy.getBody()).thenReturn("value1");
    replacedertEquals(STATUS_200_OK + ", body=#hidden#", WebLogObjectPrinter.printRestResult(joinPoint, responseEnreplacedy, false).toString());
    when(responseEnreplacedy.getBody()).thenReturn(Arrays.asList(1, 2, 3, 4, 5));
    replacedertEquals(STATUS_200_OK + ", body=#hidden#", WebLogObjectPrinter.printRestResult(joinPoint, responseEnreplacedy, false).toString());
    when(responseEnreplacedy.getStatusCode()).thenReturn(HttpStatus.BAD_REQUEST);
    when(responseEnreplacedy.getBody()).thenReturn("value1");
    replacedertEquals("status=400 BAD_REQUEST, body=value1", WebLogObjectPrinter.printRestResult(joinPoint, responseEnreplacedy).toString());
}

19 Source : BadRequestException.java
with MIT License
from wuyc

@Override
public HttpStatus getStatus() {
    return HttpStatus.BAD_REQUEST;
}

19 Source : ControllerAdvice.java
with MIT License
from woowacourse-teams

@ExceptionHandler(BadRequestException.clreplaced)
public ResponseEnreplacedy<ErrorResponse> badRequestExceptionHandler(BadRequestException exception) {
    ErrorResponse errorResponse = new ErrorResponse(exception.getMessage());
    log.info("BadRequestException : {}", exception.getMessage());
    return ResponseEnreplacedy.status(HttpStatus.BAD_REQUEST).body(errorResponse);
}

19 Source : GlobalExceptionHandler.java
with Apache License 2.0
from WinterChenS

/**
 * 捕获  RuntimeException 异常
 * TODO  如果你觉得在一个 exceptionHandler 通过  if (e instanceof xxxException) 太麻烦
 * TODO  那么你还可以自己写多个不同的 exceptionHandler 处理不同异常
 *
 * @param request  request
 * @param e        exception
 * @param response response
 * @return 响应结果
 */
@ExceptionHandler(RuntimeException.clreplaced)
public ErrorResponseEnreplacedy runtimeExceptionHandler(HttpServletRequest request, final Exception e, HttpServletResponse response) {
    response.setStatus(HttpStatus.BAD_REQUEST.value());
    RuntimeException exception = (RuntimeException) e;
    return new ErrorResponseEnreplacedy(400, exception.getMessage());
}

19 Source : JobInfoController.java
with Apache License 2.0
from WeBankFinTech

@RequestMapping(value = "/func/{tabName:\\w+}/{funcType:\\w+}", method = RequestMethod.GET)
public Response<Object> jobFuncList(@PathVariable("tabName") String tabName, @PathVariable("funcType") String funcType, HttpServletResponse response) {
    try {
        // Limit that the tab should be an engine tab
        JobEngine.valueOf(tabName.toUpperCase());
        funcType = funcType.toUpperCase();
        JobFunction.FunctionType funcTypeEnum = JobFunction.FunctionType.valueOf(funcType);
        List<JobFunction> functionList = jobFuncService.getFunctions(tabName, funcTypeEnum);
        return new Response<>().successResponse(functionList);
    } catch (IllegalArgumentException e) {
        response.setStatus(HttpStatus.BAD_REQUEST.value());
        return new Response<>().errorResponse(-1, null, "");
    }
}

19 Source : HesperidesScenario.java
with GNU General Public License v3.0
from voyages-sncf-technologies

protected void replacedertBadRequest() {
    replacedertEquals(HttpStatus.BAD_REQUEST, testContext.getResponseStatusCode());
}

19 Source : GlobalExceptionHandler.java
with GNU General Public License v3.0
from voyages-sncf-technologies

@ExceptionHandler({ IllegalArgumentException.clreplaced })
public ResponseEnreplacedy handleBadRequest(Exception exception) {
    beforeHandling(exception);
    return ResponseEnreplacedy.status(HttpStatus.BAD_REQUEST).body(exception.getMessage());
}

19 Source : GlobalExceptionHandler.java
with GNU General Public License v3.0
from voyages-sncf-technologies

/**
 * se produit quand on veut executer une commande sur un aggregat qui n'existe pas.
 *
 * @param exception "not found" failure
 * @return enreplacedy
 */
@ExceptionHandler(AggregateNotFoundException.clreplaced)
public ResponseEnreplacedy handleAggregateNotFound(AggregateNotFoundException exception) {
    beforeHandling(exception);
    return ResponseEnreplacedy.status(HttpStatus.BAD_REQUEST).body(exception.getAggregateIdentifier() + ": " + exception.getMessage());
}

19 Source : ServletInvocableHandlerMethodTests.java
with MIT License
from Vip-Augus

@Test
public void invokeAndHandle_VoidWithComposedResponseStatus() throws Exception {
    ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new Handler(), "composedResponseStatus");
    handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer);
    replacedertTrue("Null return value + @ComposedResponseStatus should result in 'request handled'", this.mavContainer.isRequestHandled());
    replacedertEquals(HttpStatus.BAD_REQUEST.value(), this.response.getStatus());
}

19 Source : ServletInvocableHandlerMethodTests.java
with MIT License
from Vip-Augus

// SPR-9159
@Test
public void invokeAndHandle_NotVoidWithResponseStatusAndReason() throws Exception {
    ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new Handler(), "responseStatusWithReason");
    handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer);
    replacedertTrue("When a status reason w/ used, the request is handled", this.mavContainer.isRequestHandled());
    replacedertEquals(HttpStatus.BAD_REQUEST.value(), this.response.getStatus());
    replacedertEquals("400 Bad Request", this.response.getErrorMessage());
}

19 Source : ServletInvocableHandlerMethodTests.java
with MIT License
from Vip-Augus

@Test
public void invokeAndHandle_VoidWithResponseStatus() throws Exception {
    ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new Handler(), "responseStatus");
    handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer);
    replacedertTrue("Null return value + @ResponseStatus should result in 'request handled'", this.mavContainer.isRequestHandled());
    replacedertEquals(HttpStatus.BAD_REQUEST.value(), this.response.getStatus());
}

19 Source : ServletInvocableHandlerMethodTests.java
with MIT License
from Vip-Augus

@Test
public void invokeAndHandle_VoidWithTypeLevelResponseStatus() throws Exception {
    ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new ResponseStatusHandler(), "handle");
    handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer);
    replacedertTrue(this.mavContainer.isRequestHandled());
    replacedertEquals(HttpStatus.BAD_REQUEST.value(), this.response.getStatus());
}

19 Source : DefaultServerResponseBuilderTests.java
with MIT License
from Vip-Augus

@Test
public void badRequest() {
    ServerResponse response = ServerResponse.badRequest().build();
    replacedertEquals(HttpStatus.BAD_REQUEST, response.statusCode());
}

19 Source : ClientResponseWrapperTests.java
with MIT License
from Vip-Augus

@Test
public void statusCode() {
    HttpStatus status = HttpStatus.BAD_REQUEST;
    given(mockResponse.statusCode()).willReturn(status);
    replacedertSame(status, wrapper.statusCode());
}

19 Source : ExceptionHandlingWebHandlerTests.java
with MIT License
from Vip-Augus

@Test
public void thrownExceptionBecomesErrorSignal() throws Exception {
    createWebHandler(new BadRequestExceptionHandler()).handle(this.exchange).block();
    replacedertEquals(HttpStatus.BAD_REQUEST, this.exchange.getResponse().getStatusCode());
}

19 Source : ExceptionHandlingWebHandlerTests.java
with MIT License
from Vip-Augus

@Test
public void handleErrorSignal() throws Exception {
    createWebHandler(new BadRequestExceptionHandler()).handle(this.exchange).block();
    replacedertEquals(HttpStatus.BAD_REQUEST, this.exchange.getResponse().getStatusCode());
}

19 Source : ExceptionHandlingWebHandlerTests.java
with MIT License
from Vip-Augus

@Test
public void handleErrorSignalWithMultipleHttpErrorHandlers() throws Exception {
    createWebHandler(new UnresolvedExceptionHandler(), new UnresolvedExceptionHandler(), new BadRequestExceptionHandler(), new UnresolvedExceptionHandler()).handle(this.exchange).block();
    replacedertEquals(HttpStatus.BAD_REQUEST, this.exchange.getResponse().getStatusCode());
}

19 Source : StatusAssertionTests.java
with MIT License
from Vip-Augus

@Test
public void statusSerius4xx() {
    Statusreplacedertions replacedertions = statusreplacedertions(HttpStatus.BAD_REQUEST);
    // Success
    replacedertions.is4xxClientError();
    try {
        replacedertions.is2xxSuccessful();
        fail("Wrong series expected");
    } catch (replacedertionError error) {
    // Expected
    }
}

19 Source : StatusResultMatchers.java
with MIT License
from Vip-Augus

/**
 * replacedert the response status code is {@code HttpStatus.BAD_REQUEST} (400).
 */
public ResultMatcher isBadRequest() {
    return matcher(HttpStatus.BAD_REQUEST);
}

19 Source : StatusAssertions.java
with MIT License
from Vip-Augus

/**
 * replacedert the response status code is {@code HttpStatus.BAD_REQUEST} (400).
 */
public WebTestClient.ResponseSpec isBadRequest() {
    return replacedertStatusAndReturn(HttpStatus.BAD_REQUEST);
}

19 Source : MarqetaErrorTest.java
with MIT License
from verygoodsecurity

@Test
public void shouldReturnMessageAsJson() {
    final String errorCode = "400002";
    final String errorMessage = "Birth date cannot be a future date";
    final MarqetaError exception = new MarqetaError();
    exception.setStatusCode(HttpStatus.BAD_REQUEST);
    exception.setErrorCode(errorCode);
    exception.setErrorMessage(errorMessage);
    final String expectedMessage = format("{\"error_code\":\"%s\",\"error_message\":\"%s\"}", errorCode, errorMessage);
    replacedertThat(exception.getMessage(), is(equalTo(expectedMessage)));
}

19 Source : VaadinConnectControllerTest.java
with Apache License 2.0
from vaadin

@Test
public void should_Return400_When_MoreParametersSpecified() {
    ResponseEnreplacedy<String> response = createVaadinController(TEST_SERVICE).serveVaadinService(TEST_SERVICE_NAME, TEST_METHOD.getName(), createRequestParameters("{\"value1\": 222, \"value2\": 333}"));
    replacedertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
    String responseBody = response.getBody();
    replacedertServiceInfoPresent(responseBody);
    replacedertTrue(String.format("Invalid response body: '%s'", responseBody), responseBody.contains("2"));
    replacedertTrue(String.format("Invalid response body: '%s'", responseBody), responseBody.contains(Integer.toString(TEST_METHOD.getParameterCount())));
}

19 Source : VaadinConnectControllerTest.java
with Apache License 2.0
from vaadin

@Test
public void should_Return400_When_LessParametersSpecified1() {
    ResponseEnreplacedy<String> response = createVaadinController(TEST_SERVICE).serveVaadinService(TEST_SERVICE_NAME, TEST_METHOD.getName(), null);
    replacedertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
    String responseBody = response.getBody();
    replacedertServiceInfoPresent(responseBody);
    replacedertTrue(String.format("Invalid response body: '%s'", responseBody), responseBody.contains("0"));
    replacedertTrue(String.format("Invalid response body: '%s'", responseBody), responseBody.contains(Integer.toString(TEST_METHOD.getParameterCount())));
}

19 Source : VaadinConnectControllerTest.java
with Apache License 2.0
from vaadin

@Test
public void should_Return400_When_IncorrectParameterTypesAreProvided() {
    ResponseEnreplacedy<String> response = createVaadinController(TEST_SERVICE).serveVaadinService(TEST_SERVICE_NAME, TEST_METHOD.getName(), createRequestParameters("{\"value\": [222]}"));
    replacedertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
    String responseBody = response.getBody();
    replacedertServiceInfoPresent(responseBody);
    replacedertTrue(String.format("Invalid response body: '%s'", responseBody), responseBody.contains(TEST_METHOD.getParameterTypes()[0].getSimpleName()));
}

19 Source : VaadinConnectControllerTest.java
with Apache License 2.0
from vaadin

@Test
public void should_ReturnAllValidationErrors_When_DeserializationFailsForMultipleParameters() throws IOException {
    String inputValue = String.format("{\"number\": %s, \"text\": %s, \"date\": %s}", "\"NotANumber\"", "\"ValidText\"", "\"NotADate\"");
    String testMethodName = "testMethodWithMultipleParameter";
    String expectedErrorMessage = String.format("Validation error in service '%s' method '%s'", TEST_SERVICE_NAME, testMethodName);
    ResponseEnreplacedy<String> response = createVaadinController(TEST_SERVICE).serveVaadinService(TEST_SERVICE_NAME, testMethodName, createRequestParameters(inputValue));
    replacedertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
    ObjectNode jsonNodes = new ObjectMapper().readValue(response.getBody(), ObjectNode.clreplaced);
    replacedertNotNull(jsonNodes);
    replacedertEquals(VaadinConnectValidationException.clreplaced.getName(), jsonNodes.get("type").asText());
    replacedertEquals(expectedErrorMessage, jsonNodes.get("message").asText());
    replacedertEquals(2, jsonNodes.get("validationErrorData").size());
    List<String> parameterNames = jsonNodes.get("validationErrorData").findValuesAsText("parameterName");
    replacedertEquals(2, parameterNames.size());
    replacedertTrue(parameterNames.contains("date"));
    replacedertTrue(parameterNames.contains("number"));
}

19 Source : FileUploadControllerTest.java
with Apache License 2.0
from usdot-jpo-ode

@Test
public void handleFileUploadReturnsErrorOnStorageException() {
    new Expectations() {

        {
            mockStorageService.store((MultipartFile) any, anyString);
            result = new StorageFileNotFoundException("testException123");
        }
    };
    replacedertEquals(HttpStatus.BAD_REQUEST, testFileUploadController.handleFileUpload(mockMultipartFile, "type").getStatusCode());
}

19 Source : TimQueryControllerTest.java
with Apache License 2.0
from usdot-jpo-ode

@Test
public void testNullResponseReturnsTimeout() throws IOException {
    new Expectations() {

        {
            mockOdeProperties.getRsuSrmSlots();
            result = 1;
            capturingSnmpSession.getSnmp();
            result = mockSnmp;
            mockSnmp.send((PDU) any, (UserTarget) any);
            result = null;
        }
    };
    ResponseEnreplacedy<String> actualResponse = testTimQueryController.bulkQuery("{\"request\":{},\"tim\":{}}");
    replacedertEquals(HttpStatus.BAD_REQUEST, actualResponse.getStatusCode());
    replacedertTrue(actualResponse.getBody().contains("Timeout, no response from RSU."));
}

19 Source : TimQueryControllerTest.java
with Apache License 2.0
from usdot-jpo-ode

@Test
public void nullRequestShouldReturnError() {
    ResponseEnreplacedy<?> result = testTimQueryController.bulkQuery(null);
    replacedertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
    replacedertEquals("{\"error\":\"Empty request.\"}", result.getBody());
}

19 Source : TimQueryControllerTest.java
with Apache License 2.0
from usdot-jpo-ode

@Test
public void testNullResponseResponseReturnsTimeout() throws IOException {
    new Expectations() {

        {
            mockOdeProperties.getRsuSrmSlots();
            result = 1;
            capturingSnmpSession.getSnmp();
            result = mockSnmp;
            mockSnmp.send((PDU) any, (UserTarget) any);
            result = mockResponseEvent;
            mockResponseEvent.getResponse();
            result = null;
        }
    };
    ResponseEnreplacedy<String> actualResponse = testTimQueryController.bulkQuery("{\"request\":{},\"tim\":{}}");
    replacedertEquals(HttpStatus.BAD_REQUEST, actualResponse.getStatusCode());
    replacedertTrue(actualResponse.getBody().contains("Timeout, no response from RSU."));
}

19 Source : TimQueryControllerTest.java
with Apache License 2.0
from usdot-jpo-ode

@Test
public void emptyRequestShouldReturnError() {
    ResponseEnreplacedy<?> result = testTimQueryController.bulkQuery("");
    replacedertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
    replacedertEquals("{\"error\":\"Empty request.\"}", result.getBody());
}

19 Source : TimDeleteControllerTest.java
with Apache License 2.0
from usdot-jpo-ode

@Test
public void deleteShouldReturnBadRequestWhenNull() {
    replacedertEquals(HttpStatus.BAD_REQUEST, testTimDeleteController.deleteTim(null, 42).getStatusCode());
}

19 Source : TimDeleteControllerTest.java
with Apache License 2.0
from usdot-jpo-ode

@Test
public void deleteTestInvalidIndex() throws IOException {
    new Expectations() {

        {
            capturingSnmpSession.set((PDU) any, (Snmp) any, (UserTarget) any, anyBoolean);
            result = mockResponseEvent;
            mockResponseEvent.getResponse().getErrorStatus();
            result = 10;
        }
    };
    replacedertEquals(HttpStatus.BAD_REQUEST, testTimDeleteController.deleteTim("{\"rsuTarget\":\"127.0.0.1\",\"rsuRetries\":\"1\",\"rsuTimeout\":\"2000\"}", 42).getStatusCode());
}

19 Source : TimDeleteControllerTest.java
with Apache License 2.0
from usdot-jpo-ode

@Test
public void deleteTestUnknownErrorCode() throws IOException {
    new Expectations() {

        {
            capturingSnmpSession.set((PDU) any, (Snmp) any, (UserTarget) any, anyBoolean);
            result = mockResponseEvent;
            mockResponseEvent.getResponse().getErrorStatus();
            result = 5;
        }
    };
    replacedertEquals(HttpStatus.BAD_REQUEST, testTimDeleteController.deleteTim("{\"rsuTarget\":\"127.0.0.1\",\"rsuRetries\":\"1\",\"rsuTimeout\":\"2000\"}", 42).getStatusCode());
}

19 Source : TimDeleteControllerTest.java
with Apache License 2.0
from usdot-jpo-ode

@Test
public void deleteTestMessageAlreadyExists() throws IOException {
    new Expectations() {

        {
            capturingSnmpSession.set((PDU) any, (Snmp) any, (UserTarget) any, anyBoolean);
            result = mockResponseEvent;
            mockResponseEvent.getResponse().getErrorStatus();
            result = 12;
        }
    };
    replacedertEquals(HttpStatus.BAD_REQUEST, testTimDeleteController.deleteTim("{\"rsuTarget\":\"127.0.0.1\",\"rsuRetries\":\"1\",\"rsuTimeout\":\"2000\"}", 42).getStatusCode());
}

19 Source : TimDeleteControllerTest.java
with Apache License 2.0
from usdot-jpo-ode

@Test
public void deleteShouldCatchSessionNullPointerException() {
    try {
        new Expectations() {

            {
                new SnmpSession((RSU) any);
                result = new NullPointerException("testException123");
            }
        };
    } catch (IOException e) {
        fail("Unexpected Exception in expectations block: " + e);
    }
    replacedertEquals(HttpStatus.BAD_REQUEST, testTimDeleteController.deleteTim("{\"rsuTarget\":\"127.0.0.1\",\"rsuRetries\":\"1\",\"rsuTimeout\":\"2000\"}", 42).getStatusCode());
}

19 Source : PdmControllerTest.java
with Apache License 2.0
from usdot-jpo-ode

@Test
public void nullRequestShouldReturnBadRequest() {
    replacedertEquals(HttpStatus.BAD_REQUEST, testPdmController.pdmMessage(null).getStatusCode());
}

19 Source : SystemRoleController.java
with Apache License 2.0
from tysxquan

@DeleteMapping("{roleIds}")
@RequiresPermissions("role:delete")
@ControllerEndpoint(operation = "删除角色", exceptionMessage = "删掉角色失败")
public ServerResponse deleteRole(@PathVariable String roleIds) {
    String[] split = StringUtils.split(roleIds, StringPool.COMMA);
    List<String> list = Arrays.asList(split);
    boolean isExist = list.stream().anyMatch(x -> Long.parseLong(x) < SystemRole.NOT_DELETE_RANGE);
    if (isExist) {
        return ServerResponse.error(HttpStatus.BAD_REQUEST.value(), "含有不可删除的数据");
    }
    systemRoleService.deleteRole(list);
    return ServerResponse.success();
}

19 Source : GlobalExceptionHandler.java
with Apache License 2.0
from tomsun28

/**
 * handler the exception thrown for data input verify
 * @param exception data input verify exception
 * @return response
 */
@ExceptionHandler(MethodArgumentNotValidException.clreplaced)
@ResponseBody
ResponseEnreplacedy<Message> handleInputValidException(MethodArgumentNotValidException exception) {
    StringBuffer errorMessage = new StringBuffer();
    if (exception != null) {
        exception.getBindingResult().getAllErrors().forEach(error -> errorMessage.append(error.getDefaultMessage()).append("."));
    }
    if (log.isDebugEnabled()) {
        log.debug("[sample-tom]-[input argument not valid happen]-{}", errorMessage, exception);
    }
    Message message = Message.builder().errorMsg(errorMessage.toString()).build();
    return ResponseEnreplacedy.status(HttpStatus.BAD_REQUEST).body(message);
}

19 Source : SSLCertificateSchedulerServiceTest.java
with Apache License 2.0
from tmobile

@Test
public void checkApplicationMetaDataChanges_failed_to_read_metadata() throws Exception {
    when(tokenUtils.getSelfServiceTokenWithAppRole()).thenReturn(token);
    List<TMOAppMetadataDetails> tmoAppMetadataListFromCLM = new ArrayList<>();
    tmoAppMetadataListFromCLM.add(new TMOAppMetadataDetails("tst1", "[email protected]", "tst2-tag", "[email protected]", null, null, false));
    when(workloadDetailsService.getAllApplicationDetailsFromCLM()).thenReturn(tmoAppMetadataListFromCLM);
    List<TMOAppMetadataDetails> tmoAppMetadataList = new ArrayList<>();
    List<String> internalCertList = new ArrayList<>();
    internalCertList.add("cert1.company.com");
    tmoAppMetadataList.add(new TMOAppMetadataDetails("tst1", "[email protected]", "tst1-tag", "[email protected]", internalCertList, null, false));
    when(workloadDetailsService.getAllAppMetadata(token)).thenReturn(tmoAppMetadataList);
    when(reqProcessor.process(eq("/read"), Mockito.any(), eq(token))).thenReturn(getMockResponse(HttpStatus.BAD_REQUEST, false, ""));
    when(workloadDetailsService.udpateApplicationMetadata(eq(token), Mockito.any(), Mockito.any())).thenReturn(getMockResponse(HttpStatus.INTERNAL_SERVER_ERROR, false, ""));
    sslCertificateSchedulerService.checkApplicationMetaDataChanges();
    replacedertTrue(true);
}

19 Source : SecretServiceTest.java
with Apache License 2.0
from tmobile

@Test
public void test_deleteFromVault_failure_400() {
    String token = "5PDrOhsy4ig8L3EpsJZSLAMg";
    String path = "shared/mysafe01/myfolder";
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid path\"]}");
    when(ControllerUtil.isValidDataPath(path)).thenReturn(false);
    ResponseEnreplacedy<String> responseEnreplacedy = secretService.deleteFromVault(token, path);
    replacedertEquals(HttpStatus.BAD_REQUEST, responseEnreplacedy.getStatusCode());
    replacedertEquals(responseEnreplacedyExpected, responseEnreplacedy);
}

See More Examples