Class MockServerRule

java.lang.Object
org.mockserver.junit.MockServerRule
All Implemented Interfaces:
org.junit.rules.TestRule

public class MockServerRule extends Object implements org.junit.rules.TestRule
  • Constructor Summary

    Constructors
    Constructor
    Description
    Start the MockServer prior to test execution and stop the MockServer after the tests have completed.
    MockServerRule(Object target, boolean perTestSuite)
    Start the MockServer prior to test execution and stop the MockServer after the tests have completed.
    MockServerRule(Object target, boolean perTestSuite, Integer... ports)
    Start the proxy prior to test execution and stop the proxy after the tests have completed.
    MockServerRule(Object target, Integer... ports)
    Start the proxy prior to test execution and stop the proxy after the tests have completed.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.junit.runners.model.Statement
    apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
     
    org.mockserver.client.MockServerClient
     
     
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MockServerRule

      public MockServerRule(Object target)
      Start the MockServer prior to test execution and stop the MockServer after the tests have completed. This constructor dynamically allocates a free port for the MockServer to use.

      If the test class contains a MockServerClient field it is set with a client configured for the created MockServer.

      Parameters:
      target - an instance of the test being executed
    • MockServerRule

      public MockServerRule(Object target, boolean perTestSuite)
      Start the MockServer prior to test execution and stop the MockServer after the tests have completed. This constructor dynamically allocates a free port for the MockServer to use.

      If the test class contains a MockServerClient field it is set with a client configured for the created MockServer.

      Parameters:
      target - an instance of the test being executed
      perTestSuite - indicates how many instances of MockServer are created if true a single MockServer is created per JVM if false one instance per test class is created
    • MockServerRule

      public MockServerRule(Object target, Integer... ports)
      Start the proxy prior to test execution and stop the proxy after the tests have completed. This constructor dynamically create a MockServer that accepts HTTP(s) requests on the specified port

      If the test class contains a MockServerClient field it is set with a client configured for the created MockServer.

      Parameters:
      perTestSuite - indicates how many instances of MockServer are created if true a single MockServer is created per JVM if false one instance per test class is created
      ports - the HTTP(S) port for the proxy
    • MockServerRule

      public MockServerRule(Object target, boolean perTestSuite, Integer... ports)
      Start the proxy prior to test execution and stop the proxy after the tests have completed. This constructor dynamically create a proxy that accepts HTTP(s) requests on the specified port
      Parameters:
      target - an instance of the test being executed
      perTestSuite - indicates how many instances of MockServer are created if true a single MockServer is created per JVM if false one instance per test class is created
      ports - the HTTP(S) port for the proxy
  • Method Details

    • getPort

      public Integer getPort()
    • getPorts

      public Integer[] getPorts()
    • apply

      public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
      Specified by:
      apply in interface org.junit.rules.TestRule
    • getClient

      public org.mockserver.client.MockServerClient getClient()