Merge newe2 into master
[ric-plt/submgr.git] / e2ap / pkg / e2ap / e2ap_tests / msg.go
1 /*
2 ==================================================================================
3   Copyright (c) 2019 AT&T Intellectual Property.
4   Copyright (c) 2019 Nokia
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 ==================================================================================
18 */
19
20 package e2ap_tests
21
22 import (
23         "encoding/hex"
24         "fmt"
25         "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
26         "github.com/google/go-cmp/cmp"
27         "log"
28         "os"
29         "testing"
30 )
31
32 //-----------------------------------------------------------------------------
33 //
34 //-----------------------------------------------------------------------------
35
36 var testLogger *log.Logger
37
38 func init() {
39         testLogger = log.New(os.Stdout, "TEST: ", log.LstdFlags)
40 }
41
42 type ApTests struct {
43         name string
44         desc string
45 }
46
47 func (testctxt *ApTests) Name() string { return testctxt.name }
48
49 func (testctxt *ApTests) Desc() string { return testctxt.desc }
50
51 func (testctxt *ApTests) SetDesc(desc string) { testctxt.desc = desc }
52
53 func (testctxt *ApTests) String() string { return testctxt.name + string("-") + testctxt.desc }
54
55 func (testctxt *ApTests) testPrint(pattern string, args ...interface{}) {
56         testLogger.Printf("(%s): %s", testctxt.String(), fmt.Sprintf(pattern, args...))
57 }
58
59 func (testctxt *ApTests) testError(t *testing.T, pattern string, args ...interface{}) {
60         testLogger.Printf("(%s): %s", testctxt.String(), fmt.Sprintf(pattern, args...))
61         t.Errorf("(%s): %s", testctxt.String(), fmt.Sprintf(pattern, args...))
62 }
63
64 func (testctxt *ApTests) testValueEquality(t *testing.T, msg string, a interface{}, b interface{}) {
65         if !cmp.Equal(a, b) {
66                 testLogger.Printf("(%s) %s Difference: %s", testctxt.String(), msg, cmp.Diff(a, b))
67                 t.Errorf("(%s) %s Difference: %s", testctxt.String(), msg, cmp.Diff(a, b))
68         }
69 }
70
71 //-----------------------------------------------------------------------------
72 //
73 //-----------------------------------------------------------------------------
74
75 type E2ApTests struct {
76         ApTests
77         packerif e2ap.E2APPackerIf
78 }
79
80 func (testCtxt *E2ApTests) toPackedData(t *testing.T, buffer string) *e2ap.PackedData {
81         msg, err := hex.DecodeString(buffer)
82         if err != nil {
83                 testCtxt.testError(t, "Hex DecodeString Failed: %s [%s]", err.Error(), buffer)
84                 return nil
85         }
86         packedData := &e2ap.PackedData{}
87         packedData.Buf = msg
88         return packedData
89 }
90
91 func NewE2ApTests(name string, packerif e2ap.E2APPackerIf) *E2ApTests {
92         testCtxt := &E2ApTests{}
93         testCtxt.packerif = packerif
94         testCtxt.name = name
95         return testCtxt
96 }
97
98 //-----------------------------------------------------------------------------
99 //
100 //-----------------------------------------------------------------------------
101
102 func RunTests(t *testing.T, e2aptestctxt *E2ApTests) {
103
104         subMsgContent := &SubscriptionTestMsgContent{}
105         subMsgContent.NBNRTEventTriggerDefinitionPresent = true
106         subMsgContent.ActionDefinitionNRTFormat1Present = true
107         subMsgContent.RANParameterValueEnumPresent = true
108         t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionRequest(t, subMsgContent) })
109
110         subMsgContent2 := &SubscriptionTestMsgContent{}
111         subMsgContent2.NBX2EventTriggerDefinitionPresent = true
112         subMsgContent2.ActionDefinitionX2Format1Present = true
113         subMsgContent2.ActionParameterValueBoolPresent = true
114         subMsgContent2.RANParameterValueBoolPresent = true
115         t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionRequest(t, subMsgContent2) })
116
117         subMsgContent3 := &SubscriptionTestMsgContent{}
118         subMsgContent3.NBX2EventTriggerDefinitionPresent = true
119         subMsgContent3.ActionDefinitionX2Format2Present = true
120         subMsgContent3.ActionParameterValueBitSPresent = true
121         subMsgContent3.RANParameterValueBitSPresent = true
122         t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionRequest(t, subMsgContent3) })
123
124         subMsgContent4 := &SubscriptionTestMsgContent{}
125         subMsgContent4.NBX2EventTriggerDefinitionPresent = true
126         subMsgContent4.ActionDefinitionX2Format2Present = true
127         subMsgContent4.ActionParameterValueOctSPresent = true
128         subMsgContent4.RANParameterValueOctSPresent = true
129         t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionRequest(t, subMsgContent4) })
130
131         subMsgContent5 := &SubscriptionTestMsgContent{}
132         subMsgContent5.NBX2EventTriggerDefinitionPresent = true
133         subMsgContent5.ActionDefinitionX2Format2Present = true
134         subMsgContent5.ActionParameterValuePrtSPresent = true
135         subMsgContent5.RANParameterValuePrtSPresent = true
136         t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionRequest(t, subMsgContent5) })
137
138         t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionResponse(t) })
139         t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionFailure(t) })
140         t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionDeleteRequest(t) })
141         t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionDeleteResponse(t) })
142         t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionDeleteFailure(t) })
143
144         /*
145                 t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionRequestBuffers(t) })
146                 t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionResponseBuffers(t) })
147                 t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionFailureBuffers(t) })
148                 t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionDeleteRequestBuffers(t) })
149                 t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionDeleteResponseBuffers(t) })
150                 t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionDeleteFailureBuffers(t) })
151         */
152
153 }