2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 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.
20 * ============LICENSE_END=========================================================
23 package org.onap.aai.sparky.security;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.Mockito;
28 import org.onap.aai.sparky.security.portal.PortalRestAPICentralServiceImpl;
29 import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
30 import org.onap.portalsdk.core.restful.domain.EcompRole;
32 import javax.servlet.http.Cookie;
33 import javax.servlet.http.HttpServletRequest;
34 import java.util.ArrayList;
36 import static org.junit.Assert.*;
39 public class EcompSsoTest {
41 private EcompSso ecompSso;
42 private PortalRestAPICentralServiceImpl portalRestCentralServiceImpl;
45 public void init() throws Exception {
46 ecompSso = new EcompSso();
47 portalRestCentralServiceImpl = Mockito.mock(PortalRestAPICentralServiceImpl.class);
52 public void TestValidateUserAccess() throws PortalAPIException {
54 Mockito.when(portalRestCentralServiceImpl.getUserRoles(Mockito.anyString()))
55 .thenReturn(new ArrayList<EcompRole>());
56 assertNotNull(ecompSso.validateUserAccess("ui_view"));
60 public void getCookie() {
61 String TestCookieValue = "TestCookieValue";
62 String testCookieName = "testCookieName";
63 Cookie cookie1 = new Cookie(testCookieName+"1", TestCookieValue+"1");
64 Cookie cookie2 = new Cookie(testCookieName+"2", TestCookieValue+"2");
65 Cookie[] cookies = {cookie1, cookie2};
67 HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
68 Mockito.when(request.getCookies()).thenReturn(cookies);
69 Cookie result = EcompSso.getCookie(request, testCookieName + "1");
70 assertEquals(cookie1.getName(), result.getName());
71 assertEquals(cookie1.getValue(), result.getValue());
72 assertNull(EcompSso.getCookie(request, testCookieName + "3"));