From e15a08d633ca30f45f17f0ac7b7cbcdd45288d92 Mon Sep 17 00:00:00 2001 From: DanB Date: Wed, 28 May 2014 10:12:38 +0200 Subject: [PATCH] Adding SMS Charging test --- engine/storage_sql.go | 2 - general_tests/smschrg1_test_tmp.go | 90 ++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 general_tests/smschrg1_test_tmp.go diff --git a/engine/storage_sql.go b/engine/storage_sql.go index 653067023..4ccb3b2bf 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -583,7 +583,6 @@ func (self *SQLStorage) SetCdr(cdr *utils.StoredCdr) (err error) { } func (self *SQLStorage) SetRatedCdr(storedCdr *utils.StoredCdr, extraInfo string) (err error) { - Logger.Debug(fmt.Sprintf("SetRatedCdr for CDR: %+v", storedCdr)) _, err = self.Db.Exec(fmt.Sprintf("INSERT INTO %s (mediation_time,cgrid,runid,reqtype,direction,tenant,category,account,subject,destination,setup_time,answer_time,`usage`,cost,extra_info) VALUES (now(),'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',%v,%f,'%s') ON DUPLICATE KEY UPDATE mediation_time=now(),reqtype=values(reqtype),direction=values(direction),tenant=values(tenant),category=values(category),account=values(account),subject=values(subject),destination=values(destination),setup_time=values(setup_time),answer_time=values(answer_time),`usage`=values(`usage`),cost=values(cost),extra_info=values(extra_info)", utils.TBL_RATED_CDRS, storedCdr.CgrId, @@ -1109,7 +1108,6 @@ func (self *SQLStorage) GetTpRatingPlans(tpid, tag string) (map[string][]*utils. TimingId: timings_tag, Weight: weight, } - // Logger.Debug(fmt.Sprintf("For RatingPlan id: %s, loading RatingPlanBinding: %v", tag, rpb)) if _, exists := rpbns[id]; exists { rpbns[id] = append(rpbns[id], rpb) } else { // New diff --git a/general_tests/smschrg1_test_tmp.go b/general_tests/smschrg1_test_tmp.go new file mode 100644 index 000000000..2c1c972a8 --- /dev/null +++ b/general_tests/smschrg1_test_tmp.go @@ -0,0 +1,90 @@ +/* +Real-time Charging System for Telecom & ISP environments +Copyright (C) 2012-2014 ITsysCOM GmbH + +This program is free software: you can Storagetribute 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 WITH*out 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 general_tests + +import ( + "testing" + "time" + + "github.com/cgrates/cgrates/cache2go" + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +func TestSetStorageSmsChrg1(t *testing.T) { + ratingDb, _ = engine.NewMapStorageJson() + engine.SetRatingStorage(ratingDb) + acntDb, _ = engine.NewMapStorageJson() + engine.SetAccountingStorage(acntDb) +} + +func TestLoadCsvTpSmsChrg1(t *testing.T) { + timings := `ALWAYS,*any,*any,*any,*any,00:00:00` + rates := `RT_SMS_5c,0,0.005,1,1,0` + destinationRates := `DR_SMS_1,*any,RT_SMS_5c,*up,4` + ratingPlans := `RP_SMS1,DR_SMS_1,ALWAYS,10` + ratingProfiles := `*out,cgrates.org,sms,*any,2012-01-01T00:00:00Z,RP_SMS1,` + csvr := engine.NewStringCSVReader(ratingDb, acntDb, ',', "", timings, rates, destinationRates, ratingPlans, ratingProfiles, + "", "", "", "", "", "", "") + if err := csvr.LoadTimings(); err != nil { + t.Fatal(err) + } + if err := csvr.LoadRates(); err != nil { + t.Fatal(err) + } + if err := csvr.LoadDestinationRates(); err != nil { + t.Fatal(err) + } + if err := csvr.LoadRatingPlans(); err != nil { + t.Fatal(err) + } + if err := csvr.LoadRatingProfiles(); err != nil { + t.Fatal(err) + } + csvr.WriteToDatabase(false, false) + ratingDb.CacheRating(nil, nil, nil, nil, nil) + + if cachedRPlans := cache2go.CountEntries(engine.RATING_PLAN_PREFIX); cachedRPlans != 1 { + t.Error("Wrong number of cached rating plans found", cachedRPlans) + } + if cachedRProfiles := cache2go.CountEntries(engine.RATING_PROFILE_PREFIX); cachedRProfiles != 1 { + t.Error("Wrong number of cached rating profiles found", cachedRProfiles) + } +} + +func TestGetDataCostSmsChrg1(t *testing.T) { + usageDur := time.Duration(1) * time.Second + timeStart := time.Date(2014, 3, 4, 0, 0, 0, 0, time.Local) + cd := &engine.CallDescriptor{ + Direction: "*out", + Category: "data", + Tenant: "cgrates.org", + Subject: "12345", + Account: "12345", + TimeStart: timeStart, + TimeEnd: timeStart.Add(usageDur), + DurationIndex: usageDur, + TOR: utils.SMS, + } + if cc, err := cd.GetCost(); err != nil { + t.Error(err) + } else if cc.Cost != 0.005 { + t.Error("Wrong cost returned: ", cc.Cost) + } +}