Create SVG in UI
[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", 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, Integer maxInstancesAllowed) {
58         LoopTemplate template = new LoopTemplate(name, blueprint, maxInstancesAllowed, null);
59         template.addLoopElementModel(loopElementModel);
60         return template;
61     }
62
63     /**
64      * This tests compareTo method.
65      */
66     @Test
67     public void compareToTest() {
68         LoopTemplateLoopElementModel model1 = new LoopTemplateLoopElementModel();
69         LoopTemplateLoopElementModel model2 = new LoopTemplateLoopElementModel();
70         assertThat(model1.compareTo(model2)).isEqualTo(1);
71
72         model1.setFlowOrder(2);
73         assertThat(model1.compareTo(model2)).isEqualTo(-1);
74
75         model2.setFlowOrder(3);
76         assertThat(model1.compareTo(model2)).isEqualTo(1);
77     }
78
79     /**
80      * This tests equals method.
81      */
82     @Test
83     public void equalsTest() {
84         LoopTemplateLoopElementModel model1 = new LoopTemplateLoopElementModel();
85         LoopTemplateLoopElementModel model2 = new LoopTemplateLoopElementModel();
86
87         assertThat(model1.equals(model2)).isTrue();
88
89         model1.setLoopTemplate(loopTemplate);
90         assertThat(model1.equals(model2)).isFalse();
91         model2.setLoopTemplate(loopTemplate);
92         assertThat(model1.equals(model2)).isTrue();
93
94         model1.setLoopElementModel(loopElementModel);
95         assertThat(model1.equals(model2)).isFalse();
96         model2.setLoopElementModel(loopElementModel);
97         assertThat(model1.equals(model2)).isTrue();
98
99         model1.setFlowOrder(1);
100         assertThat(model1.equals(model2)).isTrue();
101         model2.setFlowOrder(2);
102         assertThat(model1.equals(model2)).isTrue();
103     }
104
105 }