From 4a5769f746379b4001f95eef671bcfabd0689317 Mon Sep 17 00:00:00 2001 From: DanB Date: Thu, 5 May 2016 20:29:52 +0200 Subject: [PATCH] CDRC XML initial files --- cdrc/xml.go | 35 +++++++++ cdrc/xml_test.go | 188 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 223 insertions(+) create mode 100644 cdrc/xml.go create mode 100644 cdrc/xml_test.go diff --git a/cdrc/xml.go b/cdrc/xml.go new file mode 100644 index 000000000..3d0092859 --- /dev/null +++ b/cdrc/xml.go @@ -0,0 +1,35 @@ +/* +Real-time Charging System for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +package cdrc + +//import +import ( + "github.com/cgrates/cgrates/engine" +) + +type XMLRecordsProcessor struct { +} + +func (xmlProc *XMLRecordsProcessor) ProcessNextRecord() ([]*engine.CDR, error) { + return nil, nil +} + +func (xmlProc *XMLRecordsProcessor) ProcessedRecordsNr() int64 { + return 0 +} diff --git a/cdrc/xml_test.go b/cdrc/xml_test.go new file mode 100644 index 000000000..e6791afde --- /dev/null +++ b/cdrc/xml_test.go @@ -0,0 +1,188 @@ +/* +Real-time Charging System for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +package cdrc + +import ( + "bytes" + "encoding/xml" + "fmt" + "path" + "testing" + + "github.com/ChrisTrenkamp/goxpath" + "github.com/ChrisTrenkamp/goxpath/tree" + "github.com/ChrisTrenkamp/goxpath/tree/xmltree" +) + +var cdrXmlBroadsoft = ` + + + + + + 0002183384 + CGRateSaabb + 20160419210000.104 + 1+020000 + + Start + + + + + + 0002183385 + CGRateSaabb + 20160419210005.247 + 1+020000 + + MBC + Normal + + + 1001 + 2001 + Terminating + Network + +4986517174963 + Public + 1001 + 20160419210005.247 + 1+020000 + 25160047719:0 + Yes + 20160419210006.813 + 20160419210020.296 + 016 + y + local + 1001@cgrates.org + Yes + Yes + + + CGR_GROUP + CGR_GROUP/CGR_GROUP_TRUNK30 + Normal + + + 1001@cgrates.org + Primary Device + + + 31.882 + + + gw04.cgrates.org + 74122796919420162305@172.16.1.2 + PCMA/8000 + 172.16.1.4 + BW2300052501904161738474465@172.16.1.10 + 31.882 + OmniPCX Enterprise R11.0.1 k1.520.22.b + + + + + + 0002183386 + CGRateSaabb + 20160419210006.909 + 1+020000 + + MBC + Normal + + + 1002 + 2001 + Terminating + Network + +4986517174964 + Public + 1002 + 20160419210006.909 + 1+020000 + 27280048121:0 + Yes + 20160419210007.037 + 20160419210030.322 + 016 + y + local + 314028947650@cgrates.org + Yes + Yes + + + CGR_GROUP + CGR_GROUP/CGR_GROUP_TRUNK65 + Normal + + + 31403456100@cgrates.org + Primary Device + + + 26.244 + + + gw01.cgrates.org + 108352493719420162306@172.31.250.150 + PCMA/8000 + 172.16.1.4 + 2345300069121904161716512907@172.16.1.10 + 26.244 + Altitude vBox + + + + + + 0002183486 + CGRateSaabb + 20160419211500.104 + 1+020000 + + End + + +` + +func optsNotStrict(s *xmltree.ParseOptions) { + s.Strict = false +} + +func TestXmlPathCDRs(t *testing.T) { + xp := goxpath.MustParse(path.Join("/broadWorksCDR/cdrData/")) + xmlTree := xmltree.MustParseXML(bytes.NewBufferString(cdrXmlBroadsoft), optsNotStrict) + cdrs := goxpath.MustExec(xp, xmlTree, nil) + for _, cdr := range cdrs { + cdrBuf := bytes.NewBufferString(xml.Header) + if err := goxpath.Marshal(cdr.(tree.Node), cdrBuf); err != nil { + t.Error(err) + } + xp := goxpath.MustParse(path.Join("/cdrData/basicModule/userNumber")) + userNumberNode := xmltree.MustParseXML(cdrBuf, optsNotStrict) + userNumber := goxpath.MustExec(xp, userNumberNode, nil) + if len(userNumber) != 0 { + fmt.Printf("UserNumber: %s\n", userNumber[0].String()) + } + } +}