Code refactoring
[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-2018 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 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29
30 import java.io.IOException;
31
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.clamp.clds.model.CldsModel;
35 import org.onap.clamp.clds.model.properties.Holmes;
36 import org.onap.clamp.clds.model.properties.ModelProperties;
37 import org.onap.clamp.clds.model.properties.Policy;
38 import org.onap.clamp.clds.model.properties.Tca;
39 import org.onap.clamp.clds.util.ResourceFileUtil;
40
41 /**
42  * Test org.onap.clamp.ClampDesigner.model.prop package using ModelProperties.
43  */
44 public class ModelPropertiesTest {
45
46     @Before
47     public void registerNewClasses() {
48         ModelProperties.registerModelElement(Holmes.class, Holmes.getType());
49     }
50
51     @Test
52     public void testTcaModelDecoding() throws IOException {
53         String modelBpmnProp = ResourceFileUtil
54                 .getResourceAsString("example/model-properties/tca/modelBpmnProperties.json");
55         String modelBpmn = ResourceFileUtil.getResourceAsString("example/model-properties/tca/modelBpmn.json");
56         ModelProperties prop = new ModelProperties("example-model-name", "example-control-name", null, true, modelBpmn,
57                 modelBpmnProp);
58         Policy policy = prop.getType(Policy.class);
59         assertTrue(policy.isFound());
60         assertEquals(1, policy.getPolicyChains().size());
61         assertEquals("0", policy.getPolicyChains().get(0).getPolicyId());
62         assertEquals(1, policy.getPolicyChains().get(0).getPolicyItems().size());
63         assertEquals("resourceid", policy.getPolicyChains().get(0).getPolicyItems().get(0).getTargetResourceId());
64         assertEquals(180, policy.getPolicyChains().get(0).getPolicyItems().get(0).getRetryTimeLimit());
65         assertEquals(3, policy.getPolicyChains().get(0).getPolicyItems().get(0).getMaxRetries());
66         assertEquals("", policy.getPolicyChains().get(0).getPolicyItems().get(0).getParentPolicy());
67         assertEquals(null, policy.getPolicyChains().get(0).getPolicyItems().get(0).getParentPolicyConditions());
68         Tca tca = prop.getType(Tca.class);
69         assertNotNull(tca);
70         assertTrue(tca.isFound());
71         assertEquals("vFirewallBroadcastPackets", tca.getTcaItem().getEventName());
72         assertEquals("VNF", tca.getTcaItem().getControlLoopSchemaType());
73         assertEquals("policy1", tca.getTcaItem().getPolicyId());
74         assertEquals("f734f031-10aa-t8fb-330f-04dde2886325", tca.getTcaItem().getTcaUuId());
75         assertEquals(2, tca.getTcaItem().getTcaThresholds().size());
76         assertEquals("ABATED", tca.getTcaItem().getTcaThresholds().get(0).getClosedLoopEventStatus());
77         assertEquals(
78                 "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated",
79                 tca.getTcaItem().getTcaThresholds().get(0).getFieldPath());
80         assertEquals("LESS_OR_EQUAL", tca.getTcaItem().getTcaThresholds().get(0).getOperator());
81         assertEquals(Integer.valueOf(123), tca.getTcaItem().getTcaThresholds().get(0).getThreshold());
82         assertEquals("ONSET", tca.getTcaItem().getTcaThresholds().get(1).getClosedLoopEventStatus());
83         assertEquals("$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedDiscardedPacketsDelta",
84                 tca.getTcaItem().getTcaThresholds().get(1).getFieldPath());
85         assertEquals("GREATER_OR_EQUAL", tca.getTcaItem().getTcaThresholds().get(1).getOperator());
86         assertEquals(Integer.valueOf(123), tca.getTcaItem().getTcaThresholds().get(1).getThreshold());
87     }
88
89     @Test
90     public void testHolmesModelDecoding() throws IOException {
91         String modelBpmnProp = ResourceFileUtil
92                 .getResourceAsString("example/model-properties/holmes/modelBpmnProperties.json");
93         String modelBpmn = ResourceFileUtil.getResourceAsString("example/model-properties/holmes/modelBpmn.json");
94         ModelProperties prop = new ModelProperties("example-model-name", "example-control-name", null, true, modelBpmn,
95                 modelBpmnProp);
96         Policy policy = prop.getType(Policy.class);
97         assertTrue(policy.isFound());
98         assertEquals(1, policy.getPolicyChains().size());
99         assertEquals("0", policy.getPolicyChains().get(0).getPolicyId());
100         assertEquals(1, policy.getPolicyChains().get(0).getPolicyItems().size());
101         assertEquals("resourceid", policy.getPolicyChains().get(0).getPolicyItems().get(0).getTargetResourceId());
102         assertEquals(180, policy.getPolicyChains().get(0).getPolicyItems().get(0).getRetryTimeLimit());
103         assertEquals(3, policy.getPolicyChains().get(0).getPolicyItems().get(0).getMaxRetries());
104         assertEquals("", policy.getPolicyChains().get(0).getPolicyItems().get(0).getParentPolicy());
105         assertEquals(null, policy.getPolicyChains().get(0).getPolicyItems().get(0).getParentPolicyConditions());
106         Holmes holmes = prop.getType(Holmes.class);
107         assertNotNull(holmes);
108         assertTrue(holmes.isFound());
109         assertEquals("configPolicy1", holmes.getConfigPolicyName());
110         assertEquals("blabla", holmes.getCorrelationLogic());
111     }
112
113     @Test
114     public void testGetVf() throws IOException {
115         CldsModel cldsModel = new CldsModel();
116         cldsModel.setPropText(
117                 ResourceFileUtil.getResourceAsString("example/model-properties/tca/modelBpmnProperties.json"));
118         assertEquals("023a3f0d-1161-45ff-b4cf-8918a8ccf3ad", ModelProperties.getVf(cldsModel));
119     }
120 }