2 // Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
16 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
17 // platform project (RICP).
29 func CleanXML(payload []byte) []byte {
30 xmlStr := string(payload)
31 normalized := strings.NewReplacer("\r","","\n",""," ","").Replace(xmlStr)
33 return []byte(normalized)
36 func ReadXmlFile(t *testing.T, xmlPath string) []byte {
37 path, err := filepath.Abs(xmlPath)
41 xmlAsBytes, err := ioutil.ReadFile(path)
49 func ReadXmlFileNoTest(xmlPath string) ([]byte, error) {
50 path, err := filepath.Abs(xmlPath)
54 xmlAsBytes, err := ioutil.ReadFile(path)
62 func NormalizeXml(payload []byte) []byte {
63 xmlStr := string(payload)
64 normalized := strings.NewReplacer("<", "<", ">", ">").Replace(xmlStr)
66 return []byte(normalized)
69 func ReplaceEmptyTagsWithSelfClosing(responsePayload []byte, emptyTagsToReplace []string) []byte {
70 emptyTagVsSelfClosingTagPairs := make([]string, len(emptyTagsToReplace)*2)
73 for i := 0; i < len(emptyTagsToReplace); i++ {
74 emptyTagVsSelfClosingTagPairs[j] = fmt.Sprintf("<%[1]s></%[1]s>", emptyTagsToReplace[i])
75 emptyTagVsSelfClosingTagPairs[j+1] = fmt.Sprintf("<%s/>", emptyTagsToReplace[i])
78 responseString := strings.NewReplacer(emptyTagVsSelfClosingTagPairs...).Replace(string(responsePayload))
79 return []byte(responseString)