-
Notifications
You must be signed in to change notification settings - Fork 64
/
activity_test.go
executable file
·79 lines (63 loc) · 1.89 KB
/
activity_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
package actreply
import (
"encoding/json"
"testing"
"github.com/project-flogo/core/activity"
"github.com/project-flogo/core/data"
"github.com/project-flogo/core/data/mapper"
"github.com/project-flogo/core/data/metadata"
"github.com/project-flogo/core/data/resolve"
"github.com/project-flogo/core/support/test"
"github.com/stretchr/testify/assert"
)
func TestRegister(t *testing.T) {
ref := activity.GetRef(&Activity{})
act := activity.Get(ref)
assert.NotNil(t, act)
}
func TestSimpleReply(t *testing.T) {
//set mappings
mappingsJson :=
`{
"Output1": "1",
"Output2": 2
}`
var mappings interface{}
err := json.Unmarshal([]byte(mappingsJson), &mappings)
if err != nil {
panic("Unable to parse mappings: " + err.Error())
}
settings := map[string]interface{}{"mappings": mappings}
mf := mapper.NewFactory(resolve.GetBasicResolver())
iCtx := test.NewActivityInitContext(settings, mf)
act, err := New(iCtx)
assert.Nil(t, err)
ac := newActionContext()
tc := test.NewActivityContextWithAction(act.Metadata(), ac)
//eval
done, err := act.Eval(tc)
assert.Nil(t, err)
assert.True(t, done)
assert.Nil(t, ac.ReplyErr)
o1, exists1 := ac.ReplyData["Output1"]
assert.True(t, exists1, "Output1 not set")
if exists1 {
assert.Equal(t, "1", o1)
}
o2, exists2 := ac.ReplyData["Output2"]
assert.True(t, exists2, "Output2 not set")
if exists2 {
assert.Equal(t, 2.0, o2)
}
}
func newActionContext() *test.TestActivityHost {
input := map[string]data.TypedValue{"Input1": data.NewTypedValue(data.TypeString, "")}
output := map[string]data.TypedValue{"Output1": data.NewTypedValue(data.TypeString, ""), "Output2": data.NewTypedValue(data.TypeInt, "")}
ac := &test.TestActivityHost{
HostId: "1",
HostRef: "github.com/project-flogo/flow",
IoMetadata: &metadata.IOMetadata{Input: input, Output: output},
HostData: data.NewSimpleScope(nil, nil),
}
return ac
}