02e27ea8f44c6788b5ae823da673b4676c811b96
[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 import static org.junit.Assert.assertTrue;
28
29 import java.io.IOException;
30 import java.util.ArrayList;
31 import java.util.List;
32
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.clamp.clds.util.ResourceFileUtil;
36
37 /**
38  * Test org.onap.clamp.ClampDesigner.model.prop package using ModelProperties.
39  */
40 public class ModelPropertiesTest {
41
42     @Before
43     public void registerNewClasses() {
44         ModelProperties.registerModelElement(Holmes.class, Holmes.getType());
45     }
46
47     @Test
48     public void testHolmes() throws IOException {
49
50         String modelBpmnProp = ResourceFileUtil.getResourceAsString("example/model-properties/modelBpmnProp.json");
51         String modelBpmn = ResourceFileUtil.getResourceAsString("example/model-properties/modelBpmn.json");
52
53         ModelProperties prop = new ModelProperties("example-model-name", "example-control-name", null, true, modelBpmn,
54                 modelBpmnProp);
55
56         StringMatch stringMatch = prop.getType(StringMatch.class);
57         assertTrue(stringMatch.isFound());
58         assertEquals("1505133578560", stringMatch.getResourceGroups().get(0).getGroupNumber());
59         assertEquals("0", stringMatch.getResourceGroups().get(0).getPolicyId());
60         assertEquals(1, stringMatch.getResourceGroups().get(0).getServiceConfigurations().size());
61         List<String> aaiMathcingFields = new ArrayList<String>();
62         aaiMathcingFields.add("complex.city");
63         assertEquals(aaiMathcingFields,
64                 stringMatch.getResourceGroups().get(0).getServiceConfigurations().get(0).getaaiMatchingFields());
65         assertEquals("1600", stringMatch.getResourceGroups().get(0).getServiceConfigurations().get(0).getAgeLimit());
66         assertEquals(1, stringMatch.getResourceGroups().get(0).getServiceConfigurations().get(0).getStringSet().size());
67
68         Collector collector = prop.getType(Collector.class);
69         assertTrue(collector.isFound());
70         assertEquals("DCAE-COLLECTOR-UCSNMP", collector.getTopicPublishes());
71
72         Policy policy = prop.getType(Policy.class);
73         assertTrue(policy.isFound());
74         assertEquals(1, policy.getPolicyChains().size());
75         assertEquals("0", policy.getPolicyChains().get(0).getPolicyId());
76         assertEquals(1, policy.getPolicyChains().get(0).getPolicyItems().size());
77
78         Tca tca = prop.getType(Tca.class);
79         assertTrue(tca.isFound());
80         assertEquals(1, tca.getTcaItems().size());
81         assertEquals(0, tca.getTcaItems().get(0).getTcaThreshholds().size());
82
83         Holmes holmes = prop.getType(Holmes.class);
84         assertTrue(holmes.isFound());
85         assertEquals("policy1", holmes.getOperationalPolicy());
86         assertEquals("blabla", holmes.getCorrelationLogic());
87     }
88 }