balance destinationIDs exceptions

This commit is contained in:
Radu Ioan Fericean
2016-04-02 22:53:47 +03:00
parent 23eaaa0bc7
commit f3f257eff1
7 changed files with 91 additions and 9 deletions

View File

@@ -8,3 +8,4 @@ cgrates.org,1009,TEST_EXE,,,
cgrates.org,1010,TEST_DATA_r,,true,
cgrates.org,1011,TEST_VOICE,,,
cgrates.org,1012,PREPAID_10,,,
cgrates.org,1013,TEST_NEG,,,
1 #Tenant Account ActionPlanId ActionTriggersId AllowNegative Disabled
8 cgrates.org 1010 TEST_DATA_r true
9 cgrates.org 1011 TEST_VOICE
10 cgrates.org 1012 PREPAID_10
11 cgrates.org 1013 TEST_NEG

View File

@@ -4,3 +4,4 @@ PREPAID_10,BONUS_1,ASAP,10
TEST_EXE,TOPUP_EXE,ALWAYS,10
TEST_DATA_r,TOPUP_DATA_r,ASAP,10
TEST_VOICE,TOPUP_VOICE,ASAP,10
TEST_NEG,TOPUP_NEG,ASAP,10
1 #Tag ActionsTag TimingTag Weight
4 TEST_EXE TOPUP_EXE ALWAYS 10
5 TEST_DATA_r TOPUP_DATA_r ASAP 10
6 TEST_VOICE TOPUP_VOICE ASAP 10
7 TEST_NEG TOPUP_NEG ASAP 10

View File

@@ -7,4 +7,5 @@ CDRST_LOG,*log,,,,,,,,,,,,,,false,false,10
TOPUP_EXE,*topup,,,,*monetary,*out,,*any,,,*unlimited,,5,10,false,false,10
TOPUP_DATA_r,*topup,,,,*monetary,*out,,DATA_DEST,,,*unlimited,,5000000,10,false,false,10
TOPUP_DATA_r,*topup,,,,*data,*out,,DATA_DEST,datar,,*unlimited,,50000000000,10,false,false,10
TOPUP_VOICE,*topup,,,,*voice,*out,,GERMANY_MOBILE,,,*unlimited,,50000,10,false,false,10
TOPUP_VOICE,*topup,,,,*voice,*out,,GERMANY_MOBILE,,,*unlimited,,50000,10,false,false,10
TOPUP_NEG,*topup,,,,*voice,*out,,GERMANY;!GERMANY_MOBILE,*zero1m,,*unlimited,,100,10,false,false,10
1 #ActionsTag[0] Action[1] ActionExtraParameters[2] Filter[3] BalanceTag[4] BalanceType[5] Directions[6] Categories[7] DestinationIds[8] RatingSubject[9] SharedGroup[10] ExpiryTime[11] TimingTags[12] Units[13] BalanceWeight[14] BalanceBlocker[15] BalanceDisabled[16] Weight[17]
7 TOPUP_EXE *topup *monetary *out *any *unlimited 5 10 false false 10
8 TOPUP_DATA_r *topup *monetary *out DATA_DEST *unlimited 5000000 10 false false 10
9 TOPUP_DATA_r *topup *data *out DATA_DEST datar *unlimited 50000000000 10 false false 10
10 TOPUP_VOICE *topup *voice *out GERMANY_MOBILE *unlimited 50000 10 false false 10
11 TOPUP_NEG *topup *voice *out GERMANY;!GERMANY_MOBILE *zero1m *unlimited 100 10 false false 10

View File

@@ -306,14 +306,21 @@ func (ub *Account) getBalancesForPrefix(prefix, category, direction, tor string,
if x, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
destIds := x.(map[interface{}]struct{})
for dId, _ := range destIds {
if b.DestinationIDs[dId.(string)] == true {
b.precision = len(p)
usefulBalances = append(usefulBalances, b)
break
includeDest, found := b.DestinationIDs[dId.(string)]
utils.Logger.Debug("DID: " + dId.(string))
if found {
if includeDest {
b.precision = len(p)
usefulBalances = append(usefulBalances, b)
break
} else { // the balance had !, so now equals false => exclude balance
b.precision = 1 // fake to exit the outer loop
break
}
}
if b.precision > 0 {
/*if b.precision > 0 {
break
}
}*/
}
}
if b.precision > 0 {

View File

@@ -187,3 +187,34 @@ func TestTpZeroCost(t *testing.T) {
t.Errorf("Calling ApierV2.GetAccount received: %s", utils.ToIJSON(acnt))
}
}
func TestTpZeroNegativeCost(t *testing.T) {
if !*testIntegration {
return
}
tStart := time.Date(2016, 3, 31, 0, 0, 0, 0, time.UTC)
cd := engine.CallDescriptor{
Direction: "*out",
Category: "call",
Tenant: "cgrates.org",
Subject: "free",
Account: "1013",
Destination: "+4915",
DurationIndex: 0,
TimeStart: tStart,
TimeEnd: tStart.Add(time.Duration(20) * time.Second),
}
var cc engine.CallCost
if err := tpRPC.Call("Responder.Debit", cd, &cc); err != nil {
t.Error("Got error on Responder.GetCost: ", err.Error())
} else if cc.GetDuration() != 20*time.Second {
t.Errorf("Calling Responder.MaxDebit got callcost: %v", utils.ToIJSON(cc))
}
var acnt *engine.Account
attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1013"}
if err := tpRPC.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
t.Error("Got error on ApierV2.GetAccount: ", err.Error())
} else if acnt.BalanceMap[utils.VOICE][0].Value != 100.0 {
t.Errorf("Calling ApierV2.GetAccount received: %s", utils.ToIJSON(acnt))
}
}

View File

@@ -67,7 +67,11 @@ func NewStringMap(s ...string) StringMap {
for _, v := range s {
v = strings.TrimSpace(v)
if v != "" {
result[v] = true
if strings.HasPrefix(v, "!") {
result[v[1:]] = false
} else {
result[v] = true
}
}
}
return result
@@ -128,7 +132,11 @@ func StringMapFromSlice(s []string) StringMap {
for _, v := range s {
v = strings.TrimSpace(v)
if v != "" {
result[v] = true
if strings.HasPrefix(v, "!") {
result[v[1:]] = false
} else {
result[v] = true
}
}
}
return result

33
utils/map_test.go Normal file
View File

@@ -0,0 +1,33 @@
package utils
import "testing"
func TestStringMapParse(t *testing.T) {
sm := ParseStringMap("1;2;3;4")
if len(sm) != 4 {
t.Error("Error pasring map: ", sm)
}
}
func TestStringMapParseNegative(t *testing.T) {
sm := ParseStringMap("1;2;!3;4")
if len(sm) != 4 {
t.Error("Error pasring map: ", sm)
}
if sm["3"] != false {
t.Error("Error parsing negative: ", sm)
}
}
func TestStringMapCompare(t *testing.T) {
sm := ParseStringMap("1;2;!3;4")
if include, found := sm["2"]; include != true && found != true {
t.Error("Error detecting positive: ", sm)
}
if include, found := sm["3"]; include != false && found != true {
t.Error("Error detecting negative: ", sm)
}
if include, found := sm["5"]; include != false && found != false {
t.Error("Error detecting missing: ", sm)
}
}