Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/441#discussion_r88349432
  
    --- Diff: 
core/src/test/java/org/apache/brooklyn/util/executor/HttpExecutorImplTest.java 
---
    @@ -71,6 +75,36 @@ public void afterMethod() throws Exception {
         }
     
         @Test
    +    public void testHttpResponse() throws Exception {
    +        Multimap<String, String> responseHeaders = 
ArrayListMultimap.<String, String>create();
    +        responseHeaders.put(HTTP_RESPONSE_CUSTOM_HEADER_KEY, 
HTTP_RESPONSE_CUSTOM_HEADER_VALUE);
    +        HttpResponse httpResponse = new HttpResponse.Builder()
    +                .headers(responseHeaders)
    +                .header(HTTP_RESPONSE_HEADER_KEY, 
HTTP_RESPONSE_HEADER_VALUE)
    +                .build();
    +
    +        MockResponse serverResponse = new MockResponse()
    +                .setResponseCode(200)
    +                .setBody(HTTP_BODY);
    +        
    +        for (Map.Entry<String, String> entry : 
httpResponse.headers().entries()) {
    +            serverResponse.addHeader(entry.getKey(), entry.getValue());
    +        }
    +        server.enqueue(serverResponse);
    +        HttpExecutor executor = factory.getHttpExecutor(getProps());
    +        HttpRequest executorRequest = new HttpRequest.Builder()
    +                .method("GET")
    +                .uri(baseUrl.toURI())
    +                .build();
    +        HttpResponse executorResponse = executor.execute(executorRequest);
    +        
assertTrue(executorResponse.headers().containsKey(HTTP_RESPONSE_CUSTOM_HEADER_KEY));
    +        
assertTrue(Iterables.getOnlyElement(executorResponse.headers().get(HTTP_RESPONSE_HEADER_KEY)).equals(HTTP_RESPONSE_HEADER_VALUE));
    +
    +        
assertTrue(executorResponse.headers().containsKey(HTTP_RESPONSE_HEADER_KEY));
    +        
assertTrue(Iterables.getOnlyElement(executorResponse.headers().get(HTTP_RESPONSE_CUSTOM_HEADER_KEY)).equals(HTTP_RESPONSE_CUSTOM_HEADER_VALUE));
    +    }
    --- End diff --
    
    Agreed. I'd probably simplify it to something like:
    ```
            HttpResponse executorResponse = executor.execute(executorRequest);
            Multimap<String, String> actualHeaders = executorResponse.headers();
            
assertEquals(Iterables.getOnlyElement(actualHeaders.get(HTTP_RESPONSE_CUSTOM_HEADER_KEY)),
 HTTP_RESPONSE_CUSTOM_HEADER_VALUE);
            
assertEquals(Iterables.getOnlyElement(actualHeaders.get(HTTP_RESPONSE_HEADER_KEY)),
 HTTP_RESPONSE_HEADER_VALUE);
    ```
    That probably good enough for an error message if it fails (the line number 
is probably enough here, as you've managed to make it a nice self-contained 
test with use of `MockResponse`).
    
    Do you want to look at simplifying that, and then good to merge?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to