2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6 * file except in compliance with the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the License
11 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12 * or implied. See the License for the specific language governing permissions and limitations under
15 * SPDX-License-Identifier: Apache-2.0
16 * ============LICENSE_END=========================================================
19 package org.onap.appc.listener.demo.impl;
21 import static org.mockito.Matchers.anyObject;
22 import static org.mockito.Mockito.when;
23 import static org.mockito.Mockito.verify;
24 import static org.mockito.Mockito.times;
26 import org.json.JSONObject;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.Mockito;
31 import org.onap.appc.exceptions.APPCException;
32 import org.onap.appc.listener.EventHandler;
33 import org.onap.appc.listener.demo.model.CommonMessage.CommonHeader;
34 import org.onap.appc.listener.demo.model.IncomingMessage;
35 import org.powermock.api.mockito.PowerMockito;
36 import org.powermock.core.classloader.annotations.PrepareForTest;
37 import org.powermock.modules.junit4.PowerMockRunner;
39 @RunWith(PowerMockRunner.class)
40 @PrepareForTest(ProviderOperations.class)
41 public class TestWorkerImpl {
43 private WorkerImpl workerImplSpy;
44 private IncomingMessage message;
45 private EventHandler dmaap;
49 message = Mockito.mock(IncomingMessage.class);
50 dmaap = Mockito.mock(EventHandler.class);
51 workerImplSpy = Mockito.spy(new WorkerImpl(message, dmaap));
55 public void testRun() throws APPCException {
56 CommonHeader commonHeader = Mockito.mock(CommonHeader.class);
57 when(message.getHeader()).thenReturn(commonHeader);
58 when(commonHeader.getRequestID()).thenReturn("requestId");
59 PowerMockito.mockStatic(ProviderOperations.class);
60 PowerMockito.when(ProviderOperations.topologyDG(anyObject())).thenReturn(true);
62 verify(workerImplSpy, times(1)).run();
66 public void testRunElseCase() throws APPCException {
67 CommonHeader commonHeader = Mockito.mock(CommonHeader.class);
68 when(message.getHeader()).thenReturn(commonHeader);
69 when(commonHeader.getRequestID()).thenReturn("requestId");
70 when(message.toJson()).thenReturn(new JSONObject());
71 PowerMockito.mockStatic(ProviderOperations.class);
72 PowerMockito.when(ProviderOperations.topologyDG(anyObject())).thenReturn(false);
74 verify(workerImplSpy, times(1)).run();
78 public void testRunWithException() throws APPCException {
79 CommonHeader commonHeader = Mockito.mock(CommonHeader.class);
80 when(message.getHeader()).thenReturn(commonHeader);
81 when(commonHeader.getRequestID()).thenReturn("requestId");
83 verify(workerImplSpy, times(1)).run();