summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-fw/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk/epsdk-fw/src/test/java')
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/AbstractModelTest.java75
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/DomainTest.java169
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/ExceptionTest.java73
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/ExtendSessionTimeoutTest.java99
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/InMemoryRestServer.java150
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/PortalTimeoutHandlerTest.java100
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/RestClientTest.java112
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/SessionSlotCheckIntervalTest.java103
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/UtilTest.java80
9 files changed, 961 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/AbstractModelTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/AbstractModelTest.java
new file mode 100644
index 00000000..ca35446b
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/AbstractModelTest.java
@@ -0,0 +1,75 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright © 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.portalsdk.fw.test;
+
+import java.util.Date;
+
+public abstract class AbstractModelTest {
+
+ // Values for properties
+ final long time = new Date().getTime();
+ final boolean b1 = true;
+ final boolean b2 = false;
+ final Byte[] by1 = { 0, 1, 2, 3 };
+ final Date d1 = new Date(time + 1 * 24 * 60 * 60 * 1000);
+ final Date d2 = new Date(time + 2 * 24 * 60 * 60 * 1000);
+ final Date d3 = new Date(time + 3 * 24 * 60 * 60 * 1000);
+ final Date d4 = new Date(time + 4 * 24 * 60 * 60 * 1000);
+ final Date d5 = new Date(time + 5 * 24 * 60 * 60 * 1000);
+ final Integer i1 = 1;
+ final Integer i2 = 2;
+ final Integer i3 = 3;
+ final Integer i4 = 4;
+ final Integer i5 = 5;
+ final Long l1 = 1L;
+ final Long l2 = 2L;
+ final Long l3 = 3L;
+ final Long l4 = 4L;
+ final String s1 = "string1";
+ final String s2 = "string2";
+ final String s3 = "string3";
+ final String s4 = "string4";
+ final String s5 = "string5";
+ final String s6 = "string6";
+ final String s7 = "string7";
+ final String s8 = "string8";
+ final String s9 = "string9";
+ final String s10 = "string10";
+
+}
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/DomainTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/DomainTest.java
new file mode 100644
index 00000000..700c8b3e
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/DomainTest.java
@@ -0,0 +1,169 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright © 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.portalsdk.fw.test;
+
+import java.util.HashSet;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.portalsdk.core.onboarding.crossapi.PortalAPIResponse;
+import org.onap.portalsdk.core.restful.domain.EcompRole;
+import org.onap.portalsdk.core.restful.domain.EcompUser;
+import org.onap.portalsdk.core.restful.domain.PortalTimeoutVO;
+import org.onap.portalsdk.core.restful.domain.SharedContext;
+
+public class DomainTest extends AbstractModelTest {
+
+ private final Log logger = LogFactory.getLog(DomainTest.class);
+
+ @Test
+ public void testPortalAPIResponse() {
+ PortalAPIResponse m = new PortalAPIResponse(true, s1);
+ Assert.assertEquals("ok", m.getStatus());
+ Assert.assertEquals(s1, m.getMessage());
+ logger.info(m.toString());
+ }
+
+ @Test
+ public void testEcompRole() {
+ EcompRole m = new EcompRole();
+ m.setId(l1);
+ m.setName(s1);
+ Assert.assertEquals(l1, m.getId());
+ Assert.assertEquals(s1, m.getName());
+ Assert.assertTrue(m.equals(m));
+ Assert.assertFalse(m.equals(new EcompRole()));
+ Assert.assertNotNull(m.hashCode());
+ logger.info(m.toString());
+ }
+
+ @Test
+ public void testEcompUser() {
+ EcompUser m = new EcompUser();
+ m.setActive(false);
+ m.setEmail(s1);
+ m.setFirstName(s2);
+ m.setHrid(s3);
+ m.setJobTitle(s4);
+ m.setLastName(s5);
+ m.setLoginId(s6);
+ m.setManagerId(s7);
+ m.setMiddleInitial(s8);
+ m.setOrgCode(s9);
+ m.setOrgId(l1);
+ m.setOrgManagerUserId(s10);
+ // Start over at 1, but double
+ m.setOrgUserId(s1 + s1);
+ m.setPhone(s2 + s2);
+ EcompRole r = new EcompRole();
+ HashSet<EcompRole> roles = new HashSet<>();
+ roles.add(r);
+ m.setRoles(roles);
+ Assert.assertEquals(false, m.isActive());
+ Assert.assertEquals(s1, m.getEmail());
+ Assert.assertEquals(s2, m.getFirstName());
+ Assert.assertEquals(s3, m.getHrid());
+ Assert.assertEquals(s4, m.getJobTitle());
+ Assert.assertEquals(s5, m.getLastName());
+ Assert.assertEquals(s6, m.getLoginId());
+ Assert.assertEquals(s7, m.getManagerId());
+ Assert.assertEquals(s8, m.getMiddleInitial());
+ Assert.assertEquals(s9, m.getOrgCode());
+ Assert.assertEquals(l1, m.getOrgId());
+ Assert.assertEquals(s10, m.getOrgManagerUserId());
+ Assert.assertEquals(s1 + s1, m.getOrgUserId());
+ Assert.assertEquals(s2 + s2, m.getPhone());
+ // this is weak
+ Assert.assertEquals(roles, m.getRoles());
+ Assert.assertTrue(m.equals(m));
+ Assert.assertFalse(m.equals(null));
+ Assert.assertFalse(m.equals(new EcompUser()));
+ Assert.assertNotNull(m.hashCode());
+ logger.info(m.toString());
+ }
+
+ @Test
+ public void testPortalTimeoutVO() {
+ PortalTimeoutVO m = new PortalTimeoutVO();
+ m.setjSessionId(s1);
+ m.setSessionTimOutMilliSec(l1);
+ Assert.assertEquals(s1, m.getjSessionId());
+ Assert.assertEquals(l1, m.getSessionTimOutMilliSec());
+ Assert.assertTrue(m.equals(m));
+ Assert.assertFalse(m.equals(null));
+ Assert.assertFalse(m.equals(new PortalTimeoutVO()));
+ }
+
+ @Test
+ public void testSharedContext() {
+ SharedContext m = new SharedContext();
+ m.setAuditTrail(s1);
+ m.setAuditUserId(s2);
+ m.setCkey(s3);
+ m.setContext_id(s4);
+ m.setCreate_time(l1);
+ m.setCreated(s5);
+ m.setCreatedId(s6);
+ m.setCvalue(s7);
+ m.setId(l2);
+ m.setModified(s8);
+ m.setModifiedId(s9);
+ m.setResponse(s10);
+ m.setRowNum(s1 + s1);
+ Assert.assertEquals(s1, m.getAuditTrail());
+ Assert.assertEquals(s2, m.getAuditUserId());
+ Assert.assertEquals(s3, m.getCkey());
+ Assert.assertEquals(s4, m.getContext_id());
+ Assert.assertEquals(l1, m.getCreate_time());
+ Assert.assertEquals(s5, m.getCreated());
+ Assert.assertEquals(s6, m.getCreatedId());
+ Assert.assertEquals(s7, m.getCvalue());
+ Assert.assertEquals(l2, m.getId());
+ Assert.assertEquals(s8, m.getModified());
+ Assert.assertEquals(s9, m.getModifiedId());
+ Assert.assertEquals(s10, m.getResponse());
+ Assert.assertEquals(s1 + s1, m.getRowNum());
+ Assert.assertTrue(m.equals(m));
+ Assert.assertFalse(m.equals(null));
+ Assert.assertFalse(m.equals(new SharedContext()));
+ }
+
+}
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/ExceptionTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/ExceptionTest.java
new file mode 100644
index 00000000..76f8f072
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/ExceptionTest.java
@@ -0,0 +1,73 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright © 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.portalsdk.fw.test;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.portalsdk.core.onboarding.exception.CipherUtilException;
+import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
+
+public class ExceptionTest extends AbstractModelTest {
+
+ private final Log logger = LogFactory.getLog(ExceptionTest.class);
+
+ @Test
+ public void coverCipherUtilException() {
+ Exception e = new CipherUtilException();
+ e = new CipherUtilException("message", new Exception(), false, false);
+ e = new CipherUtilException("message", new Exception());
+ e = new CipherUtilException("message");
+ e = new CipherUtilException(new Exception());
+ Assert.assertNotNull(e);
+ logger.info(e);
+ }
+
+ @Test
+ public void coverPortalAPIException() {
+ Exception e = new PortalAPIException();
+ e = new PortalAPIException("message", new Exception(), false, false);
+ e = new PortalAPIException("message", new Exception());
+ e = new PortalAPIException("message");
+ e = new PortalAPIException(new Exception());
+ Assert.assertNotNull(e);
+ logger.info(e);
+ }
+}
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/ExtendSessionTimeoutTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/ExtendSessionTimeoutTest.java
new file mode 100644
index 00000000..a87639d8
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/ExtendSessionTimeoutTest.java
@@ -0,0 +1,99 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright © 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.portalsdk.fw.test;
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.portalsdk.core.onboarding.crossapi.SessionCommunicationService;
+import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler;
+import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler.SessionCommInf;
+import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
+import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
+
+public class ExtendSessionTimeoutTest {
+
+ private final Log logger = LogFactory.getLog(ExtendSessionTimeoutTest.class);
+ private InMemoryRestServer server;
+
+ @Path("extendSessionTimeOuts")
+ public static class RestResource {
+ @POST
+ @Produces(MediaType.APPLICATION_JSON)
+ public String get( @HeaderParam("username") String username,
+ @HeaderParam("password") String password, @HeaderParam("uebkey") String uebkey) {
+ return "{ 'post-session' : '" + username + "' }";
+ }
+ }
+
+ @Before
+ public void before() throws Exception {
+ URL url = new URL(PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL));
+ server = InMemoryRestServer.create(url.getPort(), new RestResource());
+ }
+
+ @After
+ public void after() throws Exception {
+ server.close();
+ }
+
+ @Test
+ public void testRequestSessionTimeoutExtension() throws IOException {
+ String url = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL);
+ String get = SessionCommunicationService.requestPortalSessionTimeoutExtension(url, "userName", "word", "uebKey", "map");
+ Assert.assertNotNull(get);
+ logger.info("extend session test yields: " + get);
+ // Similar test via a different path
+ SessionCommInf sc = new PortalTimeoutHandler.SessionComm();
+ sc.extendSessionTimeOuts(url, "userName", "word", "uebKey", "map");
+ }
+
+}
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/InMemoryRestServer.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/InMemoryRestServer.java
new file mode 100644
index 00000000..2c37e214
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/InMemoryRestServer.java
@@ -0,0 +1,150 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * https://github.com/mp911de/rest-api-test
+ *
+ * Embedded InMemory REST server for RESTEasy. Usage:
+ * <ul>
+ * <li>InMemoryRestServer srv = InMemoryRestServer.create(...) passing your resources and provider classes</li>
+ * <li>srv.baseUri() for BaseUrl</li>
+ * <li>srv.newRequest("/relative/resource/path") to issue requests</li>
+ * <li>srv.close() to stop</li>
+ * </ul>
+ *
+ */
+package org.onap.portalsdk.fw.test;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+import org.jboss.resteasy.client.jaxrs.ResteasyClient;
+import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
+import org.jboss.resteasy.plugins.server.embedded.SecurityDomain;
+import org.jboss.resteasy.plugins.server.tjws.TJWSEmbeddedJaxrsServer;
+
+
+public class InMemoryRestServer implements AutoCloseable {
+
+ private int port;
+
+ private Set<Object> objects = new HashSet<Object>();
+ @SuppressWarnings("rawtypes")
+ private Set<Class> classes = new HashSet<Class>();
+
+ private TJWSEmbeddedJaxrsServer server;
+ private SecurityDomain securityDomain;
+ private ResteasyClient resteasyClient;
+ private String bindAddress = "localhost";
+
+ private InMemoryRestServer(Object... objects) {
+ append(objects);
+ }
+
+ /**
+ * Create instance and pass given instances/classes as singletons/providers.
+ *
+ * @param port
+ * Port number to bind
+ * @param objects
+ * Resource providers
+ * @return running instance of {@link InMemoryRestServer}
+ * @throws IOException
+ * In case of error
+ */
+ public static InMemoryRestServer create(int port, Object... objects) throws IOException {
+ InMemoryRestServer inMemoryRestServer = new InMemoryRestServer(objects);
+ inMemoryRestServer.start(port);
+ return inMemoryRestServer;
+ }
+
+ @SuppressWarnings("rawtypes")
+ private void append(Object... objects) {
+ for (Object object : objects) {
+ if (object instanceof Class) {
+ classes.add((Class) object);
+ } else {
+ this.objects.add(object);
+ }
+ }
+ }
+
+ private void start(int requestPort) throws IOException {
+ if (requestPort <= 0)
+ port = findFreePort();
+ else
+ port = requestPort;
+ server = new TJWSEmbeddedJaxrsServer();
+ server.setPort(port);
+ server.setBindAddress(bindAddress);
+ server.setSecurityDomain(securityDomain);
+
+ for (Object object : objects) {
+ if (object instanceof Application) {
+ server.getDeployment().setApplication((Application) object);
+ } else {
+ server.getDeployment().getResources().add(object);
+ }
+ }
+
+ for (@SuppressWarnings("rawtypes") Class resourceOrProvider : classes) {
+ if (Application.class.isAssignableFrom(resourceOrProvider)) {
+ server.getDeployment().setApplicationClass(resourceOrProvider.getName());
+ } else {
+ server.getDeployment().getProviderClasses().add(resourceOrProvider.getName());
+ }
+ }
+
+ server.start();
+ }
+
+ /**
+ * @return baseURI (http://localhost:PORT) to the REST server.
+ */
+ public String baseUri() {
+ return "http://" + bindAddress + ":" + port;
+ }
+
+ /**
+ * Begin a new {@link ResteasyWebTarget} with additional, relative path with leading /.
+ *
+ * @param uriTemplate
+ * URI template
+ * @return ResteasyWebTarget
+ */
+ public ResteasyWebTarget newRequest(String uriTemplate) {
+ return resteasyClient.target(baseUri() + uriTemplate);
+ }
+
+ /**
+ * Find a free server port.
+ *
+ * @return port number.
+ * @throws IOException
+ * On failure to create server socket
+ */
+ private static int findFreePort() throws IOException {
+ ServerSocket server = new ServerSocket(0);
+ int port = server.getLocalPort();
+ server.close();
+ return port;
+ }
+
+ /**
+ * Close the server and free resources.
+ */
+ @Override
+ public void close() {
+ if (server != null) {
+ server.stop();
+ server = null;
+ }
+ }
+} \ No newline at end of file
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/PortalTimeoutHandlerTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/PortalTimeoutHandlerTest.java
new file mode 100644
index 00000000..8826237d
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/PortalTimeoutHandlerTest.java
@@ -0,0 +1,100 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright © 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.portalsdk.fw.test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.stubbing.Answer;
+import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler;
+
+@RunWith(MockitoJUnitRunner.class)
+public class PortalTimeoutHandlerTest extends AbstractModelTest {
+
+ private final Log logger = LogFactory.getLog(PortalTimeoutHandlerTest.class);
+
+ @Mock
+ private HttpSession mockHttpSession;
+ private Map<String, Object> attributes = new HashMap<String, Object>();
+
+ @Before
+ public void before() {
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ String key = (String) invocation.getArguments()[0];
+ logger.debug("get for key " + key);
+ return attributes.get(key);
+ }
+ }).when(mockHttpSession).getAttribute(Mockito.anyString());
+
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ String key = (String) invocation.getArguments()[0];
+ logger.debug("set for key " + key);
+ Object value = invocation.getArguments()[1];
+ attributes.put(key, value);
+ return null;
+ }
+ }).when(mockHttpSession).setAttribute(Mockito.anyString(), Mockito.any());
+ }
+
+ @Test
+ public void testPortalTimeoutHandler() {
+ Assert.assertNotNull(PortalTimeoutHandler.getInstance());
+ Assert.assertNotNull(PortalTimeoutHandler.getSessionMap());
+ PortalTimeoutHandler.sessionCreated("portalJSessionId", "jSessionId", mockHttpSession);
+ PortalTimeoutHandler.invalidateSession("portalJSessionId");
+ PortalTimeoutHandler.sessionDestroyed(mockHttpSession);
+ PortalTimeoutHandler.gatherSessionExtensions();
+ }
+}
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/RestClientTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/RestClientTest.java
new file mode 100644
index 00000000..d36ee79d
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/RestClientTest.java
@@ -0,0 +1,112 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright © 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.portalsdk.fw.test;
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.portalsdk.core.onboarding.rest.RestWebServiceClient;
+import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
+import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
+
+public class RestClientTest {
+
+ private final Log logger = LogFactory.getLog(RestClientTest.class);
+ private InMemoryRestServer server;
+
+ @Path("portal")
+ public static class RestResource {
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public String get(@HeaderParam("LoginId") String loginId, @HeaderParam("username") String username,
+ @HeaderParam("password") String password) {
+ return "{ 'get' : '" + loginId + "' }";
+ }
+ @POST
+ public String post(@HeaderParam("LoginId") String loginId, @HeaderParam("username") String username,
+ @HeaderParam("password") String password) {
+ return "{ 'post' : '" + loginId + "' }";
+ }
+ @DELETE
+ public String delete(@HeaderParam("LoginId") String loginId, @HeaderParam("username") String username,
+ @HeaderParam("password") String password) {
+ return "{ 'delete' : '" + loginId + "' }";
+ }
+ }
+
+ @Before
+ public void before() throws Exception {
+ URL url = new URL(PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL));
+ server = InMemoryRestServer.create(url.getPort(), new RestResource());
+ }
+
+ @After
+ public void after() throws Exception {
+ server.close();
+ }
+
+ @Test
+ public void testRestClient() throws IOException {
+ RestWebServiceClient client = RestWebServiceClient.getInstance();
+ String get = client.getPortalContent("/portal", "userid", "appName", "requestId", "appUserName", "appPassword", true);
+ Assert.assertNotNull(get);
+ logger.info("Get test yields: " + get);
+ String post = client.postPortalContent("/portal", "userid", "appName", "requestId", "appUserName", "appPassword", MediaType.APPLICATION_JSON, "content", true);
+ Assert.assertNotNull(post);
+ logger.info("Post test yields: " + post);
+ String delete = client.deletePortalContent("/portal", "userid", "appName", "requestId", "appUserName", "appPassword", MediaType.APPLICATION_JSON, "content", true);
+ Assert.assertNotNull(delete);
+ logger.info("Delete test yields: " + delete);
+ }
+
+}
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/SessionSlotCheckIntervalTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/SessionSlotCheckIntervalTest.java
new file mode 100644
index 00000000..79e87532
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/SessionSlotCheckIntervalTest.java
@@ -0,0 +1,103 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright © 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.portalsdk.fw.test;
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.portalsdk.core.onboarding.crossapi.SessionCommunicationService;
+import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler;
+import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler.SessionCommInf;
+import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
+import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
+
+public class SessionSlotCheckIntervalTest {
+
+ private final Log logger = LogFactory.getLog(SessionSlotCheckIntervalTest.class);
+ private static final String timeoutValue = "1";
+ private InMemoryRestServer server;
+
+ @Path("getSessionSlotCheckInterval")
+ public static class RestResource {
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public String get( @HeaderParam("username") String username,
+ @HeaderParam("password") String password, @HeaderParam("uebkey") String uebkey) {
+ // Expects only an integer, not even a POJO/JSON model.
+ return timeoutValue;
+ }
+ }
+
+ @Before
+ public void before() throws Exception {
+ URL url = new URL(PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL));
+ server = InMemoryRestServer.create(url.getPort(), new RestResource());
+ }
+
+ @After
+ public void after() throws Exception {
+ server.close();
+ }
+
+ @Test
+ public void testSessionSlot() throws IOException {
+ String url = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL);
+ String get = SessionCommunicationService.getSessionSlotCheckInterval(url, "userName", "word", "uebKey");
+ Assert.assertTrue(get.equals(timeoutValue));
+ logger.info("Get test yields: " + get);
+ // Similar test via a different path
+ SessionCommInf sc = new PortalTimeoutHandler.SessionComm();
+ Integer i = sc.fetchSessionSlotCheckInterval(url, "userName", "word", "uebKey");
+ Assert.assertTrue(i.toString().equals(timeoutValue));
+ logger.info("Fetched slot-check interval: " + i);
+ }
+
+}
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/UtilTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/UtilTest.java
new file mode 100644
index 00000000..66a81a04
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/UtilTest.java
@@ -0,0 +1,80 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright © 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.portalsdk.fw.test;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.portalsdk.core.onboarding.exception.CipherUtilException;
+import org.onap.portalsdk.core.onboarding.util.CipherUtil;
+import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
+import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
+
+public class UtilTest extends AbstractModelTest {
+
+ private final Log logger = LogFactory.getLog(UtilTest.class);
+
+
+ @Test
+ public void testCipherUtil() throws CipherUtilException {
+ String cipher;
+
+ cipher = CipherUtil.encryptPKC(s1);
+ Assert.assertNotNull(cipher);
+ Assert.assertNotEquals(cipher, s1);
+ Assert.assertEquals(s1, CipherUtil.decryptPKC(cipher));
+
+ cipher = CipherUtil.encryptPKC(s2);
+ Assert.assertNotNull(cipher);
+ Assert.assertNotEquals(cipher, s2);
+ Assert.assertEquals(s2, CipherUtil.decryptPKC(cipher));
+
+ logger.info("CipherUtils tested");
+ }
+
+ @Test
+ public void testProperties() {
+ // Relies on portal.properties file in src/test/resources
+ String val = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL);
+ Assert.assertNotNull(val);
+ logger.info("PortalApiProperties tested");
+ }
+
+}