tomjankes/wiremock-groovy


groovy bindings for wiremock

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.tomjankes:wiremock-groovy:wiremock-groovy-0.2.0'
	}
	dependencies {
		implementation("com.github.tomjankes:wiremock-groovy:wiremock-groovy-0.2.0")
	}
	<dependency>
	    <groupId>com.github.tomjankes</groupId>
	    <artifactId>wiremock-groovy</artifactId>
	    <version>wiremock-groovy-0.2.0</version>
	</dependency>

                            
    libraryDependencies += "com.github.tomjankes" % "wiremock-groovy" % "wiremock-groovy-0.2.0"
        
        

                            
    :dependencies [[com.github.tomjankes/wiremock-groovy "wiremock-groovy-0.2.0"]]
        
        

Readme


Wiremock groovy

Build Status Maven Central

What it is

I love WireMock and use it extensively in integration tests. I also love how Spock allows to write very readable and clean tests. This project aims to create more suitable groovy API, that will allow more concise stubbing and verifying syntax in integration tests written in groovy/spock using WireMock, without using WireMock's default static imports API.

What it does

Currently there is only extremely thin wrapper for Wire Mock REST API, that is exposed as raw json builder. Examples of what can be currently achieved:

Stubbing

@Rule
WireMockRule wireMockRule = new WireMockRule()

def wireMockStub = new WireMockGroovy()

def "some integration test that tests feature using external REST resource" () {
    given:
    wireMockStub.stub {
        request {
            method "GET"
            url "/some/thing"
        }
        response {
            status 200
            body "Some body"
            headers {
                "Content-Type" "text/plain"
            }
        }
    }
    ...
}

Verifying

Verifying can be achieved by querying for count of matching requests that have been sent to WireMock server.

@Rule
WireMockRule wireMockRule = new WireMockRule()

def wireMockStub = new WireMockGroovy()

def "example verifying test" () {
    ...
    then:
    1 == wireMockStub.count {
        method "GET"
        url "/some/url"
    }
}

def "test using groovy truth if you need at least one request and shows example matcher" () {
    ...
    then:
    wireMockStub.count {
        method "POST"
        url "/some/url"
        headers {
            "Content-Type" {
                matches ".*xml"
            }
        }
    }
}

##Contribution

Project is in very early stage, pull requests and ideas in form of feature requests are welcome.

Building

  • Clone the repository
  • Run ./gradlew clean build (on Linux/Mac) or gradlew.bat build (on Windows)

Licence

Apache Licence v2.0 (see LICENCE.txt)