@Test public void shouldBeAbleToLoadHttpMethod() throws Exception { headers.header("header1", "value1"); HttpRequestBase httpMethod = new HttpGet(uri); engine.loadHttpMethod(request, httpMethod); Header[] headers = httpMethod.getAllHeaders(); assertEquals(1, headers.length); assertEquals("header1", headers[0].getName()); assertEquals("value1", headers[0].getValue()); }
@Test public void shouldNotBeAbleToLoadHttpMethodForGet() throws Exception { OauthAccessToken accessToken = new OauthAccessToken(); when(request.getEntity()).thenReturn(accessToken); HttpRequestBase httpMethod = new HttpGet(uri); try { engine.loadHttpMethod(request, httpMethod); Assert.fail(); } catch (ProcessingException e) { assertTrue(e.getMessage().contains("RESTEASY004565")); } }
@Test public void shouldBeAbleToLoadHttpMethodForPost() throws Exception { headers.setMediaType(MediaType.TEXT_PLAIN_TYPE); when(request.getDelegatingOutputStream()).thenReturn(new DelegatingOutputStream()); InputStream requestBody = getClass().getClassLoader().getResourceAsStream("mocks/pull_request_1.json"); ByteArrayOutputStream requestBodyOut = new ByteArrayOutputStream(); int bytes = IOUtils.copy(requestBody, requestBodyOut); when(request.getEntityStream()).thenReturn(requestBodyOut); OauthAccessToken accessToken = new OauthAccessToken(); when(request.getEntity()).thenReturn(accessToken); HttpPost post = new HttpPost(uri); engine.loadHttpMethod(request, post); verify(request).writeRequestBody(requestBodyOut); }