2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software 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 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
38 package org.onap.portalapp.portal.ueb;
40 import static org.junit.Assert.assertFalse;
42 import java.net.HttpURLConnection;
44 import java.util.ArrayList;
45 import java.util.List;
47 import org.hibernate.Session;
48 import org.hibernate.SessionFactory;
49 import org.hibernate.Transaction;
50 import org.junit.Before;
51 import org.junit.Test;
52 import org.junit.runner.RunWith;
53 import org.mockito.InjectMocks;
54 import org.mockito.Mock;
55 import org.mockito.Mockito;
56 import org.mockito.MockitoAnnotations;
57 import org.onap.portalapp.portal.domain.EcompApp;
58 import org.onap.portalapp.portal.service.EPAppCommonServiceImpl;
59 import org.onap.portalapp.portal.utils.PortalConstants;
60 import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
61 import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
62 import org.powermock.api.mockito.PowerMockito;
63 import org.powermock.core.classloader.annotations.PrepareForTest;
64 import org.powermock.modules.junit4.PowerMockRunner;
66 import com.att.nsa.apiClient.http.HttpClient;
68 @RunWith(PowerMockRunner.class)
69 @PrepareForTest({PortalApiProperties.class, HttpClient.class, URL.class, PortalConstants.class})
70 public class EPUebHelperTest {
73 EPAppCommonServiceImpl epAppCommonServiceImpl = new EPAppCommonServiceImpl();
76 SessionFactory sessionFactory;
82 Transaction transaction;
86 MockitoAnnotations.initMocks(this);
87 Mockito.when(sessionFactory.openSession()).thenReturn(session);
91 EPUebHelper epUebHelper = new EPUebHelper();
94 public void refreshPublisherForPortalListTest() {
95 List<EcompApp> ecompApps = new ArrayList<>();
96 EcompApp ecompApp = new EcompApp();
97 ecompApp.setCentralAuth(true);
99 ecompApp.setName("test");
100 ecompApp.setEnabled(true);
101 ecompApp.setUebTopicName("ECOMP-PORTAL-INBOX");
102 ecompApps.add(ecompApp);
103 Mockito.when(epAppCommonServiceImpl.getEcompAppAppsFullList()).thenReturn(ecompApps);
104 epUebHelper.refreshPublisherList();
108 public void refreshPublisherForPartnersListTest() {
109 PowerMockito.mockStatic(PortalConstants.class);
110 PowerMockito.mockStatic(PortalApiProperties.class);
111 List<EcompApp> ecompApps = new ArrayList<>();
112 EcompApp ecompApp = new EcompApp();
113 ecompApp.setCentralAuth(true);
115 ecompApp.setName("test");
116 ecompApp.setEnabled(true);
117 ecompApp.setUebTopicName("Test");
118 ecompApps.add(ecompApp);
119 Mockito.when(epAppCommonServiceImpl.getEcompAppAppsFullList()).thenReturn(ecompApps);
120 Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.ECOMP_PORTAL_INBOX_NAME)).thenReturn("ecomp_portal_inbox_name");
121 Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_INBOUND_MAILBOX_NAME)).thenReturn("ueb_app_mailbox_name");
122 Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY)).thenReturn("ueb_app_key");
123 Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_SECRET)).thenReturn("ueb_app_secret");
124 Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_CONSUMER_GROUP_NAME)).thenReturn("ueb_app_consumer_group_name");
125 Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_URL_LIST)).thenReturn("ueb_url_list");
126 epUebHelper.refreshPublisherList();
130 public void refreshPublisherForExceptionListTest() {
131 List<EcompApp> ecompApps = new ArrayList<>();
132 EcompApp ecompApp = new EcompApp();
133 ecompApp.setCentralAuth(true);
135 ecompApp.setName("test");
136 ecompApp.setEnabled(true);
137 ecompApp.setUebTopicName("Test");
138 ecompApps.add(ecompApp);
139 Mockito.doThrow(new NullPointerException()).when(epAppCommonServiceImpl).getEcompAppAppsFullList();
140 epUebHelper.refreshPublisherList();
144 public void checkAvailabilityConectionRefusedTest() throws Exception {
145 PowerMockito.mockStatic(PortalConstants.class);
146 PowerMockito.mockStatic(PortalApiProperties.class);
147 Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_URL_LIST)).thenReturn("localhost");
148 URL u = PowerMockito.mock(URL.class);
149 String url = "http://localhost:3904/topics/null";
150 PowerMockito.whenNew(URL.class).withArguments(url).thenReturn(u);
151 HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class);
152 PowerMockito.when(u.openConnection()).thenReturn(huc);
153 PowerMockito.when(huc.getResponseCode()).thenReturn(200);
154 boolean actual = epUebHelper.checkAvailability();