diff --git a/cdrc/xml_it_test.go b/cdrc/xml_it_test.go index 2562a9d6d..e229fe5b3 100644 --- a/cdrc/xml_it_test.go +++ b/cdrc/xml_it_test.go @@ -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) + } +} diff --git a/data/conf/samples/cdrcxmlwithfilter/cgrates.json b/data/conf/samples/cdrcxmlwithfilter/cgrates.json index eeca926ae..0630705b6 100755 --- a/data/conf/samples/cdrcxmlwithfilter/cgrates.json +++ b/data/conf/samples/cdrcxmlwithfilter/cgrates.json @@ -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