+func TestSetPolicyInstanceFail(t *testing.T) {
+ var policyTypeId int
+ policyTypeId = 0
+ policyInstanceID := ""
+ var status string
+ status = "NOK"
+ sdlInst.On("Set", "A1m_ns", mock.Anything).Return(errors.New("Some Error"))
+ errresp := pm.SetPolicyInstanceStatus(policyTypeId, policyInstanceID, status)
+ a1.Logger.Debug("err from set test : %+v", errresp)
+ assert.Error(t, errresp)
+ sdlInst.AssertExpectations(t)
+}
+
+func TestGetPolicyInstance(t *testing.T) {
+
+ var policyTypeId models.PolicyTypeID
+ policyTypeId = 20001
+ var policyInstanceID models.PolicyInstanceID
+ policyInstanceID = "123456"
+ policyString := "testval"
+ typekey := a1PolicyPrefix + strconv.FormatInt((int64(policyTypeId)), 10)
+ a1.Logger.Debug("policyString String : %+v", policyString)
+ a1.Logger.Debug("typekey from get test : %+v", typekey)
+ var keys [1]string
+ keys[0] = typekey
+ testmp1 := map[string]interface{}{typekey: string(policyString)}
+ //Setup Expectations
+ sdlInst.On("Get", "A1m_ns", keys[:]).Return(testmp1, nil).Once()
+ instancekey := a1InstancePrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + string(policyInstanceID)
+ a1.Logger.Debug("policyString String : %+v", policyString)
+ a1.Logger.Debug("instancekey from get test : %+v", instancekey)
+ var instancekeys [1]string
+ instancekeys[0] = instancekey
+ testmp2 := map[string]interface{}{instancekey: string(policyString)}
+ //Setup Expectations
+ sdlInst.On("Get", "A1m_ns", instancekeys[:]).Return(testmp2, nil).Once()
+ resp, err := pm.GetPolicyInstance(policyTypeId, policyInstanceID)
+ a1.Logger.Debug("resp from get test : %+v", resp)
+ a1.Logger.Debug("err from get test : %+v", err)
+ //sdlInst.AssertExpectations(t)
+ assert.NoError(t, err)
+ assert.NotNil(t, resp)
+ sdlInst.AssertExpectations(t)
+}
+
+func TestGetPolicyInstanceFail1(t *testing.T) {
+ var policyTypeId models.PolicyTypeID
+ policyTypeId = 20009
+ var policyInstanceID models.PolicyInstanceID
+ policyInstanceID = "123"
+ policyString := "testval"
+ typekey := a1PolicyPrefix + strconv.FormatInt((int64(policyTypeId)), 10)
+ a1.Logger.Debug("policyString String : %+v", policyString)
+ a1.Logger.Debug("typekey from get test : %+v", typekey)
+ var keys [1]string
+ keys[0] = typekey
+ testmp1 := map[string]interface{}{typekey: string(policyString)}
+ //Setup Expectations
+ sdlInst.On("Get", "A1m_ns", keys[:]).Return(testmp1,errors.New("Some Error")).Once()
+ resp, err := pm.GetPolicyInstance(policyTypeId, policyInstanceID)
+ a1.Logger.Debug("resp from get test : %+v", resp)
+ a1.Logger.Debug("err from get test : %+v", err)
+ //sdlInst.AssertExpectations(t)
+ assert.Nil(t, resp)
+ assert.NotNil(t, err)
+ sdlInst.AssertExpectations(t)
+
+}
+func TestGetPolicyInstanceFail2(t *testing.T) {
+ var policyTypeId models.PolicyTypeID
+ policyTypeId = 20009
+ var policyInstanceID models.PolicyInstanceID
+ policyInstanceID = "123"
+ policyString := "testval"
+ typekey := a1PolicyPrefix + strconv.FormatInt((int64(policyTypeId)), 10)
+ a1.Logger.Debug("policyString String : %+v", policyString)
+ a1.Logger.Debug("typekey from get test : %+v", typekey)
+ var keys [1]string
+ keys[0] = typekey
+ testmp1 := map[string]interface{}{typekey: string(policyString)}
+ //Setup Expectations
+ sdlInst.On("Get", "A1m_ns", keys[:]).Return(testmp1,nil).Once()
+ resp, err := pm.GetPolicyInstance(policyTypeId, policyInstanceID)
+ a1.Logger.Debug("resp from get test : %+v", resp)
+ a1.Logger.Debug("err from get test : %+v", err)
+ //sdlInst.AssertExpectations(t)
+ assert.Nil(t, resp)
+ assert.NotNil(t, err)
+ sdlInst.AssertExpectations(t)
+}
+
+func TestGetPolicyInstanceFail3(t *testing.T) {
+
+ var policyTypeId models.PolicyTypeID
+ policyTypeId = 20001
+ var policyInstanceID models.PolicyInstanceID
+ policyInstanceID = "123456"
+ policyString := "testval"
+ typekey := a1PolicyPrefix + strconv.FormatInt((int64(policyTypeId)), 10)
+ a1.Logger.Debug("policyString String : %+v", policyString)
+ a1.Logger.Debug("typekey from get test : %+v", typekey)
+ var keys [1]string
+ keys[0] = typekey
+ testmp1 := map[string]interface{}{typekey: string(policyString)}
+ //Setup Expectations
+ sdlInst.On("Get", "A1m_ns", keys[:]).Return(testmp1, nil).Once()
+ instancekey := a1InstancePrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + string(policyInstanceID)
+ a1.Logger.Debug("policyString String : %+v", policyString)
+ a1.Logger.Debug("instancekey from get test : %+v", instancekey)
+ var instancekeys [1]string
+ instancekeys[0] = instancekey
+ testmp2 := map[string]interface{}{instancekey: string(policyString)}
+ //Setup Expectations
+ sdlInst.On("Get", "A1m_ns", instancekeys[:]).Return(testmp2,errors.New("Some Error")).Once()
+ resp, err := pm.GetPolicyInstance(policyTypeId, policyInstanceID)
+ a1.Logger.Debug("resp from get test : %+v", resp)
+ a1.Logger.Debug("err from get test : %+v", err)
+ //sdlInst.AssertExpectations(t)
+ assert.NotNil(t, err)
+ sdlInst.AssertExpectations(t)
+}
+
+func TestGetPolicyInstanceStatus(t *testing.T) {
+ var policyTypeId int
+ policyTypeId = 20001
+ policyInstanceID := "123456"
+ policyString := "testval"
+ instancekey := a1HandlerPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + policyInstanceID
+ a1.Logger.Debug("policyString String : %+v", policyString)
+ a1.Logger.Debug("key from get test : %+v", instancekey)
+ var keys [1]string
+ keys[0] = instancekey
+ instancearr := []interface{}{instancekey, "OK"}
+ //Setup Expectations
+ sdlInst.On("Get", "A1m_ns", keys[:]).Return(instancearr, nil).Once()
+ resp, errresp := pm.GetPolicyInstanceStatus(policyTypeId, policyInstanceID)
+ a1.Logger.Debug("resp from get test : %+v", resp)
+ a1.Logger.Debug("errresp from get test : %+v", errresp)
+ assert.Nil(t, errresp)
+ assert.NotNil(t, resp)
+ sdlInst.AssertExpectations(t)
+}
+
+func TestGetPolicyInstanceStatusFail(t *testing.T) {
+ var policyTypeId int
+ policyTypeId = 200
+ policyInstanceID := "123"
+ policyString := "testval"
+ instancekey := a1HandlerPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + policyInstanceID
+ a1.Logger.Debug("policyString String : %+v", policyString)
+ a1.Logger.Debug("key from get test : %+v", instancekey)
+ var keys [1]string
+ keys[0] = instancekey
+ instancearr := []interface{}{instancekey, "NOK"}
+ //Setup Expectations
+ sdlInst.On("Get", "A1m_ns", keys[:]).Return(instancearr, errors.New("Some Error")).Once()
+ resp, errresp := pm.GetPolicyInstanceStatus(policyTypeId, policyInstanceID)
+ a1.Logger.Debug("resp from get test : %+v", resp)
+ a1.Logger.Debug("errresp from get test : %+v", errresp)
+ assert.NotNil(t, errresp)
+ sdlInst.AssertExpectations(t)
+}
+
+func TestSendPolicyStatusNotification(t *testing.T) {
+ var policyTypeId int
+ policyTypeId = 20001
+ policyInstanceID := "123456"
+ notificationDestinationkey := a1NotificationDestinationPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + fmt.Sprint(policyInstanceID)
+ urlString := "http://www.abc.com"
+ a1.Logger.Debug("Test: Calling key from get test : %+v", notificationDestinationkey)
+ keys := [1]string{notificationDestinationkey}
+ var status string
+ status = "OK"
+ notDes := map[string]interface{}{notificationDestinationkey: string(urlString)}
+ //Setup Expectations
+ sdlInst.On("Get", "A1m_ns", keys[:]).Return(notDes, nil).Once()
+ instancekey := a1HandlerPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + policyInstanceID
+ var instancekeys [1]string
+ instancekeys[0] = instancekey
+ instancearr := []interface{}{instancekey, "OK"}
+ //Setup Expectations
+ sdlInst.On("Get", "A1m_ns", instancekeys[:]).Return(instancearr, nil).Once()
+ err := pm.SendPolicyStatusNotification(policyTypeId,policyInstanceID,notificationDestinationkey,status)
+ assert.Nil(t, err)
+ sdlInst.AssertExpectations(t)
+}
+
+func TestSendPolicyStatusNotificationFail1(t *testing.T) {
+ var policyTypeId int
+ policyTypeId = 20000
+ policyInstanceID := "12345"
+ notificationDestinationkey := a1NotificationDestinationPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + fmt.Sprint(policyInstanceID)
+ urlString := "www.abc.com"
+ a1.Logger.Debug("Test: Calling key from get test : %+v", notificationDestinationkey)
+ keys := [1]string{notificationDestinationkey}
+ var status string
+ status = "OK"
+ notDes := map[string]interface{}{notificationDestinationkey: string(urlString)}
+ //Setup Expectations
+ sdlInst.On("Get", "A1m_ns", keys[:]).Return(notDes, errors.New("Some Error")).Once()
+ err := pm.SendPolicyStatusNotification(policyTypeId,policyInstanceID,notificationDestinationkey,status)
+ assert.NotNil(t, err)
+ sdlInst.AssertExpectations(t)
+}
+
+func TestSendPolicyStatusNotificationFail2(t *testing.T) {
+ var policyTypeId int
+ policyTypeId = 20001
+ policyInstanceID := "123456"
+ notificationDestinationkey := a1NotificationDestinationPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + fmt.Sprint(policyInstanceID)
+ urlString := "http://www.abc.com"
+ a1.Logger.Debug("Test: Calling key from get test : %+v", notificationDestinationkey)
+ keys := [1]string{notificationDestinationkey}
+ var status string
+ status = "OK"
+ notDes := map[string]interface{}{notificationDestinationkey: string(urlString)}
+ //Setup Expectations
+ sdlInst.On("Get", "A1m_ns", keys[:]).Return(notDes,nil).Once()
+ instancekey := a1HandlerPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + policyInstanceID
+ var instancekeys [1]string
+ instancekeys[0] = instancekey
+ instancearr := []interface{}{instancekey, "NOK"}
+ //Setup Expectations
+ sdlInst.On("Get", "A1m_ns", instancekeys[:]).Return(instancearr, errors.New("Some Error")).Once()
+ err := pm.SendPolicyStatusNotification(policyTypeId,policyInstanceID,notificationDestinationkey,status)
+ assert.NotNil(t, err)
+ sdlInst.AssertExpectations(t)
+}
+