diff --git a/utils/eventcharges_test.go b/utils/eventcharges_test.go index 681a924ce..487c3c134 100644 --- a/utils/eventcharges_test.go +++ b/utils/eventcharges_test.go @@ -1834,3 +1834,198 @@ func TestSyncIDsEventCharges(t *testing.T) { t.Errorf("Expected %v \n but received \n %v", ToJSON(expEc), ToJSON(eEvChgs)) } } + +func TestEqualsAccounting(t *testing.T) { + + acc1 := &AccountCharge{ + AccountID: "AccountID1", + BalanceID: "BalanceID1", + Units: NewDecimal(20, 0), + BalanceLimit: NewDecimal(40, 0), + UnitFactorID: "UF1", + AttributeIDs: []string{"ID1", "ID2"}, + RatingID: "RatingID1", + JoinedChargeIDs: []string{"chID1", "chID3"}, + } + acc2 := &AccountCharge{ + AccountID: "AccountID2", + BalanceID: "BalanceID2", + Units: NewDecimal(20, 0), + BalanceLimit: NewDecimal(40, 0), + UnitFactorID: "UF2", + AttributeIDs: []string{"ID3", "ID4"}, + RatingID: "RatingID2", + JoinedChargeIDs: []string{"chID2"}, + } + + accM1 := map[string]*AccountCharge{ + "chID1": { + AccountID: "AccountID2", + BalanceID: "BalanceID2", + Units: NewDecimal(20, 0), + BalanceLimit: NewDecimal(40, 0), + UnitFactorID: "UF2", + AttributeIDs: []string{"ID3", "ID4"}, + RatingID: "RatingID2", + }, + "chID3": { + AccountID: "AccountID3", + BalanceID: "BalanceID3", + Units: NewDecimal(20, 0), + BalanceLimit: NewDecimal(40, 0), + UnitFactorID: "UF2", + AttributeIDs: []string{"ID3", "ID4"}, + RatingID: "RatingID3", + }, + "GENUUID1": { + AccountID: "AccountID1", + BalanceID: "BalanceID1", + Units: NewDecimal(20, 0), + BalanceLimit: NewDecimal(40, 0), + UnitFactorID: "UF1", + AttributeIDs: []string{"ID1", "ID2"}, + RatingID: "RatingID1", + JoinedChargeIDs: []string{"chID1", "chID3"}, + }, + } + accM2 := map[string]*AccountCharge{ + "chID2": { + AccountID: "AccountID2", + BalanceID: "BalanceID2", + Units: NewDecimal(20, 0), + BalanceLimit: NewDecimal(40, 0), + UnitFactorID: "UF2", + AttributeIDs: []string{"ID1", "ID2"}, + RatingID: "RatingID2", + }, + "GENUUID2": { + AccountID: "AccountID2", + BalanceID: "BalanceID2", + Units: NewDecimal(20, 0), + BalanceLimit: NewDecimal(40, 0), + UnitFactorID: "UF2", + AttributeIDs: []string{"ID3", "ID4"}, + RatingID: "RatingID2", + JoinedChargeIDs: []string{"chID2"}, + }} + + uf1 := map[string]*UnitFactor{ + "UF2": { + Factor: NewDecimal(200, 0), + }, + } + uf2 := map[string]*UnitFactor{ + "UF2": { + Factor: NewDecimal(200, 0), + }, + } + rat1 := map[string]*RateSInterval{ + "RatingID1": { + Increments: []*RateSIncrement{ + { + Usage: NewDecimal(int64(time.Minute), 0), + CompressFactor: 1, + RateID: "IvalRate1", + }, + }, + IntervalStart: NewDecimal(int64(time.Second), 0), + CompressFactor: 1, + }} + rat2 := map[string]*RateSInterval{ + "RatingID1": { + Increments: []*RateSIncrement{ + { + Usage: NewDecimal(int64(time.Minute), 0), + CompressFactor: 1, + RateID: "IvalRate1", + }, + }, + IntervalStart: NewDecimal(int64(time.Second), 0), + CompressFactor: 1, + }} + rts1 := map[string]*IntervalRate{"IvalRate1": { + IntervalStart: NewDecimalFromFloat64(1.2), + FixedFee: NewDecimalFromFloat64(1.234), + RecurrentFee: NewDecimalFromFloat64(0.5), + Unit: NewDecimalFromFloat64(7.1), + Increment: NewDecimalFromFloat64(-321), + }} + rts2 := map[string]*IntervalRate{"IvalRate1": { + IntervalStart: NewDecimalFromFloat64(1.2), + FixedFee: NewDecimalFromFloat64(1.234), + RecurrentFee: NewDecimalFromFloat64(0.5), + Unit: NewDecimalFromFloat64(7.1), + Increment: NewDecimalFromFloat64(-321), + }} + ////////////////////////// + acc10 := &AccountCharge{ + AccountID: "AccountID2", + BalanceID: "BalanceID2", + Units: NewDecimal(20, 0), + BalanceLimit: NewDecimal(40, 0), + UnitFactorID: "UF2", + AttributeIDs: []string{"ID3", "ID4"}, + RatingID: "RatingID2", + JoinedChargeIDs: []string{"chID2"}, + } + + acc20 := &AccountCharge{ + AccountID: "AccountID2", + BalanceID: "BalanceID2", + Units: NewDecimal(20, 0), + BalanceLimit: NewDecimal(40, 0), + UnitFactorID: "UF2", + AttributeIDs: []string{"ID3", "ID4"}, + RatingID: "RatingID2", + JoinedChargeIDs: []string{"chID3"}, + } + + accM10 := map[string]*AccountCharge{ + + "chID2": { + AccountID: "AccountID2", + BalanceID: "BalanceID2", + Units: NewDecimal(20, 0), + BalanceLimit: NewDecimal(40, 0), + UnitFactorID: "UF2", + AttributeIDs: []string{"ID3", "ID4"}, + RatingID: "RatingID2", + }, + "GENUUID1": { + AccountID: "AccountID1", + BalanceID: "BalanceID1", + Units: NewDecimal(20, 0), + BalanceLimit: NewDecimal(40, 0), + UnitFactorID: "UF1", + AttributeIDs: []string{"ID1", "ID2"}, + RatingID: "RatingID1", + JoinedChargeIDs: []string{"chID2"}, + }, + } + + accM20 := map[string]*AccountCharge{ + "chID3": { + AccountID: "AccountID2", + BalanceID: "BalanceID5", + Units: NewDecimal(20, 0), + BalanceLimit: NewDecimal(40, 0), + UnitFactorID: "UF2", + AttributeIDs: []string{"ID3", "ID4"}, + RatingID: "RatingID2", + }, + + "GENUUID1": { + AccountID: "AccountID1", + BalanceID: "BalanceID1", + Units: NewDecimal(20, 0), + BalanceLimit: NewDecimal(40, 0), + UnitFactorID: "UF1", + AttributeIDs: []string{"ID1", "ID2"}, + RatingID: "RatingID1", + JoinedChargeIDs: []string{"chID3"}, + }, + } + + equalsAccounting(acc1, acc2, accM1, accM2, uf1, uf2, rat1, rat2, rts1, rts2) + equalsAccounting(acc10, acc20, accM10, accM20, uf1, uf2, rat1, rat2, rts1, rts2) +} diff --git a/utils/librates_test.go b/utils/librates_test.go index 32d16dd1d..fef58cc8f 100644 --- a/utils/librates_test.go +++ b/utils/librates_test.go @@ -2260,3 +2260,185 @@ func TestAsRateAPIConvert(t *testing.T) { t.Errorf("%+v", err) } } + +func TestCloneRate(t *testing.T) { + rt := &Rate{ + FilterIDs: []string{"id1", "id2"}, + Weights: DynamicWeights{ + { + Weight: 0, + }, + }, + IntervalRates: []*IntervalRate{ + { + IntervalStart: NewDecimal(0, 0), + RecurrentFee: NewDecimal(12, 2), + }, + }, + } + + exp := &Rate{ + FilterIDs: []string{"id1", "id2"}, + Weights: DynamicWeights{ + { + Weight: 0, + }, + }, + IntervalRates: []*IntervalRate{ + { + IntervalStart: NewDecimal(0, 0), + RecurrentFee: NewDecimal(12, 2), + }, + }, + } + if rcv := rt.Clone(); !reflect.DeepEqual(exp, rcv) { + + t.Errorf("Expected <%v>, Received <%v>", exp, rcv) + } + +} + +func TestEqualsNRpCt(t *testing.T) { + rtPrfCost := &RateProfileCost{ + ID: "RATE_1", + Cost: NewDecimal(2, 1), + MinCost: NewDecimal(1, 2), + MaxCost: NewDecimal(15, 0), + MaxCostStrategy: "*round", + CostIntervals: []*RateSIntervalCost{ + { + Increments: []*RateSIncrementCost{ + { + RateIntervalIndex: 0, + RateID: "RATE1", + CompressFactor: 1, + Usage: NewDecimal(int64(time.Minute), 0), + }, + }, + CompressFactor: 1, + }, + }, + Rates: map[string]*IntervalRate{ + "RATE1": { + IntervalStart: NewDecimal(0, 0), + RecurrentFee: NewDecimal(2, 1), + Unit: NewDecimal(int64(time.Second), 1), + Increment: NewDecimal(int64(time.Second), 1), + }, + }, + Altered: []string{MetaRoundingDown}, + } + expectedRT := &RateProfileCost{ + ID: "RATE_1", + Cost: NewDecimal(2, 1), + MinCost: NewDecimal(1, 2), + MaxCost: NewDecimal(15, 0), + MaxCostStrategy: "*round", + CostIntervals: []*RateSIntervalCost{ + { + Increments: []*RateSIncrementCost{ + { + RateIntervalIndex: 0, + RateID: "RATE1", + CompressFactor: 1, + Usage: NewDecimal(int64(time.Minute), 0), + }, + }, + CompressFactor: 1, + }, + }, + Rates: map[string]*IntervalRate{ + "RATE1": { + IntervalStart: NewDecimal(0, 0), + RecurrentFee: NewDecimal(2, 1), + Unit: NewDecimal(int64(time.Second), 1), + Increment: NewDecimal(int64(time.Second), 1), + }, + }, + Altered: []string{MetaRoundingUp}, + } + if rtPrfCost.Equals(expectedRT) { + t.Errorf("%v and \n%v are equals", ToJSON(rtPrfCost), ToJSON(expectedRT)) + } +} + +func TestMergeRate(t *testing.T) { + rt := &Rate{ID: "rate_id1", + FilterIDs: []string{"fltr1"}, + ActivationTimes: "1 1 3", + Weights: DynamicWeights{ + { + Weight: 10, + }, + }, + Blocker: false, + IntervalRates: []*IntervalRate{ + { + IntervalStart: NewDecimal(int64(1), 0), + FixedFee: NewDecimal(int64(10), 0), + RecurrentFee: NewDecimal(int64(2), 0), + Unit: NewDecimal(int64(2), 0), + Increment: NewDecimal(int64(3), 0), + }, + }} + vi := &Rate{ + ID: "rate_id1", + FilterIDs: []string{"fltr1"}, + ActivationTimes: "1 1 3", + Weights: DynamicWeights{ + { + Weight: 10, + }, + }, + Blocker: false, + IntervalRates: []*IntervalRate{ + { + IntervalStart: NewDecimal(int64(1), 0), + FixedFee: NewDecimal(int64(10), 0), + RecurrentFee: NewDecimal(int64(2), 0), + Unit: NewDecimal(int64(2), 0), + Increment: NewDecimal(int64(3), 0), + }, + }, + } + + rt.Merge(vi) + +} + +// unfinished +func TestAsDataDBMap(t *testing.T) { + rp := &RateProfile{ + FilterIDs: []string{"fltr1", "fltr2"}, + Weights: DynamicWeights{{ + + Weight: 10, + }}, + MinCost: NewDecimal(10, 0), + MaxCost: NewDecimal(10, 0), + MaxCostStrategy: "strategy", + Rates: map[string]*Rate{ + "rat1": { + ID: "rat1", + FilterIDs: []string{"fltr1"}, + ActivationTimes: "* * * * *", + Weights: DynamicWeights{{}}, + Blocker: true, + IntervalRates: []*IntervalRate{{}}, + }, + "rat2": { + ID: "rat2", + }, + "rat3": {}, + }, + } + + // exp := map[FilterIDs:fltr1;fltr2 MaxCost:10 MaxCostStrategy:strategy MinCost:10 Rates:rat1:{"ID":"rat1","FilterIDs":["fltr1"],"ActivationTimes":"* * * * *","Weights":[{"FilterIDs":null,"Weight":0}],"Blocker":true,"IntervalRates":[{"IntervalStart":null,"FixedFee":null,"RecurrentFee":null,"Unit":null,"Increment":null}]} Rates:rat2:{"ID":"rat2","FilterIDs":null,"ActivationTimes":"","Weights":null,"Blocker":false,"IntervalRates":null} Rates:rat3:{"ID":"","FilterIDs":null,"ActivationTimes":"","Weights":null,"Blocker":false,"IntervalRates":null} Weights:;10] + if _, err := rp.AsDataDBMap(JSONMarshaler{}); err != nil { + t.Error(err) + + } + // else if !reflect.DeepEqual(ToJSON(rp), ToJSON(rcv)) { + // t.Error(ToJSON(rcv)) + // } +} diff --git a/utils/logger_test.go b/utils/logger_test.go index e651720b9..e71ad8047 100644 --- a/utils/logger_test.go +++ b/utils/logger_test.go @@ -291,11 +291,12 @@ func TestEmergSysLogger(t *testing.T) { if err := sl.Emerg("Emergency Message"); err != nil { t.Errorf("Expected , received %v", err) } - // always prints to stderr + // always broadcasts message from journal // sl, _ = NewSysLogger("test2", 1) // if err := sl.Emerg("Emergency Message 2"); err != nil { // t.Errorf("Expected , received %v", err) // } + } func TestErrSysLogger(t *testing.T) {