forked from TIBCOSoftware/flogo-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrigger_test.go
executable file
·125 lines (99 loc) · 2.64 KB
/
trigger_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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package mqtt
import (
"encoding/json"
"io/ioutil"
"testing"
//MQTT "github.com/eclipse/paho.mqtt.golang"
"github.com/TIBCOSoftware/flogo-lib/core/trigger"
)
var jsonTestMetadata = getTestJsonMetadata()
func getTestJsonMetadata() string {
jsonMetadataBytes, err := ioutil.ReadFile("trigger.json")
if err != nil {
panic("No Json Metadata found for trigger.json path")
}
return string(jsonMetadataBytes)
}
const testConfig string = `{
"name": "flogo-mqtt",
"settings": {
"topic": "flogo/#",
"broker": "tcp://127.0.0.1:1883",
"id": "flogoEngine",
"user": "",
"password": "",
"store": "",
"qos": "0",
"cleansess": "false"
},
"handlers": [
{
"actionId": "device_info",
"settings": {
"topic": "test_start"
}
}
]
}`
//type TestRunner struct {
//}
//
//// Run implements action.Runner.Run
//func (tr *TestRunner) Run(context context.Context, action action.Action, uri string, options interface{}) (code int, data interface{}, err error) {
// log.Debugf("Ran Action: %v", uri)
// return 0, nil, nil
//}
//
//func (tr *TestRunner) RunHandler(ctx context.Context, act action.Action, options map[string]interface{}) (results map[string]*data.Attribute, err error) {
// log.Debugf("Ran Action: %v", act.Config().Id)
// return nil, nil
//}
func TestInit(t *testing.T) {
// New factory
md := trigger.NewMetadata(jsonMetadata)
f := NewFactory(md)
// New Trigger
config := trigger.Config{}
json.Unmarshal([]byte(testConfig), config)
f.New(&config)
//runner := &TestRunner{}
//tgr.Init(runner)
}
/*
// TODO Fix this test
func TestEndpoint(t *testing.T) {
// New factory
md := trigger.NewMetadata(jsonMetadata)
f := NewFactory(md)
// New Trigger
config := trigger.Config{}
json.Unmarshal([]byte(testConfig), &config)
tgr := f.New(&config)
runner := &TestRunner{}
tgr.Init(runner)
tgr.Start()
defer tgr.Stop()
opts := MQTT.NewClientOptions()
opts.AddBroker("tcp://127.0.0.1:1883")
opts.SetClientID("flogo_test")
opts.SetUsername("")
opts.SetPassword("")
opts.SetCleanSession(false)
client := MQTT.NewClient(opts)
if token := client.Connect(); token.Wait() && token.Error() != nil {
panic(token.Error())
}
log.Debug("---- doing first publish ----")
token := client.Publish("test_start", 0, false, "Test message payload!")
token.Wait()
duration2 := time.Duration(2)*time.Second
time.Sleep(duration2)
log.Debug("---- doing second publish ----")
token = client.Publish("test_start", 0, false, "Test message payload!")
token.Wait()
duration5 := time.Duration(5)*time.Second
time.Sleep(duration5)
client.Disconnect(250)
log.Debug("Sample Publisher Disconnected")
}
*/