From 529159cd0bba1aef51f65aa0ef05e7bb3d56ebf1 Mon Sep 17 00:00:00 2001 From: DanB Date: Mon, 11 Feb 2019 19:06:34 +0100 Subject: [PATCH] Updating integration tests with RatingProfiles.csv changes --- apier/v1/apier_it_test.go | 28 +++++----- apier/v1/precache_it_test.go | 2 +- apier/v1/resourcesv1_it_test.go | 2 +- apier/v1/smgenericv1_it_test.go | 2 +- apier/v1/tpratingprofiles.go | 3 +- apier/v2/cdrs_it_test.go | 7 +-- .../mysql/create_tariffplan_tables.sql | 5 +- .../postgres/create_tariffplan_tables.sql | 5 +- .../oldtutorial/RatingProfiles.csv | 17 ++---- .../osips_training/RatingProfiles.csv | 4 +- data/tariffplans/test/a1/RatingProfiles.csv | 4 +- .../destinations/cacheall/RatingProfiles.csv | 3 +- .../destinations/cacheone/RatingProfiles.csv | 3 +- .../destinations/multiid/RatingProfiles.csv | 4 +- data/tariffplans/testit/RatingProfiles.csv | 13 ++--- data/tariffplans/testtp/RatingProfiles.csv | 12 ++-- data/tariffplans/tutorial/RatingProfiles.csv | 10 ++-- engine/onstor_it_test.go | 14 ++--- engine/storage_sql.go | 20 +++++-- engine/stordb_it_test.go | 55 ++++++++++--------- general_tests/tut_smgeneric_it_test.go | 45 +-------------- migrator/tp_rating_profiles_it_test.go | 13 ++--- 22 files changed, 116 insertions(+), 155 deletions(-) diff --git a/apier/v1/apier_it_test.go b/apier/v1/apier_it_test.go index d3ccfff82..a2215ee41 100644 --- a/apier/v1/apier_it_test.go +++ b/apier/v1/apier_it_test.go @@ -390,7 +390,8 @@ func TestApierTPRatingPlan(t *testing.T) { // Test here TPRatingPlan APIs func TestApierTPRatingProfile(t *testing.T) { reply := "" - rpf := &utils.TPRatingProfile{TPid: utils.TEST_SQL, LoadId: utils.TEST_SQL, Tenant: "cgrates.org", Category: "call", Direction: "*out", Subject: "*any", + rpf := &utils.TPRatingProfile{TPid: utils.TEST_SQL, LoadId: utils.TEST_SQL, + Tenant: "cgrates.org", Category: "call", Subject: "*any", RatingPlanActivations: []*utils.TPRatingActivation{ {ActivationTime: "2012-01-01T00:00:00Z", RatingPlanId: "RETAIL1", FallbackSubjects: ""}, }} @@ -413,7 +414,7 @@ func TestApierTPRatingProfile(t *testing.T) { // Check missing params if err := rater.Call("ApierV1.SetTPRatingProfile", new(utils.TPRatingProfile), &reply); err == nil { t.Error("Calling ApierV1.SetTPRatingProfile, expected error, received: ", reply) - } else if err.Error() != "MANDATORY_IE_MISSING: [TPid LoadId Tenant Category Direction Subject RatingPlanActivations]" { + } else if err.Error() != "MANDATORY_IE_MISSING: [TPid LoadId Tenant Category Subject RatingPlanActivations]" { t.Error("Calling ApierV1.SetTPRatingProfile got unexpected error: ", err.Error()) } // Test get @@ -673,7 +674,9 @@ func TestApierLoadRatingPlan(t *testing.T) { // Test here LoadRatingProfile func TestApierLoadRatingProfile(t *testing.T) { reply := "" - rpf := &utils.TPRatingProfile{TPid: utils.TEST_SQL, LoadId: utils.TEST_SQL, Tenant: "cgrates.org", Category: "call", Direction: "*out", Subject: "*any"} + rpf := &utils.TPRatingProfile{ + TPid: utils.TEST_SQL, LoadId: utils.TEST_SQL, + Tenant: "cgrates.org", Category: "call", Subject: "*any"} if err := rater.Call("ApierV1.LoadRatingProfile", rpf, &reply); err != nil { t.Error("Got error on ApierV1.LoadRatingProfile: ", err.Error()) } else if reply != "OK" { @@ -723,7 +726,7 @@ func TestApierSetRatingProfile(t *testing.T) { reply := "" rpa := &utils.TPRatingActivation{ActivationTime: "2012-01-01T00:00:00Z", RatingPlanId: "RETAIL1", FallbackSubjects: "dan2"} rpf := &utils.AttrSetRatingProfile{Tenant: "cgrates.org", Category: "call", - Direction: "*out", Subject: "dan", RatingPlanActivations: []*utils.TPRatingActivation{rpa}} + Subject: "dan", RatingPlanActivations: []*utils.TPRatingActivation{rpa}} if err := rater.Call("ApierV1.SetRatingProfile", rpf, &reply); err != nil { t.Error("Got error on ApierV1.SetRatingProfile: ", err.Error()) } else if reply != "OK" { @@ -781,7 +784,8 @@ func TestApierSetRatingProfile(t *testing.T) { func TestApierV1GetRatingProfile(t *testing.T) { var rpl engine.RatingProfile - attrGetRatingPlan := &utils.AttrGetRatingProfile{Tenant: "cgrates.org", Category: "call", Direction: "*out", Subject: "dan"} + attrGetRatingPlan := &utils.AttrGetRatingProfile{ + Tenant: "cgrates.org", Category: "call", Subject: "dan"} actTime, err := utils.ParseTimeDetectLayout("2012-01-01T00:00:00Z", "") if err != nil { t.Error(err) @@ -790,16 +794,14 @@ func TestApierV1GetRatingProfile(t *testing.T) { Id: "*out:cgrates.org:call:dan", RatingPlanActivations: engine.RatingPlanActivations{ { - ActivationTime: actTime, - RatingPlanId: "RETAIL1", - FallbackKeys: []string{"*out:cgrates.org:call:dan2"}, - CdrStatQueueIds: nil, + ActivationTime: actTime, + RatingPlanId: "RETAIL1", + FallbackKeys: []string{"*out:cgrates.org:call:dan2"}, }, { - ActivationTime: actTime, - RatingPlanId: "RETAIL1", - FallbackKeys: []string{"*out:cgrates.org:call:dan2"}, - CdrStatQueueIds: nil, + ActivationTime: actTime, + RatingPlanId: "RETAIL1", + FallbackKeys: []string{"*out:cgrates.org:call:dan2"}, }, }, } diff --git a/apier/v1/precache_it_test.go b/apier/v1/precache_it_test.go index e9135769f..d66732758 100644 --- a/apier/v1/precache_it_test.go +++ b/apier/v1/precache_it_test.go @@ -360,7 +360,7 @@ func testPrecacheGetCacheStatsAfterRestart(t *testing.T) { Groups: 0, }, "rating_profiles": { - Items: 10, // expected to have 10 items + Items: 5, // expected to have 10 items Groups: 0, }, "resource_filter_indexes": { diff --git a/apier/v1/resourcesv1_it_test.go b/apier/v1/resourcesv1_it_test.go index 82eb9667e..ad051d949 100644 --- a/apier/v1/resourcesv1_it_test.go +++ b/apier/v1/resourcesv1_it_test.go @@ -679,7 +679,7 @@ func testV1RsGetResourceProfileAfterDelete(t *testing.T) { func testV1RsResourcePing(t *testing.T) { var resp string - if err := rlsV1Rpc.Call(utils.ResourceSv1Ping, "", &resp); err != nil { + if err := rlsV1Rpc.Call(utils.ResourceSv1Ping, new(utils.CGREvent), &resp); err != nil { t.Error(err) } else if resp != utils.Pong { t.Error("Unexpected reply returned", resp) diff --git a/apier/v1/smgenericv1_it_test.go b/apier/v1/smgenericv1_it_test.go index efe76f637..1200e45ef 100644 --- a/apier/v1/smgenericv1_it_test.go +++ b/apier/v1/smgenericv1_it_test.go @@ -99,7 +99,7 @@ func TestSMGV1CacheStats(t *testing.T) { t.Error(reply) } var rcvStats *utils.CacheStats - expectedStats := &utils.CacheStats{Destinations: 5, ReverseDestinations: 7, RatingPlans: 4, RatingProfiles: 10, + expectedStats := &utils.CacheStats{Destinations: 5, ReverseDestinations: 7, RatingPlans: 4, RatingProfiles: 5, Actions: 9, ActionPlans: 4, AccountActionPlans: 5, SharedGroups: 1, DerivedChargers: 1, Users: 3, Aliases: 1, ReverseAliases: 2, ResourceProfiles: 3, Resources: 3, StatQueues: 1, StatQueueProfiles: 1, Thresholds: 7, ThresholdProfiles: 7, Filters: 16, SupplierProfiles: 3, AttributeProfiles: 1} diff --git a/apier/v1/tpratingprofiles.go b/apier/v1/tpratingprofiles.go index f8087e1d1..bf89e0b20 100644 --- a/apier/v1/tpratingprofiles.go +++ b/apier/v1/tpratingprofiles.go @@ -27,7 +27,8 @@ import ( // Creates a new RatingProfile within a tariff plan func (self *ApierV1) SetTPRatingProfile(attrs utils.TPRatingProfile, reply *string) error { - if missing := utils.MissingStructFields(&attrs, []string{"TPid", "LoadId", "Tenant", "Category", "Direction", "Subject", "RatingPlanActivations"}); len(missing) != 0 { + if missing := utils.MissingStructFields(&attrs, + []string{"TPid", "LoadId", "Tenant", "Category", "Subject", "RatingPlanActivations"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } if err := self.StorDb.SetTPRatingProfiles([]*utils.TPRatingProfile{&attrs}); err != nil { diff --git a/apier/v2/cdrs_it_test.go b/apier/v2/cdrs_it_test.go index c4e338209..553dd1b41 100644 --- a/apier/v2/cdrs_it_test.go +++ b/apier/v2/cdrs_it_test.go @@ -202,10 +202,9 @@ func testV2CDRsGetCdrs(t *testing.T) { // Should re-rate the supplier1 cost with RP_ANY2CNT func testV2CDRsRateCDRs(t *testing.T) { rpf := &utils.AttrSetRatingProfile{ - Tenant: "cgrates.org", - Category: "call", - Direction: "*out", - Subject: "SUPPLIER1", + Tenant: "cgrates.org", + Category: "call", + Subject: "SUPPLIER1", RatingPlanActivations: []*utils.TPRatingActivation{ { ActivationTime: "2018-01-01T00:00:00Z", diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index a5d5c7724..01aba2494 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -116,7 +116,7 @@ CREATE TABLE `tp_rating_profiles` ( PRIMARY KEY (`id`), KEY `tpid` (`tpid`), KEY `tpid_loadid` (`tpid`, `loadid`), - UNIQUE KEY `tpid_loadid_tenant_category_dir_subj_atime` (`tpid`,`loadid`, `tenant`,`category`,`subject`,`activation_time`) + UNIQUE KEY `tpid_loadid_tenant_category_subj_atime` (`tpid`,`loadid`, `tenant`,`category`,`subject`,`activation_time`) ); -- @@ -205,7 +205,6 @@ CREATE TABLE `tp_action_triggers` ( `activation_time` varchar(26) NOT NULL, `balance_tag` varchar(64) NOT NULL, `balance_type` varchar(24) NOT NULL, - `balance_directions` varchar(8) NOT NULL, `balance_categories` varchar(32) NOT NULL, `balance_destination_tags` varchar(64) NOT NULL, `balance_rating_subject` varchar(64) NOT NULL, @@ -220,7 +219,7 @@ CREATE TABLE `tp_action_triggers` ( `created_at` TIMESTAMP, PRIMARY KEY (`id`), KEY `tpid` (`tpid`), - UNIQUE KEY `unique_trigger_definition` (`tpid`,`tag`,`balance_tag`,`balance_type`,`balance_directions`,`threshold_type`,`threshold_value`,`balance_destination_tags`,`actions_tag`) + UNIQUE KEY `unique_trigger_definition` (`tpid`,`tag`,`balance_tag`,`balance_type`,`threshold_type`,`threshold_value`,`balance_destination_tags`,`actions_tag`) ); -- diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index 209c2ecb5..67d41a85d 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -109,7 +109,7 @@ CREATE TABLE tp_rating_profiles ( rating_plan_tag VARCHAR(64) NOT NULL, fallback_subjects VARCHAR(64), created_at TIMESTAMP WITH TIME ZONE, - UNIQUE (tpid, loadid, tenant, category, direction, subject, activation_time) + UNIQUE (tpid, loadid, tenant, category, subject, activation_time) ); CREATE INDEX tpratingprofiles_tpid_idx ON tp_rating_profiles (tpid); CREATE INDEX tpratingprofiles_idx ON tp_rating_profiles (tpid,loadid,tenant,category,subject); @@ -200,7 +200,6 @@ CREATE TABLE tp_action_triggers ( activation_time VARCHAR(26) NOT NULL, balance_tag VARCHAR(64) NOT NULL, balance_type VARCHAR(24) NOT NULL, - balance_directions VARCHAR(8) NOT NULL, balance_categories VARCHAR(32) NOT NULL, balance_destination_tags VARCHAR(64) NOT NULL, balance_rating_subject VARCHAR(64) NOT NULL, @@ -213,7 +212,7 @@ CREATE TABLE tp_action_triggers ( actions_tag VARCHAR(64) NOT NULL, weight NUMERIC(8,2) NOT NULL, created_at TIMESTAMP WITH TIME ZONE, - UNIQUE (tpid, tag, balance_tag, balance_type, balance_directions, threshold_type, threshold_value, balance_destination_tags, actions_tag) + UNIQUE (tpid, tag, balance_tag, balance_type, threshold_type, threshold_value, balance_destination_tags, actions_tag) ); CREATE INDEX tpactiontrigers_tpid_idx ON tp_action_triggers (tpid); CREATE INDEX tpactiontrigers_idx ON tp_action_triggers (tpid,tag); diff --git a/data/tariffplans/oldtutorial/RatingProfiles.csv b/data/tariffplans/oldtutorial/RatingProfiles.csv index 04f768da5..5df325a5d 100644 --- a/data/tariffplans/oldtutorial/RatingProfiles.csv +++ b/data/tariffplans/oldtutorial/RatingProfiles.csv @@ -1,11 +1,6 @@ -#Direction,Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject,CdrStatQueueIds -*out,cgrates.org,call,*any,2014-01-14T00:00:00Z,RP_RETAIL1,, -*out,cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_RETAIL2,, -*out,cgrates.org,call,SPECIAL_1002,2014-01-14T00:00:00Z,RP_SPECIAL_1002,, -*out,cgrates.org,generic,*any,2014-01-14T00:00:00Z,RP_GENERIC,, -*out,cgrates.org,data,*any,2014-01-14T00:00:00Z,RP_GENERIC,, -*out,cgrates.org,lcr_profile1,suppl1,2014-01-14T00:00:00Z,RP_RETAIL1,,STATS_SUPPL1 -*out,cgrates.org,lcr_profile1,suppl2,2014-01-14T00:00:00Z,RP_RETAIL2,,STATS_SUPPL2 -*out,cgrates.org,lcr_profile2,suppl1,2014-01-14T00:00:00Z,RP_RETAIL2,,STATS_SUPPL1 -*out,cgrates.org,lcr_profile2,suppl2,2014-01-14T00:00:00Z,RP_RETAIL1,,STATS_SUPPL2 -*out,cgrates.org,lcr_profile2,suppl3,2014-01-14T00:00:00Z,RP_SPECIAL_1002,, \ No newline at end of file +#Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject +cgrates.org,call,*any,2014-01-14T00:00:00Z,RP_RETAIL1, +cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_RETAIL2, +cgrates.org,call,SPECIAL_1002,2014-01-14T00:00:00Z,RP_SPECIAL_1002, +cgrates.org,generic,*any,2014-01-14T00:00:00Z,RP_GENERIC, +cgrates.org,data,*any,2014-01-14T00:00:00Z,RP_GENERIC, \ No newline at end of file diff --git a/data/tariffplans/osips_training/RatingProfiles.csv b/data/tariffplans/osips_training/RatingProfiles.csv index f6290fd4e..6a35e2cfc 100644 --- a/data/tariffplans/osips_training/RatingProfiles.csv +++ b/data/tariffplans/osips_training/RatingProfiles.csv @@ -1,2 +1,2 @@ -#Direction,Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject,CdrStatQueueIds -*out,cgrates.org,call,*any,2016-08-01T00:00:00Z,RP_TRAINING1,, +#Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject +cgrates.org,call,*any,2016-08-01T00:00:00Z,RP_TRAINING1, diff --git a/data/tariffplans/test/a1/RatingProfiles.csv b/data/tariffplans/test/a1/RatingProfiles.csv index c72e83a99..870263b11 100644 --- a/data/tariffplans/test/a1/RatingProfiles.csv +++ b/data/tariffplans/test/a1/RatingProfiles.csv @@ -1,2 +1,2 @@ -#Direction,Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject,CdrStatQueueIds -*out,cgrates.org,data1,rpdata1,2015-01-01T00:00:00Z,RP_DATA1,, +#Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject +cgrates.org,data1,rpdata1,2015-01-01T00:00:00Z,RP_DATA1, diff --git a/data/tariffplans/test/destinations/cacheall/RatingProfiles.csv b/data/tariffplans/test/destinations/cacheall/RatingProfiles.csv index 63587a0a8..6cb45eae9 100644 --- a/data/tariffplans/test/destinations/cacheall/RatingProfiles.csv +++ b/data/tariffplans/test/destinations/cacheall/RatingProfiles.csv @@ -1 +1,2 @@ -*out,cgrates.org,call,test,2014-01-14T00:00:00Z,RPL_100x,, +#Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject +cgrates.org,call,test,2014-01-14T00:00:00Z,RPL_100x, diff --git a/data/tariffplans/test/destinations/cacheone/RatingProfiles.csv b/data/tariffplans/test/destinations/cacheone/RatingProfiles.csv index 63587a0a8..6cb45eae9 100644 --- a/data/tariffplans/test/destinations/cacheone/RatingProfiles.csv +++ b/data/tariffplans/test/destinations/cacheone/RatingProfiles.csv @@ -1 +1,2 @@ -*out,cgrates.org,call,test,2014-01-14T00:00:00Z,RPL_100x,, +#Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject +cgrates.org,call,test,2014-01-14T00:00:00Z,RPL_100x, diff --git a/data/tariffplans/test/destinations/multiid/RatingProfiles.csv b/data/tariffplans/test/destinations/multiid/RatingProfiles.csv index 9242632e1..5ed82b7c6 100644 --- a/data/tariffplans/test/destinations/multiid/RatingProfiles.csv +++ b/data/tariffplans/test/destinations/multiid/RatingProfiles.csv @@ -1,2 +1,2 @@ -#Direction,Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject,CdrStatQueueIds -*out,cgrates.org,call,*any,2012-01-01T00:00:00Z,RP_RETAIL,, \ No newline at end of file +#Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject +cgrates.org,call,*any,2012-01-01T00:00:00Z,RP_RETAIL, \ No newline at end of file diff --git a/data/tariffplans/testit/RatingProfiles.csv b/data/tariffplans/testit/RatingProfiles.csv index 0743bd6ae..dc9219188 100644 --- a/data/tariffplans/testit/RatingProfiles.csv +++ b/data/tariffplans/testit/RatingProfiles.csv @@ -1,7 +1,6 @@ -#Direction,Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject,CdrStatQueueIds -*out,cgrates.org,call,*any,2018-01-01T00:00:00Z,RP_TESTIT1,, -*out,cgrates.org,call,SPECIAL_1002,2014-01-14T00:00:00Z,RP_SPECIAL_1002,, -*out,cgrates.org,call,ANY2CNT,2018-01-01T00:00:00Z,RP_ANY2CNT,, -*out,cgrates.org,call,SUPPLIER1,2018-01-01T00:00:00Z,RP_ANY1CNT,, -*out,cgrates.org,Standard,TEST,2017-11-27T00:00:00Z,RP_TEST,, - +#Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject +cgrates.org,call,*any,2018-01-01T00:00:00Z,RP_TESTIT1, +cgrates.org,call,SPECIAL_1002,2014-01-14T00:00:00Z,RP_SPECIAL_1002, +cgrates.org,call,ANY2CNT,2018-01-01T00:00:00Z,RP_ANY2CNT, +cgrates.org,call,SUPPLIER1,2018-01-01T00:00:00Z,RP_ANY1CNT, +cgrates.org,Standard,TEST,2017-11-27T00:00:00Z,RP_TEST, diff --git a/data/tariffplans/testtp/RatingProfiles.csv b/data/tariffplans/testtp/RatingProfiles.csv index 3a6a28222..ad78f75d7 100644 --- a/data/tariffplans/testtp/RatingProfiles.csv +++ b/data/tariffplans/testtp/RatingProfiles.csv @@ -1,6 +1,6 @@ -#Direction,Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject,CdrStatQueueIds -*out,cgrates.org,call,*any,2012-01-01T00:00:00Z,RP_RETAIL,, -*out,cgrates.org,data,*any,2012-01-01T00:00:00Z,RP_DATA1,, -*out,cgrates.org,sms,*any,2012-01-01T00:00:00Z,RP_SMS1,, -*out,cgrates.org,data,datar,2016-01-01T00:00:00Z,RP_DATAr,, -*out,cgrates.org,call,free,2016-01-01T00:00:00Z,RP_FREE,, +#Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject +cgrates.org,call,*any,2012-01-01T00:00:00Z,RP_RETAIL, +cgrates.org,data,*any,2012-01-01T00:00:00Z,RP_DATA1, +cgrates.org,sms,*any,2012-01-01T00:00:00Z,RP_SMS1, +cgrates.org,data,datar,2016-01-01T00:00:00Z,RP_DATAr, +cgrates.org,call,free,2016-01-01T00:00:00Z,RP_FREE, diff --git a/data/tariffplans/tutorial/RatingProfiles.csv b/data/tariffplans/tutorial/RatingProfiles.csv index bc6e99448..b5b64723e 100644 --- a/data/tariffplans/tutorial/RatingProfiles.csv +++ b/data/tariffplans/tutorial/RatingProfiles.csv @@ -1,5 +1,5 @@ -#Direction,Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject,CdrStatQueueIds -*out,cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_1001,, -*out,cgrates.org,call,1002,2014-01-14T00:00:00Z,RP_1002,, -*out,cgrates.org,call,1003,2014-01-14T00:00:00Z,RP_1003,, -*out,cgrates.org,sms,*any,2014-01-14T00:00:00Z,RP_SMS,, +#Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject +cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_1001, +cgrates.org,call,1002,2014-01-14T00:00:00Z,RP_1002, +cgrates.org,call,1003,2014-01-14T00:00:00Z,RP_1003, +cgrates.org,sms,*any,2014-01-14T00:00:00Z,RP_SMS, diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index 423f858b6..c88be227a 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -678,10 +678,9 @@ func testOnStorITRatingProfile(t *testing.T) { Id: "*out:test:1:trp", RatingPlanActivations: RatingPlanActivations{ &RatingPlanActivation{ - ActivationTime: time.Date(2013, 10, 1, 0, 0, 0, 0, time.UTC), - RatingPlanId: "TDRT", - FallbackKeys: []string{"*out:test:1:danb", "*out:test:1:rif"}, - CdrStatQueueIds: []string{}, + ActivationTime: time.Date(2013, 10, 1, 0, 0, 0, 0, time.UTC), + RatingPlanId: "TDRT", + FallbackKeys: []string{"*out:test:1:danb", "*out:test:1:rif"}, }}, } if _, rcvErr := onStor.GetRatingProfile(rpf.Id, false, @@ -716,10 +715,9 @@ func testOnStorITRatingProfile(t *testing.T) { //update rpf.RatingPlanActivations = RatingPlanActivations{ &RatingPlanActivation{ - ActivationTime: time.Date(2013, 10, 1, 0, 0, 0, 0, time.UTC), - RatingPlanId: "TDRT", - FallbackKeys: []string{"*out:test:1:danb", "*out:test:1:teo"}, - CdrStatQueueIds: []string{}, + ActivationTime: time.Date(2013, 10, 1, 0, 0, 0, 0, time.UTC), + RatingPlanId: "TDRT", + FallbackKeys: []string{"*out:test:1:danb", "*out:test:1:teo"}, }, } if err := onStor.SetRatingProfile(rpf, utils.NonTransactional); err != nil { diff --git a/engine/storage_sql.go b/engine/storage_sql.go index b59590abc..bb2c25744 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -277,6 +277,7 @@ func (self *SQLStorage) SetTPTimings(timings []*utils.ApierTPTiming) error { } t := APItoModelTiming(timing) if err := tx.Save(&t).Error; err != nil { + tx.Rollback() return err } } @@ -297,15 +298,10 @@ func (self *SQLStorage) SetTPDestinations(dests []*utils.TPDestination) error { } for _, d := range APItoModelDestination(dst) { if err := tx.Save(&d).Error; err != nil { + tx.Rollback() return err } } - // for _, dstPrfx := range dst.Prefixes { - // if err := tx.Save(&TpDestination{Tpid: dst.TPid, Tag: dst.Tag, Prefix: dstPrfx}).Error; err != nil { - // tx.Rollback() - // return err - // } - // } } tx.Commit() return nil @@ -327,6 +323,7 @@ func (self *SQLStorage) SetTPRates(rs []*utils.TPRate) error { } for _, r := range APItoModelRate(rate) { if err := tx.Save(&r).Error; err != nil { + tx.Rollback() return err } } @@ -351,6 +348,7 @@ func (self *SQLStorage) SetTPDestinationRates(drs []*utils.TPDestinationRate) er } for _, d := range APItoModelDestinationRate(dRate) { if err := tx.Save(&d).Error; err != nil { + tx.Rollback() return err } } @@ -375,6 +373,7 @@ func (self *SQLStorage) SetTPRatingPlans(rps []*utils.TPRatingPlan) error { } for _, r := range APItoModelRatingPlan(rPlan) { if err := tx.Save(&r).Error; err != nil { + tx.Rollback() return err } } @@ -397,6 +396,7 @@ func (self *SQLStorage) SetTPRatingProfiles(rpfs []*utils.TPRatingProfile) error } for _, r := range APItoModelRatingProfile(rpf) { if err := tx.Save(&r).Error; err != nil { + tx.Rollback() return err } } @@ -421,6 +421,7 @@ func (self *SQLStorage) SetTPSharedGroups(sgs []*utils.TPSharedGroups) error { } for _, s := range APItoModelSharedGroup(sGroup) { if err := tx.Save(&s).Error; err != nil { + tx.Rollback() return err } } @@ -453,6 +454,7 @@ func (self *SQLStorage) SetTPDerivedChargers(sgs []*utils.TPDerivedChargers) err } for _, d := range APItoModelDerivedCharger(dCharger) { if err := tx.Save(&d).Error; err != nil { + tx.Rollback() return err } } @@ -477,6 +479,7 @@ func (self *SQLStorage) SetTPActions(acts []*utils.TPActions) error { } for _, sa := range APItoModelAction(a) { if err := tx.Save(&sa).Error; err != nil { + tx.Rollback() return err } } @@ -502,6 +505,7 @@ func (self *SQLStorage) SetTPActionPlans(ats []*utils.TPActionPlan) error { } for _, a := range APItoModelActionPlan(aPlan) { if err := tx.Save(&a).Error; err != nil { + tx.Rollback() return err } } @@ -526,6 +530,7 @@ func (self *SQLStorage) SetTPActionTriggers(ats []*utils.TPActionTriggers) error } for _, a := range APItoModelActionTrigger(aTrigger) { if err := tx.Save(&a).Error; err != nil { + tx.Rollback() return err } } @@ -552,6 +557,7 @@ func (self *SQLStorage) SetTPAccountActions(aas []*utils.TPAccountActions) error } sa := APItoModelAccountAction(aa) if err := tx.Save(&sa).Error; err != nil { + tx.Rollback() return err } } @@ -1401,6 +1407,7 @@ func (self *SQLStorage) SetTPUsers(users []*utils.TPUsers) error { } for _, u := range APItoModelUsers(user) { if err := tx.Save(&u).Error; err != nil { + tx.Rollback() return err } } @@ -1455,6 +1462,7 @@ func (self *SQLStorage) SetTPAliases(aliases []*utils.TPAliases) error { } for _, a := range APItoModelAliases(alias) { if err := tx.Save(&a).Error; err != nil { + tx.Rollback() return err } } diff --git a/engine/stordb_it_test.go b/engine/stordb_it_test.go index 3f40ac5e3..468a6f117 100644 --- a/engine/stordb_it_test.go +++ b/engine/stordb_it_test.go @@ -517,34 +517,30 @@ func testStorDBitCRUDTpRatingProfiles(t *testing.T) { // WRITE var snd = []*utils.TPRatingProfile{ { - TPid: "testTPid", - LoadId: "TEST_LOADID", - Direction: "*out", - Tenant: "cgrates.org", - Category: "call", - Subject: "test", + TPid: "testTPid", + LoadId: "TEST_LOADID", + Tenant: "cgrates.org", + Category: "call", + Subject: "test", RatingPlanActivations: []*utils.TPRatingActivation{ { ActivationTime: "2014-07-29T15:00:00Z", RatingPlanId: "test", FallbackSubjects: "", - CdrStatQueueIds: "", }, }, }, { - TPid: "testTPid", - LoadId: "TEST_LOADID2", - Direction: "*out", - Tenant: "cgrates.org", - Category: "call", - Subject: "test", + TPid: "testTPid", + LoadId: "TEST_LOADID2", + Tenant: "cgrates.org", + Category: "call", + Subject: "test", RatingPlanActivations: []*utils.TPRatingActivation{ { ActivationTime: "2014-07-29T15:00:00Z", RatingPlanId: "test", FallbackSubjects: "", - CdrStatQueueIds: "", }, }, }, @@ -556,13 +552,25 @@ func testStorDBitCRUDTpRatingProfiles(t *testing.T) { if rcv, err := storDB.GetTPRatingProfiles(&filter); err != nil { t.Error(err) } else { - if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { - t.Errorf("\nExpecting:\n%+v\nReceived:\n%+v\n||\n%+v", utils.ToIJSON(snd[0]), utils.ToIJSON(rcv[0]), utils.ToIJSON(rcv[1])) + if !(reflect.DeepEqual(snd[0], rcv[0]) || + reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("\nExpecting:\n%+v\nReceived:\n%+v\n||\n%+v", + utils.ToIJSON(snd[0]), utils.ToIJSON(rcv[0]), utils.ToIJSON(rcv[1])) } } // UPDATE - snd[0].RatingPlanActivations[0].CdrStatQueueIds = "test" - snd[1].RatingPlanActivations[0].CdrStatQueueIds = "test" + snd[0].RatingPlanActivations = append(snd[0].RatingPlanActivations, + &utils.TPRatingActivation{ + ActivationTime: "2019-02-11T15:00:00Z", + RatingPlanId: "test", + FallbackSubjects: "", + }) + snd[1].RatingPlanActivations = append(snd[1].RatingPlanActivations, + &utils.TPRatingActivation{ + ActivationTime: "2019-02-11T15:00:00Z", + RatingPlanId: "test", + FallbackSubjects: "", + }) if err := storDB.SetTPRatingProfiles(snd); err != nil { t.Error(err) } @@ -571,7 +579,8 @@ func testStorDBitCRUDTpRatingProfiles(t *testing.T) { t.Error(err) } else { if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { - t.Errorf("\nExpecting:\n%+v\nReceived:\n%+v\n||\n%+v", utils.ToIJSON(snd[0]), utils.ToIJSON(rcv[0]), utils.ToIJSON(rcv[1])) + t.Errorf("\nExpecting:\n%+v\nReceived:\n%+v\n||\n%+v", + utils.ToIJSON(snd[0]), utils.ToIJSON(rcv[0]), utils.ToIJSON(rcv[1])) } } // REMOVE @@ -831,7 +840,6 @@ func testStorDBitCRUDTpActionTriggers(t *testing.T) { ActivationDate: "2014-07-29T15:00:00Z", BalanceId: "test", BalanceType: "*monetary", - BalanceDirections: "*out", BalanceDestinationIds: "call", BalanceWeight: "0.0", BalanceExpirationDate: "2014-07-29T15:00:00Z", @@ -841,7 +849,6 @@ func testStorDBitCRUDTpActionTriggers(t *testing.T) { BalanceSharedGroups: "SHARED_1", BalanceBlocker: "false", BalanceDisabled: "false", - MinQueuedItems: 0, ActionsId: "test", Weight: 1.0, }, @@ -862,7 +869,6 @@ func testStorDBitCRUDTpActionTriggers(t *testing.T) { ActivationDate: "2014-07-29T15:00:00Z", BalanceId: "test", BalanceType: "*monetary", - BalanceDirections: "*out", BalanceDestinationIds: "call", BalanceWeight: "0.0", BalanceExpirationDate: "2014-07-29T15:00:00Z", @@ -872,7 +878,6 @@ func testStorDBitCRUDTpActionTriggers(t *testing.T) { BalanceSharedGroups: "SHARED_1", BalanceBlocker: "false", BalanceDisabled: "false", - MinQueuedItems: 0, ActionsId: "test", Weight: 1.0, }, @@ -891,8 +896,8 @@ func testStorDBitCRUDTpActionTriggers(t *testing.T) { } } // UPDATE - snd[0].ActionTriggers[0].MinQueuedItems = 2 - snd[1].ActionTriggers[0].MinQueuedItems = 2 + snd[0].ActionTriggers[0].ActionsId = "test2" + snd[1].ActionTriggers[0].ActionsId = "test2" if err := storDB.SetTPActionTriggers(snd); err != nil { t.Error(err) } diff --git a/general_tests/tut_smgeneric_it_test.go b/general_tests/tut_smgeneric_it_test.go index 18659c502..5549199a8 100644 --- a/general_tests/tut_smgeneric_it_test.go +++ b/general_tests/tut_smgeneric_it_test.go @@ -98,7 +98,7 @@ func TestTutSMGCacheStats(t *testing.T) { t.Error(reply) } var rcvStats *utils.CacheStats - expectedStats := &utils.CacheStats{Destinations: 5, ReverseDestinations: 7, RatingPlans: 4, RatingProfiles: 10, + expectedStats := &utils.CacheStats{Destinations: 5, ReverseDestinations: 7, RatingPlans: 4, RatingProfiles: 5, Actions: 9, ActionPlans: 4, AccountActionPlans: 5, SharedGroups: 1, DerivedChargers: 1, Users: 3, Aliases: 1, ReverseAliases: 2, ResourceProfiles: 3, Resources: 3, StatQueues: 1, StatQueueProfiles: 1, Thresholds: 7, ThresholdProfiles: 7, Filters: 16, SupplierProfiles: 3, AttributeProfiles: 1} @@ -110,49 +110,6 @@ func TestTutSMGCacheStats(t *testing.T) { } } -/* -// Make sure account was debited properly -func TestTutSMGAccountsBefore(t *testing.T) { - var reply *engine.Account - attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - if err := tutSMGRpc.Call("ApierV2.GetAccount", attrs, &reply); err != nil { - t.Error("Got error on ApierV2.GetAccount: ", err.Error()) - } else if reply.BalanceMap[utils.MONETARY].GetTotalValue() != 10.0 { // Make sure we debitted - jsn, _ := json.Marshal(reply) - t.Errorf("Calling ApierV2.GetBalance received: %s", jsn) - } - attrs = &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1002"} - if err := tutSMGRpc.Call("ApierV2.GetAccount", attrs, &reply); err != nil { - t.Error("Got error on ApierV2.GetAccount: ", err.Error()) - } else if reply.BalanceMap[utils.MONETARY].GetTotalValue() != 10.0 { // Make sure we debitted - t.Errorf("Calling ApierV1.GetBalance received: %f", reply.BalanceMap[utils.MONETARY].GetTotalValue()) - } - attrs = &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1003"} - if err := tutSMGRpc.Call("ApierV2.GetAccount", attrs, &reply); err != nil { - t.Error("Got error on ApierV2.GetAccount: ", err.Error()) - } else if reply.BalanceMap[utils.MONETARY].GetTotalValue() != 10.0 { // Make sure we debitted - t.Errorf("Calling ApierV1.GetBalance received: %f", reply.BalanceMap[utils.MONETARY].GetTotalValue()) - } - attrs = &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1004"} - if err := tutSMGRpc.Call("ApierV2.GetAccount", attrs, &reply); err != nil { - t.Error("Got error on ApierV2.GetAccount: ", err.Error()) - } else if reply.BalanceMap[utils.MONETARY].GetTotalValue() != 10.0 { // Make sure we debitted - t.Errorf("Calling ApierV1.GetBalance received: %f", reply.BalanceMap[utils.MONETARY].GetTotalValue()) - } - attrs = &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1007"} - if err := tutSMGRpc.Call("ApierV2.GetAccount", attrs, &reply); err != nil { - t.Error("Got error on ApierV2.GetAccount: ", err.Error()) - } else if reply.BalanceMap[utils.MONETARY].GetTotalValue() != 0.0 { // Make sure we debitted - t.Errorf("Calling ApierV1.GetBalance received: %f", reply.BalanceMap[utils.MONETARY].GetTotalValue()) - } - attrs = &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1005"} - if err := tutSMGRpc.Call("ApierV2.GetAccount", attrs, &reply); err == nil || !strings.HasSuffix(err.Error(), "does not exist") { - t.Error("Got error on ApierV2.GetAccount: %v", err) - } -} - -*/ - func TestTutSMGStopCgrEngine(t *testing.T) { if err := engine.KillEngine(100); err != nil { t.Error(err) diff --git a/migrator/tp_rating_profiles_it_test.go b/migrator/tp_rating_profiles_it_test.go index f220dd4b6..ae727b431 100644 --- a/migrator/tp_rating_profiles_it_test.go +++ b/migrator/tp_rating_profiles_it_test.go @@ -109,24 +109,21 @@ func testTpRatPrfITFlush(t *testing.T) { func testTpRatPrfITPopulate(t *testing.T) { tpRatingProfile = []*utils.TPRatingProfile{ { - TPid: "TPRProf1", - LoadId: "RPrf", - Direction: "*out", - Tenant: "Tenant1", - Category: "Category", - Subject: "Subject", + TPid: "TPRProf1", + LoadId: "RPrf", + Tenant: "Tenant1", + Category: "Category", + Subject: "Subject", RatingPlanActivations: []*utils.TPRatingActivation{ { ActivationTime: "2014-07-29T15:00:00Z", RatingPlanId: "PlanOne", FallbackSubjects: "FallBack", - CdrStatQueueIds: "RandomId", }, { ActivationTime: "2015-07-29T10:00:00Z", RatingPlanId: "PlanTwo", FallbackSubjects: "FallOut", - CdrStatQueueIds: "RandomIdTwo", }, }, },