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