Demonstrates issue with comparing objects with set properties whose elements are > 1 level deep value objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.transform.TupleConstructor | |
import org.javers.core.JaversBuilder | |
import org.javers.core.diff.changetype.container.SetChange | |
import org.javers.core.diff.changetype.container.ValueAdded | |
import org.javers.core.metamodel.annotation.Id | |
import spock.lang.Specification | |
import static java.util.UUID.randomUUID | |
class SetPropertySpec extends Specification { | |
def javers = JaversBuilder | |
.javers() | |
.registerValueObject(IngressRule) | |
.registerValueObject(Port) | |
.build() | |
def "can detect new element added to set property"() { | |
given: | |
def a = new Firewall( | |
randomUUID(), | |
"foo", | |
[ | |
new IngressRule("bar", new Port(80)), | |
new IngressRule("baz", new Port(80)) | |
].toSet() | |
) | |
def b = new Firewall( | |
a.id, | |
a.name, | |
a.ingressRules + new IngressRule("bar", new Port(443)) | |
) | |
when: | |
def diff = javers.compare(a, b) | |
then: | |
diff.hasChanges() | |
diff.changes.any { change -> | |
change instanceof SetChange && change.changes.any { elementChange -> | |
elementChange instanceof ValueAdded | |
} | |
} | |
} | |
} | |
@TupleConstructor | |
class Firewall { | |
@Id final UUID id | |
final String name | |
final Set<IngressRule> ingressRules | |
} | |
@TupleConstructor | |
class IngressRule { | |
final String name | |
final Port port | |
} | |
@TupleConstructor | |
class Port { | |
final int number | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment