diff --git a/apier/v1/dispatcher_it_test.go b/apier/v1/dispatcher_it_test.go index 5c23c78ea..4e2e24f83 100644 --- a/apier/v1/dispatcher_it_test.go +++ b/apier/v1/dispatcher_it_test.go @@ -85,7 +85,6 @@ func testDispatcherSInitCfg(t *testing.T) { t.Error(err) } dispatcherCfg.DataFolderPath = *dataDir - config.SetCgrConfig(dispatcherCfg) } func testDispatcherSInitDataDb(t *testing.T) { diff --git a/data/tariffplans/dispatchers/Attributes.csv b/data/tariffplans/dispatchers/Attributes.csv index c216b2427..fd6a7b575 100644 --- a/data/tariffplans/dispatchers/Attributes.csv +++ b/data/tariffplans/dispatchers/Attributes.csv @@ -13,4 +13,5 @@ cgrates.org,ATTR_API_RSP_AUTH,*auth,*string:~APIKey:rsp12345,,,APIMethods,*const cgrates.org,ATTR_API_CHC_AUTH,*auth,*string:~APIKey:chc12345,,,APIMethods,*constant,CacheSv1.Ping&CacheSv1.GetCacheStats&CacheSv1.LoadCache&CacheSv1.PrecacheStatus&CacheSv1.GetItemIDs&CacheSv1.HasItem&CacheSv1.GetItemExpiryTime&CacheSv1.ReloadCache&CacheSv1.RemoveItem&CacheSv1.FlushCache&CacheSv1.Clear,false,20 cgrates.org,ATTR_API_GRD_AUTH,*auth,*string:~APIKey:grd12345,,,APIMethods,*constant,GuardianSv1.Ping&GuardianSv1.RemoteLock&GuardianSv1.RemoteUnlock,false,20 cgrates.org,ATTR_API_SCHD_AUTH,*auth,*string:~APIKey:sched12345,,,APIMethods,*constant,SchedulerSv1.Ping,false,20 -cgrates.org,ATTR_API_CDRS_AUTH,*auth,*string:~APIKey:cdrs12345,,,APIMethods,*constant,CDRsV1.Ping,false,20 \ No newline at end of file +cgrates.org,ATTR_API_CDRS_AUTH,*auth,*string:~APIKey:cdrs12345,,,APIMethods,*constant,CDRsV1.Ping,false,20 +cgrates.org,ATTR_API_DSP_AUTH,*auth,*string:~APIKey:dsp12345,,,APIMethods,*constant,DispatcherSv1.Ping&DispatcherSv1.GetProfileForEvent,false,20 \ No newline at end of file diff --git a/dispatchers/dispatchersv1_it_test.go b/dispatchers/dispatchersv1_it_test.go new file mode 100644 index 000000000..8c4b7741d --- /dev/null +++ b/dispatchers/dispatchersv1_it_test.go @@ -0,0 +1,102 @@ +// +build integration + +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +package dispatchers + +import ( + "path" + "reflect" + "testing" + "time" + + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +var sTestsDspDspv1 = []func(t *testing.T){ + testDspDspv1GetProfileForEvent, +} + +//Test start here +func TestDspDspv1SMySQL(t *testing.T) { + engine.KillEngine(0) + dispEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "dispatchers"), true, true) + dispEngine.loadData2(t, path.Join(dspDataDir, "tariffplans", "dispatchers")) + time.Sleep(500 * time.Millisecond) + for _, stest := range sTestsDspDspv1 { + t.Run("TestDspDspv1", stest) + } + dispEngine.stopEngine(t) + engine.KillEngine(0) +} + +func TestDspDspv1SMongo(t *testing.T) { + engine.KillEngine(0) + dispEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "dispatchers_mongo"), true, true) + dispEngine.loadData2(t, path.Join(dspDataDir, "tariffplans", "dispatchers")) + time.Sleep(500 * time.Millisecond) + for _, stest := range sTestsDspDspv1 { + t.Run("TestDspDspv1", stest) + } + dispEngine.stopEngine(t) + engine.KillEngine(0) +} + +func testDspDspv1GetProfileForEvent(t *testing.T) { + arg := DispatcherEvent{ + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + ID: "testDspv1", + Event: map[string]interface{}{ + utils.EVENT_NAME: "Event1", + }, + }, + Subsystem: utils.META_ANY, + } + var reply engine.DispatcherProfile + expected := engine.DispatcherProfile{ + Tenant: "cgrates.org", + ID: "EVENT1", + Subsystems: []string{utils.META_ANY}, + FilterIDs: []string{"*string:~EventName:Event1"}, + StrategyParams: make(map[string]interface{}), + Strategy: utils.MetaWeight, + Weight: 30, + Hosts: engine.DispatcherHostProfiles{ + &engine.DispatcherHostProfile{ + ID: "ALL2", + FilterIDs: []string{}, + Weight: 20, + Params: make(map[string]interface{}), + }, + &engine.DispatcherHostProfile{ + ID: "ALL", + FilterIDs: []string{}, + Weight: 10, + Params: make(map[string]interface{}), + }, + }, + } + if err := dispEngine.RCP.Call(utils.DispatcherSv1GetProfileForEvent, &arg, &reply); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(expected, reply) { + t.Errorf("expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(reply)) + } +}