Skip to content

Instantly share code, notes, and snippets.

@boundedinfinity
Created October 22, 2012 20:55
Show Gist options
  • Save boundedinfinity/3934202 to your computer and use it in GitHub Desktop.
Save boundedinfinity/3934202 to your computer and use it in GitHub Desktop.
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