1 //==================================================================================
2 // Copyright (c) 2022 Samsung
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
16 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
17 // platform project (RICP).
18 //==================================================================================
32 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/health"
33 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/models"
34 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/onboard"
35 h "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/health"
36 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms"
37 "github.com/stretchr/testify/assert"
38 "github.com/stretchr/testify/mock"
42 var successStatus *models.Status
44 func TestMain(m *testing.M) {
46 successStatus = &models.Status{
47 Status: &health.HEALTHY,
51 HealthChecker: HealthCheckerMock{},
52 Onboarder: onboard.NewOnboarder(),
58 func TestHealth(t *testing.T) {
59 resp := rh.GetDMSHealth()
61 case *h.GetHealthCheckOK:
62 assert.Equal(t, successStatus, resp.(*h.GetHealthCheckOK).Payload)
64 case *h.GetHealthCheckInternalServerError:
65 assert.Fail(t, "Internal Server generated: %v", resp)
68 assert.Fail(t, "Unknown type of resp : %v", resp)
72 func TestOnboard(t *testing.T) {
73 xApp := &models.Descriptor{
74 Config: "SAMPLE_CONFIGURATION",
75 Schema: "SAMPLE_SCHEMA",
78 svr := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
79 var d map[string]interface{}
80 reqBytes, _ := ioutil.ReadAll(r.Body)
83 err := json.Unmarshal(reqBytes, &d)
85 ricdms.Logger.Debug("after unmarshal : %+v body: %+v", d, string(reqBytes))
88 assert.Fail(t, "Not able to parse the request body")
91 assert.Equal(t, xApp.Config, d["config-file.json"])
92 assert.Equal(t, xApp.Schema, d["controls-schema.json"])
93 fmt.Fprintf(w, "SAMPLE_RESPONSE")
96 svr.Listener, _ = net.Listen("tcp", ricdms.Config.MockServer)
101 resp := rh.OnBoard(xApp)
102 assert.NotEqual(t, nil, resp)
105 type HealthCheckerMock struct {
109 func (h HealthCheckerMock) GetStatus() *models.Status {