-
-
Notifications
You must be signed in to change notification settings - Fork 394
Expand file tree
/
Copy pathBasicCommitAndQueryExample.groovy
More file actions
64 lines (45 loc) · 1.92 KB
/
Copy pathBasicCommitAndQueryExample.groovy
File metadata and controls
64 lines (45 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.javers.core.examples
import org.javers.core.Changes
import org.javers.core.Javers
import org.javers.core.JaversBuilder
import org.javers.core.examples.model.Person
import org.javers.core.examples.model.Position
import org.javers.core.metamodel.object.CdoSnapshot
import org.javers.repository.jql.JqlQuery
import org.javers.repository.jql.QueryBuilder
import org.javers.shadow.Shadow
import spock.lang.Specification
class BasicCommitAndQueryExample extends Specification {
def "should commit and query from JaversRepository"() {
given:
// prepare JaVers instance. By default, JaVers uses InMemoryRepository,
// it's useful for testing
Javers javers = JaversBuilder.javers().build()
Person robert = new Person("bob", "Robert Martin")
javers.commit("user", robert) // persist initial commit
robert.setName("Robert C.") // do some changes
robert.setPosition(Position.Developer)
javers.commit("user", robert) // and persist another commit
JqlQuery query = QueryBuilder.byInstanceId("bob", Person.class).build()
when:
println "Shadows query:"
List<Shadow<Person>> shadows = javers.findShadows(query)
shadows.forEach { println it.get() }
then: "there should be two Bob's Shadows"
assert shadows.size() == 2
when:
println "Snapshots query:"
List<CdoSnapshot> snapshots = javers.findSnapshots(query)
snapshots.forEach { println it }
then: "there should be two Bob's Shadows"
assert snapshots.size() == 2
when:
println "Changes query:"
Changes changes = javers.findChanges(query)
// or the old approach:
// List<Change> changes = javers.findChanges(query)
println changes.prettyPrint()
then: "there should be five Changes on Bob"
assert changes.size() == 5
}
}