From caf1b43ea3d5bf65fe1ac65aae9e4067da159dfa Mon Sep 17 00:00:00 2001 From: adragusin Date: Wed, 11 Mar 2020 15:46:16 +0200 Subject: [PATCH] Updated it tests in dispatchers --- apier/v1/api_interfaces.go | 2 +- apier/v1/dispatcher.go | 6 +- apier/v1/replicator.go | 4 +- data/tariffplans/dispatchers/Attributes.csv | 2 +- dispatchers/replicator.go | 6 +- dispatchers/replicator_it_test.go | 218 +++++++++++++++++++- engine/datamanager.go | 2 +- utils/consts.go | 2 +- 8 files changed, 229 insertions(+), 13 deletions(-) diff --git a/apier/v1/api_interfaces.go b/apier/v1/api_interfaces.go index a150099fe..5a4d7f503 100644 --- a/apier/v1/api_interfaces.go +++ b/apier/v1/api_interfaces.go @@ -184,7 +184,7 @@ type ReplicatorSv1Interface interface { GetResource(tntID *utils.TenantIDWithArgDispatcher, reply *engine.Resource) error GetResourceProfile(tntID *utils.TenantIDWithArgDispatcher, reply *engine.ResourceProfile) error GetActionTriggers(id *utils.StringWithApiKey, reply *engine.ActionTriggers) error - GetShareGroup(id *utils.StringWithApiKey, reply *engine.SharedGroup) error + GetSharedGroup(id *utils.StringWithApiKey, reply *engine.SharedGroup) error GetActions(id *utils.StringWithApiKey, reply *engine.Actions) error GetActionPlan(id *utils.StringWithApiKey, reply *engine.ActionPlan) error GetAllActionPlans(_ *utils.StringWithApiKey, reply *map[string]*engine.ActionPlan) error diff --git a/apier/v1/dispatcher.go b/apier/v1/dispatcher.go index 1bd627beb..0f2fc52a0 100755 --- a/apier/v1/dispatcher.go +++ b/apier/v1/dispatcher.go @@ -906,9 +906,9 @@ func (dS *DispatcherReplicatorSv1) GetActionTriggers(id *utils.StringWithApiKey, return dS.dS.ReplicatorSv1GetActionTriggers(id, reply) } -// GetShareGroup -func (dS *DispatcherReplicatorSv1) GetShareGroup(id *utils.StringWithApiKey, reply *engine.SharedGroup) error { - return dS.dS.ReplicatorSv1GetShareGroup(id, reply) +// GetSharedGroup +func (dS *DispatcherReplicatorSv1) GetSharedGroup(id *utils.StringWithApiKey, reply *engine.SharedGroup) error { + return dS.dS.ReplicatorSv1GetSharedGroup(id, reply) } // GetActions diff --git a/apier/v1/replicator.go b/apier/v1/replicator.go index 5445d10c2..74e37fb2b 100644 --- a/apier/v1/replicator.go +++ b/apier/v1/replicator.go @@ -157,8 +157,8 @@ func (rplSv1 *ReplicatorSv1) GetActionTriggers(id *utils.StringWithApiKey, reply return nil } -//GetShareGroup -func (rplSv1 *ReplicatorSv1) GetShareGroup(id *utils.StringWithApiKey, reply *engine.SharedGroup) error { +//GetSharedGroup +func (rplSv1 *ReplicatorSv1) GetSharedGroup(id *utils.StringWithApiKey, reply *engine.SharedGroup) error { if rcv, err := rplSv1.dm.DataDB().GetSharedGroupDrv(id.Arg); err != nil { return err } else { diff --git a/data/tariffplans/dispatchers/Attributes.csv b/data/tariffplans/dispatchers/Attributes.csv index cd3721409..08cf54d66 100644 --- a/data/tariffplans/dispatchers/Attributes.csv +++ b/data/tariffplans/dispatchers/Attributes.csv @@ -20,4 +20,4 @@ cgrates.org,ATTR_API_PSE_AUTH,*auth,*string:~*req.APIKey:pse12345,,,*req.APIMeth cgrates.org,ATTR_API_CFG_AUTH,*auth,*string:~*req.APIKey:cfg12345,,,*req.APIMethods,*constant,ConfigSv1.GetJSONSection&ConfigSv1.ReloadConfig,false,20 cgrates.org,ATTR_API_APIER_AUTH,*auth,*string:~*req.APIKey:apier12345,,,*req.APIMethods,*constant,APIerSv1.GetAttributeProfile&APIerSv1.SetAttributeProfile,false,20 cgrates.org,ATTR_API_RALS_AUTH,*auth,*string:~*req.APIKey:rals12345,,,*req.APIMethods,*constant,RALsV1.Ping&RALsV1.GetRatingPlansCost,false,20 -cgrates.org,ATTR_API_REPLICATOR_AUTH,*auth,*string:~*req.APIKey:repl12345,,,*req.APIMethods,*constant,ReplicatorSv1.Ping&ReplicatorSv1.GetAccount&ReplicatorSv1.SetAccount&ReplicatorSv1.RemoveAccount&ReplicatorSv1.GetSupplierProfile&ReplicatorSv1.SetSupplierProfile&ReplicatorSv1.RemoveSupplierProfile&ReplicatorSv1.GetAttributeProfile&ReplicatorSv1.SetAttributeProfile&ReplicatorSv1.RemoveAttributeProfile&ReplicatorSv1.SetChargerProfile&ReplicatorSv1.GetChargerProfile&ReplicatorSv1.RemoveChargerProfile&ReplicatorSv1.GetDispatcherProfile&ReplicatorSv1.SetDispatcherProfile&ReplicatorSv1.RemoveDispatcherProfile&ReplicatorSv1.GetDispatcherHost&ReplicatorSv1.SetDispatcherHost&ReplicatorSv1.RemoveDispatcherHost&ReplicatorSv1.GetFilter&ReplicatorSv1.SetFilter&ReplicatorSv1.RemoveFilter&ReplicatorSv1.GetThreshold&ReplicatorSv1.SetThreshold&ReplicatorSv1.RemoveThreshold&ReplicatorSv1.GetStatQueue&ReplicatorSv1.SetStatQueue&ReplicatorSv1.RemoveStatQueue&ReplicatorSv1.GetResource&ReplicatorSv1.SetResource&ReplicatorSv1.RemoveResource&ReplicatorSv1.GetResourceProfile&ReplicatorSv1.SetResourceProfile&ReplicatorSv1.RemoveResourceProfile&ReplicatorSv1.GetStatQueueProfile&ReplicatorSv1.SetStatQueueProfile&ReplicatorSv1.RemoveStatQueueProfile&ReplicatorSv1.GetThresholdProfile&ReplicatorSv1.SetThresholdProfile&ReplicatorSv1.RemoveThresholdProfile&ReplicatorSv1.GetTiming&ReplicatorSv1.SetTiming&ReplicatorSv1.RemoveTiming&ReplicatorSv1.GetActionTriggers&ReplicatorSv1.SetActionTriggers&ReplicatorSv1.RemoveActionTriggers,false,20 +cgrates.org,ATTR_API_REPLICATOR_AUTH,*auth,*string:~*req.APIKey:repl12345,,,*req.APIMethods,*constant,ReplicatorSv1.Ping&ReplicatorSv1.GetAccount&ReplicatorSv1.SetAccount&ReplicatorSv1.RemoveAccount&ReplicatorSv1.GetSupplierProfile&ReplicatorSv1.SetSupplierProfile&ReplicatorSv1.RemoveSupplierProfile&ReplicatorSv1.GetAttributeProfile&ReplicatorSv1.SetAttributeProfile&ReplicatorSv1.RemoveAttributeProfile&ReplicatorSv1.SetChargerProfile&ReplicatorSv1.GetChargerProfile&ReplicatorSv1.RemoveChargerProfile&ReplicatorSv1.GetDispatcherProfile&ReplicatorSv1.SetDispatcherProfile&ReplicatorSv1.RemoveDispatcherProfile&ReplicatorSv1.GetDispatcherHost&ReplicatorSv1.SetDispatcherHost&ReplicatorSv1.RemoveDispatcherHost&ReplicatorSv1.GetFilter&ReplicatorSv1.SetFilter&ReplicatorSv1.RemoveFilter&ReplicatorSv1.GetThreshold&ReplicatorSv1.SetThreshold&ReplicatorSv1.RemoveThreshold&ReplicatorSv1.GetStatQueue&ReplicatorSv1.SetStatQueue&ReplicatorSv1.RemoveStatQueue&ReplicatorSv1.GetResource&ReplicatorSv1.SetResource&ReplicatorSv1.RemoveResource&ReplicatorSv1.GetResourceProfile&ReplicatorSv1.SetResourceProfile&ReplicatorSv1.RemoveResourceProfile&ReplicatorSv1.GetStatQueueProfile&ReplicatorSv1.SetStatQueueProfile&ReplicatorSv1.RemoveStatQueueProfile&ReplicatorSv1.GetThresholdProfile&ReplicatorSv1.SetThresholdProfile&ReplicatorSv1.RemoveThresholdProfile&ReplicatorSv1.GetTiming&ReplicatorSv1.SetTiming&ReplicatorSv1.RemoveTiming&ReplicatorSv1.GetActionTriggers&ReplicatorSv1.SetActionTriggers&ReplicatorSv1.RemoveActionTriggers&ReplicatorSv1.SetSharedGroup&ReplicatorSv1.GetSharedGroup&ReplicatorSv1.RemoveSharedGroup&ReplicatorSv1.SetActions&ReplicatorSv1.GetActions&ReplicatorSv1.RemoveActions&ReplicatorSv1.SetActionPlan&ReplicatorSv1.GetActionPlan&ReplicatorSv1.RemoveActionPlan&ReplicatorSv1.SetAccountActionPlans&ReplicatorSv1.GetAccountActionPlans&ReplicatorSv1.RemAccountActionPlans,false,20 diff --git a/dispatchers/replicator.go b/dispatchers/replicator.go index e70c977ae..7a7f374a9 100644 --- a/dispatchers/replicator.go +++ b/dispatchers/replicator.go @@ -304,7 +304,7 @@ func (dS *DispatcherService) ReplicatorSv1GetActionTriggers(args *utils.StringWi utils.ReplicatorSv1GetActionTriggers, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1GetShareGroup(args *utils.StringWithApiKey, rpl *engine.SharedGroup) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetSharedGroup(args *utils.StringWithApiKey, rpl *engine.SharedGroup) (err error) { if args == nil { args = &utils.StringWithApiKey{} } @@ -313,7 +313,7 @@ func (dS *DispatcherService) ReplicatorSv1GetShareGroup(args *utils.StringWithAp if args.ArgDispatcher == nil { return utils.NewErrMandatoryIeMissing(utils.ArgDispatcherField) } - if err = dS.authorize(utils.ReplicatorSv1GetShareGroup, args.TenantArg.Tenant, + if err = dS.authorize(utils.ReplicatorSv1GetSharedGroup, args.TenantArg.Tenant, args.APIKey, utils.TimePointer(time.Now())); err != nil { return } @@ -323,7 +323,7 @@ func (dS *DispatcherService) ReplicatorSv1GetShareGroup(args *utils.StringWithAp routeID = args.ArgDispatcher.RouteID } return dS.Dispatch(&utils.CGREvent{Tenant: args.TenantArg.Tenant}, utils.MetaReplicator, routeID, - utils.ReplicatorSv1GetShareGroup, args, rpl) + utils.ReplicatorSv1GetSharedGroup, args, rpl) } func (dS *DispatcherService) ReplicatorSv1GetActions(args *utils.StringWithApiKey, rpl *engine.Actions) (err error) { diff --git a/dispatchers/replicator_it_test.go b/dispatchers/replicator_it_test.go index 544908a39..5b57641ed 100644 --- a/dispatchers/replicator_it_test.go +++ b/dispatchers/replicator_it_test.go @@ -44,6 +44,10 @@ var sTestsDspRpl = []func(t *testing.T){ testDspRplResourceProfile, testDspRplTiming, testDspRplActionTriggers, + testDspRplSharedGroup, + // testDspRplActions, + testDspRplActionPlan, + // testDspRplAccountActionPlans, } //Test start here @@ -179,7 +183,6 @@ func testDspRplAccount(t *testing.T) { if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetAccount, argsGetAccount, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } - } func testDspRplSupplierProfile(t *testing.T) { @@ -981,3 +984,216 @@ func testDspRplActionTriggers(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } + +func testDspRplSharedGroup(t *testing.T) { + // Set SharedGroup + var replyStr string + setSharedGroup := &engine.SharedGroupWithArgDispatcher{ + SharedGroup: &engine.SharedGroup{ + Id: "IDSharedGroup", + }, + ArgDispatcher: &utils.ArgDispatcher{ + APIKey: utils.StringPointer("repl12345")}, + } + if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetSharedGroup, setSharedGroup, &replyStr); err != nil { + t.Error("Unexpected error when calling ReplicatorSv1.SetSharedGroup: ", err) + } else if replyStr != utils.OK { + t.Error("Unexpected reply returned", replyStr) + } + // Get SharedGroup + var reply engine.SharedGroup + argsSharedGroup := &utils.StringWithApiKey{ + Arg: "IDSharedGroup", + TenantArg: utils.TenantArg{ + Tenant: "cgrates.org", + }, + ArgDispatcher: &utils.ArgDispatcher{ + APIKey: utils.StringPointer("repl12345")}, + } + if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetSharedGroup, argsSharedGroup, &reply); err != nil { + t.Error("Unexpected error when calling ReplicatorSv1.GetSharedGroup: ", err) + } else if reply.Id != setSharedGroup.Id { + t.Errorf("Expecting: %+v, received: %+v", setSharedGroup.Id, reply.Id) + } + // Stop engine 1 + allEngine.stopEngine(t) + + // Get SharedGroup + if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetSharedGroup, argsSharedGroup, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) + } + + // Start engine 1 + allEngine.startEngine(t) + + // Remove SharedGroup + if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveSharedGroup, argsSharedGroup, &replyStr); err != nil { + t.Error(err) + } else if replyStr != utils.OK { + t.Error("Unexpected reply returned", replyStr) + } + + // Get SharedGroup + if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetSharedGroup, argsSharedGroup, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) + } +} + +func testDspRplActions(t *testing.T) { + // Set Actions + var replyStr string + setActions := &engine.SetActionsArgsWithArgDispatcher{ + Key: "KeyActions", + TenantArg: utils.TenantArg{Tenant: "cgrates.org"}, + ArgDispatcher: &utils.ArgDispatcher{ + APIKey: utils.StringPointer("repl12345")}, + } + if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetActions, setActions, &replyStr); err != nil { + t.Error("Unexpected error when calling ReplicatorSv1.SetActions: ", err) + } else if replyStr != utils.OK { + t.Error("Unexpected reply returned", replyStr) + } + // Get Actions + var reply engine.Actions + argsActions := &utils.StringWithApiKey{ + Arg: "KeyActions", + TenantArg: utils.TenantArg{ + Tenant: "cgrates.org", + }, + ArgDispatcher: &utils.ArgDispatcher{ + APIKey: utils.StringPointer("repl12345")}, + } + if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActions, argsActions, &reply); err != nil { + t.Error("Unexpected error when calling ReplicatorSv1.GetActions: ", err) + } else if reply[0].Id != setActions.Key { + t.Errorf("Expecting: %+v, received: %+v", setActions.Key, reply[0].Id) + } + // Stop engine 1 + allEngine.stopEngine(t) + + // Get Actions + if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActions, argsActions, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) + } + + // Start engine 1 + allEngine.startEngine(t) + + // Remove Actions + if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveActions, argsActions, &replyStr); err != nil { + t.Error(err) + } else if replyStr != utils.OK { + t.Error("Unexpected reply returned", replyStr) + } + + // Get Actions + if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActions, argsActions, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) + } +} + +func testDspRplActionPlan(t *testing.T) { + // Set ActionPlan + var replyStr string + setActionPlan := &engine.SetActionPlanArgWithArgDispatcher{ + Key: "KeyActionPlan", + TenantArg: utils.TenantArg{Tenant: "cgrates.org"}, + ArgDispatcher: &utils.ArgDispatcher{ + APIKey: utils.StringPointer("repl12345")}, + } + if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetActionPlan, setActionPlan, &replyStr); err != nil { + t.Error("Unexpected error when calling ReplicatorSv1.SetActionPlan: ", err) + } else if replyStr != utils.OK { + t.Error("Unexpected reply returned", replyStr) + } + // Get ActionPlan + var reply engine.ActionPlan + argsActionPlan := &utils.StringWithApiKey{ + Arg: "KeyActionPlan", + TenantArg: utils.TenantArg{ + Tenant: "cgrates.org", + }, + ArgDispatcher: &utils.ArgDispatcher{ + APIKey: utils.StringPointer("repl12345")}, + } + if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActionPlan, argsActionPlan, &reply); err != nil { + t.Error("Unexpected error when calling ReplicatorSv1.GetActionPlan: ", err) + } else if reply.Id != setActionPlan.Key { + t.Errorf("Expecting: %+v, received: %+v", setActionPlan.Key, reply.Id) + } + // Stop engine 1 + allEngine.stopEngine(t) + + // Get ActionPlan + if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActionPlan, argsActionPlan, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) + } + + // Start engine 1 + allEngine.startEngine(t) + + // Remove ActionPlan + if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveActionPlan, argsActionPlan, &replyStr); err != nil { + t.Error(err) + } else if replyStr != utils.OK { + t.Error("Unexpected reply returned", replyStr) + } + + // Get ActionPlan + if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActionPlan, argsActionPlan, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) + } +} + +func testDspRplAccountActionPlans(t *testing.T) { + // Set AccountActionPlans + var replyStr string + setAccountActionPlans := &engine.SetAccountActionPlansArgWithArgDispatcher{ + AcntID: "KeyAccountActionPlans", + TenantArg: utils.TenantArg{Tenant: "cgrates.org"}, + ArgDispatcher: &utils.ArgDispatcher{ + APIKey: utils.StringPointer("repl12345")}, + } + if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetAccountActionPlans, setAccountActionPlans, &replyStr); err != nil { + t.Error("Unexpected error when calling ReplicatorSv1.SetAccountActionPlans: ", err) + } else if replyStr != utils.OK { + t.Error("Unexpected reply returned", replyStr) + } + // Get AccountActionPlans + var reply []string + argsAccountActionPlans := &utils.StringWithApiKey{ + Arg: "KeyAccountActionPlans", + TenantArg: utils.TenantArg{ + Tenant: "cgrates.org", + }, + ArgDispatcher: &utils.ArgDispatcher{ + APIKey: utils.StringPointer("repl12345")}, + } + if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetAccountActionPlans, argsAccountActionPlans, &reply); err != nil { + t.Error("Unexpected error when calling ReplicatorSv1.GetAccountActionPlans: ", err) + } else if reply[0] != setAccountActionPlans.AcntID { + t.Errorf("Expecting: %+v, received: %+v", setAccountActionPlans.AcntID, reply[0]) + } + // Stop engine 1 + allEngine.stopEngine(t) + + // Get AccountActionPlans + if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetAccountActionPlans, argsAccountActionPlans, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) + } + + // Start engine 1 + allEngine.startEngine(t) + + // Remove AccountActionPlans + if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemAccountActionPlans, argsAccountActionPlans, &replyStr); err != nil { + t.Error(err) + } else if replyStr != utils.OK { + t.Error("Unexpected reply returned", replyStr) + } + + // Get AccountActionPlans + if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetAccountActionPlans, argsAccountActionPlans, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) + } +} diff --git a/engine/datamanager.go b/engine/datamanager.go index 4ef8d605c..8f36e870b 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -1376,7 +1376,7 @@ func (dm *DataManager) GetSharedGroup(key string, skipCache bool, if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaSharedGroups]; err == utils.ErrNotFound && itm.Remote { if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, - utils.ReplicatorSv1GetShareGroup, &utils.StringWithApiKey{ + utils.ReplicatorSv1GetSharedGroup, &utils.StringWithApiKey{ Arg: key, TenantArg: utils.TenantArg{Tenant: config.CgrConfig().GeneralCfg().DefaultTenant}, ArgDispatcher: &utils.ArgDispatcher{ diff --git a/utils/consts.go b/utils/consts.go index 375dae047..95996d3d0 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -954,7 +954,7 @@ const ( ReplicatorSv1GetResource = "ReplicatorSv1.GetResource" ReplicatorSv1GetResourceProfile = "ReplicatorSv1.GetResourceProfile" ReplicatorSv1GetActionTriggers = "ReplicatorSv1.GetActionTriggers" - ReplicatorSv1GetShareGroup = "ReplicatorSv1.GetShareGroup" + ReplicatorSv1GetSharedGroup = "ReplicatorSv1.GetSharedGroup" ReplicatorSv1GetActions = "ReplicatorSv1.GetActions" ReplicatorSv1GetActionPlan = "ReplicatorSv1.GetActionPlan" ReplicatorSv1GetAllActionPlans = "ReplicatorSv1.GetAllActionPlans"