Fixed equals and hashcode
This commit is contained in:
@@ -40,15 +40,43 @@ class Contract {
|
||||
* take precedence
|
||||
*/
|
||||
Integer priority
|
||||
/**
|
||||
* The HTTP request part of the contract
|
||||
*/
|
||||
Request request
|
||||
/**
|
||||
* The HTTP response part of the contract
|
||||
*/
|
||||
Response response
|
||||
/**
|
||||
* The label by which you'll reference the contract on the message consumer side
|
||||
*/
|
||||
String label
|
||||
/**
|
||||
* Description of a contract. May be used in the documentation generation.
|
||||
*/
|
||||
String description
|
||||
/**
|
||||
* Name of the generated test / stub. If not provided then the file name will be used.
|
||||
* If you have multiple contracts in a single file and you don't provide this value
|
||||
* then a prefix will be added to the file with the index number while iterating
|
||||
* over the collection of contracts.
|
||||
*
|
||||
* Remember to have a unique name for every single contract. Otherwise you might
|
||||
* generate tests that have two identical methods or you will override the stubs.
|
||||
*/
|
||||
String name
|
||||
/**
|
||||
* The input side of a messaging contract.
|
||||
*/
|
||||
Input input
|
||||
/**
|
||||
* The output side of a messaging contract.
|
||||
*/
|
||||
OutputMessage outputMessage
|
||||
|
||||
/**
|
||||
* Whether the contract should be ignored or not
|
||||
* Whether the contract should be ignored or not.
|
||||
*/
|
||||
boolean ignored
|
||||
|
||||
@@ -68,6 +96,10 @@ class Contract {
|
||||
this.priority = priority
|
||||
}
|
||||
|
||||
void name(String name) {
|
||||
this.name = name
|
||||
}
|
||||
|
||||
void label(String label) {
|
||||
this.label = label
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ import groovy.transform.ToString
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@ToString(includePackage = false, includeFields = true, includeNames = true)
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@ToString(includePackage = false, includeFields = true, includeNames = true, includeSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@CompileStatic
|
||||
class Body extends DslProperty {
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package org.springframework.cloud.contract.spec.internal
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.transform.EqualsAndHashCode
|
||||
import groovy.transform.ToString
|
||||
|
||||
/**
|
||||
* Represents a client side {@link DslProperty}
|
||||
@@ -24,6 +26,8 @@ import groovy.transform.CompileStatic
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@CompileStatic
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(includeSuper = true)
|
||||
class ClientDslProperty extends DslProperty {
|
||||
|
||||
ClientDslProperty(Object singleValue) {
|
||||
|
||||
@@ -20,7 +20,6 @@ import groovy.transform.PackageScope
|
||||
import groovy.transform.TypeChecked
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
* Contains useful common methods for the DSL.
|
||||
*
|
||||
|
||||
@@ -19,14 +19,13 @@ package org.springframework.cloud.contract.spec.internal
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.transform.EqualsAndHashCode
|
||||
import groovy.transform.ToString
|
||||
|
||||
/**
|
||||
* Represents an element of a DSL that can contain client or sever side values
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@CompileStatic
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@EqualsAndHashCode
|
||||
@ToString(includePackage = false, includeNames = true)
|
||||
class DslProperty<T> {
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.cloud.contract.spec.internal
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.transform.EqualsAndHashCode
|
||||
|
||||
/**
|
||||
* Represents a property that will become an executable method in the
|
||||
@@ -25,6 +26,7 @@ import groovy.transform.CompileStatic
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@CompileStatic
|
||||
@EqualsAndHashCode
|
||||
class ExecutionProperty {
|
||||
|
||||
private static final String PLACEHOLDER_VALUE = '\\$it'
|
||||
|
||||
@@ -24,8 +24,8 @@ import groovy.transform.ToString
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true)
|
||||
@EqualsAndHashCode(includeFields = true, callSuper = true)
|
||||
@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true, includeSuper = true)
|
||||
@CompileStatic
|
||||
class Header extends DslProperty {
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import groovy.transform.ToString
|
||||
* @since 1.0.2
|
||||
*/
|
||||
@CompileStatic
|
||||
@EqualsAndHashCode
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@ToString(includePackage = false)
|
||||
class HttpMethods {
|
||||
|
||||
|
||||
@@ -88,6 +88,8 @@ class Input extends Common {
|
||||
return new DslProperty(client.clientValue, clientValue)
|
||||
}
|
||||
|
||||
@EqualsAndHashCode(includeFields = true, callSuper = true)
|
||||
@ToString(includeSuper = true)
|
||||
static class BodyType extends DslProperty {
|
||||
|
||||
BodyType(Object clientValue, Object serverValue) {
|
||||
|
||||
@@ -25,8 +25,8 @@ import groovy.transform.ToString;
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true)
|
||||
@EqualsAndHashCode(includeFields = true, callSuper = true)
|
||||
@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true, includeSuper = true)
|
||||
@CompileStatic
|
||||
class MatchingStrategy extends DslProperty {
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ import groovy.transform.CompileStatic
|
||||
import groovy.transform.EqualsAndHashCode
|
||||
import groovy.transform.ToString
|
||||
|
||||
@ToString(includePackage = false, includeFields = true, includeNames = true)
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@ToString(includePackage = false, includeFields = true, includeNames = true, includeSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@CompileStatic
|
||||
class Multipart extends DslProperty {
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import groovy.transform.CompileStatic
|
||||
import groovy.transform.PackageScope
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
|
||||
@@ -27,8 +27,8 @@ import static org.springframework.cloud.contract.spec.util.ValidateUtils.validat
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true)
|
||||
@EqualsAndHashCode(includeFields = true, callSuper = true)
|
||||
@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true, includeSuper = true)
|
||||
@CompileStatic
|
||||
class QueryParameter extends DslProperty {
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ class Request extends Common {
|
||||
}
|
||||
|
||||
@CompileStatic
|
||||
@EqualsAndHashCode
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@ToString(includePackage = false)
|
||||
private class ServerRequest extends Request {
|
||||
ServerRequest(Request request) {
|
||||
@@ -222,7 +222,7 @@ class Request extends Common {
|
||||
}
|
||||
|
||||
@CompileStatic
|
||||
@EqualsAndHashCode
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@ToString(includePackage = false)
|
||||
private class ClientRequest extends Request {
|
||||
ClientRequest(Request request) {
|
||||
@@ -231,7 +231,7 @@ class Request extends Common {
|
||||
}
|
||||
|
||||
@CompileStatic
|
||||
@EqualsAndHashCode
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@ToString(includePackage = false)
|
||||
private class RequestHeaders extends Headers {
|
||||
|
||||
@@ -243,7 +243,7 @@ class Request extends Common {
|
||||
}
|
||||
|
||||
@CompileStatic
|
||||
@EqualsAndHashCode
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@ToString(includePackage = false)
|
||||
private class ClientPatternValueDslProperty extends PatternValueDslProperty<ClientDslProperty> {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.util.regex.Pattern
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@TypeChecked
|
||||
@EqualsAndHashCode
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@ToString(includePackage = false, includeFields = true)
|
||||
class Response extends Common {
|
||||
|
||||
@@ -120,7 +120,7 @@ class Response extends Common {
|
||||
}
|
||||
|
||||
@CompileStatic
|
||||
@EqualsAndHashCode
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(includePackage = false)
|
||||
private class ServerResponse extends Response {
|
||||
ServerResponse(Response request) {
|
||||
@@ -129,7 +129,7 @@ class Response extends Common {
|
||||
}
|
||||
|
||||
@CompileStatic
|
||||
@EqualsAndHashCode
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(includePackage = false)
|
||||
private class ClientResponse extends Response {
|
||||
ClientResponse(Response request) {
|
||||
@@ -138,7 +138,7 @@ class Response extends Common {
|
||||
}
|
||||
|
||||
@CompileStatic
|
||||
@EqualsAndHashCode
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@ToString(includePackage = false)
|
||||
private class ResponseHeaders extends Headers {
|
||||
|
||||
@@ -150,7 +150,7 @@ class Response extends Common {
|
||||
}
|
||||
|
||||
@CompileStatic
|
||||
@EqualsAndHashCode
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@ToString(includePackage = false)
|
||||
private class ServerPatternValueDslProperty extends PatternValueDslProperty<ServerDslProperty> {
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ import groovy.transform.ToString
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@CompileStatic
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@ToString(includePackage = false)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(includePackage = false, includeSuper = true)
|
||||
class ServerDslProperty extends DslProperty {
|
||||
|
||||
ServerDslProperty(Object singleValue) {
|
||||
|
||||
@@ -27,8 +27,8 @@ import static org.springframework.cloud.contract.spec.util.ValidateUtils.validat
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@ToString(includePackage = false, includeFields = true, includeNames = true)
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@ToString(includePackage = false, includeFields = true, includeNames = true, includeSuper = true)
|
||||
@EqualsAndHashCode(includeFields = true, callSuper = true)
|
||||
@CompileStatic
|
||||
class Url extends DslProperty {
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ import groovy.transform.ToString
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@ToString(includePackage = false, includeFields = true, includeNames = true)
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@ToString(includePackage = false, includeFields = true, includeNames = true, includeSuper = true)
|
||||
@EqualsAndHashCode(includeFields = true, callSuper = true)
|
||||
@CompileStatic
|
||||
class UrlPath extends Url {
|
||||
|
||||
|
||||
@@ -102,4 +102,154 @@ then:
|
||||
}
|
||||
// end::ignored[]
|
||||
}
|
||||
|
||||
def 'should make equals and hashcode work properly for URL'() {
|
||||
expect:
|
||||
def a = Contract.make {
|
||||
request {
|
||||
url("/1")
|
||||
}
|
||||
}
|
||||
def b = Contract.make {
|
||||
request {
|
||||
url("/1")
|
||||
}
|
||||
}
|
||||
a == b
|
||||
}
|
||||
|
||||
def 'should make equals and hashcode work properly for URL with consumer producer'() {
|
||||
expect:
|
||||
Contract.make {
|
||||
request {
|
||||
url($(c("/1"), p("/1")))
|
||||
}
|
||||
} == Contract.make {
|
||||
request {
|
||||
url($(c("/1"), p("/1")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def 'should return true when comparing two equal contracts with gstring'() {
|
||||
expect:
|
||||
int index = 1
|
||||
def a = Contract.make {
|
||||
request {
|
||||
method(PUT())
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
}
|
||||
url "/${index}"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}
|
||||
def b = Contract.make {
|
||||
request {
|
||||
method(PUT())
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
}
|
||||
url "/${index}"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}
|
||||
a == b
|
||||
}
|
||||
|
||||
def 'should return false when comparing two unequal contracts with gstring'() {
|
||||
expect:
|
||||
int index = 1
|
||||
def a = Contract.make {
|
||||
request {
|
||||
method(PUT())
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
}
|
||||
url "/${index}"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}
|
||||
int index2 = 2
|
||||
def b = Contract.make {
|
||||
request {
|
||||
method(PUT())
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
}
|
||||
url "/${index2}"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}
|
||||
a != b
|
||||
}
|
||||
|
||||
def 'should return true when comparing two equal complex contracts'() {
|
||||
expect:
|
||||
def a = Contract.make {
|
||||
request {
|
||||
method 'GET'
|
||||
url '/path'
|
||||
headers {
|
||||
header('Accept': $(
|
||||
consumer(regex('text/.*')),
|
||||
producer('text/plain')
|
||||
))
|
||||
header('X-Custom-Header': $(
|
||||
consumer(regex('^.*2134.*$')),
|
||||
producer('121345')
|
||||
))
|
||||
}
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body(
|
||||
id: [value: '132'],
|
||||
surname: 'Kowalsky',
|
||||
name: 'Jan',
|
||||
created: '2014-02-02 12:23:43'
|
||||
)
|
||||
headers {
|
||||
header 'Content-Type': 'text/plain'
|
||||
}
|
||||
}
|
||||
}
|
||||
def b = Contract.make {
|
||||
request {
|
||||
method 'GET'
|
||||
url '/path'
|
||||
headers {
|
||||
header('Accept': $(
|
||||
consumer(regex('text/.*')),
|
||||
producer('text/plain')
|
||||
))
|
||||
header('X-Custom-Header': $(
|
||||
consumer(regex('^.*2134.*$')),
|
||||
producer('121345')
|
||||
))
|
||||
}
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body(
|
||||
id: [value: '132'],
|
||||
surname: 'Kowalsky',
|
||||
name: 'Jan',
|
||||
created: '2014-02-02 12:23:43'
|
||||
)
|
||||
headers {
|
||||
header 'Content-Type': 'text/plain'
|
||||
}
|
||||
}
|
||||
}
|
||||
a == b
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user