Added Junis for Policy ONAP-REST
[policy/engine.git] / ONAP-REST / src / test / java / org / onap / policy / rest / util / MSModelUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-REST
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20 package org.onap.policy.rest.util;
21
22 import static org.junit.Assert.*;
23
24 import java.io.File;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30
31 import org.apache.commons.lang.StringUtils;
32 import org.junit.Test;
33 import org.onap.policy.rest.util.MSModelUtils.MODEL_TYPE;
34
35 public class MSModelUtilsTest {
36         
37         @Test
38         public void testMSModelUtils(){
39                 HashMap<String, MSAttributeObject> classMap = new HashMap<>();
40                 ClassLoader classLoader = getClass().getClassLoader();
41                 File file = new File(classLoader.getResource("DKaTVESPolicy-v1802.xmi").getFile());
42                 MSModelUtils utils = new MSModelUtils("http://org.onap", "http://org.onap.policy");
43                 Map<String, MSAttributeObject> tempMap = utils.processEpackage(file.getAbsolutePath().toString(), MODEL_TYPE.XMI);
44                 classMap.putAll(tempMap);
45                 MSAttributeObject mainClass = classMap.get("StandardDeviationThreshold");
46                 String dependTemp = StringUtils.replaceEach(mainClass.getDependency(), new String[]{"[", "]", " "}, new String[]{"", "", ""});
47                 List<String> dependency = new ArrayList<String>(Arrays.asList(dependTemp.split(",")));
48                 dependency = utils.getFullDependencyList(dependency, classMap);
49                 String subAttribute = utils.createSubAttributes(dependency, classMap, "StandardDeviationThreshold");
50                 assertTrue(subAttribute != null);
51         }
52 }