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

    https://github.com/apache/incubator-brooklyn/pull/185#discussion_r17905943
  
    --- Diff: core/src/test/java/brooklyn/util/ResourceUtilsHttpTest.java ---
    @@ -0,0 +1,173 @@
    +package brooklyn.util;
    +
    +import static org.testng.Assert.assertEquals;
    +import static org.testng.Assert.assertFalse;
    +import static org.testng.Assert.assertTrue;
    +
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.net.InetSocketAddress;
    +
    +import org.apache.http.Header;
    +import org.apache.http.HttpException;
    +import org.apache.http.HttpRequest;
    +import org.apache.http.HttpResponse;
    +import org.apache.http.HttpStatus;
    +import org.apache.http.entity.StringEntity;
    +import org.apache.http.localserver.LocalTestServer;
    +import org.apache.http.localserver.RequestBasicAuth;
    +import org.apache.http.localserver.ResponseBasicUnauthorized;
    +import org.apache.http.message.BasicHeader;
    +import org.apache.http.protocol.BasicHttpProcessor;
    +import org.apache.http.protocol.HttpContext;
    +import org.apache.http.protocol.HttpRequestHandler;
    +import org.apache.http.protocol.ResponseConnControl;
    +import org.apache.http.protocol.ResponseContent;
    +import org.apache.http.protocol.ResponseServer;
    +import org.testng.annotations.AfterClass;
    +import org.testng.annotations.BeforeClass;
    +import org.testng.annotations.Test;
    +
    +import brooklyn.util.stream.Streams;
    +
    +public class ResourceUtilsHttpTest {
    +    private ResourceUtils utils;
    +    private LocalTestServer server;
    +    private String baseUrl;
    +
    +    @BeforeClass(alwaysRun=true)
    +    public void setUp() throws Exception {
    +        utils = ResourceUtils.create(this, "mycontext");
    +
    +        BasicHttpProcessor httpProcessor = new BasicHttpProcessor();
    +        httpProcessor.addInterceptor(new ResponseServer());
    +        httpProcessor.addInterceptor(new ResponseContent());
    +        httpProcessor.addInterceptor(new ResponseConnControl());
    +        httpProcessor.addInterceptor(new RequestBasicAuth());
    +        httpProcessor.addInterceptor(new ResponseBasicUnauthorized());
    +
    +        server = new LocalTestServer(httpProcessor, null);
    +        server.register("/simple", new SimpleResponseHandler("OK"));
    +        server.register("/empty", new 
SimpleResponseHandler(HttpStatus.SC_NO_CONTENT, ""));
    +        server.register("/missing", new 
SimpleResponseHandler(HttpStatus.SC_NOT_FOUND, "Missing"));
    +        server.register("/redirect", new 
SimpleResponseHandler(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect", new 
BasicHeader("Location", "/simple")));
    +        server.register("/cycle", new 
SimpleResponseHandler(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect", new 
BasicHeader("Location", "/cycle")));
    +        server.register("/secure", new 
SimpleResponseHandler(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect", new 
BasicHeader("Location", "https://0.0.0.0/";)));
    +        server.register("/auth", new AuthHandler("test", "test", "OK"));
    +        server.start();
    +
    +        InetSocketAddress addr = server.getServiceAddress();
    +        baseUrl = "http://"; + addr.getHostName() + ":" + addr.getPort();
    +    }
    +
    +    @AfterClass(alwaysRun=true)
    +    public void tearDown() throws Exception {
    +        server.stop();
    +    }
    +
    +    @Test
    +    public void testGet() throws Exception {
    +        InputStream stream = utils.getResourceFromUrl(baseUrl + "/simple");
    +        assertEquals(Streams.readFullyString(stream), "OK");
    +    }
    +
    +    @Test
    +    public void testGetEmpty() throws Exception {
    +        InputStream stream = utils.getResourceFromUrl(baseUrl + "/empty");
    +        assertEquals(Streams.readFullyString(stream), "");
    +    }
    +
    +    @Test
    +    public void testGetProtected() throws Exception {
    --- End diff --
    
    test that *not* supplying credentials fails?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to