Add tests with FilterIDs for xml

This commit is contained in:
Trial97
2018-09-25 14:56:45 +03:00
committed by Dan Christian Bogos
parent a1a43fa181
commit 095735ee66
2 changed files with 137 additions and 3 deletions

View File

@@ -388,3 +388,114 @@ func TestXmlIT4KillEngine(t *testing.T) {
t.Error(err)
}
}
// Begin tests for cdrc xml with new filters
func TestXmlIT5InitConfig(t *testing.T) {
var err error
xmlCfgPath = path.Join(*dataDir, "conf", "samples", "cdrcxmlwithfilter")
if xmlCfg, err = config.NewCGRConfigFromFolder(xmlCfgPath); err != nil {
t.Fatal("Got config error: ", err.Error())
}
}
// InitDb so we can rely on count
func TestXmlIT5InitCdrDb(t *testing.T) {
if err := engine.InitStorDb(xmlCfg); err != nil {
t.Fatal(err)
}
}
func TestXmlIT5CreateCdrDirs(t *testing.T) {
for _, cdrcProfiles := range xmlCfg.CdrcProfiles {
for _, cdrcInst := range cdrcProfiles {
for _, dir := range []string{cdrcInst.CdrInDir, cdrcInst.CdrOutDir} {
if err := os.RemoveAll(dir); err != nil {
t.Fatal("Error removing folder: ", dir, err)
}
if err := os.MkdirAll(dir, 0755); err != nil {
t.Fatal("Error creating folder: ", dir, err)
}
}
if cdrcInst.ID == "XMLWithFilterID" { // Initialize the folders to check later
xmlPathIn1 = cdrcInst.CdrInDir
xmlPathOut1 = cdrcInst.CdrOutDir
}
}
}
}
func TestXmlIT5StartEngine(t *testing.T) {
if _, err := engine.StopStartEngine(xmlCfgPath, *waitRater); err != nil {
t.Fatal(err)
}
}
// Connect rpc client to rater
func TestXmlIT5RpcConn(t *testing.T) {
var err error
cdrcXmlRPC, err = jsonrpc.Dial("tcp", xmlCfg.RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
if err != nil {
t.Fatal("Could not connect to rater: ", err.Error())
}
}
func TestXmlIT5AddFilters(t *testing.T) {
filter := &engine.Filter{
Tenant: "cgrates.org",
ID: "FLTR_XML",
Rules: []*engine.FilterRule{
{
Type: "*string",
FieldName: "broadWorksCDR.cdrData.basicModule.userNumber",
Values: []string{"1002"},
},
{
Type: "*string",
FieldName: "broadWorksCDR.cdrData.headerModule.type",
Values: []string{"Normal"},
},
},
}
var result string
if err := cdrcXmlRPC.Call("ApierV1.SetFilter", filter, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
}
// The default scenario, out of cdrc defined in .cfg file
func TestXmlIT5HandleCdr1File(t *testing.T) {
fileName := "file1.xml"
tmpFilePath := path.Join("/tmp", fileName)
if err := ioutil.WriteFile(tmpFilePath, []byte(cdrXmlBroadsoft), 0644); err != nil {
t.Fatal(err.Error())
}
if err := os.Rename(tmpFilePath, path.Join(xmlPathIn1, fileName)); err != nil {
t.Fatal("Error moving file to processing directory: ", err)
}
}
func TestXmlIT5ProcessedFiles(t *testing.T) {
time.Sleep(time.Duration(2**waitRater) * time.Millisecond)
if outContent1, err := ioutil.ReadFile(path.Join(xmlPathOut1, "file1.xml")); err != nil {
t.Error(err)
} else if cdrXmlBroadsoft != string(outContent1) {
t.Errorf("Expecting: %q, received: %q", cdrXmlBroadsoft, string(outContent1))
}
}
func TestXmlIT5AnalyseCDRs(t *testing.T) {
var reply []*engine.ExternalCDR
if err := cdrcXmlRPC.Call("ApierV2.GetCdrs", utils.RPCCDRsFilter{}, &reply); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if len(reply) != 1 {
t.Error("Unexpected number of CDRs returned: ", len(reply))
}
}
func TestXmlIT5KillEngine(t *testing.T) {
if err := engine.KillEngine(*waitRater); err != nil {
t.Error(err)
}
}

View File

@@ -1,7 +1,7 @@
{
// Real-time Charging System for Telecom & ISP environments
// Copyright (C) ITsysCOM GmbH
// Copyright (C) ITsysCOM GmbH
"stor_db": { // database used to store offline tariff plans and CDRs
"db_password": "CGRateS.org", // password to use when connecting to stordb
@@ -42,12 +42,12 @@
],
},
{
"id": "msw_xml", // identifier of the CDRC runner
"id": "msw_xml", // identifier of the CDRC runner
"enabled": true, // enable CDR client functionality
"cdr_format": "xml", // CDR file format <csv|freeswitch_csv|fwv|opensips_flatstore|partial_csv.
"cdr_in_dir": "/tmp/cdrcxmlwithfilters2/xmlit2/in",
"cdr_out_dir": "/tmp/cdrcxmlwithfilters2/xmlit2/out",
"cdr_path": "File.CDRs.Call", // path towards one CDR element in case of XML CDRs
"cdr_path": "File.CDRs.Call", // path towards one CDR element in case of XML CDRs
"cdr_source_id": "zw_cfs1", // free form field, tag identifying the source of the CDRs within CDRS database
"content_fields":[ // import content_fields template, id will match internally CDR field, in case of .csv value will be represented by index of the field value
{"tag": "TOR", "field_id": "ToR", "type": "*composed", "value": "*voice", "mandatory": true},
@@ -89,6 +89,29 @@
{"tag": "Usage", "field_id": "Usage", "type": "*handler", "handler_id": "*substract_usage", "value": "~File.CDRs.Call.ReleaseTime;|;~File.CDRs.Call.ConnectTime", "mandatory": true}
],
},
{
"id": "XMLWithFilterID",
"enabled": true,
"cdr_format": "xml",
"cdr_in_dir": "/tmp/cdrcxmlwithfilters/xmlit5/in",
"cdr_out_dir": "/tmp/cdrcxmlwithfilters/xmlit5/out",
"cdr_path": "broadWorksCDR.cdrData",
"cdr_source_id": "xmlit1",
"filters": ["FLTR_XML"],
"content_fields":[ // import content_fields template, id will match internally CDR field, in case of .csv value will be represented by index of the field value
{"tag": "TOR", "field_id": "ToR", "type": "*composed", "value": "*voice", "mandatory": true},
{"tag": "OriginID", "field_id": "OriginID", "type": "*composed", "value": "~broadWorksCDR.cdrData.basicModule.localCallId", "mandatory": true},
{"tag": "RequestType", "field_id": "RequestType", "type": "*composed", "value": "*rated", "mandatory": true},
{"tag": "Direction", "field_id": "Direction", "type": "*composed", "value": "*out", "mandatory": true},
{"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "~broadWorksCDR.cdrData.basicModule.userId:s/.*@(.*)/${1}/", "mandatory": true},
{"tag": "Category", "field_id": "Category", "type": "*composed", "value": "call", "mandatory": true},
{"tag": "Account", "field_id": "Account", "type": "*composed", "value": "~broadWorksCDR.cdrData.basicModule.userNumber", "mandatory": true},
{"tag": "Destination", "field_id": "Destination", "type": "*composed", "value": "~broadWorksCDR.cdrData.basicModule.calledNumber", "mandatory": true},
{"tag": "SetupTime", "field_id": "SetupTime", "type": "*composed", "value": "~broadWorksCDR.cdrData.basicModule.startTime", "mandatory": true},
{"tag": "AnswerTime", "field_id": "AnswerTime", "type": "*composed", "value": "~broadWorksCDR.cdrData.basicModule.answerTime", "mandatory": true},
{"tag": "Usage", "field_id": "Usage", "type": "*handler", "handler_id": "*substract_usage", "value": "~broadWorksCDR.cdrData.basicModule.releaseTime;|;~broadWorksCDR.cdrData.basicModule.answerTime", "mandatory": true},
],
},
],