Rework of the unit tests (mainly IT)
[clamp.git] / src / test / java / org / onap / clamp / clds / model / prop / ModelPropertiesTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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============================================
20  * ===================================================================
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23
24 package org.onap.clamp.clds.model.prop;
25
26 import org.onap.clamp.clds.transform.TransformUtil;
27 import org.junit.Assert;
28 import org.junit.Test;
29 import static org.junit.Assert.assertEquals;
30 import java.io.IOException;
31
32 /**
33  * Test org.onap.clamp.ClampDesigner.model.prop package using ModelProperties.
34  */
35 public class ModelPropertiesTest {
36
37     @Test
38     public void testJsonParse() throws IOException {
39         String modelBpmnProp = TransformUtil.getResourceAsString("example/modelBpmnProp.json");
40         String modelProp = TransformUtil.getResourceAsString("example/modelProp.json");
41         String modName = "example-model-name";
42         String controlName = "example-control-name";
43
44         ModelProperties prop = new ModelProperties(modName, controlName, null, true, modelBpmnProp, modelProp);
45         Assert.assertEquals(modName, prop.getModelName());
46         Assert.assertEquals(controlName, prop.getControlName());
47         Assert.assertEquals(null, prop.getActionCd());
48
49         Global g = prop.getGlobal();
50         Assert.assertEquals("0f983e18-4603-4bb4-a98c-e29691fb16a1", g.getService());
51         Assert.assertEquals("[SNDGCA64]", g.getLocation().toString());
52         Assert.assertEquals("[6c7aaec2-59eb-41d9-8681-b7f976ab668d]", g.getResourceVf().toString());
53
54         StringMatch sm = prop.getType(StringMatch.class);
55         Assert.assertEquals("StringMatch_", sm.getId());
56
57         Policy p = prop.getType(Policy.class);
58         Assert.assertEquals("Policy_", p.getId());
59         Assert.assertEquals(null, p.getTopicPublishes());
60         Assert.assertEquals(null, p.getTopicSubscribes());
61
62         Tca t = prop.getType(Tca.class);
63         Assert.assertEquals("Narra", t.getTcaItems().get(0).getTcaName());
64         Assert.assertEquals(Integer.valueOf(4), t.getTcaItems().get(0).getTcaThreshholds().get(0).getThreshhold());
65     }
66
67     @Test
68         public void testPolicy() throws IOException {
69
70                 String modelBpmnProp = TransformUtil.getResourceAsString("example/modelBpmnPropForPolicy.json");
71                 System.out.println(modelBpmnProp);
72
73                 String modelProp = TransformUtil.getResourceAsString("example/modelPropForPolicy.json");
74                 System.out.println(modelProp);
75
76                 ModelProperties prop = new ModelProperties("example-model-name", "example-control-name", null, true, modelBpmnProp, modelProp);
77                 System.out.println("attempting prop.getGlobal()...");
78                 Global g = prop.getGlobal();
79                 System.out.println("attempting prop.getStringMatch()...");
80                 StringMatch stringMatch = prop.getType(StringMatch.class);
81                 if(stringMatch.isFound()){
82                         System.out.println("stringMatch json object is present...");
83                         assertEquals("1", stringMatch.getResourceGroups().get(0).getPolicyId());
84                 }
85                 System.out.println("attempting prop.getPolicy()...");
86                 Policy policy = prop.getType(Policy.class);
87                 if(policy.isFound()){
88                         System.out.println("policy json object is present...");
89                         assertEquals("1", policy.getPolicyChains().get(0).getPolicyId());
90                 }
91         }
92
93
94 }