From fa788103cf408d3d301d5b4a7831bbdc7f21c879 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Sat, 14 Sep 2013 17:58:52 +0300 Subject: [PATCH] added test for all csv loaders --- engine/action.go | 1 + engine/action_timing.go | 2 +- engine/loader_csv.go | 2 + engine/loader_csv_test.go | 87 +++++++++++++++++++++++++++++++++++++-- engine/rateinterval.go | 2 +- engine/userbalance.go | 7 ++-- 6 files changed, 92 insertions(+), 9 deletions(-) diff --git a/engine/action.go b/engine/action.go index 23463914f..9c4810da1 100644 --- a/engine/action.go +++ b/engine/action.go @@ -48,6 +48,7 @@ const ( DEBIT = "*debit" RESET_COUNTER = "*reset_counter" RESET_COUNTERS = "*reset_counters" + UNLIMITED = "*unlimited" ) type actionTypeFunc func(*UserBalance, *Action) error diff --git a/engine/action_timing.go b/engine/action_timing.go index ae84f8835..9262bd71d 100644 --- a/engine/action_timing.go +++ b/engine/action_timing.go @@ -287,6 +287,6 @@ func (atpl ActionTimingPriotityList) Sort() { sort.Sort(atpl) } -func (at *ActionTiming) String() string { +func (at *ActionTiming) String_DISABLED() string { return at.Tag + " " + at.GetNextStartTime().String() + ",w: " + strconv.FormatFloat(at.Weight, 'f', -1, 64) } diff --git a/engine/loader_csv.go b/engine/loader_csv.go index 1413a8a64..c98a1b849 100644 --- a/engine/loader_csv.go +++ b/engine/loader_csv.go @@ -368,6 +368,7 @@ func (csvr *CSVReader) LoadActions() (err error) { Weight: weight, ExpirationString: record[5], Balance: &Balance{ + Id: utils.GenUUID(), Value: units, Weight: minutesWeight, SpecialPrice: value, @@ -412,6 +413,7 @@ func (csvr *CSVReader) LoadActionTimings() (err error) { Tag: record[2], Weight: weight, Timing: &RateInterval{ + Years: t.Years, Months: t.Months, MonthDays: t.MonthDays, WeekDays: t.WeekDays, diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 28c7e884b..90ee0ac1c 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -87,14 +87,14 @@ vdf,0,*out,inf,2012-02-28T00:00:00Z,STANDARD,inf vdf,0,*out,fall,2012-02-28T00:00:00Z,PREMIUM,rif ` actions = ` -MINI,TOPUP,MINUTES,*out,100,*unlimited,NAT,*absolute,0,10,10 +MINI,*topup,*minutes,*out,100,*unlimited,NAT,*absolute,0,10,10 ` actionTimings = ` MORE_MINUTES,MINI,ONE_TIME_RUN,10 ` actionTriggers = ` -STANDARD_TRIGGER,MINUTES,*out,*min_counter,10,GERMANY_O2,SOME_1,10 -STANDARD_TRIGGER,MINUTES,*out,*max_balance,200,GERMANY,SOME_2,10 +STANDARD_TRIGGER,*minutes,*out,*min_counter,10,GERMANY_O2,SOME_1,10 +STANDARD_TRIGGER,*minutes,*out,*max_balance,200,GERMANY,SOME_2,10 ` accountActions = ` vdf,minitsboy,*out,MORE_MINUTES,STANDARD_TRIGGER @@ -607,22 +607,103 @@ func TestLoadActions(t *testing.T) { if len(csvr.actions) != 1 { t.Error("Failed to load actions: ", csvr.actions) } + a := csvr.actions["MINI"][0] + expected := &Action{ + Id: a.Id, + ActionType: TOPUP, + BalanceId: MINUTES, + Direction: OUTBOUND, + ExpirationString: UNLIMITED, + Weight: 10, + Balance: &Balance{ + Id: a.Balance.Id, + Value: 100, + Weight: 10, + SpecialPriceType: PRICE_ABSOLUTE, + SpecialPrice: 0, + DestinationId: "NAT", + }, + } + if !reflect.DeepEqual(a, expected) { + t.Error("Error loading action: ", a) + } } func TestLoadActionTimings(t *testing.T) { if len(csvr.actionsTimings) != 1 { t.Error("Failed to load action timings: ", csvr.actionsTimings) } + atm := csvr.actionsTimings["MORE_MINUTES"][0] + expected := &ActionTiming{ + Id: atm.Id, + Tag: "ONE_TIME_RUN", + UserBalanceIds: []string{"*out:vdf:minitsboy"}, + Timing: &RateInterval{ + Years: Years{2012}, + Months: Months{}, + MonthDays: MonthDays{}, + WeekDays: WeekDays{}, + StartTime: ASAP, + }, + Weight: 10, + ActionsId: "MINI", + } + if !reflect.DeepEqual(atm, expected) { + t.Error("Error loading action timing: ", atm) + } } func TestLoadActionTriggers(t *testing.T) { if len(csvr.actionsTriggers) != 1 { t.Error("Failed to load action triggers: ", csvr.actionsTriggers) } + atr := csvr.actionsTriggers["STANDARD_TRIGGER"][0] + expected := &ActionTrigger{ + Id: atr.Id, + BalanceId: MINUTES, + Direction: OUTBOUND, + ThresholdType: TRIGGER_MIN_COUNTER, + ThresholdValue: 10, + DestinationId: "GERMANY_O2", + Weight: 10, + ActionsId: "SOME_1", + Executed: false, + } + if !reflect.DeepEqual(atr, expected) { + t.Error("Error loading action trigger: ", atr) + } + atr = csvr.actionsTriggers["STANDARD_TRIGGER"][1] + expected = &ActionTrigger{ + Id: atr.Id, + BalanceId: MINUTES, + Direction: OUTBOUND, + ThresholdType: TRIGGER_MAX_BALANCE, + ThresholdValue: 200, + DestinationId: "GERMANY", + Weight: 10, + ActionsId: "SOME_2", + Executed: false, + } + if !reflect.DeepEqual(atr, expected) { + t.Error("Error loading action trigger: ", atr) + } } func TestLoadAccountActions(t *testing.T) { if len(csvr.accountActions) != 1 { t.Error("Failed to load account actions: ", csvr.accountActions) } + aa := csvr.accountActions[0] + expected := &UserBalance{ + Id: "*out:vdf:minitsboy", + Type: UB_TYPE_PREPAID, + ActionTriggers: csvr.actionsTriggers["STANDARD_TRIGGER"], + } + if !reflect.DeepEqual(aa, expected) { + t.Error("Error loading account action: ", aa) + } } + +/* +vdf,minitsboy,*out,MORE_MINUTES,STANDARD_TRIGGER +*/ diff --git a/engine/rateinterval.go b/engine/rateinterval.go index 60b2293e7..c6da5ed9f 100644 --- a/engine/rateinterval.go +++ b/engine/rateinterval.go @@ -183,7 +183,7 @@ func (i *RateInterval) getLeftMargin(t time.Time) (rigthtTime time.Time) { return time.Date(year, month, day, hour, min, sec, nsec, loc) } -func (i *RateInterval) String() string { +func (i *RateInterval) String_DISABLED() string { return fmt.Sprintf("%v %v %v %v %v %v", i.Years, i.Months, i.MonthDays, i.WeekDays, i.StartTime, i.EndTime) } diff --git a/engine/userbalance.go b/engine/userbalance.go index b387144f9..81f254cf2 100644 --- a/engine/userbalance.go +++ b/engine/userbalance.go @@ -55,10 +55,9 @@ Structure containing information about user's credit (minutes, cents, sms...).' This can represent a user or a shared group. */ type UserBalance struct { - Id string - Type string // prepaid-postpaid - BalanceMap map[string]BalanceChain - //MinuteBuckets []*MinuteBucket + Id string + Type string // prepaid-postpaid + BalanceMap map[string]BalanceChain UnitCounters []*UnitsCounter ActionTriggers ActionTriggerPriotityList