Exemplo n.º 1
0
        public virtual void TestValidateResponseJsonErrorUnknownException()
        {
            IDictionary <string, object> json = new Dictionary <string, object>();

            json[HttpExceptionUtils.ErrorExceptionJson] = "FooException";
            json[HttpExceptionUtils.ErrorClassnameJson] = "foo.FooException";
            json[HttpExceptionUtils.ErrorMessageJson]   = "EX";
            IDictionary <string, object> response = new Dictionary <string, object>();

            response[HttpExceptionUtils.ErrorJson] = json;
            ObjectMapper jsonMapper = new ObjectMapper();
            string       msg        = jsonMapper.WriteValueAsString(response);
            InputStream  @is        = new ByteArrayInputStream(Runtime.GetBytesForString(msg)
                                                               );
            HttpURLConnection conn = Org.Mockito.Mockito.Mock <HttpURLConnection>();

            Org.Mockito.Mockito.When(conn.GetErrorStream()).ThenReturn(@is);
            Org.Mockito.Mockito.When(conn.GetResponseMessage()).ThenReturn("msg");
            Org.Mockito.Mockito.When(conn.GetResponseCode()).ThenReturn(HttpURLConnection.HttpBadRequest
                                                                        );
            try
            {
                HttpExceptionUtils.ValidateResponse(conn, HttpURLConnection.HttpCreated);
                NUnit.Framework.Assert.Fail();
            }
            catch (IOException ex)
            {
                Assert.True(ex.Message.Contains("EX"));
                Assert.True(ex.Message.Contains("foo.FooException"));
            }
        }
Exemplo n.º 2
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestValidateResponseFailNoErrorMessage()
        {
            HttpURLConnection conn = Org.Mockito.Mockito.Mock <HttpURLConnection>();

            Org.Mockito.Mockito.When(conn.GetResponseCode()).ThenReturn(HttpURLConnection.HttpBadRequest
                                                                        );
            HttpExceptionUtils.ValidateResponse(conn, HttpURLConnection.HttpCreated);
        }
Exemplo n.º 3
0
        public virtual void TestValidateResponseNonJsonErrorMessage()
        {
            string      msg = "stream";
            InputStream @is = new ByteArrayInputStream(Runtime.GetBytesForString(msg)
                                                       );
            HttpURLConnection conn = Org.Mockito.Mockito.Mock <HttpURLConnection>();

            Org.Mockito.Mockito.When(conn.GetErrorStream()).ThenReturn(@is);
            Org.Mockito.Mockito.When(conn.GetResponseMessage()).ThenReturn("msg");
            Org.Mockito.Mockito.When(conn.GetResponseCode()).ThenReturn(HttpURLConnection.HttpBadRequest
                                                                        );
            try
            {
                HttpExceptionUtils.ValidateResponse(conn, HttpURLConnection.HttpCreated);
                NUnit.Framework.Assert.Fail();
            }
            catch (IOException ex)
            {
                Assert.True(ex.Message.Contains("msg"));
                Assert.True(ex.Message.Contains(string.Empty + HttpURLConnection
                                                .HttpBadRequest));
            }
        }