b31aa8e4fc4fbac7beca633001ce7d59633262df
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation.
4  * ================================================================================
5  * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.clamp.controlloop.runtime.supervision;
24
25 import static org.mockito.ArgumentMatchers.eq;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.spy;
28 import static org.mockito.Mockito.timeout;
29 import static org.mockito.Mockito.verify;
30
31 import org.junit.jupiter.api.Test;
32 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus;
33 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
34
35 class SupervisionAspectTest {
36
37     @Test
38     void testSchedule() throws Exception {
39         var supervisionScanner = spy(mock(SupervisionScanner.class));
40         try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) {
41             supervisionAspect.schedule();
42             verify(supervisionScanner, timeout(500)).run(true);
43         }
44     }
45
46     @Test
47     void testDoCheck() throws Exception {
48         var supervisionScanner = spy(mock(SupervisionScanner.class));
49         try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) {
50             supervisionAspect.doCheck();
51             supervisionAspect.doCheck();
52             verify(supervisionScanner, timeout(500).times(2)).run(false);
53         }
54     }
55
56     @Test
57     void testHandleParticipantStatus() throws Exception {
58         var supervisionScanner = spy(mock(SupervisionScanner.class));
59         var participantStatusMessage = new ParticipantStatus();
60         var identifier = new ToscaConceptIdentifier("abc", "1.0.0");
61         participantStatusMessage.setParticipantId(identifier);
62
63         try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) {
64             supervisionAspect.handleParticipantStatus(participantStatusMessage);
65             verify(supervisionScanner, timeout(500)).handleParticipantStatus(identifier);
66         }
67     }
68 }