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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.service.engine.engdep;
24 import static org.awaitility.Awaitility.await;
25 import static org.junit.Assert.assertFalse;
27 import java.util.concurrent.TimeUnit;
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;
39 * Test the EngDep messaging Service.
41 public class EngDepMessagingServiceTest {
43 private MessagingService<Message> messageServiceMock;
44 private EngDepMessagingService edMessagingService;
47 * Set up mocking of the engine service facade.
49 * @throws ApexException on engine service facade setup errors
52 public void initializeMocking() throws ApexException {
53 MockitoAnnotations.initMocks(this);
55 edMessagingService = Mockito.spy(new EngDepMessagingService(new DummyEngineService(), 12345));
56 Mockito.doReturn(messageServiceMock).when(edMessagingService).getMessageService(12345);
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());