Created
October 22, 2012 20:55
-
-
Save boundedinfinity/3934202 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
import com.pingidentity.sqe.automationcommons.validate.impl.JsonValidator; | |
import com.pingidentity.sqe.automationcommons.validate.impl.LocationHeaderResponseStartsWithValidator; | |
import com.pingidentity.sqe.clientwrapper.data.HttpResponseWrapper; | |
public interface ResponseValidator | |
{ | |
void validate(HttpResponseWrapper response); | |
static class Builder { | |
public static Builder validate() { | |
return new Builder(); | |
} | |
private final List<ResponseValidator> list; | |
private Builder() { | |
list = new ArrayList<ResponseValidator>(); | |
} | |
public Builder and() { | |
return this; | |
} | |
public Builder isJson() { | |
list.add(new JsonValidator()); | |
return this; | |
} | |
public Builder locationHeaderStartsWith(final String expectedUrl) { | |
list.add(new LocationHeaderResponseStartsWithValidator(expectedUrl)); | |
return this; | |
} | |
// etc... | |
public List<ResponseValidator> list() { | |
return list; | |
} | |
} | |
} | |
// Then in your test you can build a set of validators like so: | |
import java.net.URI; | |
import java.util.List; | |
import org.junit.Test; | |
import com.pingidentity.sqe.automationcommons.validate.ResponseValidator; | |
import com.pingidentity.sqe.clientwrapper.HttpClientWrapper; | |
public class ValidatorBuilderTest { | |
@Test | |
public void test() { | |
List<ResponseValidator> list = ResponseValidator.Builder.validate() | |
.isJson().and().locationHeaderStartsWith("SPECIAL-THING") | |
.list(); | |
URI uri = new URI(""); // Real URI goes here | |
HttpClientWrapper wrapper = null; // Real wrapper goes here | |
HttpTestComponentImpl(wrapper, list).run(uri); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment