From 094bce7fd50dc733e33adec6b9ca241ff3f2e543 Mon Sep 17 00:00:00 2001 From: DanB Date: Wed, 8 Mar 2017 14:40:26 +0100 Subject: [PATCH] SMGA1 IT tests --- data/conf/samples/tutmongo/cgrates.json | 8 +- data/conf/samples/tutmysql/cgrates.json | 4 + data/conf/samples/tutpostgres/cgrates.json | 4 + .../test/smg_a1/RatingProfiles.csv | 2 +- general_tests/smg_a1_it_test.go | 119 +++++++++++++++++- 5 files changed, 131 insertions(+), 6 deletions(-) diff --git a/data/conf/samples/tutmongo/cgrates.json b/data/conf/samples/tutmongo/cgrates.json index 7ce525ff1..a7343521c 100644 --- a/data/conf/samples/tutmongo/cgrates.json +++ b/data/conf/samples/tutmongo/cgrates.json @@ -4,6 +4,7 @@ "general": { "log_level": 7, + "reply_timeout": "30s", }, "listen": { @@ -14,20 +15,17 @@ "tariffplan_db": { "db_type": "mongo", - "db_password": "", "db_port": 27017, }, "data_db": { "db_type": "mongo", - "db_password": "", "db_port": 27017, }, "stor_db": { "db_type": "mongo", - "db_password": "", "db_port": 27017, }, @@ -77,5 +75,9 @@ "enabled": true, }, +"sm_generic": { + "enabled": true, +}, + } diff --git a/data/conf/samples/tutmysql/cgrates.json b/data/conf/samples/tutmysql/cgrates.json index 0f88bc5cf..f53cdc0a0 100644 --- a/data/conf/samples/tutmysql/cgrates.json +++ b/data/conf/samples/tutmysql/cgrates.json @@ -112,4 +112,8 @@ "enabled": true, // starts Aliases service: . }, +"sm_generic": { + "enabled": true, +}, + } diff --git a/data/conf/samples/tutpostgres/cgrates.json b/data/conf/samples/tutpostgres/cgrates.json index 0cdebff89..e8b24ddd3 100644 --- a/data/conf/samples/tutpostgres/cgrates.json +++ b/data/conf/samples/tutpostgres/cgrates.json @@ -60,5 +60,9 @@ "enabled": true, // starts Aliases service: . }, +"sm_generic": { + "enabled": true, +}, + } diff --git a/data/tariffplans/test/smg_a1/RatingProfiles.csv b/data/tariffplans/test/smg_a1/RatingProfiles.csv index 047acc090..3ec883fe0 100644 --- a/data/tariffplans/test/smg_a1/RatingProfiles.csv +++ b/data/tariffplans/test/smg_a1/RatingProfiles.csv @@ -1 +1 @@ -*out,cgrates.org,data1,subj_rpdata1,2015-01-01T00:00:00Z,RP_DATA1,, +*out,cgrates.org,data1,rpdata1,2015-01-01T00:00:00Z,RP_DATA1,, diff --git a/general_tests/smg_a1_it_test.go b/general_tests/smg_a1_it_test.go index ec0ed827d..786545d4c 100644 --- a/general_tests/smg_a1_it_test.go +++ b/general_tests/smg_a1_it_test.go @@ -26,8 +26,10 @@ import ( "testing" "time" + "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/sessionmanager" "github.com/cgrates/cgrates/utils" ) @@ -39,7 +41,7 @@ var ( func TestSMGa1ITLoadConfig(t *testing.T) { smgA1CfgPath = path.Join(*dataDir, "conf", "samples", "tutmongo") - if smgA1Cfg, err = config.NewCGRConfigFromFolder(tpCfgPath); err != nil { + if smgA1Cfg, err = config.NewCGRConfigFromFolder(smgA1CfgPath); err != nil { t.Error(err) } } @@ -63,6 +65,7 @@ func TestSMGa1ITStartEngine(t *testing.T) { } func TestSMGa1ITRPCConn(t *testing.T) { + time.Sleep(1500 * time.Millisecond) // flushdb takes time in mongo var err error smgA1rpc, err = jsonrpc.Dial("tcp", smgA1Cfg.RPCJSONListen) if err != nil { @@ -85,7 +88,7 @@ func TestSMGa1ITLoadTPFromFolder(t *testing.T) { Direction: "*out", Category: "data1", Tenant: "cgrates.org", - Subject: "subj_rpdata1", + Subject: "rpdata1", Destination: "data", TimeStart: tStart, TimeEnd: tEnd, @@ -97,3 +100,115 @@ func TestSMGa1ITLoadTPFromFolder(t *testing.T) { t.Errorf("Calling Responder.GetCost got callcost: %v", cc) } } + +func TestSMGa1ITAddBalance1(t *testing.T) { + var reply string + argAdd := &v1.AttrAddBalance{Tenant: "cgrates.org", Account: "rpdata1", + BalanceType: utils.DATA, BalanceId: utils.StringPointer("rpdata1_test"), + Value: 10000000000} + if err := smgA1rpc.Call("ApierV1.AddBalance", argAdd, &reply); err != nil { + t.Error(err) + } else if reply != utils.OK { + t.Errorf(reply) + } + argGet := &utils.AttrGetAccount{Tenant: argAdd.Tenant, Account: argAdd.Account} + var acnt *engine.Account + if err := smgA1rpc.Call("ApierV2.GetAccount", argGet, &acnt); err != nil { + t.Error(err) + } else { + if acnt.BalanceMap[utils.DATA].GetTotalValue() != argAdd.Value { // We expect 11.5 since we have added in the previous test 1.5 + t.Errorf("Received account value: %f", acnt.BalanceMap[utils.DATA].GetTotalValue()) + } + } +} + +func TestSMGa1ITDataSession1(t *testing.T) { + smgEv := sessionmanager.SMGenericEvent{ + utils.EVENT_NAME: "INITIATE_SESSION", + utils.TOR: utils.DATA, + utils.ACCID: "504966119", + utils.DIRECTION: utils.OUT, + utils.ACCOUNT: "rpdata1", + utils.SUBJECT: "rpdata1", + utils.DESTINATION: "data", + utils.CATEGORY: "data1", + utils.TENANT: "cgrates.org", + utils.REQTYPE: utils.META_PREPAID, + utils.SETUP_TIME: "2017-03-03 11:39:32 +0100 CET", + utils.ANSWER_TIME: "2017-03-03 11:39:32 +0100 CET", + utils.USAGE: "10240", + utils.SessionTTL: "28800s", + utils.SessionTTLLastUsed: "0s", + utils.SessionTTLUsage: "0s", + } + var maxUsage float64 + if err := smgA1rpc.Call("SMGenericV1.InitiateSession", smgEv, &maxUsage); err != nil { + t.Error(err) + } else if maxUsage != 10240 { + t.Error("Received: ", maxUsage) + } + + smgEv = sessionmanager.SMGenericEvent{ + utils.EVENT_NAME: "UPDATE_SESSION", + utils.ACCOUNT: "rpdata1", + utils.CATEGORY: "data1", + utils.DESTINATION: "data", + utils.DIRECTION: utils.OUT, + utils.InitialOriginID: "504966119", + utils.LastUsed: "0s", + utils.ACCID: "504966119-1", + utils.REQTYPE: utils.META_PREPAID, + utils.SessionTTL: "28800s", + utils.SessionTTLLastUsed: "2097152s", + utils.SessionTTLUsage: "0s", + utils.SUBJECT: "rpdata1", + utils.TENANT: "cgrates.org", + utils.TOR: utils.DATA, + utils.SETUP_TIME: "2017-03-03 11:39:32 +0100 CET", + utils.ANSWER_TIME: "2017-03-03 11:39:32 +0100 CET", + utils.USAGE: "2097152", + } + if err := smgA1rpc.Call("SMGenericV1.UpdateSession", smgEv, &maxUsage); err != nil { + t.Error(err) + } else if maxUsage != 2097152 { + t.Error("Bad max usage: ", maxUsage) + } + smgEv = sessionmanager.SMGenericEvent{ + utils.EVENT_NAME: "TERMINATE_SESSION", + utils.ACCOUNT: "rpdata1", + utils.CATEGORY: "data1", + utils.DESTINATION: "data", + utils.DIRECTION: utils.OUT, + utils.LastUsed: "2202800", + utils.ACCID: "504966119-1", + utils.OriginIDPrefix: "504966119-1", + utils.REQTYPE: utils.META_PREPAID, + utils.SETUP_TIME: "2017-03-03 11:39:32 +0100 CET", + utils.ANSWER_TIME: "2017-03-03 11:39:32 +0100 CET", + utils.SUBJECT: "rpdata1", + utils.TENANT: "cgrates.org", + utils.TOR: utils.DATA, + } + var rpl string + if err = smgA1rpc.Call("SMGenericV1.TerminateSession", smgEv, &rpl); err != nil || rpl != utils.OK { + t.Error(err) + } + /* + if err := smgA1rpc.Call("SMGenericV1.ProcessCDR", smgEv, &rpl); err != nil { + t.Error(err) + } else if rpl != utils.OK { + t.Errorf("Received reply: %s", rpl) + } + var cdrs []*engine.ExternalCDR + req := utils.RPCCDRsFilter{RunIDs: []string{utils.META_DEFAULT}} + if err := smgA1rpc.Call("ApierV2.GetCdrs", req, &cdrs); err != nil { + t.Error("Unexpected error: ", err.Error()) + } else if len(cdrs) != 1 { + t.Error("Unexpected number of CDRs returned: ", len(cdrs)) + } else { + if cdrs[0].Usage != "60" { + t.Errorf("Unexpected CDR Usage received, cdr: %v %+v ", cdrs[0].Usage, cdrs[0]) + } + } + */ +}