Merge "Fix for Sonar major issues"
[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  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.policy.admin;
21
22 import static org.junit.Assert.assertTrue;
23 import static org.junit.Assert.fail;
24 import static org.mockito.Mockito.mock;
25
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpSession;
28
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mockito;
32 import org.openecomp.portalsdk.core.domain.User;
33 import org.openecomp.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"))).thenReturn(user);
49                  Mockito.when(request.getSession(false)).thenReturn(mockSession);
50         }
51
52         @Test
53         public final void testGetPolicyUserInfo() {
54                 PolicyUserInfoController controller = new PolicyUserInfoController();
55                 controller.getPolicyUserInfo(request, response);
56                 try{
57                         assertTrue(response.getStatus() == 200);
58                 }catch(Exception e){
59                         fail();
60                 }
61
62         }
63
64 }