Changes for checkstyle 8.32
[policy/apex-pdp.git] / services / services-engine / src / test / java / org / onap / policy / apex / service / engine / engdep / EngDepMessagingServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.service.engine.engdep;
23
24 import static org.awaitility.Awaitility.await;
25 import static org.junit.Assert.assertFalse;
26
27 import java.util.concurrent.TimeUnit;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.mockito.Mock;
31 import org.mockito.Mockito;
32 import org.mockito.MockitoAnnotations;
33 import org.onap.policy.apex.core.infrastructure.messaging.MessagingService;
34 import org.onap.policy.apex.core.protocols.Message;
35 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
36
37 /**
38  * Test the EngDep messaging Service.
39  */
40 public class EngDepMessagingServiceTest {
41     @Mock
42     private MessagingService<Message> messageServiceMock;
43     private EngDepMessagingService edMessagingService;
44
45     /**
46      * Set up mocking of the engine service facade.
47      * 
48      * @throws ApexException on engine service facade setup errors
49      */
50     @Before
51     public void initializeMocking() throws ApexException {
52         MockitoAnnotations.initMocks(this);
53
54         edMessagingService = Mockito.spy(new EngDepMessagingService(new DummyEngineService(), 12345));
55         Mockito.doReturn(messageServiceMock).when(edMessagingService).getMessageService(12345);
56     }
57
58     @Test
59     public void testStartStop() throws ApexException {
60         edMessagingService.start();
61         await().atMost(1, TimeUnit.SECONDS).until(() -> edMessagingService.isStarted());
62         assertFalse(edMessagingService.isStopped());
63         edMessagingService.stop();
64         await().atMost(1, TimeUnit.SECONDS).until(() -> edMessagingService.isStopped());
65         assertFalse(edMessagingService.isStarted());
66     }
67 }