X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=a1-go%2Fpkg%2Fresthooks%2Fresthooks_test.go;h=45e76660451286a19e7155aeb5917d31b32b306b;hb=b513650252f1a739e3e9e2d02f2598d506aa86cf;hp=3afbb8e1835e36febf52ad8269aa6c48af71b909;hpb=584d75571c8035f21051d26d3a020e8eb1ae89a0;p=ric-plt%2Fa1.git diff --git a/a1-go/pkg/resthooks/resthooks_test.go b/a1-go/pkg/resthooks/resthooks_test.go index 3afbb8e..45e7666 100644 --- a/a1-go/pkg/resthooks/resthooks_test.go +++ b/a1-go/pkg/resthooks/resthooks_test.go @@ -33,8 +33,13 @@ import ( "github.com/stretchr/testify/mock" ) +type RmrSenderMock struct { + mock.Mock +} + var rh *Resthook var sdlInst *SdlMock +var rmrSenderInst *RmrSenderMock func TestMain(m *testing.M) { sdlInst = new(SdlMock) @@ -46,9 +51,9 @@ func TestMain(m *testing.M) { "a1.policy_type.20000", "a1.policy_inst_metadata.1006001.qos", }, nil) - + RMRclient = new(RMRClientMock) a1.Init() - rh = createResthook(sdlInst) + rh = createResthook(sdlInst, RMRclient) code := m.Run() os.Exit(code) } @@ -139,6 +144,7 @@ func TestCreatePolicyTypeInstance(t *testing.T) { a1.Logger.Debug("metadatainstancekey : %+v", metadatainstancekey) metadatainstancearr := []interface{}{metadatainstancekey, string(metadata)} sdlInst.On("Set", "A1m_ns", metadatainstancearr).Return(nil) + rmrSenderInst.On("RmrSendToXapp", "httpBodyString").Return(true) errresp := rh.CreatePolicyInstance(policyTypeId, policyInstanceID, instancedata) @@ -158,7 +164,7 @@ func TestGetPolicyInstance(t *testing.T) { "blocking_rate":20, "trigger_threshold":10 }` - instancekey := a1PolicyPrefix + strconv.FormatInt(20001, 10) + "." + string(policyInstanceID) + instancekey := a1InstancePrefix + strconv.FormatInt(20001, 10) + "." + string(policyInstanceID) a1.Logger.Debug("httpBody String : %+v", httpBody) a1.Logger.Debug("key : %+v", instancekey) var keys [1]string @@ -181,6 +187,22 @@ func TestGetAllPolicyIntances(t *testing.T) { assert.Equal(t, 2, len(resp)) } +func TestDeletePolicyType(t *testing.T) { + + policyTypeId := models.PolicyTypeID(20001) + key := a1PolicyPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + var keys [1]string + keys[0] = key + + //Setup Expectations + sdlInst.On("Remove", a1MediatorNs, keys[:]).Return(nil) + + errresp := rh.DeletePolicyType(policyTypeId) + + assert.Nil(t, errresp) + sdlInst.AssertExpectations(t) +} + type SdlMock struct { mock.Mock } @@ -207,24 +229,17 @@ func (s *SdlMock) Get(ns string, keys []string) (map[string]interface{}, error) }` key = a1InstancePrefix + strconv.FormatInt(policytypeid, 10) + "." + string(policyInstanceID) } else if keys[0] == "a1.policy_type.20001" { - policySchemaString = `{"name":"admission_control_policy_mine", - "description":"various parameters to control admission of dual connection", - "policy_type_id": 20001, - "create_schema":{"$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": 1001, - "description": "% Connections to block"}, - "additionalProperties": false}}}` + policySchemaString = `{"create_schema":{"$schema":"http://json-schema.org/draft-07/schema#","properties":{"additionalProperties":false,"blocking_rate":{"default":10,"description":"% Connections to block","maximum":1001,"minimum":1,"type":"number"},"enforce":{"default":"true","type":"boolean"},"window_length":{"default":1,"description":"Sliding window length (in minutes)","maximum":60,"minimum":1,"type":"integer"}},"type":"object"},"description":"various parameters to control admission of dual connection","name":"admission_control_policy_mine","policy_type_id":20001}` key = a1PolicyPrefix + strconv.FormatInt((policytypeid), 10) } - a1.Logger.Error(" policy SchemaString %+v", policySchemaString) + a1.Logger.Debug(" policy SchemaString %+v", policySchemaString) policyTypeSchema, _ := json.Marshal((policySchemaString)) - a1.Logger.Error(" policyTypeSchema %+v", string(policyTypeSchema)) - a1.Logger.Error(" key for policy type %+v", key) - mp := map[string]interface{}{key: string(policyTypeSchema)} - a1.Logger.Error("Get Called and mp return %+v ", mp) + a1.Logger.Debug(" policyTypeSchema %+v", string(policyTypeSchema)) + + a1.Logger.Debug(" key for policy type %+v", key) + mp := map[string]interface{}{key: string(policySchemaString)} + a1.Logger.Debug("Get Called and mp return %+v ", mp) + return mp, nil } @@ -241,3 +256,13 @@ func (s *SdlMock) SetIf(ns string, key string, oldData, newData interface{}) (bo args := s.MethodCalled("SetIfNotExists", ns, key, oldData, newData) return args.Bool(0), args.Error(1) } + +func (rmr *RmrSenderMock) RmrSendToXapp(httpBodyString string) bool { + args := rmr.MethodCalled("RmrSendToXapp", httpBodyString) + return args.Bool(0) +} + +func (s *SdlMock) Remove(ns string, keys []string) error { + args := s.MethodCalled("Remove", ns, keys) + return args.Error(0) +}