42ea4a5513ad3120ec63ede9befdfa6ba178c599
[aai/sparky-be.git] / sparkybe-onap-service / src / test / java / org / onap / aai / sparky / security / EcompSsoTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * Copyright © 2019 IBM
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  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.aai.sparky.security;
24
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;
31
32 import javax.servlet.http.Cookie;
33 import javax.servlet.http.HttpServletRequest;
34 import java.util.ArrayList;
35
36 import static org.junit.Assert.*;
37
38
39 public class EcompSsoTest {
40
41   private EcompSso ecompSso;
42   private PortalRestAPICentralServiceImpl portalRestCentralServiceImpl;
43
44   @Before
45   public void init() throws Exception {
46     ecompSso = new EcompSso();
47     portalRestCentralServiceImpl = Mockito.mock(PortalRestAPICentralServiceImpl.class);
48   }
49
50
51   @Test
52   public void TestValidateUserAccess() throws PortalAPIException {
53
54     Mockito.when(portalRestCentralServiceImpl.getUserRoles(Mockito.anyString()))
55         .thenReturn(new ArrayList<EcompRole>());
56     assertNotNull(ecompSso.validateUserAccess("ui_view"));
57   }
58
59   @Test
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};
66
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"));
73   }
74
75
76 }