901cbeac4aacc7f9a667080e9cf85c6051795caf
[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  * ================================================================================
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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.service.engine.engdep;
22
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertTrue;
25
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.Mock;
29 import org.mockito.Mockito;
30 import org.mockito.MockitoAnnotations;
31 import org.onap.policy.apex.core.infrastructure.messaging.MessagingService;
32 import org.onap.policy.apex.core.protocols.Message;
33 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
34
35 /**
36  * Test the EngDep messaging Service.
37  */
38 public class EngDepMessagingServiceTest {
39     @Mock
40     private MessagingService<Message> messageServiceMock;
41     private EngDepMessagingService edMessagingService;
42
43     /**
44      * Set up mocking of the engine service facade.
45      * 
46      * @throws ApexException on engine service facade setup errors
47      */
48     @Before
49     public void initializeMocking() throws ApexException {
50         MockitoAnnotations.initMocks(this);
51
52         edMessagingService = Mockito.spy(new EngDepMessagingService(new DummyEngineService(), 12345));
53         Mockito.doReturn(messageServiceMock).when(edMessagingService).getMessageService(12345);
54     }
55
56     @Test
57     public void testStartStop() throws ApexException {
58         edMessagingService.start();
59         assertTrue(edMessagingService.isStarted());
60         assertFalse(edMessagingService.isStopped());
61         edMessagingService.stop();
62         assertTrue(edMessagingService.isStopped());
63         assertFalse(edMessagingService.isStarted());
64     }
65 }