BrokenEvent nanotests

com.brokenevent.nanotests
Class HttpAssert

java.lang.Object
  extended by com.brokenevent.nanotests.HttpAssert

public final class HttpAssert
extends java.lang.Object

Helper class for http-related asserts. These methods can be used directly: HttpAssert.assertHttpOk(...), however, they read better if they are referenced through static import:

 import static com.brokenevent.nanotests.HttpAssert.*;
    ...
    assertHttpOk(...);
 

Author:
BrokenEvent

Constructor Summary
protected HttpAssert()
          Protect constructor since it is a static only class
 
Method Summary
static void assertHttp404(java.lang.String resource)
          Asserts that the http query result code is Not Found (404).
static void assertHttpCode(java.lang.String resource, int code)
          Asserts that the http query result code is equal to expected value.
static void assertHttpCode(java.lang.String message, TestRequest request, int code)
          Asserts that the http query result code is equal with the expected.
static void assertHttpCode(TestRequest request, int code)
          Asserts that the http query result code is equal with the expected.
static void assertHttpContent(java.lang.String resource, byte[] expected)
          Asserts that the http query result content is equal to the expected value.
static void assertHttpContent(java.lang.String resource, java.util.regex.Pattern expected)
          Asserts that the http query result content matches given Pattern.
static void assertHttpContent(java.lang.String resource, java.lang.String expected)
          Asserts that the http query result content is equal to the expected value.
static void assertHttpContent(TestRequest request, byte[] expected)
          Asserts that the http query result content is equal to the expected value.
static void assertHttpContent(TestRequest request, java.util.regex.Pattern expected)
          Asserts that the http query result content matches given Pattern.
static void assertHttpContent(TestRequest request, java.lang.String expected)
          Asserts that the http query result content is equal to the expected value.
static void assertHttpHeader(java.lang.String message, TestRequest request, java.lang.String name, java.lang.String value)
          Asserts that the http query result contains expected header field and its value is equal to expected.
static void assertHttpHeader(TestRequest request, java.lang.String name, java.lang.String value)
          Asserts that the http query result contains expected header field and its value is equal to expected.
static void assertHttpIsHeader(java.lang.String message, TestRequest request, java.lang.String name)
          Asserts that the http query result contains expected header field.
static void assertHttpIsHeader(TestRequest request, java.lang.String name)
          Asserts that the http query result contains expected header field.
static void assertHttpNoHeader(java.lang.String message, TestRequest request, java.lang.String name)
          Asserts that the http query result doesn't contains expected header field.
static void assertHttpNoHeader(TestRequest request, java.lang.String name)
          Asserts that the http query result doesn't contains expected header field.
static void assertHttpOk(java.lang.String resource)
          Asserts that the http query result code is OK (200).
static void assertHttpOk(java.lang.String message, TestRequest request)
          Asserts that the http query result code is OK (200).
static void assertHttpOk(TestRequest request)
          Asserts that the http query result code is OK (200).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpAssert

protected HttpAssert()
Protect constructor since it is a static only class

Method Detail

assertHttpOk

public static void assertHttpOk(TestRequest request)
Asserts that the http query result code is OK (200). If it isn't, an AssertionError is thrown.
Use this method to make a set of asserts for a single request. To just check the result code for request, use assertHttpOk(String).

Parameters:
request - TestRequest to get result from

assertHttpOk

public static void assertHttpOk(java.lang.String message,
                                TestRequest request)
Asserts that the http query result code is OK (200). If it isn't, an AssertionError is thrown with the given message.
Use this method to make a set of asserts for a single request. To just check the result code for request, use assertHttpOk(String).

Parameters:
message - the identifying message for the AssertionError (null okay)
request - TestRequest to get result from

assertHttpCode

public static void assertHttpCode(TestRequest request,
                                  int code)
Asserts that the http query result code is equal with the expected. If it isn't, an AssertionError is thrown.
Use this method to make a set of asserts for a single request. To just check the result code for request, use assertHttpCode(String, int).

Parameters:
request - TestRequest to get result from
code - expected http code value

assertHttpCode

public static void assertHttpCode(java.lang.String message,
                                  TestRequest request,
                                  int code)
Asserts that the http query result code is equal with the expected. If it isn't, an AssertionError is thrown with the given message.
Use this method to make a set of asserts for a single request. To just check the result code for request, use assertHttpCode(String, int).

Parameters:
message - the identifying message for the AssertionError (null okay)
request - TestRequest to get result from
code - expected http code value

assertHttpHeader

public static void assertHttpHeader(TestRequest request,
                                    java.lang.String name,
                                    java.lang.String value)
Asserts that the http query result contains expected header field and its value is equal to expected. If it isn't equal to the expected or header doesn't contains expected header, an AssertionError is thrown.

Parameters:
request - TestRequest to get result from.
name - header field name
value - expected header value

assertHttpHeader

public static void assertHttpHeader(java.lang.String message,
                                    TestRequest request,
                                    java.lang.String name,
                                    java.lang.String value)
Asserts that the http query result contains expected header field and its value is equal to expected. If it isn't equal to the expected or header doesn't contains expected header, an AssertionError is thrown with the given message.

Parameters:
message - the identifying message for the AssertionError (null okay)
request - TestRequest to get result from.
name - header field name
value - expected header value

assertHttpIsHeader

public static void assertHttpIsHeader(TestRequest request,
                                      java.lang.String name)
Asserts that the http query result contains expected header field. If it isn't, an AssertionError is thrown with the given message.

