Testcase for Policy type Creation 30/7830/2
authornaman.gupta <naman.gupta@samsung.com>
Wed, 23 Feb 2022 06:14:43 +0000 (11:44 +0530)
committernaman.gupta <naman.gupta@samsung.com>
Wed, 23 Feb 2022 13:46:38 +0000 (19:16 +0530)
Testcase for Policy type Creation

Signed-off-by: naman.gupta <naman.gupta@samsung.com>
Change-Id: I649dd94059263244645e7a8236ad058c3f0ef25f

a1-go/pkg/resthooks/resthooks_test.go

index e74ed3a..e8ea9fe 100644 (file)
@@ -22,9 +22,11 @@ package resthooks
 
 import (
        "os"
+       "strconv"
        "testing"
 
        "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/a1"
+       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/models"
        "github.com/stretchr/testify/assert"
        "github.com/stretchr/testify/mock"
 )
@@ -52,6 +54,34 @@ func TestGetAllPolicyType(t *testing.T) {
        assert.Equal(t, 2, len(resp))
 }
 
+func TestCreatePolicyType(t *testing.T) {
+       var policyTypeId models.PolicyTypeID
+       policyTypeId = 20001
+       var policyTypeSchema models.PolicyTypeSchema
+       name := "admission_control_policy_mine"
+       policyTypeSchema.Name = &name
+       policytypeid := int64(20001)
+       policyTypeSchema.PolicyTypeID = &policytypeid
+       description := "various parameters to control admission of dual connection"
+       policyTypeSchema.Description = &description
+       policyTypeSchema.CreateSchema = `{"$schema": "http://json-schema.org/draft-07/schema#","type":"object","properties": {"enforce": {"type":"boolean","default":"true",},"window_length": {"type":        "integer","default":1,"minimum":1,"maximum":60,"description": "Sliding window length (in minutes)",},
+"blocking_rate": {"type":"number","default":10,"minimum":1,"maximum":100,"description": "% Connections to block",},"additionalProperties": false,},}`
+
+       data, err := policyTypeSchema.MarshalBinary()
+       a1.Logger.Debug("error : %+v ", err)
+       a1.Logger.Debug("data : %+v ", data)
+       key := "a1.policy_type." + strconv.FormatInt(20001, 10)
+       a1.Logger.Debug("key : %+v ", key)
+       //Setup Expectations
+       sdlInst.On("SetIfNotExists", a1MediatorNs, key, string(data)).Return(true, nil)
+
+       errresp := rh.CreatePolicyType(policyTypeId, policyTypeSchema)
+       //Data Assertion
+       assert.Nil(t, errresp)
+       //Mock Assertion :Behavioral
+       sdlInst.AssertExpectations(t)
+}
+
 type SdlMock struct {
        mock.Mock
 }
@@ -62,5 +92,7 @@ func (s *SdlMock) GetAll(ns string) ([]string, error) {
 }
 
 func (s *SdlMock) SetIfNotExists(ns string, key string, data interface{}) (bool, error) {
-       return true, nil
+       a1.Logger.Debug("SetIfNotExists mock called")
+       args := s.MethodCalled("SetIfNotExists", ns, key, data)
+       return args.Bool(0), nil
 }