99d3122a23b855befa9cbae0547632ff50e3dae9
[appc.git] / appc-provider / appc-provider-bundle / src / test / java / org / openecomp / appc / provider / AppcProviderClientTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.openecomp.appc.provider;
26
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;
42
43 import java.util.Properties;
44
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;
51
52 @RunWith(PowerMockRunner.class)
53 @PrepareForTest({AppcProviderClient.class, FrameworkUtil.class})
54 public class AppcProviderClientTest {
55     @Mock
56     private SvcLogicService svcLogicService;
57     @Mock
58     private AppcProviderClient appcProviderClient;
59
60     @Before
61     public void setUp() throws Exception {
62         // Prepare all mocks
63         mockStatic(FrameworkUtil.class);
64         Bundle mockedBundle = mock(Bundle.class);
65         PowerMockito.when(FrameworkUtil.getBundle(SvcLogicService.class)).thenReturn(mockedBundle);
66
67         BundleContext mockedBundleContext = mock(BundleContext.class);
68         Mockito.when(mockedBundle.getBundleContext()).thenReturn(mockedBundleContext);
69
70         ServiceReference svcRef = mock(ServiceReference.class);
71         Mockito.when(mockedBundleContext.getServiceReference(SvcLogicService.NAME)).thenReturn(svcRef);
72
73         Mockito.when(mockedBundleContext.getService(svcRef)).thenReturn(svcLogicService);
74
75         appcProviderClient = new AppcProviderClient();
76     }
77
78     @Test
79     public void testNonArgumentConstructor() {
80         AppcProviderClient appcProviderClient = new AppcProviderClient();
81         Assert.assertEquals(Whitebox.getInternalState(appcProviderClient, "svcLogic"), svcLogicService);
82     }
83
84     @Test
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);
89     }
90
91     @Test
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",
96             properties);
97     }
98
99 }