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;
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;
38 * Test the EngDep messaging Service.
40 public class EngDepMessagingServiceTest {
42 private MessagingService<Message> messageServiceMock;
43 private EngDepMessagingService edMessagingService;
46 * Set up mocking of the engine service facade.
48 * @throws ApexException on engine service facade setup errors
51 public void initializeMocking() throws ApexException {
52 MockitoAnnotations.initMocks(this);
54 edMessagingService = Mockito.spy(new EngDepMessagingService(new DummyEngineService(), 12345));
55 Mockito.doReturn(messageServiceMock).when(edMessagingService).getMessageService(12345);
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());