2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 package rmrmsghandlerprovider
23 "rsm/handlers/rmrmsghandlers"
25 "rsm/tests/testhelper"
33 * Verify support for known providers.
35 func TestGetNotificationHandlerSuccess(t *testing.T) {
37 rnibDataService, rmrSender, logger := testhelper.InitTestCase(t)
38 config, err := configuration.ParseConfiguration()
40 t.Errorf("#... - failed to parse configuration error: %s", err)
42 resourceStatusInitiateManager := managers.NewResourceStatusInitiateManager(logger, rnibDataService, rmrSender)
44 var testCases = []struct {
46 handler rmrmsghandlers.RmrMessageHandler
48 {rmrcgo.RanConnected, rmrmsghandlers.NewResourceStatusInitiateNotificationHandler(logger, config, resourceStatusInitiateManager, RanConnected)},
49 {rmrcgo.RanRestarted, rmrmsghandlers.NewResourceStatusInitiateNotificationHandler(logger, config, resourceStatusInitiateManager, RanRestarted)},
52 for _, tc := range testCases {
53 provider := NewMessageHandlerProvider(logger, config, rnibDataService, rmrSender, resourceStatusInitiateManager, nil)
54 t.Run(fmt.Sprintf("%d", tc.msgType), func(t *testing.T) {
55 handler, err := provider.GetMessageHandler(tc.msgType)
57 t.Errorf("want: handler for message type %d, got: error %s", tc.msgType, err)
59 if strings.Compare(fmt.Sprintf("%T", handler), fmt.Sprintf("%T", tc.handler)) != 0 {
60 t.Errorf("want: handler %T for message type %d, got: %T", tc.handler, tc.msgType, handler)
67 * Verify handling of a request for an unsupported message.
70 func TestGetNotificationHandlerFailure(t *testing.T) {
72 rnibDataService, rmrSender, logger := testhelper.InitTestCase(t)
73 config, err := configuration.ParseConfiguration()
75 t.Errorf("#... - failed to parse configuration error: %s", err)
77 resourceStatusInitiateManager := managers.NewResourceStatusInitiateManager(logger, rnibDataService, rmrSender)
79 var testCases = []struct {
83 {9999 /*unknown*/, "notification handler not found"},
85 for _, tc := range testCases {
86 provider := NewMessageHandlerProvider(logger, config, rnibDataService, rmrSender, resourceStatusInitiateManager, nil)
87 t.Run(fmt.Sprintf("%d", tc.msgType), func(t *testing.T) {
88 _, err := provider.GetMessageHandler(tc.msgType)
90 t.Errorf("want: no handler for message type %d, got: success", tc.msgType)
92 if !strings.Contains(fmt.Sprintf("%s", err), tc.errorText) {
93 t.Errorf("want: error [%s] for message type %d, got: %s", tc.errorText, tc.msgType, err)