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