42a3a55d81e5e10e5cdf7438914d3e5a0048b8f7
[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
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mock;
32 import org.mockito.Mockito;
33 import org.mockito.MockitoAnnotations;
34 import org.onap.policy.apex.core.infrastructure.messaging.MessagingService;
35 import org.onap.policy.apex.core.protocols.Message;
36 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
37
38 /**
39  * Test the EngDep messaging Service.
40  */
41 public class EngDepMessagingServiceTest {
42     @Mock
43     private MessagingService<Message> messageServiceMock;
44     private EngDepMessagingService edMessagingService;
45
46     /**
47      * Set up mocking of the engine service facade.
48      * 
49      * @throws ApexException on engine service facade setup errors
50      */
51     @Before
52     public void initializeMocking() throws ApexException {
53         MockitoAnnotations.initMocks(this);
54
55         edMessagingService = Mockito.spy(new EngDepMessagingService(new DummyEngineService(), 12345));
56         Mockito.doReturn(messageServiceMock).when(edMessagingService).getMessageService(12345);
57     }
58
59     @Test
60     public void testStartStop() throws ApexException {
61         edMessagingService.start();
62         await().atMost(1, TimeUnit.SECONDS).until(() -> edMessagingService.isStarted());
63         assertFalse(edMessagingService.isStopped());
64         edMessagingService.stop();
65         await().atMost(1, TimeUnit.SECONDS).until(() -> edMessagingService.isStopped());
66         assertFalse(edMessagingService.isStarted());
67     }
68 }