-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction_test.go
65 lines (51 loc) · 1.65 KB
/
transaction_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
package datahub
import (
"github.com/google/uuid"
egdm "github.com/mimiro-io/entity-graph-data-model"
"testing"
)
func TestProcessTransaction(t *testing.T) {
client := NewAdminUserConfiguredClient()
// create two test datasets
datasetId1 := "dataset-" + uuid.New().String()
datasetId2 := "dataset-" + uuid.New().String()
// use the client to create the datasets
err := client.AddDataset(datasetId1, nil)
if err != nil {
t.Error(err)
}
err = client.AddDataset(datasetId2, nil)
if err != nil {
t.Error(err)
}
// create a transaction
txn := NewTransaction()
// create an entity
entityId, err := txn.NamespaceManager.AssertPrefixedIdentifierFromURI("http://data.example.io/entity1")
entity := egdm.NewEntity().SetID(entityId)
txn.DatasetEntities[datasetId1] = append(txn.DatasetEntities[datasetId1], entity)
// create another entity
entityId2, err := txn.NamespaceManager.AssertPrefixedIdentifierFromURI("http://data.example.io/entity2")
entity2 := egdm.NewEntity().SetID(entityId2)
txn.DatasetEntities[datasetId2] = append(txn.DatasetEntities[datasetId2], entity2)
// run the transaction
err = client.ProcessTransaction(txn)
if err != nil {
t.Error(err)
}
// check the entities in the datasets
dataset1, err := client.GetEntities(datasetId1, "", -1, false, true)
if err != nil {
t.Error(err)
}
if len(dataset1.Entities) != 1 {
t.Errorf("expected dataset to have 1 entity, got %d", len(dataset1.Entities))
}
dataset2, err := client.GetEntities(datasetId2, "", -1, false, true)
if err != nil {
t.Error(err)
}
if len(dataset2.Entities) != 1 {
t.Errorf("expected dataset to have 1 entity, got %d", len(dataset2.Entities))
}
}