2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
26 package org.onap.clamp.loop;
28 import static org.assertj.core.api.Assertions.assertThat;
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;
37 public class LoopTemplateLoopElementModelTest {
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);
43 private LoopElementModel getLoopElementModel(String yaml, String name, PolicyModel policyModel) {
44 LoopElementModel model = new LoopElementModel();
45 model.setBlueprint(yaml);
47 model.addPolicyModel(policyModel);
48 model.setLoopElementType("OPERATIONAL_POLICY");
52 private PolicyModel getPolicyModel(String policyType, String policyModelTosca, String version, String policyAcronym,
53 String policyVariant) {
54 return new PolicyModel(policyType, policyModelTosca, version, policyAcronym);
57 private LoopTemplate getLoopTemplate(String name, String blueprint, Integer maxInstancesAllowed) {
58 LoopTemplate template = new LoopTemplate(name, blueprint, maxInstancesAllowed, null);
59 template.addLoopElementModel(loopElementModel);
64 * This tests compareTo method.
67 public void compareToTest() {
68 LoopTemplateLoopElementModel model1 = new LoopTemplateLoopElementModel();
69 LoopTemplateLoopElementModel model2 = new LoopTemplateLoopElementModel();
70 assertThat(model1.compareTo(model2)).isEqualTo(1);
72 model1.setFlowOrder(2);
73 assertThat(model1.compareTo(model2)).isEqualTo(-1);
75 model2.setFlowOrder(3);
76 assertThat(model1.compareTo(model2)).isEqualTo(1);
80 * This tests equals method.
83 public void equalsTest() {
84 LoopTemplateLoopElementModel model1 = new LoopTemplateLoopElementModel();
85 LoopTemplateLoopElementModel model2 = new LoopTemplateLoopElementModel();
87 assertThat(model1.equals(model2)).isTrue();
89 model1.setLoopTemplate(loopTemplate);
90 assertThat(model1.equals(model2)).isFalse();
91 model2.setLoopTemplate(loopTemplate);
92 assertThat(model1.equals(model2)).isTrue();
94 model1.setLoopElementModel(loopElementModel);
95 assertThat(model1.equals(model2)).isFalse();
96 model2.setLoopElementModel(loopElementModel);
97 assertThat(model1.equals(model2)).isTrue();
99 model1.setFlowOrder(1);
100 assertThat(model1.equals(model2)).isTrue();
101 model2.setFlowOrder(2);
102 assertThat(model1.equals(model2)).isTrue();