Merge "Add Holmes to the Backend"
[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 import org.onap.clamp.clds.util.ResourceFileUtil;
33
34
35 /**
36  * Test org.onap.clamp.ClampDesigner.model.prop package using ModelProperties.
37  */
38 public class ModelPropertiesTest {
39
40     @Test
41     public void testJsonParse() throws IOException {
42         String modelBpmnProp = ResourceFileUtil.getResourceAsString("example/modelBpmnProp.json");
43         String modelProp = ResourceFileUtil.getResourceAsString("example/modelProp.json");
44         String modName = "example-model-name";
45         String controlName = "example-control-name";
46
47         ModelProperties prop = new ModelProperties(modName, controlName, null, true, modelBpmnProp, modelProp);
48         Assert.assertEquals(modName, prop.getModelName());
49         Assert.assertEquals(controlName, prop.getControlName());
50         Assert.assertEquals(null, prop.getActionCd());
51         Global global = prop.getGlobal();
52         Assert.assertEquals("0f983e18-4603-4bb4-a98c-e29691fb16a1", global.getService());
53         Assert.assertEquals("[SNDGCA64]", global.getLocation().toString());
54         Assert.assertEquals("[6c7aaec2-59eb-41d9-8681-b7f976ab668d]", global.getResourceVf().toString());
55         StringMatch sm = prop.getType(StringMatch.class);
56         Assert.assertEquals("StringMatch_", sm.getId());
57         Policy policy = prop.getType(Policy.class);
58         Assert.assertEquals("Policy_", policy.getId());
59         Assert.assertEquals(null, policy.getTopicPublishes());
60         Assert.assertEquals(null, policy.getTopicSubscribes());
61
62         Tca tca = prop.getType(Tca.class);
63         Assert.assertEquals("Narra", tca.getTcaItems().get(0).getTcaName());
64         Assert.assertEquals(Integer.valueOf(4), tca.getTcaItems().get(0).getTcaThreshholds().get(0).getThreshhold());
65     }
66
67     @Test
68     public void testPolicy() throws IOException {
69
70         String modelBpmnProp = ResourceFileUtil.getResourceAsString("example/modelBpmnPropForPolicy.json");
71         System.out.println(modelBpmnProp);
72
73         String modelProp = ResourceFileUtil.getResourceAsString("example/modelPropForPolicy.json");
74         System.out.println(modelProp);
75         ModelProperties prop = new ModelProperties("example-model-name", "example-control-name",
76                 null, true, modelBpmnProp, modelProp);
77         System.out.println("attempting prop.getGlobal()...");
78         Global global = 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 }