Esempio n. 1
0
        public void DecodeResponse()
        {
            ErrorResponseDecoder decoder = new ErrorResponseDecoder();

            Dictionary <string, object> data = new Dictionary <string, object>()
            {
                { "exceptionClass", "com.linkedin.restli.server.RestLiServiceException" },
                { "message", "Example message" },
                { "stackTrace", "Example stack trace" },
                { "status", 400 }
            };

            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { RestConstants.kHeaderRestliErrorResponse, "true" }
            };

            RestliException   exception         = new RestliException("Server returned Rest.li error response", null);
            HttpResponse      httpResponse      = new HttpResponse(RestConstants.httpStatusInternalServerError, headers, null, exception);
            TransportResponse transportResponse = new TransportResponse(data, httpResponse);

            ClientErrorResponse response = decoder.DecodeResponse(transportResponse);

            ErrorResponse error = response.error.details;

            Assert.IsNotNull(error);

            Assert.IsTrue(error.hasExceptionClass);
            Assert.IsTrue(error.hasMessage);
            Assert.IsTrue(error.hasStackTrace);
            Assert.IsTrue(error.hasStatus);

            Assert.AreEqual("com.linkedin.restli.server.RestLiServiceException", error.exceptionClass);
            Assert.AreEqual("Example message", error.message);
            Assert.AreEqual("Example stack trace", error.stackTrace);
            Assert.AreEqual(400, error.status);
        }