+func TestGetPolicyType(t *testing.T) {
+
+ policyTypeId := models.PolicyTypeID(20001)
+
+ resp := rh.GetPolicyType(policyTypeId)
+
+ 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
+ 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":100,"description": "% Connections to block",},"additionalProperties": false,},}`
+ policyTypeSchema.CreateSchema = schema
+ key := a1PolicyPrefix + strconv.FormatInt((int64(policyTypeId)), 10)
+
+ //Setup Expectations
+ sdlInst.On("Get", a1MediatorNs, policyTypeId).Return(map[string]interface{}{key: policyTypeSchema}, nil)
+
+ assert.NotNil(t, resp)
+
+ sdlInst.AssertExpectations(t)
+
+}
+
+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 := a1PolicyPrefix + 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)
+}
+
+func TestCreatePolicyTypeInstance(t *testing.T) {
+ var policyTypeId models.PolicyTypeID
+ policyTypeId = 20001
+ var policyInstanceID models.PolicyInstanceID
+ policyInstanceID = "123456"
+ httpBody := `{
+ "enforce":true,
+ "window_length":20,
+ "blocking_rate":20,
+ "trigger_threshold":10
+ }`
+ instancekey := a1PolicyPrefix + strconv.FormatInt(20001, 10) + "." + string(policyInstanceID)
+ data, _ := json.Marshal(httpBody)
+ a1.Logger.Debug("Marshaled String : %+v", string(data))
+ a1.Logger.Debug("key : %+v", instancekey)
+
+ instancearr := []interface{}{instancekey, string(data)}
+ sdlInst.On("Set", "A1m_ns", instancearr).Return("CREATE", nil)
+ errresp := rh.CreatePolicyInstance(policyTypeId, policyInstanceID, httpBody)
+
+ assert.Nil(t, errresp)
+ sdlInst.AssertExpectations(t)
+}
+
+func TestGetPolicyInstance(t *testing.T) {
+
+ var policyTypeId models.PolicyTypeID
+ policyTypeId = 20001
+ var policyInstanceID models.PolicyInstanceID
+ policyInstanceID = "123456"
+ httpBody := `{
+ "enforce":true,
+ "window_length":20,
+ "blocking_rate":20,
+ "trigger_threshold":10
+ }`
+ instancekey := a1PolicyPrefix + strconv.FormatInt(20001, 10) + "." + string(policyInstanceID)
+ a1.Logger.Debug("httpBody String : %+v", httpBody)
+ a1.Logger.Debug("key : %+v", instancekey)
+ var keys [1]string
+ keys[0] = instancekey
+ //Setup Expectations
+ sdlInst.On("Get", a1MediatorNs, keys[:]).Return(httpBody, nil)
+
+ resp := rh.GetPolicyInstance(policyTypeId, policyInstanceID)
+ a1.Logger.Error("resp : %+v", resp)
+ assert.NotNil(t, resp)
+
+ sdlInst.AssertExpectations(t)
+}
+