mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
utils csv export tests move toe model helpers
This commit is contained in:
@@ -17,6 +17,19 @@ func APItoModelTiming(t *utils.ApierTPTiming) (result *TpTiming) {
|
||||
Time: t.Time,
|
||||
}
|
||||
}
|
||||
|
||||
func APItoModelApierTiming(t *utils.ApierTPTiming) (result *TpTiming) {
|
||||
return &TpTiming{
|
||||
Tpid: t.TPid,
|
||||
Tag: t.TimingId,
|
||||
Years: t.Years,
|
||||
Months: t.Months,
|
||||
MonthDays: t.MonthDays,
|
||||
WeekDays: t.WeekDays,
|
||||
Time: t.Time,
|
||||
}
|
||||
}
|
||||
|
||||
func APItoModelDestination(dest *utils.TPDestination) (result []TpDestination) {
|
||||
for _, p := range dest.Prefixes {
|
||||
result = append(result, TpDestination{
|
||||
@@ -138,6 +151,7 @@ func APItoModelLcrRule(lcrs *utils.TPLcrRules) (result []TpLcrRule) {
|
||||
Strategy: lcr.Strategy,
|
||||
StrategyParams: lcr.StrategyParams,
|
||||
ActivationTime: lcr.ActivationTime,
|
||||
Weight: lcr.Weight,
|
||||
})
|
||||
}
|
||||
if len(lcrs.LcrRules) == 0 {
|
||||
|
||||
@@ -93,7 +93,16 @@ func csvDump(s interface{}) ([]string, error) {
|
||||
for fieldName, fieldIndex := range fieldIndexMap {
|
||||
field := elem.FieldByName(fieldName)
|
||||
if field.IsValid() && fieldIndex < len(result) {
|
||||
result[fieldIndex] = field.String()
|
||||
switch field.Kind() {
|
||||
case reflect.Float64:
|
||||
result[fieldIndex] = strconv.FormatFloat(field.Float(), 'f', -1, 64)
|
||||
case reflect.Int:
|
||||
result[fieldIndex] = strconv.FormatInt(field.Int(), 10)
|
||||
case reflect.Bool:
|
||||
result[fieldIndex] = strconv.FormatBool(field.Bool())
|
||||
case reflect.String:
|
||||
result[fieldIndex] = field.String()
|
||||
}
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
@@ -119,9 +128,25 @@ func modelEqual(this interface{}, other interface{}) bool {
|
||||
for _, fieldName := range fieldNames {
|
||||
thisField := thisElem.FieldByName(fieldName)
|
||||
otherField := otherElem.FieldByName(fieldName)
|
||||
if thisField.String() != otherField.String() {
|
||||
return false
|
||||
switch thisField.Kind() {
|
||||
case reflect.Float64:
|
||||
if thisField.Float() != otherField.Float() {
|
||||
return false
|
||||
}
|
||||
case reflect.Int:
|
||||
if thisField.Int() != otherField.Int() {
|
||||
return false
|
||||
}
|
||||
case reflect.Bool:
|
||||
if thisField.Bool() != otherField.Bool() {
|
||||
return false
|
||||
}
|
||||
case reflect.String:
|
||||
if thisField.String() != otherField.String() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -263,6 +288,7 @@ func (tps TpRatingPlans) GetRatingPlans() (map[string][]*utils.TPRatingPlanBindi
|
||||
|
||||
for _, tpRp := range tps {
|
||||
rpb := &utils.TPRatingPlanBinding{
|
||||
|
||||
DestinationRatesId: tpRp.DestratesTag,
|
||||
TimingId: tpRp.TimingTag,
|
||||
Weight: tpRp.Weight,
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package engine
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestModelHelperCsvLoad(t *testing.T) {
|
||||
l, err := csvLoad(TpDestination{}, []string{"TEST_DEST", "+492"})
|
||||
@@ -27,3 +32,597 @@ func TestModelHelperCsvDump(t *testing.T) {
|
||||
t.Errorf("model load failed: %+v", tpd)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPDestinationAsExportSlice(t *testing.T) {
|
||||
tpDst := &utils.TPDestination{
|
||||
TPid: "TEST_TPID",
|
||||
DestinationId: "TEST_DEST",
|
||||
Prefixes: []string{"49", "49176", "49151"},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"TEST_DEST", "49"},
|
||||
[]string{"TEST_DEST", "49176"},
|
||||
[]string{"TEST_DEST", "49151"},
|
||||
}
|
||||
mdst := APItoModelDestination(tpDst)
|
||||
var slc [][]string
|
||||
for _, md := range mdst {
|
||||
lc, err := csvDump(md)
|
||||
if err != nil {
|
||||
t.Error("Error dumping to csv: ", err)
|
||||
}
|
||||
slc = append(slc, lc)
|
||||
}
|
||||
if !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPRateAsExportSlice(t *testing.T) {
|
||||
tpRate := &utils.TPRate{
|
||||
TPid: "TEST_TPID",
|
||||
RateId: "TEST_RATEID",
|
||||
RateSlots: []*utils.RateSlot{
|
||||
&utils.RateSlot{
|
||||
ConnectFee: 0.100,
|
||||
Rate: 0.200,
|
||||
RateUnit: "60",
|
||||
RateIncrement: "60",
|
||||
GroupIntervalStart: "0"},
|
||||
&utils.RateSlot{
|
||||
ConnectFee: 0.0,
|
||||
Rate: 0.1,
|
||||
RateUnit: "1",
|
||||
RateIncrement: "60",
|
||||
GroupIntervalStart: "60"},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"TEST_RATEID", "0.1", "0.2", "60", "60", "0"},
|
||||
[]string{"TEST_RATEID", "0", "0.1", "1", "60", "60"},
|
||||
}
|
||||
|
||||
ms := APItoModelRate(tpRate)
|
||||
var slc [][]string
|
||||
for _, m := range ms {
|
||||
lc, err := csvDump(m)
|
||||
if err != nil {
|
||||
t.Error("Error dumping to csv: ", err)
|
||||
}
|
||||
slc = append(slc, lc)
|
||||
}
|
||||
if !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc[0], slc[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPDestinationRateAsExportSlice(t *testing.T) {
|
||||
tpDstRate := &utils.TPDestinationRate{
|
||||
TPid: "TEST_TPID",
|
||||
DestinationRateId: "TEST_DSTRATE",
|
||||
DestinationRates: []*utils.DestinationRate{
|
||||
&utils.DestinationRate{
|
||||
DestinationId: "TEST_DEST1",
|
||||
RateId: "TEST_RATE1",
|
||||
RoundingMethod: "*up",
|
||||
RoundingDecimals: 4},
|
||||
&utils.DestinationRate{
|
||||
DestinationId: "TEST_DEST2",
|
||||
RateId: "TEST_RATE2",
|
||||
RoundingMethod: "*up",
|
||||
RoundingDecimals: 4},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"TEST_DSTRATE", "TEST_DEST1", "TEST_RATE1", "*up", "4", "0", ""},
|
||||
[]string{"TEST_DSTRATE", "TEST_DEST2", "TEST_RATE2", "*up", "4", "0", ""},
|
||||
}
|
||||
ms := APItoModelDestinationRate(tpDstRate)
|
||||
var slc [][]string
|
||||
for _, m := range ms {
|
||||
lc, err := csvDump(m)
|
||||
if err != nil {
|
||||
t.Error("Error dumping to csv: ", err)
|
||||
}
|
||||
slc = append(slc, lc)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestApierTPTimingAsExportSlice(t *testing.T) {
|
||||
tpTiming := &utils.ApierTPTiming{
|
||||
TPid: "TEST_TPID",
|
||||
TimingId: "TEST_TIMING",
|
||||
Years: "*any",
|
||||
Months: "*any",
|
||||
MonthDays: "*any",
|
||||
WeekDays: "1;2;4",
|
||||
Time: "00:00:01"}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"TEST_TIMING", "*any", "*any", "*any", "1;2;4", "00:00:01"},
|
||||
}
|
||||
ms := APItoModelApierTiming(tpTiming)
|
||||
var slc [][]string
|
||||
|
||||
lc, err := csvDump(*ms)
|
||||
if err != nil {
|
||||
t.Error("Error dumping to csv: ", err)
|
||||
}
|
||||
slc = append(slc, lc)
|
||||
|
||||
if !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPRatingPlanAsExportSlice(t *testing.T) {
|
||||
tpRpln := &utils.TPRatingPlan{
|
||||
TPid: "TEST_TPID",
|
||||
RatingPlanId: "TEST_RPLAN",
|
||||
RatingPlanBindings: []*utils.TPRatingPlanBinding{
|
||||
&utils.TPRatingPlanBinding{
|
||||
DestinationRatesId: "TEST_DSTRATE1",
|
||||
TimingId: "TEST_TIMING1",
|
||||
Weight: 10.0},
|
||||
&utils.TPRatingPlanBinding{
|
||||
DestinationRatesId: "TEST_DSTRATE2",
|
||||
TimingId: "TEST_TIMING2",
|
||||
Weight: 20.0},
|
||||
}}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"TEST_RPLAN", "TEST_DSTRATE1", "TEST_TIMING1", "10"},
|
||||
[]string{"TEST_RPLAN", "TEST_DSTRATE2", "TEST_TIMING2", "20"},
|
||||
}
|
||||
|
||||
ms := APItoModelRatingPlan(tpRpln)
|
||||
var slc [][]string
|
||||
for _, m := range ms {
|
||||
lc, err := csvDump(m)
|
||||
if err != nil {
|
||||
t.Error("Error dumping to csv: ", err)
|
||||
}
|
||||
slc = append(slc, lc)
|
||||
}
|
||||
if !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPRatingProfileAsExportSlice(t *testing.T) {
|
||||
tpRpf := &utils.TPRatingProfile{
|
||||
TPid: "TEST_TPID",
|
||||
LoadId: "TEST_LOADID",
|
||||
Direction: utils.OUT,
|
||||
Tenant: "cgrates.org",
|
||||
Category: "call",
|
||||
Subject: "*any",
|
||||
RatingPlanActivations: []*utils.TPRatingActivation{
|
||||
&utils.TPRatingActivation{
|
||||
ActivationTime: "2014-01-14T00:00:00Z",
|
||||
RatingPlanId: "TEST_RPLAN1",
|
||||
FallbackSubjects: "subj1;subj2"},
|
||||
&utils.TPRatingActivation{
|
||||
ActivationTime: "2014-01-15T00:00:00Z",
|
||||
RatingPlanId: "TEST_RPLAN2",
|
||||
FallbackSubjects: "subj1;subj2"},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{utils.OUT, "cgrates.org", "call", "*any", "2014-01-14T00:00:00Z", "TEST_RPLAN1", "subj1;subj2", ""},
|
||||
[]string{utils.OUT, "cgrates.org", "call", "*any", "2014-01-15T00:00:00Z", "TEST_RPLAN2", "subj1;subj2", ""},
|
||||
}
|
||||
|
||||
ms := APItoModelRatingProfile(tpRpf)
|
||||
var slc [][]string
|
||||
for _, m := range ms {
|
||||
lc, err := csvDump(m)
|
||||
if err != nil {
|
||||
t.Error("Error dumping to csv: ", err)
|
||||
}
|
||||
slc = append(slc, lc)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPActionsAsExportSlice(t *testing.T) {
|
||||
tpActs := &utils.TPActions{
|
||||
TPid: "TEST_TPID",
|
||||
ActionsId: "TEST_ACTIONS",
|
||||
Actions: []*utils.TPAction{
|
||||
&utils.TPAction{
|
||||
Identifier: "*topup_reset",
|
||||
BalanceType: "*monetary",
|
||||
Direction: utils.OUT,
|
||||
Units: 5.0,
|
||||
ExpiryTime: "*never",
|
||||
DestinationIds: "*any",
|
||||
RatingSubject: "special1",
|
||||
Category: "call",
|
||||
SharedGroup: "GROUP1",
|
||||
BalanceWeight: 10.0,
|
||||
ExtraParameters: "",
|
||||
Weight: 10.0},
|
||||
&utils.TPAction{
|
||||
Identifier: "*http_post",
|
||||
BalanceType: "",
|
||||
Direction: "",
|
||||
Units: 0.0,
|
||||
ExpiryTime: "",
|
||||
DestinationIds: "",
|
||||
RatingSubject: "",
|
||||
Category: "",
|
||||
SharedGroup: "",
|
||||
BalanceWeight: 0.0,
|
||||
ExtraParameters: "http://localhost/¶m1=value1",
|
||||
Weight: 20.0},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"TEST_ACTIONS", "*topup_reset", "", "", "*monetary", utils.OUT, "call", "*any", "special1", "GROUP1", "*never", "", "5", "10", "10"},
|
||||
[]string{"TEST_ACTIONS", "*http_post", "http://localhost/¶m1=value1", "", "", "", "", "", "", "", "", "", "0", "0", "20"},
|
||||
}
|
||||
|
||||
ms := APItoModelAction(tpActs)
|
||||
var slc [][]string
|
||||
for _, m := range ms {
|
||||
lc, err := csvDump(m)
|
||||
if err != nil {
|
||||
t.Error("Error dumping to csv: ", err)
|
||||
}
|
||||
slc = append(slc, lc)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: \n%+v, received: \n%+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
// SHARED_A,*any,*highest,
|
||||
func TestTPSharedGroupsAsExportSlice(t *testing.T) {
|
||||
tpSGs := &utils.TPSharedGroups{
|
||||
TPid: "TEST_TPID",
|
||||
SharedGroupsId: "SHARED_GROUP_TEST",
|
||||
SharedGroups: []*utils.TPSharedGroup{
|
||||
&utils.TPSharedGroup{
|
||||
Account: "*any",
|
||||
Strategy: "*highest",
|
||||
RatingSubject: "special1"},
|
||||
&utils.TPSharedGroup{
|
||||
Account: "second",
|
||||
Strategy: "*highest",
|
||||
RatingSubject: "special2"},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"SHARED_GROUP_TEST", "*any", "*highest", "special1"},
|
||||
[]string{"SHARED_GROUP_TEST", "second", "*highest", "special2"},
|
||||
}
|
||||
|
||||
ms := APItoModelSharedGroup(tpSGs)
|
||||
var slc [][]string
|
||||
for _, m := range ms {
|
||||
lc, err := csvDump(m)
|
||||
if err != nil {
|
||||
t.Error("Error dumping to csv: ", err)
|
||||
}
|
||||
slc = append(slc, lc)
|
||||
}
|
||||
if !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
//*in,cgrates.org,*any,EU_LANDLINE,LCR_STANDARD,*static,ivo;dan;rif,2012-01-01T00:00:00Z,10
|
||||
func TestTPLcrRulesAsExportSlice(t *testing.T) {
|
||||
lcr := &utils.TPLcrRules{
|
||||
TPid: "TEST_TPID",
|
||||
LcrRulesId: "TEST_LCR",
|
||||
LcrRules: []*utils.TPLcrRule{
|
||||
&utils.TPLcrRule{
|
||||
Direction: "*in",
|
||||
Tenant: "cgrates.org",
|
||||
Account: "*any",
|
||||
Subject: "*any",
|
||||
DestinationId: "EU_LANDLINE",
|
||||
Category: "LCR_STANDARD",
|
||||
Strategy: "*static",
|
||||
StrategyParams: "ivo;dan;rif",
|
||||
ActivationTime: "2012-01-01T00:00:00Z",
|
||||
Weight: 20.0},
|
||||
//*in,cgrates.org,*any,*any,LCR_STANDARD,*lowest_cost,,2012-01-01T00:00:00Z,20
|
||||
&utils.TPLcrRule{
|
||||
Direction: "*in",
|
||||
Tenant: "cgrates.org",
|
||||
Account: "*any",
|
||||
Subject: "*any",
|
||||
DestinationId: "*any",
|
||||
Category: "LCR_STANDARD",
|
||||
Strategy: "*lowest_cost",
|
||||
StrategyParams: "",
|
||||
ActivationTime: "2012-01-01T00:00:00Z",
|
||||
Weight: 10.0},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"*in", "cgrates.org", "LCR_STANDARD", "*any", "*any", "EU_LANDLINE", "", "*static", "ivo;dan;rif", "2012-01-01T00:00:00Z", "20"},
|
||||
[]string{"*in", "cgrates.org", "LCR_STANDARD", "*any", "*any", "*any", "", "*lowest_cost", "", "2012-01-01T00:00:00Z", "10"},
|
||||
}
|
||||
ms := APItoModelLcrRule(lcr)
|
||||
var slc [][]string
|
||||
for _, m := range ms {
|
||||
lc, err := csvDump(m)
|
||||
if err != nil {
|
||||
t.Error("Error dumping to csv: ", err)
|
||||
}
|
||||
slc = append(slc, lc)
|
||||
}
|
||||
if !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
//CDRST1,5,60m,ASR,2014-07-29T15:00:00Z;2014-07-29T16:00:00Z,*voice,87.139.12.167,FS_JSON,rated,*out,cgrates.org,call,dan,dan,49,5m;10m,default,rif,rif,0;2,STANDARD_TRIGGERS
|
||||
func TestTPCdrStatsAsExportSlice(t *testing.T) {
|
||||
cdrStats := &utils.TPCdrStats{
|
||||
TPid: "TEST_TPID",
|
||||
CdrStatsId: "CDRST1",
|
||||
CdrStats: []*utils.TPCdrStat{
|
||||
&utils.TPCdrStat{
|
||||
QueueLength: "5",
|
||||
TimeWindow: "60m",
|
||||
Metrics: "ASR;ACD",
|
||||
SetupInterval: "2014-07-29T15:00:00Z;2014-07-29T16:00:00Z",
|
||||
TORs: "*voice",
|
||||
CdrHosts: "87.139.12.167",
|
||||
CdrSources: "FS_JSON",
|
||||
ReqTypes: utils.META_RATED,
|
||||
Directions: "*out",
|
||||
Tenants: "cgrates.org",
|
||||
Categories: "call",
|
||||
Accounts: "dan",
|
||||
Subjects: "dan",
|
||||
DestinationPrefixes: "49",
|
||||
UsageInterval: "5m;10m",
|
||||
Suppliers: "supplier1",
|
||||
DisconnectCauses: "NORMAL_CLEARNING",
|
||||
MediationRunIds: "default",
|
||||
RatedAccounts: "rif",
|
||||
RatedSubjects: "rif",
|
||||
CostInterval: "0;2",
|
||||
ActionTriggers: "STANDARD_TRIGGERS"},
|
||||
&utils.TPCdrStat{
|
||||
QueueLength: "5",
|
||||
TimeWindow: "60m",
|
||||
Metrics: "ASR",
|
||||
SetupInterval: "2014-07-29T15:00:00Z;2014-07-29T16:00:00Z",
|
||||
TORs: "*voice",
|
||||
CdrHosts: "87.139.12.167",
|
||||
CdrSources: "FS_JSON",
|
||||
ReqTypes: utils.META_RATED,
|
||||
Directions: "*out",
|
||||
Tenants: "cgrates.org",
|
||||
Categories: "call",
|
||||
Accounts: "dan",
|
||||
Subjects: "dan",
|
||||
DestinationPrefixes: "49",
|
||||
UsageInterval: "5m;10m",
|
||||
Suppliers: "supplier1",
|
||||
DisconnectCauses: "NORMAL_CLEARNING",
|
||||
MediationRunIds: "default",
|
||||
RatedAccounts: "dan",
|
||||
RatedSubjects: "dan",
|
||||
CostInterval: "0;2",
|
||||
ActionTriggers: "STANDARD_TRIGGERS"},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"CDRST1", "5", "60m", "ASR;ACD", "2014-07-29T15:00:00Z;2014-07-29T16:00:00Z", "*voice", "87.139.12.167", "FS_JSON", utils.META_RATED, "*out", "cgrates.org", "call",
|
||||
"dan", "dan", "49", "5m;10m", "supplier1", "NORMAL_CLEARNING", "default", "rif", "rif", "0;2", "STANDARD_TRIGGERS"},
|
||||
[]string{"CDRST1", "5", "60m", "ASR", "2014-07-29T15:00:00Z;2014-07-29T16:00:00Z", "*voice", "87.139.12.167", "FS_JSON", utils.META_RATED, "*out", "cgrates.org", "call",
|
||||
"dan", "dan", "49", "5m;10m", "supplier1", "NORMAL_CLEARNING", "default", "dan", "dan", "0;2", "STANDARD_TRIGGERS"},
|
||||
}
|
||||
ms := APItoModelCdrStat(cdrStats)
|
||||
var slc [][]string
|
||||
for _, m := range ms {
|
||||
lc, err := csvDump(m)
|
||||
if err != nil {
|
||||
t.Error("Error dumping to csv: ", err)
|
||||
}
|
||||
slc = append(slc, lc)
|
||||
}
|
||||
if !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
//#Direction,Tenant,Category,Account,Subject,RunId,RunFilter,ReqTypeField,DirectionField,TenantField,CategoryField,AccountField,SubjectField,DestinationField,SetupTimeField,AnswerTimeField,UsageField
|
||||
//*out,cgrates.org,call,1001,1001,derived_run1,,^rated,*default,*default,*default,*default,^1002,*default,*default,*default,*default
|
||||
func TestTPDerivedChargersAsExportSlice(t *testing.T) {
|
||||
dcs := &utils.TPDerivedChargers{
|
||||
TPid: "TEST_TPID",
|
||||
Loadid: "TEST_LOADID",
|
||||
Direction: "*out",
|
||||
Tenant: "cgrates.org",
|
||||
Category: "call",
|
||||
Account: "1001",
|
||||
Subject: "1001",
|
||||
DerivedChargers: []*utils.TPDerivedCharger{
|
||||
&utils.TPDerivedCharger{
|
||||
RunId: "derived_run1",
|
||||
RunFilters: "",
|
||||
ReqTypeField: "^rated",
|
||||
DirectionField: utils.META_DEFAULT,
|
||||
TenantField: utils.META_DEFAULT,
|
||||
CategoryField: utils.META_DEFAULT,
|
||||
AccountField: utils.META_DEFAULT,
|
||||
SubjectField: "^1002",
|
||||
DestinationField: utils.META_DEFAULT,
|
||||
SetupTimeField: utils.META_DEFAULT,
|
||||
AnswerTimeField: utils.META_DEFAULT,
|
||||
UsageField: utils.META_DEFAULT,
|
||||
SupplierField: utils.META_DEFAULT,
|
||||
DisconnectCauseField: utils.META_DEFAULT,
|
||||
},
|
||||
&utils.TPDerivedCharger{
|
||||
RunId: "derived_run2",
|
||||
RunFilters: "",
|
||||
ReqTypeField: "^rated",
|
||||
DirectionField: utils.META_DEFAULT,
|
||||
TenantField: utils.META_DEFAULT,
|
||||
CategoryField: utils.META_DEFAULT,
|
||||
AccountField: "^1002",
|
||||
SubjectField: utils.META_DEFAULT,
|
||||
DestinationField: utils.META_DEFAULT,
|
||||
SetupTimeField: utils.META_DEFAULT,
|
||||
AnswerTimeField: utils.META_DEFAULT,
|
||||
UsageField: utils.META_DEFAULT,
|
||||
SupplierField: utils.META_DEFAULT,
|
||||
DisconnectCauseField: utils.META_DEFAULT,
|
||||
},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"*out", "cgrates.org", "call", "1001", "1001",
|
||||
"derived_run1", "", "^rated", utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, "^1002", utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT},
|
||||
[]string{"*out", "cgrates.org", "call", "1001", "1001",
|
||||
"derived_run2", "", "^rated", utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, "^1002", utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT},
|
||||
}
|
||||
ms := APItoModelDerivedCharger(dcs)
|
||||
var slc [][]string
|
||||
for _, m := range ms {
|
||||
lc, err := csvDump(m)
|
||||
if err != nil {
|
||||
t.Error("Error dumping to csv: ", err)
|
||||
}
|
||||
slc = append(slc, lc)
|
||||
}
|
||||
if !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPActionTriggersAsExportSlice(t *testing.T) {
|
||||
ap := &utils.TPActionPlan{
|
||||
TPid: "TEST_TPID",
|
||||
Id: "PACKAGE_10",
|
||||
ActionPlan: []*utils.TPActionTiming{
|
||||
&utils.TPActionTiming{
|
||||
ActionsId: "TOPUP_RST_10",
|
||||
TimingId: "ASAP",
|
||||
Weight: 10.0},
|
||||
&utils.TPActionTiming{
|
||||
ActionsId: "TOPUP_RST_5",
|
||||
TimingId: "ASAP",
|
||||
Weight: 20.0},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"PACKAGE_10", "TOPUP_RST_10", "ASAP", "10"},
|
||||
[]string{"PACKAGE_10", "TOPUP_RST_5", "ASAP", "20"},
|
||||
}
|
||||
ms := APItoModelActionPlan(ap)
|
||||
var slc [][]string
|
||||
for _, m := range ms {
|
||||
lc, err := csvDump(m)
|
||||
if err != nil {
|
||||
t.Error("Error dumping to csv: ", err)
|
||||
}
|
||||
slc = append(slc, lc)
|
||||
}
|
||||
if !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPActionPlanAsExportSlice(t *testing.T) {
|
||||
at := &utils.TPActionTriggers{
|
||||
TPid: "TEST_TPID",
|
||||
ActionTriggersId: "STANDARD_TRIGGERS",
|
||||
ActionTriggers: []*utils.TPActionTrigger{
|
||||
&utils.TPActionTrigger{
|
||||
ThresholdType: "*min_balance",
|
||||
ThresholdValue: 2.0,
|
||||
Recurrent: false,
|
||||
MinSleep: "0",
|
||||
BalanceId: "b1",
|
||||
BalanceType: "*monetary",
|
||||
BalanceDirection: "*out",
|
||||
BalanceDestinationIds: "",
|
||||
BalanceWeight: 0.0,
|
||||
BalanceExpirationDate: "*never",
|
||||
BalanceTimingTags: "T1",
|
||||
BalanceRatingSubject: "special1",
|
||||
BalanceCategory: "call",
|
||||
BalanceSharedGroup: "SHARED_1",
|
||||
MinQueuedItems: 0,
|
||||
ActionsId: "LOG_WARNING",
|
||||
Weight: 10},
|
||||
&utils.TPActionTrigger{
|
||||
ThresholdType: "*max_counter",
|
||||
ThresholdValue: 5.0,
|
||||
Recurrent: false,
|
||||
MinSleep: "0",
|
||||
BalanceId: "b2",
|
||||
BalanceType: "*monetary",
|
||||
BalanceDirection: "*out",
|
||||
BalanceDestinationIds: "FS_USERS",
|
||||
BalanceWeight: 0.0,
|
||||
BalanceExpirationDate: "*never",
|
||||
BalanceTimingTags: "T1",
|
||||
BalanceRatingSubject: "special1",
|
||||
BalanceCategory: "call",
|
||||
BalanceSharedGroup: "SHARED_1",
|
||||
MinQueuedItems: 0,
|
||||
ActionsId: "LOG_WARNING",
|
||||
Weight: 10},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"STANDARD_TRIGGERS", "", "*min_balance", "2", "false", "0", "b1", "*monetary", "*out", "call", "", "special1", "SHARED_1", "*never", "T1", "0", "0", "LOG_WARNING", "10"},
|
||||
[]string{"STANDARD_TRIGGERS", "", "*max_counter", "5", "false", "0", "b2", "*monetary", "*out", "call", "FS_USERS", "special1", "SHARED_1", "*never", "T1", "0", "0", "LOG_WARNING", "10"},
|
||||
}
|
||||
ms := APItoModelActionTrigger(at)
|
||||
var slc [][]string
|
||||
for _, m := range ms {
|
||||
lc, err := csvDump(m)
|
||||
if err != nil {
|
||||
t.Error("Error dumping to csv: ", err)
|
||||
}
|
||||
slc = append(slc, lc)
|
||||
}
|
||||
if !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPAccountActionsAsExportSlice(t *testing.T) {
|
||||
aa := &utils.TPAccountActions{
|
||||
TPid: "TEST_TPID",
|
||||
LoadId: "TEST_LOADID",
|
||||
Tenant: "cgrates.org",
|
||||
Account: "1001",
|
||||
Direction: "*out",
|
||||
ActionPlanId: "PACKAGE_10_SHARED_A_5",
|
||||
ActionTriggersId: "STANDARD_TRIGGERS",
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"cgrates.org", "1001", "*out", "PACKAGE_10_SHARED_A_5", "STANDARD_TRIGGERS"},
|
||||
}
|
||||
ms := APItoModelAccountAction(aa)
|
||||
var slc [][]string
|
||||
lc, err := csvDump(*ms)
|
||||
if err != nil {
|
||||
t.Error("Error dumping to csv: ", err)
|
||||
}
|
||||
slc = append(slc, lc)
|
||||
if !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -638,7 +638,7 @@ func TestTutLocalLcrQos(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eStLcr.Entry, lcr.Entry)
|
||||
} else if !reflect.DeepEqual(eStLcr.SupplierCosts, lcr.SupplierCosts) && !reflect.DeepEqual(eStLcr2.SupplierCosts, lcr.SupplierCosts) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts[1], lcr.SupplierCosts[1])
|
||||
t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts[0], lcr.SupplierCosts[0])
|
||||
}
|
||||
testCdr3 := &engine.StoredCdr{CgrId: utils.Sha1("testcdr3", time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC).String()),
|
||||
TOR: utils.VOICE, AccId: "testcdr3", CdrHost: "192.168.1.1", CdrSource: "TEST_QOS_LCR", ReqType: utils.META_RATED,
|
||||
|
||||
@@ -23,466 +23,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTPDestinationAsExportSlice(t *testing.T) {
|
||||
tpDst := &TPDestination{
|
||||
TPid: "TEST_TPID",
|
||||
DestinationId: "TEST_DEST",
|
||||
Prefixes: []string{"49", "49176", "49151"},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"TEST_DEST", "49"},
|
||||
[]string{"TEST_DEST", "49176"},
|
||||
[]string{"TEST_DEST", "49151"},
|
||||
}
|
||||
if slc := tpDst.AsExportSlice(); !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPRateAsExportSlice(t *testing.T) {
|
||||
tpRate := &TPRate{
|
||||
TPid: "TEST_TPID",
|
||||
RateId: "TEST_RATEID",
|
||||
RateSlots: []*RateSlot{
|
||||
&RateSlot{
|
||||
ConnectFee: 0.100,
|
||||
Rate: 0.200,
|
||||
RateUnit: "60",
|
||||
RateIncrement: "60",
|
||||
GroupIntervalStart: "0"},
|
||||
&RateSlot{
|
||||
ConnectFee: 0.0,
|
||||
Rate: 0.1,
|
||||
RateUnit: "1",
|
||||
RateIncrement: "60",
|
||||
GroupIntervalStart: "60"},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"TEST_RATEID", "0.1", "0.2", "60", "60", "0"},
|
||||
[]string{"TEST_RATEID", "0", "0.1", "1", "60", "60"},
|
||||
}
|
||||
if slc := tpRate.AsExportSlice(); !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPDestinationRateAsExportSlice(t *testing.T) {
|
||||
tpDstRate := &TPDestinationRate{
|
||||
TPid: "TEST_TPID",
|
||||
DestinationRateId: "TEST_DSTRATE",
|
||||
DestinationRates: []*DestinationRate{
|
||||
&DestinationRate{
|
||||
DestinationId: "TEST_DEST1",
|
||||
RateId: "TEST_RATE1",
|
||||
RoundingMethod: "*up",
|
||||
RoundingDecimals: 4},
|
||||
&DestinationRate{
|
||||
DestinationId: "TEST_DEST2",
|
||||
RateId: "TEST_RATE2",
|
||||
RoundingMethod: "*up",
|
||||
RoundingDecimals: 4},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"TEST_DSTRATE", "TEST_DEST1", "TEST_RATE1", "*up", "4"},
|
||||
[]string{"TEST_DSTRATE", "TEST_DEST2", "TEST_RATE2", "*up", "4"},
|
||||
}
|
||||
if slc := tpDstRate.AsExportSlice(); !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestApierTPTimingAsExportSlice(t *testing.T) {
|
||||
tpTiming := &ApierTPTiming{
|
||||
TPid: "TEST_TPID",
|
||||
TimingId: "TEST_TIMING",
|
||||
Years: "*any",
|
||||
Months: "*any",
|
||||
MonthDays: "*any",
|
||||
WeekDays: "1;2;4",
|
||||
Time: "00:00:01"}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"TEST_TIMING", "*any", "*any", "*any", "1;2;4", "00:00:01"},
|
||||
}
|
||||
if slc := tpTiming.AsExportSlice(); !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPRatingPlanAsExportSlice(t *testing.T) {
|
||||
tpRpln := &TPRatingPlan{
|
||||
TPid: "TEST_TPID",
|
||||
RatingPlanId: "TEST_RPLAN",
|
||||
RatingPlanBindings: []*TPRatingPlanBinding{
|
||||
&TPRatingPlanBinding{
|
||||
DestinationRatesId: "TEST_DSTRATE1",
|
||||
TimingId: "TEST_TIMING1",
|
||||
Weight: 10.0},
|
||||
&TPRatingPlanBinding{
|
||||
DestinationRatesId: "TEST_DSTRATE2",
|
||||
TimingId: "TEST_TIMING2",
|
||||
Weight: 20.0},
|
||||
}}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"TEST_RPLAN", "TEST_DSTRATE1", "TEST_TIMING1", "10"},
|
||||
[]string{"TEST_RPLAN", "TEST_DSTRATE2", "TEST_TIMING2", "20"},
|
||||
}
|
||||
if slc := tpRpln.AsExportSlice(); !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPRatingProfileAsExportSlice(t *testing.T) {
|
||||
tpRpf := &TPRatingProfile{
|
||||
TPid: "TEST_TPID",
|
||||
LoadId: "TEST_LOADID",
|
||||
Direction: OUT,
|
||||
Tenant: "cgrates.org",
|
||||
Category: "call",
|
||||
Subject: "*any",
|
||||
RatingPlanActivations: []*TPRatingActivation{
|
||||
&TPRatingActivation{
|
||||
ActivationTime: "2014-01-14T00:00:00Z",
|
||||
RatingPlanId: "TEST_RPLAN1",
|
||||
FallbackSubjects: "subj1;subj2"},
|
||||
&TPRatingActivation{
|
||||
ActivationTime: "2014-01-15T00:00:00Z",
|
||||
RatingPlanId: "TEST_RPLAN2",
|
||||
FallbackSubjects: "subj1;subj2"},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{OUT, "cgrates.org", "call", "*any", "2014-01-14T00:00:00Z", "TEST_RPLAN1", "subj1;subj2"},
|
||||
[]string{OUT, "cgrates.org", "call", "*any", "2014-01-15T00:00:00Z", "TEST_RPLAN2", "subj1;subj2"},
|
||||
}
|
||||
if slc := tpRpf.AsExportSlice(); !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPActionsAsExportSlice(t *testing.T) {
|
||||
tpActs := &TPActions{
|
||||
TPid: "TEST_TPID",
|
||||
ActionsId: "TEST_ACTIONS",
|
||||
Actions: []*TPAction{
|
||||
&TPAction{
|
||||
Identifier: "*topup_reset",
|
||||
BalanceType: "*monetary",
|
||||
Direction: OUT,
|
||||
Units: 5.0,
|
||||
ExpiryTime: "*never",
|
||||
DestinationIds: "*any",
|
||||
RatingSubject: "special1",
|
||||
Category: "call",
|
||||
SharedGroup: "GROUP1",
|
||||
BalanceWeight: 10.0,
|
||||
ExtraParameters: "",
|
||||
Weight: 10.0},
|
||||
&TPAction{
|
||||
Identifier: "*http_post",
|
||||
BalanceType: "",
|
||||
Direction: "",
|
||||
Units: 0.0,
|
||||
ExpiryTime: "",
|
||||
DestinationIds: "",
|
||||
RatingSubject: "",
|
||||
Category: "",
|
||||
SharedGroup: "",
|
||||
BalanceWeight: 0.0,
|
||||
ExtraParameters: "http://localhost/¶m1=value1",
|
||||
Weight: 20.0},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"TEST_ACTIONS", "*topup_reset", "", "*monetary", OUT, "call", "*any", "special1", "GROUP1", "*never", "5", "10", "10"},
|
||||
[]string{"TEST_ACTIONS", "*http_post", "http://localhost/¶m1=value1", "", "", "", "", "", "", "", "0", "0", "20"},
|
||||
}
|
||||
if slc := tpActs.AsExportSlice(); !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
// SHARED_A,*any,*highest,
|
||||
func TestTPSharedGroupsAsExportSlice(t *testing.T) {
|
||||
tpSGs := &TPSharedGroups{
|
||||
TPid: "TEST_TPID",
|
||||
SharedGroupsId: "SHARED_GROUP_TEST",
|
||||
SharedGroups: []*TPSharedGroup{
|
||||
&TPSharedGroup{
|
||||
Account: "*any",
|
||||
Strategy: "*highest",
|
||||
RatingSubject: "special1"},
|
||||
&TPSharedGroup{
|
||||
Account: "second",
|
||||
Strategy: "*highest",
|
||||
RatingSubject: "special2"},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"SHARED_GROUP_TEST", "*any", "*highest", "special1"},
|
||||
[]string{"SHARED_GROUP_TEST", "second", "*highest", "special2"},
|
||||
}
|
||||
if slc := tpSGs.AsExportSlice(); !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
//*in,cgrates.org,*any,EU_LANDLINE,LCR_STANDARD,*static,ivo;dan;rif,2012-01-01T00:00:00Z,10
|
||||
func TestTPLcrRulesAsExportSlice(t *testing.T) {
|
||||
lcr := &TPLcrRules{
|
||||
TPid: "TEST_TPID",
|
||||
LcrRulesId: "TEST_LCR",
|
||||
LcrRules: []*TPLcrRule{
|
||||
&TPLcrRule{
|
||||
Direction: "*in",
|
||||
Tenant: "cgrates.org",
|
||||
Customer: "*any",
|
||||
DestinationId: "EU_LANDLINE",
|
||||
Category: "LCR_STANDARD",
|
||||
Strategy: "*static",
|
||||
Suppliers: "ivo;dan;rif",
|
||||
ActivatinTime: "2012-01-01T00:00:00Z",
|
||||
Weight: 20.0},
|
||||
//*in,cgrates.org,*any,*any,LCR_STANDARD,*lowest_cost,,2012-01-01T00:00:00Z,20
|
||||
&TPLcrRule{
|
||||
Direction: "*in",
|
||||
Tenant: "cgrates.org",
|
||||
Customer: "*any",
|
||||
DestinationId: "*any",
|
||||
Category: "LCR_STANDARD",
|
||||
Strategy: "*lowest_cost",
|
||||
Suppliers: "",
|
||||
ActivatinTime: "2012-01-01T00:00:00Z",
|
||||
Weight: 10.0},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"TEST_LCR", "*in", "cgrates.org", "*any", "EU_LANDLINE", "LCR_STANDARD", "*static", "ivo;dan;rif", "2012-01-01T00:00:00Z", "20"},
|
||||
[]string{"TEST_LCR", "*in", "cgrates.org", "*any", "*any", "LCR_STANDARD", "*lowest_cost", "", "2012-01-01T00:00:00Z", "10"},
|
||||
}
|
||||
if slc := lcr.AsExportSlice(); !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
//CDRST1,5,60m,ASR,2014-07-29T15:00:00Z;2014-07-29T16:00:00Z,*voice,87.139.12.167,FS_JSON,rated,*out,cgrates.org,call,dan,dan,49,5m;10m,default,rif,rif,0;2,STANDARD_TRIGGERS
|
||||
func TestTPCdrStatsAsExportSlice(t *testing.T) {
|
||||
cdrStats := &TPCdrStats{
|
||||
TPid: "TEST_TPID",
|
||||
CdrStatsId: "CDRST1",
|
||||
CdrStats: []*TPCdrStat{
|
||||
&TPCdrStat{
|
||||
QueueLength: "5",
|
||||
TimeWindow: "60m",
|
||||
Metrics: "ASR;ACD",
|
||||
SetupInterval: "2014-07-29T15:00:00Z;2014-07-29T16:00:00Z",
|
||||
TORs: "*voice",
|
||||
CdrHosts: "87.139.12.167",
|
||||
CdrSources: "FS_JSON",
|
||||
ReqTypes: META_RATED,
|
||||
Directions: "*out",
|
||||
Tenants: "cgrates.org",
|
||||
Categories: "call",
|
||||
Accounts: "dan",
|
||||
Subjects: "dan",
|
||||
DestinationPrefixes: "49",
|
||||
UsageInterval: "5m;10m",
|
||||
Suppliers: "supplier1",
|
||||
DisconnectCauses: "NORMAL_CLEARNING",
|
||||
MediationRunIds: "default",
|
||||
RatedAccounts: "rif",
|
||||
RatedSubjects: "rif",
|
||||
CostInterval: "0;2",
|
||||
ActionTriggers: "STANDARD_TRIGGERS"},
|
||||
&TPCdrStat{
|
||||
QueueLength: "5",
|
||||
TimeWindow: "60m",
|
||||
Metrics: "ASR",
|
||||
SetupInterval: "2014-07-29T15:00:00Z;2014-07-29T16:00:00Z",
|
||||
TORs: "*voice",
|
||||
CdrHosts: "87.139.12.167",
|
||||
CdrSources: "FS_JSON",
|
||||
ReqTypes: META_RATED,
|
||||
Directions: "*out",
|
||||
Tenants: "cgrates.org",
|
||||
Categories: "call",
|
||||
Accounts: "dan",
|
||||
Subjects: "dan",
|
||||
DestinationPrefixes: "49",
|
||||
UsageInterval: "5m;10m",
|
||||
Suppliers: "supplier1",
|
||||
DisconnectCauses: "NORMAL_CLEARNING",
|
||||
MediationRunIds: "default",
|
||||
RatedAccounts: "dan",
|
||||
RatedSubjects: "dan",
|
||||
CostInterval: "0;2",
|
||||
ActionTriggers: "STANDARD_TRIGGERS"},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"CDRST1", "5", "60m", "ASR;ACD", "2014-07-29T15:00:00Z;2014-07-29T16:00:00Z", "*voice", "87.139.12.167", "FS_JSON", META_RATED, "*out", "cgrates.org", "call",
|
||||
"dan", "dan", "49", "5m;10m", "supplier1", "NORMAL_CLEARNING", "default", "rif", "rif", "0;2", "STANDARD_TRIGGERS"},
|
||||
[]string{"CDRST1", "5", "60m", "ASR", "2014-07-29T15:00:00Z;2014-07-29T16:00:00Z", "*voice", "87.139.12.167", "FS_JSON", META_RATED, "*out", "cgrates.org", "call",
|
||||
"dan", "dan", "49", "5m;10m", "supplier1", "NORMAL_CLEARNING", "default", "dan", "dan", "0;2", "STANDARD_TRIGGERS"},
|
||||
}
|
||||
if slc := cdrStats.AsExportSlice(); !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
//#Direction,Tenant,Category,Account,Subject,RunId,RunFilter,ReqTypeField,DirectionField,TenantField,CategoryField,AccountField,SubjectField,DestinationField,SetupTimeField,AnswerTimeField,UsageField
|
||||
//*out,cgrates.org,call,1001,1001,derived_run1,,^rated,*default,*default,*default,*default,^1002,*default,*default,*default,*default
|
||||
func TestTPDerivedChargersAsExportSlice(t *testing.T) {
|
||||
dcs := TPDerivedChargers{
|
||||
TPid: "TEST_TPID",
|
||||
Loadid: "TEST_LOADID",
|
||||
Direction: "*out",
|
||||
Tenant: "cgrates.org",
|
||||
Category: "call",
|
||||
Account: "1001",
|
||||
Subject: "1001",
|
||||
DerivedChargers: []*TPDerivedCharger{
|
||||
&TPDerivedCharger{
|
||||
RunId: "derived_run1",
|
||||
RunFilters: "",
|
||||
ReqTypeField: "^rated",
|
||||
DirectionField: META_DEFAULT,
|
||||
TenantField: META_DEFAULT,
|
||||
CategoryField: META_DEFAULT,
|
||||
AccountField: META_DEFAULT,
|
||||
SubjectField: "^1002",
|
||||
DestinationField: META_DEFAULT,
|
||||
SetupTimeField: META_DEFAULT,
|
||||
AnswerTimeField: META_DEFAULT,
|
||||
UsageField: META_DEFAULT,
|
||||
SupplierField: META_DEFAULT,
|
||||
DisconnectCauseField: META_DEFAULT,
|
||||
},
|
||||
&TPDerivedCharger{
|
||||
RunId: "derived_run2",
|
||||
RunFilters: "",
|
||||
ReqTypeField: "^rated",
|
||||
DirectionField: META_DEFAULT,
|
||||
TenantField: META_DEFAULT,
|
||||
CategoryField: META_DEFAULT,
|
||||
AccountField: "^1002",
|
||||
SubjectField: META_DEFAULT,
|
||||
DestinationField: META_DEFAULT,
|
||||
SetupTimeField: META_DEFAULT,
|
||||
AnswerTimeField: META_DEFAULT,
|
||||
UsageField: META_DEFAULT,
|
||||
SupplierField: META_DEFAULT,
|
||||
DisconnectCauseField: META_DEFAULT,
|
||||
},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"*out", "cgrates.org", "call", "1001", "1001",
|
||||
"derived_run1", "", "^rated", META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT, "^1002", META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT},
|
||||
[]string{"*out", "cgrates.org", "call", "1001", "1001",
|
||||
"derived_run2", "", "^rated", META_DEFAULT, META_DEFAULT, META_DEFAULT, "^1002", META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT},
|
||||
}
|
||||
if slc := dcs.AsExportSlice(); !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPActionTriggersAsExportSlice(t *testing.T) {
|
||||
ap := &TPActionPlan{
|
||||
TPid: "TEST_TPID",
|
||||
Id: "PACKAGE_10",
|
||||
ActionPlan: []*TPActionTiming{
|
||||
&TPActionTiming{
|
||||
ActionsId: "TOPUP_RST_10",
|
||||
TimingId: "ASAP",
|
||||
Weight: 10.0},
|
||||
&TPActionTiming{
|
||||
ActionsId: "TOPUP_RST_5",
|
||||
TimingId: "ASAP",
|
||||
Weight: 20.0},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"PACKAGE_10", "TOPUP_RST_10", "ASAP", "10"},
|
||||
[]string{"PACKAGE_10", "TOPUP_RST_5", "ASAP", "20"},
|
||||
}
|
||||
if slc := ap.AsExportSlice(); !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPActionPlanAsExportSlice(t *testing.T) {
|
||||
at := &TPActionTriggers{
|
||||
TPid: "TEST_TPID",
|
||||
ActionTriggersId: "STANDARD_TRIGGERS",
|
||||
ActionTriggers: []*TPActionTrigger{
|
||||
&TPActionTrigger{
|
||||
ThresholdType: "*min_balance",
|
||||
ThresholdValue: 2.0,
|
||||
Recurrent: false,
|
||||
MinSleep: "0",
|
||||
BalanceId: "b1",
|
||||
BalanceType: "*monetary",
|
||||
BalanceDirection: "*out",
|
||||
BalanceDestinationIds: "",
|
||||
BalanceWeight: 0.0,
|
||||
BalanceExpirationDate: "*never",
|
||||
BalanceTimingTags: "T1",
|
||||
BalanceRatingSubject: "special1",
|
||||
BalanceCategory: "call",
|
||||
BalanceSharedGroup: "SHARED_1",
|
||||
MinQueuedItems: 0,
|
||||
ActionsId: "LOG_WARNING",
|
||||
Weight: 10},
|
||||
&TPActionTrigger{
|
||||
ThresholdType: "*max_counter",
|
||||
ThresholdValue: 5.0,
|
||||
Recurrent: false,
|
||||
MinSleep: "0",
|
||||
BalanceId: "b2",
|
||||
BalanceType: "*monetary",
|
||||
BalanceDirection: "*out",
|
||||
BalanceDestinationIds: "FS_USERS",
|
||||
BalanceWeight: 0.0,
|
||||
BalanceExpirationDate: "*never",
|
||||
BalanceTimingTags: "T1",
|
||||
BalanceRatingSubject: "special1",
|
||||
BalanceCategory: "call",
|
||||
BalanceSharedGroup: "SHARED_1",
|
||||
MinQueuedItems: 0,
|
||||
ActionsId: "LOG_WARNING",
|
||||
Weight: 10},
|
||||
},
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"STANDARD_TRIGGERS", "*min_balance", "2", "false", "0", "b1", "*monetary", "*out", "call", "", "special1", "SHARED_1", "*never", "T1", "0", "0", "LOG_WARNING", "10"},
|
||||
[]string{"STANDARD_TRIGGERS", "*max_counter", "5", "false", "0", "b2", "*monetary", "*out", "call", "FS_USERS", "special1", "SHARED_1", "*never", "T1", "0", "0", "LOG_WARNING", "10"},
|
||||
}
|
||||
if slc := at.AsExportSlice(); !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPAccountActionsAsExportSlice(t *testing.T) {
|
||||
aa := &TPAccountActions{
|
||||
TPid: "TEST_TPID",
|
||||
LoadId: "TEST_LOADID",
|
||||
Tenant: "cgrates.org",
|
||||
Account: "1001",
|
||||
Direction: "*out",
|
||||
ActionPlanId: "PACKAGE_10_SHARED_A_5",
|
||||
ActionTriggersId: "STANDARD_TRIGGERS",
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"cgrates.org", "1001", "*out", "PACKAGE_10_SHARED_A_5", "STANDARD_TRIGGERS"},
|
||||
}
|
||||
if slc := aa.AsExportSlice(); !reflect.DeepEqual(expectedSlc, slc) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedSlc, slc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewDTCSFromRPKey(t *testing.T) {
|
||||
rpKey := "*out:tenant12:call:dan12"
|
||||
if dtcs, err := NewDTCSFromRPKey(rpKey); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user