Parameters:
request - TestRequest to get result from.
name - header field name

assertHttpIsHeader

public static void assertHttpIsHeader(java.lang.String message,
                                      TestRequest request,
                                      java.lang.String name)
Asserts that the http query result contains expected header field. If it isn't, an AssertionError is thrown with the given message.

Parameters:
message - the identifying message for the AssertionError (null okay)
request - TestRequest to get result from.
name - header field name

assertHttpNoHeader

public static void assertHttpNoHeader(TestRequest request,
                                      java.lang.String name)
Asserts that the http query result doesn't contains expected header field. If it is, an AssertionError is thrown.

Parameters:
request - TestRequest to get result from.
name - header field name

assertHttpNoHeader

public static void assertHttpNoHeader(java.lang.String message,
                                      TestRequest request,
                                      java.lang.String name)
Asserts that the http query result doesn't contains expected header field. If it is, an AssertionError is thrown with the given message.

Parameters:
message - the identifying message for the AssertionError (null okay)
request - TestRequest to get result from.
name - header field name

assertHttpOk

public static void assertHttpOk(java.lang.String resource)
Asserts that the http query result code is OK (200). If it isn't, an AssertionError is thrown.
Use this method to assert the single request. If there are some checks for single URL, use TestRequest descendants:
   TestGetRequest getRequest = new TestGetRequest(url);
   getRequest.execute();

   assertHttpCode(getRequest, 200);
   // some more asserts
 

Parameters:
resource - URL for the request (/resource. Uses host from the TestRequestImpl)

assertHttp404

public static void assertHttp404(java.lang.String resource)
Asserts that the http query result code is Not Found (404). If it isn't, an AssertionError is thrown.
Use this method to assert the single request. If there are some checks for single URL, use TestRequest descendants:
   TestGetRequest getRequest = new TestGetRequest(url);
   getRequest.execute();

   assertHttpCode(getRequest, 404);
   // some more asserts
 

Parameters:
resource - URL for the request (/resource. Uses host from the TestRequestImpl)

assertHttpCode

public static void assertHttpCode(java.lang.String resource,
                                  int code)
Asserts that the http query result code is equal to expected value. If it isn't, an AssertionError is thrown.
Use this method to assert the single request. If there are some checks for single URL, use TestRequest descendants:
   TestGetRequest getRequest = new TestGetRequest(url);
   getRequest.execute();

   assertHttpCode(getRequest, code);
   // some more asserts
 

Parameters:
resource - URL for the request (/resource. Uses host from the TestRequestImpl)
code - expected http code value

assertHttpContent

public static void assertHttpContent(TestRequest request,
                                     java.lang.String expected)
Asserts that the http query result content is equal to the expected value. If it isn't, an AssertionError is thrown.
Use this method to make a set of asserts for a single request. To just check the result content for request, use assertHttpContent(String, String).

Parameters:
request - TestRequest to get result from
expected - expected content value

assertHttpContent

public static void assertHttpContent(TestRequest request,
                                     byte[] expected)
Asserts that the http query result content is equal to the expected value. If it isn't, an AssertionError is thrown.
Use this method to make a set of asserts for a single request. To just check the result content for request, use assertHttpContent(String, byte[]).

Parameters:
request - TestRequest to get result from
expected - expected content value

assertHttpContent

public static void assertHttpContent(TestRequest request,
                                     java.util.regex.Pattern expected)
Asserts that the http query result content matches given Pattern. If it isn't, an AssertionError is thrown.
Use this method to make a set of asserts for a single request. To just check the result content for request, use assertHttpContent(String, Pattern).

Parameters:
request - TestRequest to get result from
expected - regex pattern to match the content value

assertHttpContent

public static void assertHttpContent(java.lang.String resource,
                                     java.lang.String expected)
Asserts that the http query result content is equal to the expected value. If it isn't, an AssertionError is thrown.
Use this method to assert the single request. If there are some checks for single URL, use TestRequest descendants:
   TestGetRequest getRequest = new TestGetRequest(url);
   getRequest.execute();

   assertHttpCode(getRequest, 200);
   assertHttpContent(getRequest, expected);
   // some more asserts
 

Parameters:
resource - URL for the request (/resource. Uses host from the TestRequestImpl)
expected - expected content value

assertHttpContent

public static void assertHttpContent(java.lang.String resource,
                                     byte[] expected)
Asserts that the http query result content is equal to the expected value. If it isn't, an AssertionError is thrown.
Use this method to assert the single request. If there are some checks for single URL, use TestRequest descendants:
   TestGetRequest getRequest = new TestGetRequest(url);
   getRequest.execute();

   assertHttpCode(getRequest, 200);
   assertHttpContent(getRequest, expected);
   // some more asserts
 

Parameters:
resource - URL for the request (/resource. Uses host from the TestRequestImpl)
expected - expected content value

assertHttpContent

public static void assertHttpContent(java.lang.String resource,
                                     java.util.regex.Pattern expected)
Asserts that the http query result content matches given Pattern. If it isn't, an AssertionError is thrown.
Use this method to assert the single request. If there are some checks for single URL, use TestRequest descendants:
   TestGetRequest getRequest = new TestGetRequest(url);
   getRequest.execute();

   assertHttpCode(getRequest, 200);
   assertHttpContent(getRequest, expected);
   // some more asserts
 

Parameters:
resource - URL for the request (/resource. Uses host from the TestRequestImpl)
expected - regex pattern to match the content value

BrokenEvent nanotests