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.messages.dmaap.participant;
23 import static org.assertj.core.api.Assertions.assertThatThrownBy;
24 import static org.junit.Assert.assertEquals;
25 import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable;
26 import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
28 import java.time.Instant;
29 import java.util.List;
31 import java.util.UUID;
32 import org.junit.jupiter.api.Test;
33 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
34 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatisticsList;
35 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
36 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopInfo;
37 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
38 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopStatistics;
39 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition;
40 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
41 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
42 import org.onap.policy.common.utils.coder.CoderException;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
44 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
45 import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
47 class ParticipantStatusTest {
50 void testCopyConstructor() throws CoderException {
51 assertThatThrownBy(() -> new ParticipantStatus(null)).isInstanceOf(NullPointerException.class);
53 final ParticipantStatus orig = new ParticipantStatus();
55 // verify with null values
56 assertEquals(removeVariableFields(orig.toString()),
57 removeVariableFields(new ParticipantStatus(orig).toString()));
59 // verify with all values
60 ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3");
61 orig.setControlLoopId(id);
62 orig.setParticipantId(id);
63 ToscaConceptIdentifier type = new ToscaConceptIdentifier("type", "2.3.4");
64 orig.setParticipantType(type);
65 orig.setMessageId(UUID.randomUUID());
66 orig.setState(ParticipantState.ACTIVE);
67 orig.setHealthStatus(ParticipantHealthStatus.HEALTHY);
68 orig.setTimestamp(Instant.ofEpochMilli(3000));
70 ControlLoopInfo clInfo = getControlLoopInfo(id);
71 orig.setControlLoopInfoList(List.of(clInfo));
73 ParticipantDefinition participantDefinitionUpdate = new ParticipantDefinition();
74 participantDefinitionUpdate.setParticipantId(id);
75 participantDefinitionUpdate.setParticipantType(type);
76 ControlLoopElementDefinition clDefinition = getClElementDefinition(id);
77 participantDefinitionUpdate.setControlLoopElementDefinitionList(List.of(clDefinition));
78 orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate));
80 assertEquals(removeVariableFields(orig.toString()),
81 removeVariableFields(new ParticipantStatus(orig).toString()));
83 assertSerializable(orig, ParticipantStatus.class);
86 private ControlLoopInfo getControlLoopInfo(ToscaConceptIdentifier id) {
87 ControlLoopInfo clInfo = new ControlLoopInfo();
88 clInfo.setState(ControlLoopState.PASSIVE2RUNNING);
89 clInfo.setControlLoopId(id);
91 ControlLoopStatistics clStatistics = new ControlLoopStatistics();
92 clStatistics.setControlLoopId(id);
93 clStatistics.setAverageExecutionTime(12345);
94 clStatistics.setEventCount(12345);
95 clStatistics.setLastEnterTime(12345);
96 clStatistics.setLastExecutionTime(12345);
97 clStatistics.setLastStart(12345);
98 clStatistics.setTimeStamp(Instant.ofEpochMilli(3000));
99 clStatistics.setUpTime(12345);
100 ClElementStatisticsList clElementStatisticsList = new ClElementStatisticsList();
101 ClElementStatistics clElementStatistics = new ClElementStatistics();
102 clElementStatistics.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1"));
103 clElementStatistics.setTimeStamp(Instant.now());
104 clElementStatisticsList.setClElementStatistics(List.of(clElementStatistics));
105 clStatistics.setClElementStatisticsList(clElementStatisticsList);
107 clInfo.setControlLoopStatistics(clStatistics);
111 private ControlLoopElementDefinition getClElementDefinition(ToscaConceptIdentifier id) {
112 ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate();
113 toscaNodeTemplate.setName("nodeTemplate");
114 toscaNodeTemplate.setDerivedFrom("parentNodeTemplate");
115 toscaNodeTemplate.setDescription("Description of nodeTemplate");
116 toscaNodeTemplate.setVersion("1.2.3");
118 ControlLoopElementDefinition clDefinition = new ControlLoopElementDefinition();
119 clDefinition.setClElementDefinitionId(id);
120 clDefinition.setControlLoopElementToscaNodeTemplate(toscaNodeTemplate);
122 ToscaProperty property = new ToscaProperty();
123 property.setName("test");
124 property.setType("testType");
125 Map<String, ToscaProperty> commonPropertiesMap = Map.of("Prop1", property);
126 clDefinition.setCommonPropertiesMap(commonPropertiesMap);