Newer
Older
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
package servicebuildermdl
import (
"testing"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/loggermdl"
dalmdl "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/dalmdl/dao"
"github.com/caibirdme/yql"
"github.com/stretchr/testify/assert"
"github.com/tidwall/gjson"
)
//Create Type with abstract Type
type MyBLLayer struct {
AbstractBusinessLogicHolder
}
// attach methods to it
func (m *MyBLLayer) FindAndVerifyMobileNumber() map[string]interface{} {
loginID := "noone"
result1, ok := m.GetResult("daodata1")
if !ok {
loggermdl.LogError("error in convert")
}
loginID = result1.Get("#[mobileNo==\"7875383220\"].loginId").String()
m.SetFinalData(loginID)
return map[string]interface{}{
"owner": loginID,
}
}
//Now we will write DAO
func GetUsersInfo() *gjson.Result {
return dalmdl.GetDAO().FilePath("../testingdata/users.json").IsCacheable(true).Query("*").Run()
}
func TestService(t *testing.T) {
mb := MyBLLayer{}
mb.Build()
loaddata := func(ab *AbstractBusinessLogicHolder) {
mb.ServiceData["daodata1"] = GetUsersInfo()
}
// finalStep := func(ab *AbstractBusinessLogicHolder) *interface{} {
// s :=
// return &s
// }
sb := GetSB("mysrv", &mb.AbstractBusinessLogicHolder).
AddStep("Check Mobile", "owner in ('SystemIntegrator')", loaddata, mb.FindAndVerifyMobileNumber, mb.EchoBL).
AddStep("Test STEP 2", "owner = 'SystemIntegrator'", nil, mb.FindAndVerifyMobileNumber, mb.EchoBL).
Run().FinalOutput(nil)
assert.Equal(t, "SystemIntegrator", *sb, "this should be same")
}
func TestYQL(t *testing.T) {
a := map[string]interface{}{
"owner": "a",
}
result, _ := yql.Match("owner ='a')", a)
assert.Equal(t, true, result, "Yql should work")
}
func TestPanic(t *testing.T) {
var a interface{}
a = nil
// a= nil
_, ok := a.(string)
assert.False(t, ok, "should panic")
// assert.Equal(t, "something", s, "should be same")
}