d05b7933df0249f52cc1781183e4aac61ad50136
[policy/engine.git] / POLICY-SDK-APP / src / test / java / org / onap / policy / admin / PolicyUserInfoControllerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (C) 2019 Samsung
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 package org.onap.policy.admin;
23
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26 import static org.mockito.Mockito.mock;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpSession;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mockito;
32 import org.onap.portalsdk.core.domain.User;
33 import org.onap.portalsdk.core.util.SystemProperties;
34 import org.springframework.mock.web.MockHttpServletResponse;
35
36 public class PolicyUserInfoControllerTest {
37
38     private HttpServletRequest request;
39     private MockHttpServletResponse response;
40
41     @Before
42     public void setUp() throws Exception {
43         HttpSession mockSession = mock(HttpSession.class);
44         request = mock(HttpServletRequest.class);
45         response = new MockHttpServletResponse();
46         User user = new User();
47         user.setOrgUserId("Test");
48         Mockito.when(mockSession.getAttribute(SystemProperties.getProperty("user_attribute_name")))
49                 .thenReturn(user);
50         Mockito.when(request.getSession(false)).thenReturn(mockSession);
51     }
52
53     @Test
54     public final void testGetPolicyUserInfo() {
55         PolicyUserInfoController controller = new PolicyUserInfoController();
56         controller.getPolicyUserInfo(request, response);
57         try {
58             assertTrue(response.getStatus() == 200);
59         } catch (Exception e) {
60             fail();
61         }
62     }
63 }