fb1fb4ec5b364b5db7ca06c094b0aef9a89772db
[ric-plt/e2mgr.git] / E2Manager / handlers / rmrmsghandlers / enb_load_information_notification_handler_test.go
1 //
2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
4 //
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
8 //
9 //      http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 package rmrmsghandlers
19
20 import (
21         "e2mgr/logger"
22         "e2mgr/models"
23         "fmt"
24         "time"
25 )
26
27 const (
28         FullUperPdu  string = "004c07080004001980da0100075bde017c148003d5a8205000017c180003d5a875555403331420000012883a0003547400cd20002801ea16007c1f07c1f107c1f0781e007c80800031a02c000c88199040a00352083669190000d8908020000be0c4001ead4016e007ab50100002f8320067ab5005b8c1ead5070190c00001d637805f220000f56a081400005f020000f56a1d555400ccc508002801ea16007c1f07c1f107c1f0781e007c80800031a02c000c88199040a00352083669190000d8908020000be044001ead4016e007ab50100002f8120067ab5005b8c1ead5070190c00000"
29         FullAperPdu string = "" // TODO: populate and use it
30         BasicUperPdu string = "004898000400190d0000074200017c148003d5a80000"
31         BasicAperPdu string = "" // TODO: populate and use it
32         GarbagePdu   string = "12312312"
33 )
34
35 func createNotificationRequest(ranName string, transactionId string, packedPdu string) (*models.NotificationRequest, error) {
36         var packedByteSlice []byte
37
38         _, err := fmt.Sscanf(packedPdu, "%x", &packedByteSlice)
39
40         if err != nil {
41                 return nil, err
42         }
43
44         return models.NewNotificationRequest(ranName, packedByteSlice, time.Now(), transactionId), nil
45 }
46
47 func createNotificationRequestAndHandle(log *logger.Logger, ranName string, transactionId string, loadInformationHandler EnbLoadInformationNotificationHandler, pdu string) error {
48         notificationRequest, err := createNotificationRequest(ranName, transactionId, pdu)
49
50         if err != nil {
51                 return err
52         }
53
54         loadInformationHandler.Handle(log, notificationRequest, nil)
55         return nil
56 }
57
58 //func TestLoadInformationHandlerSuccess(t *testing.T) {
59 //      log, err := logger.InitLogger(logger.InfoLevel)
60 //      if err != nil {
61 //              t.Errorf("#setup_request_handler_test.TestLoadInformationHandlerSuccess - failed to initialize logger, error: %v", err)
62 //      }
63 //
64 //      inventoryName := "testRan"
65 //
66 //      writerMock := &mocks.RnibWriterMock{}
67 //      rnibWriterProvider := func() rNibWriter.RNibWriter {
68 //              return writerMock
69 //      }
70 //
71 //      var rnibErr error
72 //      writerMock.On("SaveRanLoadInformation",inventoryName, mock.Anything).Return(rnibErr)
73 //
74 //      loadInformationHandler := NewEnbLoadInformationNotificationHandler(rnibWriterProvider)
75 //
76 //      var packedExampleByteSlice []byte
77 //      _, err = fmt.Sscanf(FullUperPdu, "%x", &packedExampleByteSlice)
78 //      notificationRequest := models.NewNotificationRequest(inventoryName, packedExampleByteSlice, time.Now(), " 881828026419")
79 //      loadInformationHandler.Handle(log, notificationRequest, nil)
80 //
81 //      writerMock.AssertNumberOfCalls(t, "SaveRanLoadInformation", 1)
82 //}
83 //
84 //func TestLoadInformationHandlerPayloadFailure(t *testing.T) {
85 //      log, err := logger.InitLogger(logger.InfoLevel)
86 //      if err != nil {
87 //              t.Errorf("#setup_request_handler_test.TestLoadInformationHandlerPayloadFailure - failed to initialize logger, error: %v", err)
88 //      }
89 //
90 //      inventoryName := "testRan"
91 //
92 //      writerMock := &mocks.RnibWriterMock{}
93 //      rnibWriterProvider := func() rNibWriter.RNibWriter {
94 //              return writerMock
95 //      }
96 //
97 //      var rnibErr error
98 //      writerMock.On("SaveRanLoadInformation",inventoryName, mock.Anything).Return(rnibErr)
99 //
100 //      loadInformationHandler := NewEnbLoadInformationNotificationHandler(rnibWriterProvider)
101 //
102 //      var packedExampleByteSlice []byte
103 //      _, err = fmt.Sscanf(GarbagePdu, "%x", &packedExampleByteSlice)
104 //      notificationRequest := models.NewNotificationRequest(inventoryName, packedExampleByteSlice, time.Now(), " 881828026419")
105 //      loadInformationHandler.Handle(log, notificationRequest, nil)
106 //
107 //      writerMock.AssertNumberOfCalls(t, "SaveRanLoadInformation", 0)
108 //}
109
110 // Integration test
111 //func TestLoadInformationHandlerOverrideSuccess(t *testing.T) {
112 //      log, err := logger.InitLogger(logger.InfoLevel)
113 //      if err != nil {
114 //              t.Errorf("#setup_request_handler_test.TestLoadInformationHandlerOverrideSuccess - failed to initialize logger, error: %s", err)
115 //      }
116 //
117 //      rNibWriter.Init("e2Manager", 1)
118 //      defer rNibWriter.Close()
119 //      reader.Init("e2Manager", 1)
120 //      defer reader.Close()
121 //      loadInformationHandler := NewEnbLoadInformationNotificationHandler(rNibWriter.GetRNibWriter)
122 //
123 //      err = createNotificationRequestAndHandle(log, "ranName", " 881828026419", loadInformationHandler, FullUperPdu)
124 //
125 //      if err != nil {
126 //              t.Errorf("#setup_request_handler_test.TestLoadInformationHandlerOverrideSuccess - failed creating NotificationRequest, error: %v", err)
127 //      }
128 //
129 //      err = createNotificationRequestAndHandle(log, "ranName", " 881828026419", loadInformationHandler, BasicUperPdu)
130 //
131 //      if err != nil {
132 //              t.Errorf("#setup_request_handler_test.TestLoadInformationHandlerOverrideSuccess - failed creating NotificationRequest, error: %v", err)
133 //      }
134 //
135 //      ranLoadInformation, rnibErr := reader.GetRNibReader().GetRanLoadInformation("ranName")
136 //
137 //      if (rnibErr != nil) {
138 //              t.Errorf("#setup_request_handler_test.TestLoadInformationHandlerOverrideSuccess - RNIB error: %v", err)
139 //      }
140 //
141 //      assert.Len(t, ranLoadInformation.CellLoadInfos, 1)
142 //}