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.acm.participant.intermediary.api.impl;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotNull;
28 import java.time.Instant;
29 import java.util.UUID;
30 import org.junit.jupiter.api.Test;
31 import org.mockito.Mockito;
32 import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
33 import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData;
34 import org.onap.policy.clamp.models.acm.concepts.AcElementStatistics;
35 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
36 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
37 import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus;
38 import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
39 import org.onap.policy.clamp.models.acm.concepts.ParticipantStatistics;
40 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
41 import org.onap.policy.common.utils.coder.CoderException;
42 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
44 class ParticipantIntermediaryApiImplTest {
46 private CommonTestData commonTestData = new CommonTestData();
47 private static final String ID_NAME = "org.onap.PM_CDS_Blueprint";
48 private static final String ID_VERSION = "1.0.1";
50 private static final String ID_NAME_E = "org.onap.domain.pmsh.PMSHAutomationCompositionDefinition";
51 private static final String ID_VERSION_E = "1.0.0";
53 private static final String ID_NAME_TYPE = "org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant";
54 private static final String ID_VERSION_TYPE = "2.3.4";
57 void mockParticipantIntermediaryApiImplTest() throws CoderException {
58 var uuid = UUID.randomUUID();
59 var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
60 var participantHandler = commonTestData.getParticipantHandlerAutomationCompositions();
61 var automationComposiitonHandler = commonTestData.setTestAutomationCompositionHandler(id, uuid);
62 var apiImpl = new ParticipantIntermediaryApiImpl(participantHandler, automationComposiitonHandler);
63 var acElementListener = Mockito.mock(AutomationCompositionElementListener.class);
64 apiImpl.registerAutomationCompositionElementListener(acElementListener);
66 assertNotNull(apiImpl.getAutomationCompositions(id.getName(), id.getVersion()));
67 assertThat(apiImpl.getAcElementDefinitionCommonProperties(id)).isEmpty();
69 var participantStatistics = new ParticipantStatistics();
70 participantStatistics.setParticipantId(id);
71 participantStatistics.setTimeStamp(Instant.ofEpochMilli(123456L));
72 participantStatistics.setState(ParticipantState.PASSIVE);
73 participantStatistics.setHealthStatus(ParticipantHealthStatus.HEALTHY);
74 apiImpl.updateParticipantStatistics(participantStatistics);
76 var participants = apiImpl.getParticipants(id.getName(), id.getVersion());
77 assertEquals(ParticipantState.UNKNOWN, participants.get(0).getParticipantState());
79 var participant = apiImpl.updateParticipantState(id, ParticipantState.TERMINATED);
80 assertEquals(ParticipantState.TERMINATED, participant.getParticipantState());
82 var elements = apiImpl.getAutomationCompositionElements(ID_NAME_E, ID_VERSION_E);
83 assertFalse(elements.containsKey(uuid));
85 var element = apiImpl.getAutomationCompositionElement(elements.keySet().iterator().next());
86 var idType = new ToscaConceptIdentifier(ID_NAME_TYPE, ID_VERSION_TYPE);
87 assertEquals(idType, element.getParticipantType());
89 var acElementStatistics = new AcElementStatistics();
90 var automationCompositionId = new ToscaConceptIdentifier("defName", "0.0.1");
91 acElementStatistics.setParticipantId(automationCompositionId);
92 acElementStatistics.setState(AutomationCompositionState.RUNNING);
93 acElementStatistics.setTimeStamp(Instant.now());
95 apiImpl.updateAutomationCompositionElementStatistics(uuid, acElementStatistics);
97 apiImpl.updateAutomationCompositionElementState(id, uuid, AutomationCompositionOrderedState.UNINITIALISED,
98 AutomationCompositionState.PASSIVE, ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
99 assertEquals(AutomationCompositionOrderedState.UNINITIALISED, acElement.getOrderedState());
100 assertEquals(uuid, acElement.getId());