Adding ToJSON method in callcost, tests for MaxCallCost

This commit is contained in:
DanB
2015-05-25 17:07:05 +02:00
parent 77a9709b27
commit cf9539f2bd
4 changed files with 70 additions and 2 deletions

View File

@@ -6,5 +6,5 @@ DR_1003_10CNT,DST_1003,RT_10CNT,*up,4,0,
DR_FS_40CNT,DST_FS,RT_40CNT,*up,4,0,
DR_FS_10CNT,DST_FS,RT_10CNT,*up,4,0,
DR_SPECIAL_1002,DST_1002,RT_1CNT,*up,4,0,
DR_1007_MAXCOST_DISC,DST_1007,RT_1CNT,*up,4,0.62,*disconnect
DR_1007_MAXCOST_FREE,DST_1007,RT_1CNT,*up,4,0.62,*free
DR_1007_MAXCOST_DISC,DST_1007,RT_1CNT_PER_SEC,*up,4,0.62,*disconnect
DR_1007_MAXCOST_FREE,DST_1007,RT_1CNT_PER_SEC,*up,4,0.62,*free
1 #Tag DestinationsTag RatesTag RoundingMethod RoundingDecimals MaxCost MaxCostStrategy
6 DR_FS_40CNT DST_FS RT_40CNT *up 4 0
7 DR_FS_10CNT DST_FS RT_10CNT *up 4 0
8 DR_SPECIAL_1002 DST_1002 RT_1CNT *up 4 0
9 DR_1007_MAXCOST_DISC DST_1007 RT_1CNT RT_1CNT_PER_SEC *up 4 0.62 *disconnect
10 DR_1007_MAXCOST_FREE DST_1007 RT_1CNT RT_1CNT_PER_SEC *up 4 0.62 *free

View File

@@ -6,3 +6,4 @@ RT_20CNT,0,0.1,60s,1s,60s
RT_40CNT,0.8,0.4,60s,30s,0s
RT_40CNT,0,0.2,60s,10s,60s
RT_1CNT,0,0.01,60s,60s,0s
RT_1CNT_PER_SEC,0,0.01,1s,1s,0s
1 #Tag ConnectFee Rate RateUnit RateIncrement GroupIntervalStart
6 RT_40CNT 0.8 0.4 60s 30s 0s
7 RT_40CNT 0 0.2 60s 10s 60s
8 RT_1CNT 0 0.01 60s 60s 0s
9 RT_1CNT_PER_SEC 0 0.01 1s 1s 0s

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package engine
import (
"encoding/json"
"errors"
"reflect"
"time"
@@ -161,3 +162,8 @@ func (cc *CallCost) GetLongestRounding() (roundingDecimals int, roundingMethod s
}
return
}
func (cc *CallCost) AsJSON() string {
ccJson, _ := json.Marshal(cc)
return string(ccJson)
}

View File

@@ -296,6 +296,67 @@ func TestTutLocalGetCosts(t *testing.T) {
} else if cc.Cost != 1.3 {
t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost)
}
tStart = time.Date(2014, 8, 4, 13, 0, 0, 0, time.UTC)
cd = engine.CallDescriptor{
Direction: "*out",
Category: "call",
Tenant: "cgrates.org",
Subject: "1001",
Account: "1001",
Destination: "1007",
TimeStart: tStart,
TimeEnd: tStart.Add(time.Duration(50) * time.Second),
}
if err := tutLocalRpc.Call("Responder.GetCost", cd, &cc); err != nil {
t.Error("Got error on Responder.GetCost: ", err.Error())
} else if cc.Cost != 0.5 {
t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
}
cd = engine.CallDescriptor{
Direction: "*out",
Category: "call",
Tenant: "cgrates.org",
Subject: "1001",
Account: "1001",
Destination: "1007",
TimeStart: tStart,
TimeEnd: tStart.Add(time.Duration(70) * time.Second),
}
if err := tutLocalRpc.Call("Responder.GetCost", cd, &cc); err != nil {
t.Error("Got error on Responder.GetCost: ", err.Error())
} else if cc.Cost != 0.62 {
t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
}
cd = engine.CallDescriptor{
Direction: "*out",
Category: "call",
Tenant: "cgrates.org",
Subject: "1002",
Account: "1002",
Destination: "1007",
TimeStart: tStart,
TimeEnd: tStart.Add(time.Duration(50) * time.Second),
}
if err := tutLocalRpc.Call("Responder.GetCost", cd, &cc); err != nil {
t.Error("Got error on Responder.GetCost: ", err.Error())
} else if cc.Cost != 0.5 {
t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
}
cd = engine.CallDescriptor{
Direction: "*out",
Category: "call",
Tenant: "cgrates.org",
Subject: "1002",
Account: "1002",
Destination: "1007",
TimeStart: tStart,
TimeEnd: tStart.Add(time.Duration(70) * time.Second),
}
if err := tutLocalRpc.Call("Responder.GetCost", cd, &cc); err != nil {
t.Error("Got error on Responder.GetCost: ", err.Error())
} else if cc.Cost != 0.62 {
t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
}
}
// Check call costs