e5b64c99c0bba85f5780f7cc07fbea97d058a255
[clamp.git] / src / test / java / org / onap / clamp / loop / LoopTemplateLoopElementModelTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Modifications Copyright (c) 2019 Samsung
9  * ================================================================================
10  *  Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END============================================
22  * ===================================================================
23  *
24  */
25
26 package org.onap.clamp.loop;
27
28 import static org.assertj.core.api.Assertions.assertThat;
29
30 import org.junit.Test;
31 import org.onap.clamp.loop.template.LoopElementModel;
32 import org.onap.clamp.loop.template.LoopTemplate;
33 import org.onap.clamp.loop.template.LoopTemplateLoopElementModel;
34 import org.onap.clamp.loop.template.PolicyModel;
35
36
37 public class LoopTemplateLoopElementModelTest {
38
39     private LoopElementModel loopElementModel = getLoopElementModel("yaml", "microService1",
40         getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools", "type1"));
41     private LoopTemplate loopTemplate = getLoopTemplate("templateName", "yaml", "svg", 1);
42
43     private LoopElementModel getLoopElementModel(String yaml, String name, PolicyModel policyModel) {
44         LoopElementModel model = new LoopElementModel();
45         model.setBlueprint(yaml);
46         model.setName(name);
47         model.addPolicyModel(policyModel);
48         model.setLoopElementType("OPERATIONAL_POLICY");
49         return model;
50     }
51
52     private PolicyModel getPolicyModel(String policyType, String policyModelTosca, String version, String policyAcronym,
53                                        String policyVariant) {
54         return new PolicyModel(policyType, policyModelTosca, version, policyAcronym);
55     }
56
57     private LoopTemplate getLoopTemplate(String name, String blueprint, String svgRepresentation,
58                                          Integer maxInstancesAllowed) {
59         LoopTemplate template = new LoopTemplate(name, blueprint, svgRepresentation, maxInstancesAllowed, null);
60         template.addLoopElementModel(loopElementModel);
61         return template;
62     }
63
64     /**
65      * This tests compareTo method.
66      */
67     @Test
68     public void compareToTest() {
69         LoopTemplateLoopElementModel model1 = new LoopTemplateLoopElementModel();
70         LoopTemplateLoopElementModel model2 = new LoopTemplateLoopElementModel();
71         assertThat(model1.compareTo(model2)).isEqualTo(1);
72
73         model1.setFlowOrder(2);
74         assertThat(model1.compareTo(model2)).isEqualTo(-1);
75
76         model2.setFlowOrder(3);
77         assertThat(model1.compareTo(model2)).isEqualTo(1);
78     }
79
80     /**
81      * This tests equals method.
82      */
83     @Test
84     public void equalsTest() {
85         LoopTemplateLoopElementModel model1 = new LoopTemplateLoopElementModel();
86         LoopTemplateLoopElementModel model2 = new LoopTemplateLoopElementModel();
87
88         assertThat(model1.equals(model2)).isTrue();
89
90         model1.setLoopTemplate(loopTemplate);
91         assertThat(model1.equals(model2)).isFalse();
92         model2.setLoopTemplate(loopTemplate);
93         assertThat(model1.equals(model2)).isTrue();
94
95         model1.setLoopElementModel(loopElementModel);
96         assertThat(model1.equals(model2)).isFalse();
97         model2.setLoopElementModel(loopElementModel);
98         assertThat(model1.equals(model2)).isTrue();
99
100         model1.setFlowOrder(1);
101         assertThat(model1.equals(model2)).isTrue();
102         model2.setFlowOrder(2);
103         assertThat(model1.equals(model2)).isTrue();
104     }
105
106 }