Fixing some checkstyle issues.
[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 static org.junit.Assert.assertEquals;
27
28 import java.io.IOException;
29
30 import org.junit.Assert;
31 import org.junit.Test;
32
33 import org.onap.clamp.clds.transform.TransformUtil;
34
35
36 /**
37  * Test org.onap.clamp.ClampDesigner.model.prop package using ModelProperties.
38  */
39 public class ModelPropertiesTest {
40
41     @Test
42     public void testJsonParse() throws IOException {
43         String modelBpmnProp = TransformUtil.getResourceAsString("example/modelBpmnProp.json");
44         String modelProp = TransformUtil.getResourceAsString("example/modelProp.json");
45         String modName = "example-model-name";
46         String controlName = "example-control-name";
47
48         ModelProperties prop = new ModelProperties(modName, controlName, null, true, modelBpmnProp, modelProp);
49         Assert.assertEquals(modName, prop.getModelName());
50         Assert.assertEquals(controlName, prop.getControlName());
51         Assert.assertEquals(null, prop.getActionCd());
52         Global global = prop.getGlobal();
53         Assert.assertEquals("0f983e18-4603-4bb4-a98c-e29691fb16a1", global.getService());
54         Assert.assertEquals("[SNDGCA64]", global.getLocation().toString());
55         Assert.assertEquals("[6c7aaec2-59eb-41d9-8681-b7f976ab668d]", global.getResourceVf().toString());
56         StringMatch sm = prop.getType(StringMatch.class);
57         Assert.assertEquals("StringMatch_", sm.getId());
58         Policy policy = prop.getType(Policy.class);
59         Assert.assertEquals("Policy_", policy.getId());
60         Assert.assertEquals(null, policy.getTopicPublishes());
61         Assert.assertEquals(null, policy.getTopicSubscribes());
62
63         Tca tca = prop.getType(Tca.class);
64         Assert.assertEquals("Narra", tca.getTcaItems().get(0).getTcaName());
65         Assert.assertEquals(Integer.valueOf(4), tca.getTcaItems().get(0).getTcaThreshholds().get(0).getThreshhold());
66     }
67
68     @Test
69     public void testPolicy() throws IOException {
70
71         String modelBpmnProp = TransformUtil.getResourceAsString("example/modelBpmnPropForPolicy.json");
72         System.out.println(modelBpmnProp);
73
74         String modelProp = TransformUtil.getResourceAsString("example/modelPropForPolicy.json");
75         System.out.println(modelProp);
76         ModelProperties prop = new ModelProperties("example-model-name", "example-control-name",
77                 null, true, modelBpmnProp, modelProp);
78         System.out.println("attempting prop.getGlobal()...");
79         Global global = prop.getGlobal();
80         System.out.println("attempting prop.getStringMatch()...");
81         StringMatch stringMatch = prop.getType(StringMatch.class);
82         if (stringMatch.isFound()) {
83             System.out.println("stringMatch json object is present...");
84             assertEquals("1", stringMatch.getResourceGroups().get(0).getPolicyId());
85         }
86         System.out.println("attempting prop.getPolicy()...");
87         Policy policy = prop.getType(Policy.class);
88         if (policy.isFound()) {
89             System.out.println("policy json object is present...");
90             assertEquals("1", policy.getPolicyChains().get(0).getPolicyId());
91         }
92     }
93 }