2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 package org.onap.clamp.clds.model.prop;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
30 import java.io.IOException;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.clamp.clds.model.CldsModel;
35 import org.onap.clamp.clds.util.ResourceFileUtil;
38 * Test org.onap.clamp.ClampDesigner.model.prop package using ModelProperties.
40 public class ModelPropertiesTest {
43 public void registerNewClasses() {
44 ModelProperties.registerModelElement(Holmes.class, Holmes.getType());
48 public void testTcaModelDecoding() throws IOException {
50 String modelBpmnProp = ResourceFileUtil
51 .getResourceAsString("example/model-properties/tca/modelBpmnProperties.json");
52 String modelBpmn = ResourceFileUtil.getResourceAsString("example/model-properties/tca/modelBpmn.json");
54 ModelProperties prop = new ModelProperties("example-model-name", "example-control-name", null, true, modelBpmn,
57 Policy policy = prop.getType(Policy.class);
58 assertTrue(policy.isFound());
59 assertEquals(1, policy.getPolicyChains().size());
60 assertEquals("0", policy.getPolicyChains().get(0).getPolicyId());
61 assertEquals(1, policy.getPolicyChains().get(0).getPolicyItems().size());
62 assertEquals("resourceid", policy.getPolicyChains().get(0).getPolicyItems().get(0).getTargetResourceId());
63 assertEquals(180, policy.getPolicyChains().get(0).getPolicyItems().get(0).getRetryTimeLimit());
64 assertEquals(3, policy.getPolicyChains().get(0).getPolicyItems().get(0).getMaxRetries());
65 assertEquals("", policy.getPolicyChains().get(0).getPolicyItems().get(0).getParentPolicy());
66 assertEquals(null, policy.getPolicyChains().get(0).getPolicyItems().get(0).getParentPolicyConditions());
68 Tca tca = prop.getType(Tca.class);
70 assertTrue(tca.isFound());
71 assertEquals("vFirewallBroadcastPackets", tca.getTcaItem().getEventName());
72 assertEquals("policy1", tca.getTcaItem().getPolicyId());
73 assertEquals("f734f031-10aa-t8fb-330f-04dde2886325", tca.getTcaItem().getTcaUuId());
74 assertEquals(2, tca.getTcaItem().getTcaThresholds().size());
76 assertEquals("ABATED", tca.getTcaItem().getTcaThresholds().get(0).getClosedLoopEventStatus());
77 assertEquals("VM", tca.getTcaItem().getTcaThresholds().get(0).getControlLoopSchema());
79 "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated",
80 tca.getTcaItem().getTcaThresholds().get(0).getFieldPath());
81 assertEquals("LESS_OR_EQUAL", tca.getTcaItem().getTcaThresholds().get(0).getOperator());
82 assertEquals(Integer.valueOf(123), tca.getTcaItem().getTcaThresholds().get(0).getThreshold());
84 assertEquals("ONSET", tca.getTcaItem().getTcaThresholds().get(1).getClosedLoopEventStatus());
85 assertEquals("VNF", tca.getTcaItem().getTcaThresholds().get(1).getControlLoopSchema());
86 assertEquals("$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedDiscardedPacketsDelta",
87 tca.getTcaItem().getTcaThresholds().get(1).getFieldPath());
88 assertEquals("GREATER_OR_EQUAL", tca.getTcaItem().getTcaThresholds().get(1).getOperator());
89 assertEquals(Integer.valueOf(123), tca.getTcaItem().getTcaThresholds().get(1).getThreshold());
93 public void testHolmesModelDecoding() throws IOException {
95 String modelBpmnProp = ResourceFileUtil
96 .getResourceAsString("example/model-properties/holmes/modelBpmnProperties.json");
97 String modelBpmn = ResourceFileUtil.getResourceAsString("example/model-properties/holmes/modelBpmn.json");
99 ModelProperties prop = new ModelProperties("example-model-name", "example-control-name", null, true, modelBpmn,
102 Policy policy = prop.getType(Policy.class);
103 assertTrue(policy.isFound());
104 assertEquals(1, policy.getPolicyChains().size());
105 assertEquals("0", policy.getPolicyChains().get(0).getPolicyId());
106 assertEquals(1, policy.getPolicyChains().get(0).getPolicyItems().size());
107 assertEquals("resourceid", policy.getPolicyChains().get(0).getPolicyItems().get(0).getTargetResourceId());
108 assertEquals(180, policy.getPolicyChains().get(0).getPolicyItems().get(0).getRetryTimeLimit());
109 assertEquals(3, policy.getPolicyChains().get(0).getPolicyItems().get(0).getMaxRetries());
110 assertEquals("", policy.getPolicyChains().get(0).getPolicyItems().get(0).getParentPolicy());
111 assertEquals(null, policy.getPolicyChains().get(0).getPolicyItems().get(0).getParentPolicyConditions());
113 Holmes holmes = prop.getType(Holmes.class);
114 assertNotNull(holmes);
115 assertTrue(holmes.isFound());
116 assertEquals("policy1", holmes.getOperationalPolicy());
117 assertEquals("blabla", holmes.getCorrelationLogic());
121 public void testGetVf() throws IOException {
122 CldsModel cldsModel = new CldsModel();
123 cldsModel.setPropText(
124 ResourceFileUtil.getResourceAsString("example/model-properties/tca/modelBpmnProperties.json"));
125 assertEquals("f5213e3a-9191-4362-93b5-b67f8d770e44", ModelProperties.getVf(cldsModel));