-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassociation_test.go
104 lines (88 loc) · 2.85 KB
/
association_test.go
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package cloudcms
import "testing"
func TestAssociations(t *testing.T) {
session, err := ConnectDefault()
if err != nil {
t.Fatal(err)
}
repository, err := session.CreateRepository(nil)
if err != nil {
t.Fatal(err)
}
repositoryId := ExtractId(&repository)
branchId := "master"
defer session.DeleteRepository(repositoryId)
node1Id, _ := session.CreateNode(repositoryId, branchId, JsonObject{"title": "node 1"}, nil)
node2Id, _ := session.CreateNode(repositoryId, branchId, JsonObject{"title": "node 2"}, nil)
node3Id, _ := session.CreateNode(repositoryId, branchId, JsonObject{"title": "node 3"}, nil)
association1, err := session.Associate(repositoryId, branchId, node1Id, node2Id, "a:child", "", nil)
if err != nil {
t.Fatal(err)
}
if association1.GetString("directionality") != "DIRECTED" {
t.Fatal("wrong directionality")
}
if association1.GetString("source") != node1Id {
t.Fatal("wrong source")
}
if association1.GetString("target") != node2Id {
t.Fatal("wrong target")
}
// association2 = node1.associate(node3, QName.create('a:linked'), directionality=Directionality.UNDIRECTED, data={'test': 'field'})
association2, err := session.Associate(repositoryId, branchId, node1Id, node3Id, "a:linked", "UNDIRECTED", JsonObject{"test": "field"})
if err != nil {
t.Fatal(err)
}
if association2.GetString("source") != node1Id {
t.Fatal("wrong source")
}
if association2.GetString("target") != node3Id {
t.Fatal("wrong target")
}
if association2.GetString("source") != node1Id {
t.Fatal("wrong source")
}
node1Associations, err := session.ListNodeAssociations(repositoryId, branchId, node1Id, "", "", nil)
if err != nil {
t.Fatal(err)
}
if node1Associations.size != 3 {
t.Fatal("node1 has wrong number of associations")
}
node1Outgoing, err := session.ListOutgoingAssociations(repositoryId, branchId, node1Id, "", nil)
if err != nil {
t.Fatal(err)
}
if node1Outgoing.size != 2 {
t.Fatal("node1 has wrong number of outgoing associations")
}
node1Incoming, err := session.ListIncomingAssociations(repositoryId, branchId, node1Id, "", nil)
if err != nil {
t.Fatal(err)
}
if node1Incoming.size != 2 {
t.Fatal("node1 has wrong number of incoming associations")
}
node1Children, err := session.QueryNodeChildren(repositoryId, branchId, node1Id, nil, nil)
if err != nil {
t.Fatal(err)
}
if node1Children.size != 1 {
t.Fatal("node1 has wrong number of children")
}
err = session.UnassociateChild(repositoryId, branchId, node1Id, node2Id)
if err != nil {
t.Fatal(err)
}
err = session.Unassociate(repositoryId, branchId, node1Id, node3Id, "a:linked", "UNDIRECTED")
if err != nil {
t.Fatal(err)
}
node1Associations, err = session.ListNodeAssociations(repositoryId, branchId, node1Id, "", "", nil)
if err != nil {
t.Fatal(err)
}
if node1Associations.size != 1 {
t.Fatal("node1 has wrong number of associations")
}
}