All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mockserver.examples.mockserver.ErrorActionExamples Maven / Gradle / Ivy

There is a newer version: 5.15.0
Show newest version
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)
            );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy