org.mockserver.examples.mockserver.ErrorActionExamples Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockserver-examples Show documentation
Show all versions of mockserver-examples Show documentation
An example project demonstration tests using the mock server and proxy
package org.mockserver.examples.mockserver;
import org.mockserver.client.MockServerClient;
import java.util.Random;
import static org.mockserver.model.HttpError.error;
import static org.mockserver.model.HttpRequest.request;
/**
* @author jamesdbloom
*/
public class ErrorActionExamples {
public void randomBytesError() {
// generate random bytes
byte[] randomByteArray = new byte[25];
new Random().nextBytes(randomByteArray);
new MockServerClient("localhost", 1080)
.when(
request()
.withPath("/some/path")
)
.error(
error()
.withDropConnection(true)
.withResponseBytes(randomByteArray)
);
}
public void dropConnectionError() {
new MockServerClient("localhost", 1080)
.when(
request()
.withPath("/some/path")
)
.error(
error()
.withDropConnection(true)
);
}
}