1 diff --git a/src/orchestrationapi/orchestrationapi_test.go b/src/orchestrationapi/orchestrationapi_test.go
2 index e1eda62..c875f8a 100644
3 --- a/src/orchestrationapi/orchestrationapi_test.go
4 +++ b/src/orchestrationapi/orchestrationapi_test.go
5 @@ -141,3 +141,316 @@ func TestRequestService(t *testing.T) {
10 +func TestRequestServiceOnDevice(t *testing.T) {
11 + ctrl := gomock.NewController(t)
17 + args := []string{"a", "-b", "-c"}
19 + var requestServiceInfo ReqeustService
20 + requestServiceInfo.ServiceName = appName
21 + requestServiceInfo.SelfSelection = true
22 + requestServiceInfo.ServiceRequester = "my"
23 + requestServiceInfo.ServiceInfo = []RequestServiceInfo{
25 + ExecutionType: "platform",
30 + requestervalidator.RequesterValidator{}.StoreRequesterInfo(appName, []string{"my"})
32 + candidateInfos := make([]dbhelper.ExecutionCandidate, 0)
33 + candidateInfos = append(candidateInfos, dbhelper.ExecutionCandidate{
35 + ExecType: "platform",
36 + Endpoint: []string{"endpoint1"},
38 + candidateInfos = append(candidateInfos, dbhelper.ExecutionCandidate{
40 + ExecType: "platform",
41 + Endpoint: []string{"endpoint2"},
43 + candidateInfos = append(candidateInfos, dbhelper.ExecutionCandidate{
45 + ExecType: "platform",
46 + Endpoint: []string{"endpoint3"},
50 + t.Run("Success", func(t *testing.T) {
53 + mockService.EXPECT().SetLocalServiceExecutor(mockExecutor),
54 + mockNetwork.EXPECT().GetIPs().Return([]string{""}, nil),
55 + mockService.EXPECT().Execute(gomock.Any(), appName, gomock.Any(), gomock.Any(), gomock.Any()),
58 + o := getOcheIns(ctrl)
60 + t.Error("ochestration object is nil, expected is not nil")
63 + oche := getOrcheImple()
67 + res := oche.RequestServiceOnDevice(requestServiceInfo,"192.168.1.1")
68 + if res.Message != ERROR_NONE {
69 + t.Error("unexpected handle")
73 + t.Run("Localhost", func(t *testing.T) {
76 + mockService.EXPECT().SetLocalServiceExecutor(mockExecutor),
77 + mockNetwork.EXPECT().GetIPs().Return([]string{"192.168.1.1"}, nil),
78 + mockService.EXPECT().Execute(gomock.Any(), appName, gomock.Any(), gomock.Any(), gomock.Any()),
81 + o := getOcheIns(ctrl)
83 + t.Error("ochestration object is nil, expected is not nil")
86 + oche := getOrcheImple()
90 + res := oche.RequestServiceOnDevice(requestServiceInfo,"192.168.1.1")
91 + if res.Message != ERROR_NONE {
92 + t.Error("unexpected handle")
96 + t.Run("Error", func(t *testing.T) {
97 + t.Run("NotReady", func(t *testing.T) {
98 + mockService.EXPECT().SetLocalServiceExecutor(mockExecutor)
99 + o := getOcheIns(ctrl)
101 + t.Error("ochestration object is nil, expected is not nil")
104 + oche := getOrcheImple()
105 + res := oche.RequestService(requestServiceInfo)
106 + if res.Message != INTERNAL_SERVER_ERROR {
107 + t.Error("unexpected Error")
110 + t.Run("DiscoveryFail", func(t *testing.T) {
112 + mockService.EXPECT().SetLocalServiceExecutor(mockExecutor),
113 + mockDBHelper.EXPECT().GetDeviceInfoWithService(gomock.Eq(appName), gomock.Any()).Return(nil, errors.New("-3")),
115 + o := getOcheIns(ctrl)
117 + t.Error("ochestration object is nil, expected is not nil")
120 + oche := getOrcheImple()
124 + res := oche.RequestService(requestServiceInfo)
125 + if res.Message == ERROR_NONE {
126 + t.Error("unexpected Error")
132 +func TestGetAuthenticatedDeviceList(t *testing.T) {
133 + ctrl := gomock.NewController(t)
134 + defer ctrl.Finish()
136 + createMockIns(ctrl)
138 + t.Run("Success", func(t *testing.T){
141 + mockService.EXPECT().SetLocalServiceExecutor(mockExecutor),
142 + mockService.EXPECT().GetAuthenticatedDevices(gomock.Any(),gomock.Any()).Return(dummy,nil),
144 + o := getOcheIns(ctrl)
146 + t.Error("ochestration object is nil, expected is not nil")
149 + oche := getOrcheImple()
152 + _, err := oche.GetAuthenticatedDeviceList("ServiceName","ExType")
154 + t.Error("Err should be null")
158 + t.Run("Faliure", func(t *testing.T){
161 + mockService.EXPECT().SetLocalServiceExecutor(mockExecutor),
162 + mockService.EXPECT().GetAuthenticatedDevices(gomock.Any(),gomock.Any()).Return(dummy,errors.New("")),
164 + o := getOcheIns(ctrl)
166 + t.Error("ochestration object is nil, expected is not nil")
169 + oche := getOrcheImple()
172 + _, err := oche.GetAuthenticatedDeviceList("ServiceName","ExType")
174 + t.Error("Err should be null")
177 + t.Run("OrcFaliure", func(t *testing.T){
179 + mockService.EXPECT().SetLocalServiceExecutor(mockExecutor),
181 + o := getOcheIns(ctrl)
183 + t.Error("ochestration object is nil, expected is not nil")
186 + oche := getOrcheImple()
189 + _, err := oche.GetAuthenticatedDeviceList("ServiceName","ExType")
191 + t.Error("Err should be null")
196 +func TestWriteCapability(t *testing.T) {
197 + ctrl := gomock.NewController(t)
198 + defer ctrl.Finish()
200 + createMockIns(ctrl)
201 + t.Run("Success", func(t *testing.T){
203 + mockService.EXPECT().SetLocalServiceExecutor(mockExecutor),
204 + mockCapability.EXPECT().WriteCapability(gomock.Any()).Return(nil),
206 + o := getOcheIns(ctrl)
208 + t.Error("ochestration object is nil, expected is not nil")
211 + oche := getOrcheImple()
214 + err := oche.WriteCapability("DefaultCapability")
216 + t.Error("Err should be null")
220 + t.Run("Faliure", func(t *testing.T){
222 + mockService.EXPECT().SetLocalServiceExecutor(mockExecutor),
223 + mockCapability.EXPECT().WriteCapability(gomock.Any()).Return(errors.New("")),
225 + o := getOcheIns(ctrl)
227 + t.Error("ochestration object is nil, expected is not nil")
230 + oche := getOrcheImple()
233 + err := oche.WriteCapability("DefaultCapability")
235 + t.Error("Err should be null")
238 + t.Run("OrchFaliure", func(t *testing.T){
240 + mockService.EXPECT().SetLocalServiceExecutor(mockExecutor),
242 + o := getOcheIns(ctrl)
244 + t.Error("ochestration object is nil, expected is not nil")
247 + oche := getOrcheImple()
250 + err := oche.WriteCapability("DefaultCapability")
252 + t.Error("Err should be null")
258 +func TestReadCapability(t *testing.T) {
259 + ctrl := gomock.NewController(t)
260 + defer ctrl.Finish()
262 + createMockIns(ctrl)
263 + t.Run("Success", func(t *testing.T){
266 + mockService.EXPECT().SetLocalServiceExecutor(mockExecutor),
267 + mockCapability.EXPECT().ReadCapability(gomock.Any()).Return(dummy,nil),
269 + o := getOcheIns(ctrl)
271 + t.Error("ochestration object is nil, expected is not nil")
274 + oche := getOrcheImple()
277 + _,err := oche.ReadCapability("DefaultIP")
279 + t.Error("Err should be null")
283 + t.Run("Faliure", func(t *testing.T){
286 + mockService.EXPECT().SetLocalServiceExecutor(mockExecutor),
287 + mockCapability.EXPECT().ReadCapability(gomock.Any()).Return(dummy,errors.New("")),
289 + o := getOcheIns(ctrl)
291 + t.Error("ochestration object is nil, expected is not nil")
294 + oche := getOrcheImple()
297 + _,err := oche.ReadCapability("DefaultIP")
299 + t.Error("Err should be null")
302 + t.Run("OrchFaliure", func(t *testing.T){
304 + mockService.EXPECT().SetLocalServiceExecutor(mockExecutor),
306 + o := getOcheIns(ctrl)
308 + t.Error("ochestration object is nil, expected is not nil")
311 + oche := getOrcheImple()
314 + _,err := oche.ReadCapability("DefaultIP")
316 + t.Error("Err should be null")