2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.policy.rest.util;
22 import static org.junit.Assert.*;
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.HashMap;
29 import java.util.List;
32 import org.apache.commons.lang.StringUtils;
33 import org.junit.Test;
34 import org.onap.policy.common.logging.flexlogger.FlexLogger;
35 import org.onap.policy.common.logging.flexlogger.Logger;
36 import org.onap.policy.rest.util.MSModelUtils.MODEL_TYPE;
38 public class MSModelUtilsTest {
39 private static Logger logger = FlexLogger.getLogger(MSModelUtilsTest.class);
41 public void testMSModelUtils(){
42 HashMap<String, MSAttributeObject> classMap = new HashMap<>();
43 ClassLoader classLoader = getClass().getClassLoader();
44 File file = new File(classLoader.getResource("DKaTVESPolicy-v1802.xmi").getFile());
45 MSModelUtils utils = new MSModelUtils("http://org.onap", "http://org.onap.policy");
46 Map<String, MSAttributeObject> tempMap = utils.processEpackage(file.getAbsolutePath().toString(), MODEL_TYPE.XMI);
47 classMap.putAll(tempMap);
48 MSAttributeObject mainClass = classMap.get("StandardDeviationThreshold");
49 String dependTemp = StringUtils.replaceEach(mainClass.getDependency(), new String[]{"[", "]", " "}, new String[]{"", "", ""});
50 List<String> dependency = new ArrayList<String>(Arrays.asList(dependTemp.split(",")));
51 dependency = utils.getFullDependencyList(dependency, classMap);
52 String subAttribute = utils.createSubAttributes(dependency, classMap, "StandardDeviationThreshold");
53 assertTrue(subAttribute != null);
58 * Run the void stringBetweenDots(String, String) method test
62 public void testStringBetweenDots() {
64 //expect: uniqueKeys should contain a string value
65 MSModelUtils controllerA = new MSModelUtils();
66 String str = "testing\\.byCorrectWay\\.OfDATA";
67 assertEquals(1, controllerA.stringBetweenDots(str));
69 //expect: uniqueKeys should not contain a string value
70 str = "testing\byWrongtWay.\\OfDATA";
71 MSModelUtils controllerB = new MSModelUtils();
72 assertEquals(0, controllerB.stringBetweenDots(str));
76 * Run the Map<String,String> load(String) method test
80 public void testLoad() {
82 boolean isLocalTesting = true;
83 MSModelUtils controller = new MSModelUtils();
84 String fileName = null;
85 Map<String,String> result = null;
87 ClassLoader classLoader = getClass().getClassLoader();
88 fileName = new File(classLoader.getResource("policy_tosca_tca-v1707.yml").getFile()).getAbsolutePath();
89 } catch (Exception e1) {
90 logger.error("Exception Occured while loading file"+e1);
94 result = controller.load(fileName);
95 } catch (IOException e) {
96 logger.error("testLoad", e);
98 }catch(ParserException e){
99 logger.error("testLoad", e);
102 assertTrue(result != null && !result.isEmpty());
103 logger.debug("result : " + result);
106 logger.debug("testLoad: exit");
110 * Run the void parseTosca(String) method test
114 public void testParseTosca() {
116 logger.debug("testParseTosca: enter");
117 boolean isLocalTesting = true;
118 String fileName = null;
120 ClassLoader classLoader = getClass().getClassLoader();
121 fileName = new File(classLoader.getResource("policy_tosca_tca-v1707.yml").getFile()).getAbsolutePath();
122 } catch (Exception e1) {
123 logger.error("Exception Occured while loading file"+e1);
126 MSModelUtils controller = new MSModelUtils();
129 controller.parseTosca(fileName);
130 }catch (Exception e) {
131 fail("parseTosca caused error: " + e);
134 logger.debug("testParseTosca: exit");