Package org.apache.olingo.odata2.api.exception

Examples of org.apache.olingo.odata2.api.exception.ODataMessageException


  @Test
  public void exception() throws Exception {
    final ODataContext context = mockContext(ODataHttpMethod.GET);
    final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.BAD_REQUEST, null, null);

    ODataMessageException exception = mock(ODataMessageException.class);
    when(exception.getMessageReference()).thenReturn(ODataMessageException.COMMON);
    RuntimeException innerException = mock(RuntimeException.class);
    when(innerException.getLocalizedMessage()).thenReturn("error");
    final StackTraceElement[] stackTrace = new StackTraceElement[] {
        new StackTraceElement("innerClass", "innerMethod", "innerFile", 99),
        new StackTraceElement("class", "method", "file", 42),
        new StackTraceElement("outerClass", "outerMethod", "outerFile", 11) };
    when(innerException.getStackTrace()).thenReturn(stackTrace);
    when(exception.getCause()).thenReturn(innerException);
    when(exception.getStackTrace()).thenReturn(Arrays.copyOfRange(stackTrace, 1, 3));

    ODataResponse response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), exception,
        ODataDebugResponseWrapper.ODATA_DEBUG_JSON).wrapResponse();
    String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
    assertEquals(EXPECTED
        .replace(Integer.toString(HttpStatusCodes.OK.getStatusCode()),
            Integer.toString(HttpStatusCodes.BAD_REQUEST.getStatusCode()))
        .replace(HttpStatusCodes.OK.getInfo(), HttpStatusCodes.BAD_REQUEST.getInfo())
        .replace("null}}", "null,"
            + "\"stacktrace\":{\"exceptions\":[{\"class\":\"" + exception.getClass().getName() + "\","
            + "\"message\":\"Common exception\","
            + "\"invocation\":{\"class\":\"class\",\"method\":\"method\",\"line\":42}},"
            + "{\"class\":\"" + innerException.getClass().getName() + "\",\"message\":\"error\","
            + "\"invocation\":{\"class\":\"innerClass\",\"method\":\"innerMethod\",\"line\":99}}],"
            + "\"stacktrace\":[{\"class\":\"class\",\"method\":\"method\",\"line\":42},"
View Full Code Here


        lastFoundException = thrownException;
      }
    }

    if (lastFoundException != null) {
      ODataMessageException msgException = (ODataMessageException) lastFoundException;
      assertEquals(key, msgException.getMessageReference().getKey());
    } else {
      fail("Exception of class: " + class1.getCanonicalName() + " in stacktrace not found.");
    }
  }
