summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunder Tattavarada <statta@research.att.com>2018-03-05 15:37:41 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-05 15:37:41 +0000
commitcd58d374ba9fe39796230f14b65151cd6d335742 (patch)
treec632ad1d4c256234c0a00fd34707ea1e14624dcd
parent0d2d6a5ba5a81b19497f5ce77506c1e7aed7b776 (diff)
parent753c866f2c89841b640d9e3762201705766e5c37 (diff)
Merge "Added Junits"
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationTest.java141
1 files changed, 141 insertions, 0 deletions
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationTest.java
new file mode 100644
index 00000000..89af5263
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationTest.java
@@ -0,0 +1,141 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.portalapp.service.sessionmgt;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalapp.portal.transport.OnboardingApp;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({URL.class, HttpURLConnection.class})
+public class SessionCommunicationTest {
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @InjectMocks
+ SessionCommunication sessionCommunication = new SessionCommunication();
+
+
+ @Test
+ public void sendGetConnectionRefusedTest() throws Exception {
+ OnboardingApp app = new OnboardingApp();
+ app.setRestrictedApp(false);
+ app.setUebKey("test");
+ app.setUebSecret("test");
+ app.setUebTopicName("test");
+ app.isCentralAuth = true;
+ app.isEnabled = true;
+ app.isOpen =false;
+ app.name = "test";
+ app.restUrl ="http://localhost:1234";
+ app.username = "test";
+ app.appPassword = "xyz";
+ URL u = PowerMockito.mock(URL.class);
+ HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class);
+ String url = "http://localhost:1234/sessionTimeOuts";
+ PowerMockito.whenNew(URL.class).withArguments(url).thenReturn(u);
+ PowerMockito.whenNew(HttpURLConnection.class).withAnyArguments().thenReturn(huc);
+ PowerMockito.when(huc.getResponseCode()).thenReturn(200);
+ String actual = sessionCommunication.sendGet(app);
+ assertEquals("", actual);
+ }
+
+ @Test
+ public void pingSessionConnectionRefusedTest() throws Exception {
+ OnboardingApp app = new OnboardingApp();
+ app.setRestrictedApp(false);
+ app.setUebKey("test");
+ app.setUebSecret("test");
+ app.setUebTopicName("test");
+ app.isCentralAuth = true;
+ app.isEnabled = true;
+ app.isOpen =false;
+ app.name = "test";
+ app.restUrl ="http://localhost:1234";
+ app.username = "test";
+ app.appPassword = "xyz";
+ URL u = PowerMockito.mock(URL.class);
+ HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class);
+ String url = "http://localhost:1234/sessionTimeOuts";
+ PowerMockito.whenNew(URL.class).withArguments(url).thenReturn(u);
+ PowerMockito.whenNew(HttpURLConnection.class).withAnyArguments().thenReturn(huc);
+ PowerMockito.when(huc.getResponseCode()).thenReturn(200);
+ Boolean actual = sessionCommunication.pingSession(app, "test");
+ assertTrue(actual);
+ }
+
+
+ @Test
+ public void timeoutSessionConnectionRefusedTest() throws Exception {
+ OnboardingApp app = new OnboardingApp();
+ app.setRestrictedApp(false);
+ app.setUebKey("test");
+ app.setUebSecret("test");
+ app.setUebTopicName("test");
+ app.isCentralAuth = true;
+ app.isEnabled = true;
+ app.isOpen =false;
+ app.name = "test";
+ app.restUrl ="http://localhost:1234";
+ app.username = "test";
+ app.appPassword = "xyz";
+ URL u = PowerMockito.mock(URL.class);
+ HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class);
+ String url = "http://localhost:1234/sessionTimeOuts";
+ PowerMockito.whenNew(URL.class).withArguments(url).thenReturn(u);
+ PowerMockito.whenNew(HttpURLConnection.class).withAnyArguments().thenReturn(huc);
+ PowerMockito.when(huc.getResponseCode()).thenReturn(200);
+ Boolean actual = sessionCommunication.timeoutSession(app, "test");
+ assertTrue(actual);
+ }
+}