Add mod/runtimeapi
[dcaegen2/platform.git] / mod / runtimeapi / runtime-core / src / test / java / org / onap / dcae / runtime / core / TestYamlStringToObject.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=========================================================
17  */
18 package org.onap.dcae.runtime.core;
19
20 import org.junit.Test;
21 import org.yaml.snakeyaml.DumperOptions;
22 import org.yaml.snakeyaml.Yaml;
23
24 import java.util.Map;
25
26 public class TestYamlStringToObject {
27
28     @Test
29     public void testYamlStringToObject() throws Exception{
30         String bp_content = Helper.loadFileContent("src/test/data/blueprints/helloworld_onap_dublin.yaml");
31         String locationPort = "DCAE-HELLO-WORLD-SUB-MR";
32         Yaml yaml = getYamlInstance();
33         Map<String,Object>  obj = yaml.load(bp_content);
34         Map<String,Object> inputsObj = (Map<String, Object>) obj.get("inputs");
35         for(Map.Entry<String,Object> entry: inputsObj.entrySet()){
36             System.out.println(String.format("^%s.*url",locationPort.replaceAll("-","_")));
37             if(entry.getKey().matches(String.format("^%s.*url",locationPort.replaceAll("-","_")))) {
38                 Map<String,String> inputValue = (Map<String, String>) entry.getValue();
39                 inputValue.put("default","test_topic");
40                 System.out.println(entry);
41             }
42         }
43        // System.out.println(yaml.dump(obj));
44     }
45
46     private Yaml getYamlInstance() {
47         DumperOptions options = new DumperOptions();
48         options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
49         options.setPrettyFlow(true);
50         return new Yaml(options);
51     }
52 }