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