brooklyn.test
Class HttpTestUtils

java.lang.Object
  extended by brooklyn.test.HttpTestUtils

public class HttpTestUtils
extends Object

Utility methods to aid testing HTTP.


Field Summary
protected static org.slf4j.Logger LOG
           
 
Constructor Summary
HttpTestUtils()
           
 
Method Summary
static com.google.common.util.concurrent.ListenableFuture<?> assertAsyncHttpStatusCodeContinuallyEquals(com.google.common.util.concurrent.ListeningExecutorService executor, String url, int expectedStatusCode)
          Schedules (with the given executor) a poller that repeatedly accesses the given url, to confirm it always gives back the expected status code.
static void assertContentContainsText(String url, String phrase, String... additionalPhrases)
           
static void assertContentEventuallyContainsText(Map flags, String url, String phrase, String... additionalPhrases)
           
static void assertContentEventuallyContainsText(String url, String phrase, String... additionalPhrases)
           
static void assertHttpContentEventuallyContainsText(String url, String containedText)
          Deprecated. since 0.4.0 use assertContentEventuallyContainsText
static void assertHttpStatusCodeEquals(String url, int expectedCode)
           
static void assertHttpStatusCodeEventuallyEquals(Map flags, String url, int expectedCode)
           
static void assertHttpStatusCodeEventuallyEquals(String url, int expectedCode)
           
static void assertUrlUnreachable(String url)
           
static void assertUrlUnreachableEventually(Map flags, String url)
           
static void assertUrlUnreachableEventually(String url)
           
static URLConnection connectToUrl(String u)
          Connects to the given url and returns the connection.
static int getHttpStatusCode(String url)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final org.slf4j.Logger LOG
Constructor Detail

HttpTestUtils

public HttpTestUtils()
Method Detail

connectToUrl

public static URLConnection connectToUrl(String u)
                                  throws Exception
Connects to the given url and returns the connection. Caller should connection.getInputStream().close(); the result of this (especially if they are making heavy use of this method).

Throws:
Exception

getHttpStatusCode

public static int getHttpStatusCode(String url)
                             throws Exception
Throws:
Exception

assertUrlUnreachable

public static void assertUrlUnreachable(String url)

assertUrlUnreachableEventually

public static void assertUrlUnreachableEventually(String url)

assertUrlUnreachableEventually

public static void assertUrlUnreachableEventually(Map flags,
                                                  String url)

assertHttpStatusCodeEquals

public static void assertHttpStatusCodeEquals(String url,
                                              int expectedCode)

assertHttpStatusCodeEventuallyEquals

public static void assertHttpStatusCodeEventuallyEquals(String url,
                                                        int expectedCode)

assertHttpStatusCodeEventuallyEquals

public static void assertHttpStatusCodeEventuallyEquals(Map flags,
                                                        String url,
                                                        int expectedCode)

assertContentContainsText

public static void assertContentContainsText(String url,
                                             String phrase,
                                             String... additionalPhrases)

assertContentEventuallyContainsText

public static void assertContentEventuallyContainsText(Map flags,
                                                       String url,
                                                       String phrase,
                                                       String... additionalPhrases)

assertContentEventuallyContainsText

public static void assertContentEventuallyContainsText(String url,
                                                       String phrase,
                                                       String... additionalPhrases)

assertHttpContentEventuallyContainsText

@Deprecated
public static void assertHttpContentEventuallyContainsText(String url,
                                                                      String containedText)
Deprecated. since 0.4.0 use assertContentEventuallyContainsText


assertAsyncHttpStatusCodeContinuallyEquals

public static com.google.common.util.concurrent.ListenableFuture<?> assertAsyncHttpStatusCodeContinuallyEquals(com.google.common.util.concurrent.ListeningExecutorService executor,
                                                                                                               String url,
                                                                                                               int expectedStatusCode)
Schedules (with the given executor) a poller that repeatedly accesses the given url, to confirm it always gives back the expected status code. Expected usage is to query the future, such as: Future future = assertAsyncHttpStatusCodeContinuallyEquals(executor, url, 200); // do other stuff... if (future.isDone()) future.get(); // get exception if it's failed For stopping it, you can either do future.cancel(true), or you can just do executor.shutdownNow(). TODO Look at difference between this and WebAppMonitor, to decide if this should be kept.



Copyright © 2013. All Rights Reserved.