View Full Code Here

  @Test
  public void exception() throws Exception {
    final ODataContext context = mockContext(ODataHttpMethod.GET);
    final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.BAD_REQUEST, null, null);

    ODataMessageException exception = mock(ODataMessageException.class);
    when(exception.getMessageReference()).thenReturn(ODataMessageException.COMMON);
    RuntimeException innerException = mock(RuntimeException.class);
    when(innerException.getLocalizedMessage()).thenReturn("error");
    final StackTraceElement[] stackTrace = new StackTraceElement[] {
        new StackTraceElement("innerClass", "innerMethod", "innerFile", 99),
        new StackTraceElement("class", "method", "file", 42),
        new StackTraceElement("outerClass", "outerMethod", "outerFile", 11) };
    when(innerException.getStackTrace()).thenReturn(stackTrace);
    when(exception.getCause()).thenReturn(innerException);
    when(exception.getStackTrace()).thenReturn(Arrays.copyOfRange(stackTrace, 1, 3));

    ODataResponse response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), exception,
        ODataDebugResponseWrapper.ODATA_DEBUG_JSON).wrapResponse();
    String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
    assertEquals(EXPECTED
        .replace(Integer.toString(HttpStatusCodes.OK.getStatusCode()),
            Integer.toString(HttpStatusCodes.BAD_REQUEST.getStatusCode()))
        .replace(HttpStatusCodes.OK.getInfo(), HttpStatusCodes.BAD_REQUEST.getInfo())
        .replace("}}}", "}},\"server\":{"
            + "\"stacktrace\":{\"exceptions\":[{\"class\":\"" + exception.getClass().getName() + "\","
            + "\"message\":\"Common exception\","
            + "\"invocation\":{\"class\":\"class\",\"method\":\"method\",\"line\":42}},"
            + "{\"class\":\"" + innerException.getClass().getName() + "\",\"message\":\"error\","
            + "\"invocation\":{\"class\":\"innerClass\",\"method\":\"innerMethod\",\"line\":99}}],"
            + "\"stacktrace\":[{\"class\":\"class\",\"method\":\"method\",\"line\":42},"
View Full Code Here

    String info = "aExMessageText(" + expression + ")-->";
    if (curException == null) {
      fail("Error in aExMessageText: Expected exception.");
    }

    ODataMessageException messageException;

    try {
      messageException = (ODataMessageException) curException;
    } catch (ClassCastException ex) {
      fail("Error in aExNext: curException not an ODataMessageException");
      return this;
    }

    Message ms = MessageService.getMessage(DEFAULT_LANGUAGE, messageException.getMessageReference());
    info = "  " + info + "Expected: '" + messageText + "' Actual: '" + ms.getText() + "'";

    dout(info);
    assertEquals(info, messageText, ms.getText());
View Full Code Here

    String info = "aExMessageTextNoEmptyTag(" + expression + ")-->";
    if (curException == null) {
      fail("Error in aExMessageText: Expected exception.");
    }

    ODataMessageException messageException;

    try {
      messageException = (ODataMessageException) curException;
    } catch (ClassCastException ex) {
      fail("Error in aExNext: curException not an ODataMessageException");
      return this;
    }

    Message ms = MessageService.getMessage(DEFAULT_LANGUAGE, messageException.getMessageReference());
    info = "  " + info + "Messagetext: '" + ms.getText() + "contains [%";

    dout(info);

    if (ms.getText().contains("[%")) {
View Full Code Here

    String info = "aExTextNotEmpty(" + expression + ")-->";
    if (curException == null) {
      fail("Error in aExMessageText: Expected exception.");
    }

    ODataMessageException messageException;

    try {
      messageException = (ODataMessageException) curException;
    } catch (ClassCastException ex) {
      fail("Error in aExNext: curException not an ODataMessageException");
      return this;
    }

    Message ms = MessageService.getMessage(DEFAULT_LANGUAGE, messageException.getMessageReference());
    info = "  " + info + "check if Messagetext is empty";
    dout(info);

    if (ms.getText().length() == 0) {
      fail(info);
View Full Code Here

    return this;
  }

  public ParserTool aExKey(final MessageReference expressionExpectedAtPos) {
    String expectedKey = expressionExpectedAtPos.getKey();
    ODataMessageException messageException;

    String info = "GetExceptionType(" + expression + ")-->";

    if (curException == null) {
      fail("Error in aExType: Expected exception");
    }

    try {
      messageException = (ODataMessageException) curException;
    } catch (ClassCastException ex) {
      fail("Error in aExNext: curException not an ODataMessageException");
      return this;
    }

    String actualKey = messageException.getMessageReference().getKey();
    dout("  " + info + "Expected key: " + expectedKey + " Actual: " + actualKey);

    if (expectedKey != actualKey) {
      fail("  " + info + "Expected: " + expectedKey + " Actual: " + actualKey);
    }
View Full Code Here

    }
    return this;
  }

  public ParserTool printExMessage() {
    ODataMessageException messageException;
    if (curException == null) {
      fail("Error in aExMsgPrint: Expected exception");
    }

    try {
      messageException = (ODataMessageException) curException;
    } catch (ClassCastException ex) {
      fail("Error in aExNext: curException not an ODataMessageException");
      return this;
    }

    Message ms = MessageService.getMessage(DEFAULT_LANGUAGE, messageException.getMessageReference());
    out("Messge --> ");
    out("  " + ms.getText());
    out("Messge <-- ");

    return this;
View Full Code Here

    return this;
  }

  public String getExceptionText() {
    ODataMessageException messageException = (ODataMessageException) curException;
    Message ms = MessageService.getMessage(DEFAULT_LANGUAGE, messageException.getMessageReference());

    return ms.getText();

  }
View Full Code Here

    String info = "aExMessageTextNoEmptyTag(" + expression + ")-->";
    if (curException == null) {
      fail("Error in aExMessageText: Expected exception.");
    }

    ODataMessageException messageException;

    try {
      messageException = (ODataMessageException) curException;
    } catch (ClassCastException ex) {
      fail("Error in aExNext: curException not an ODataMessageException");
      return this;
    }

    Message ms = MessageService.getMessage(DEFAULT_LANGUAGE, messageException.getMessageReference());
    info = "  " + info + "Messagetext: '" + ms.getText() + "contains [%";

    dout(info);

    if (ms.getText().contains("[%")) {
View Full Code Here

TOP

Related Classes of org.apache.olingo.odata2.api.exception.ODataMessageException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.