3 // ========================LICENSE_START=================================
6 // Copyright (C) 2022: Nordix Foundation
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
12 // http://www.apache.org/licenses/LICENSE-2.0
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 // ========================LICENSE_END===================================
27 "main/common/dataTypes"
32 func TestXMLToJSONConv_Success(t *testing.T) {
33 // Prepare the input data
34 var evt_data dataTypes.XmlFileEventHeader = dataTypes.XmlFileEventHeader{
35 ProductName: "O-RAN SC",
36 VendorName: "Ericsson AB",
39 SourceName: "GNODEB-0",
40 FileFormatType: "xml",
41 FileFormatVersion: "1.0",
43 ChangeIdentifier: "Sample Change ID",
44 InternalLocation: "Sample Internal Location",
45 TimeZoneOffset: "+05:00",
46 ObjectStoreBucket: "Sample Bucket",
49 filename := "A20230515.0700_0100-0715_0100_GNODEB-0.xml"
50 fi, err := os.Open(filename)
53 t.Fatalf("File %s - cannot be opened - discarding message, error details: %s", filename, err.Error())
60 _, err2 := io.Copy(&buf3, reader)
62 t.Fatalf("File %s - cannot be read, discarding message, %s", filename, err.Error())
65 file_bytes := buf3.Bytes()
66 b, err := xml_to_json_conv(&file_bytes, &evt_data)
68 json_filename := "A20230515.0700_0100-0715_0100_GNODEB-0.json"
70 err3 := os.WriteFile(json_filename, b, 0644)
73 t.Fatalf("Error writing %s to JSON :, %s ", json_filename, err3.Error())
77 t.Fatalf("Cannot convert file %s - discarding message, %s", filename, err.Error())
81 t.Fatalf("Conversion of %s returned %d bytes", filename, len(b))
84 fi, err = os.Open(json_filename)
87 t.Fatalf("File %s - cannot be opened - discarding message, error details: %s", json_filename, err.Error())
89 fmt.Println("XML file Converted to JSON")