2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.controlloop.models.controlloop.concepts;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertNull;
30 import java.util.LinkedHashMap;
31 import java.util.UUID;
32 import org.junit.jupiter.api.Test;
33 import org.onap.policy.models.base.PfKey;
34 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
36 class ControlLoopTest {
38 void testControlLoop() {
39 ControlLoop cl0 = new ControlLoop();
40 cl0.setDefinition(new ToscaConceptIdentifier("dfName", "1.2.3"));
41 assertEquals("dfName", cl0.getType());
42 assertEquals("1.2.3", cl0.getTypeVersion());
44 ControlLoop cl1 = new ControlLoop(cl0);
45 assertEquals(cl0, cl1);
47 assertEquals(0, cl0.compareTo(cl1));
51 void testControlLoopLombok() {
52 assertNotNull(new ControlLoop());
53 ControlLoop cl0 = new ControlLoop();
54 cl0.setElements(new LinkedHashMap<>());
56 assertThat(cl0.toString()).contains("ControlLoop(");
57 assertThat(cl0.hashCode()).isNotZero();
58 assertEquals(true, cl0.equals(cl0));
59 assertEquals(false, cl0.equals(null));
61 ControlLoop cl1 = new ControlLoop();
63 cl1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1"));
64 cl1.setDescription("Description");
65 cl1.setElements(new LinkedHashMap<>());
67 cl1.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
68 cl1.setState(ControlLoopState.UNINITIALISED);
69 cl1.setVersion("0.0.1");
71 assertThat(cl1.toString()).contains("ControlLoop(");
72 assertEquals(false, cl1.hashCode() == 0);
73 assertEquals(false, cl1.equals(cl0));
74 assertEquals(false, cl1.equals(null));
76 assertNotEquals(cl1, cl0);
78 ControlLoop cl2 = new ControlLoop();
79 cl2.setElements(new LinkedHashMap<>());
82 assertThatThrownBy(() -> cl2.setDefinition(null)). isInstanceOf(NullPointerException.class);
83 assertThatThrownBy(() -> cl2.setOrderedState(null)).isInstanceOf(NullPointerException.class);
84 assertThatThrownBy(() -> cl2.setState(null)). isInstanceOf(NullPointerException.class);
87 assertEquals(cl2, cl0);
89 cl1.setCascadedOrderedState(ControlLoopOrderedState.PASSIVE);
90 assertEquals(ControlLoopOrderedState.PASSIVE, cl1.getOrderedState());
92 cl1.getElements().put(UUID.randomUUID(), new ControlLoopElement());
93 cl1.setCascadedOrderedState(ControlLoopOrderedState.RUNNING);
94 assertEquals(ControlLoopOrderedState.RUNNING, cl1.getOrderedState());
95 assertEquals(ControlLoopOrderedState.RUNNING, cl1.getElements().values().iterator().next().getOrderedState());
97 assertNull(cl0.getElements().get(UUID.randomUUID()));
98 assertNull(cl1.getElements().get(UUID.randomUUID()));
100 assertEquals(PfKey.NULL_KEY_NAME, cl0.getDefinition().getName());