2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.provider;
27 import org.junit.Assert;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.Mock;
32 import org.mockito.Mockito;
33 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
34 import org.osgi.framework.Bundle;
35 import org.osgi.framework.BundleContext;
36 import org.osgi.framework.FrameworkUtil;
37 import org.osgi.framework.ServiceReference;
38 import org.powermock.api.mockito.PowerMockito;
39 import org.powermock.core.classloader.annotations.PrepareForTest;
40 import org.powermock.modules.junit4.PowerMockRunner;
41 import org.powermock.reflect.Whitebox;
43 import java.util.Properties;
45 import static org.mockito.Matchers.any;
46 import static org.mockito.Mockito.doReturn;
47 import static org.mockito.Mockito.mock;
48 import static org.mockito.Mockito.times;
49 import static org.mockito.Mockito.verify;
50 import static org.powermock.api.mockito.PowerMockito.mockStatic;
52 @RunWith(PowerMockRunner.class)
53 @PrepareForTest({AppcProviderClient.class, FrameworkUtil.class})
54 public class AppcProviderClientTest {
56 private SvcLogicService svcLogicService;
58 private AppcProviderClient appcProviderClient;
61 public void setUp() throws Exception {
63 mockStatic(FrameworkUtil.class);
64 Bundle mockedBundle = mock(Bundle.class);
65 PowerMockito.when(FrameworkUtil.getBundle(SvcLogicService.class)).thenReturn(mockedBundle);
67 BundleContext mockedBundleContext = mock(BundleContext.class);
68 Mockito.when(mockedBundle.getBundleContext()).thenReturn(mockedBundleContext);
70 ServiceReference svcRef = mock(ServiceReference.class);
71 Mockito.when(mockedBundleContext.getServiceReference(SvcLogicService.NAME)).thenReturn(svcRef);
73 Mockito.when(mockedBundleContext.getService(svcRef)).thenReturn(svcLogicService);
75 appcProviderClient = new AppcProviderClient();
79 public void testNonArgumentConstructor() {
80 AppcProviderClient appcProviderClient = new AppcProviderClient();
81 Assert.assertEquals(Whitebox.getInternalState(appcProviderClient, "svcLogic"), svcLogicService);
85 public void hasGraph() throws Exception {
86 doReturn(true).when(svcLogicService).hasGraph(any(), any(), any(), any());
87 boolean hasGraph = appcProviderClient.hasGraph("test-module", "test-rpc", "test-version", "test-mode");
88 Assert.assertTrue(hasGraph);
92 public void execute() throws Exception {
93 Properties properties = new Properties();
94 appcProviderClient.execute("test-module", "test-rpc", "test-version", "test-mode", properties);
95 verify(svcLogicService, times(1)).execute("test-module", "test-rpc", "test-version", "test-mode",