Update poms to conform to merge job requirements
[aai/search-data-service.git] / search-data-service-app / src / test / java / org / onap / aai / sa / auth / SearchDbServiceAuthTest.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  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.sa.auth;
22
23 import java.io.File;
24 import java.io.IOException;
25 import java.lang.reflect.Field;
26 import java.lang.reflect.Modifier;
27 import org.junit.Assert;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.mockito.Mock;
31 import org.mockito.MockitoAnnotations;
32 import org.onap.aai.sa.searchdbabstraction.util.SearchDbConstants;
33 import org.springframework.http.HttpHeaders;
34
35 // import javax.servlet.http.Cookie;
36
37 public class SearchDbServiceAuthTest {
38
39     @Mock
40     HttpHeaders headers;
41
42     // @Mock
43     // Cookie mockedCookie;
44
45     @Before
46     public void setUp() throws NoSuchFieldException, IllegalAccessException, IOException {
47         MockitoAnnotations.initMocks(this);
48         System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
49         setFinalStatic(System.getProperty("AJSC_HOME") + "/src/test/resources/json/search_policy.json");
50     }
51
52     @Test
53     public void testAuthUser() {
54         SearchDbServiceAuth aaiAuth = new SearchDbServiceAuth();
55         String auth = aaiAuth.authUser(headers, "user-1", "function-1");
56         Assert.assertEquals(auth, "AAI_9101");
57     }
58
59     // @Test
60     // public void testAuthCookie_NullCookie(){
61     // SearchDbServiceAuth aaiAuth = new SearchDbServiceAuth();
62     // Cookie cookie = null;
63     // Assert.assertFalse(aaiAuth.authCookie(cookie, "function-1", new StringBuilder("user-1")));
64     // }
65
66     // @Test
67     // public void testAuthCookie_NotNullCookie(){
68     // SearchDbServiceAuth aaiAuth = new SearchDbServiceAuth();
69     // Cookie cookie = new Cookie ( "TestCookie", "TestValue");
70     // // Cookie cookie = new Cookie ( "TestCookie", "TestValue" );
71     // boolean retValue = aaiAuth.authCookie(cookie, "GET:testFunction", new StringBuilder("testuser"));
72     // Assert.assertTrue(retValue);
73     // }
74
75     static void setFinalStatic(String fieldValue)
76             throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
77         Field configField = SearchDbConstants.class.getDeclaredField("SDB_AUTH_CONFIG_FILENAME");
78         configField.setAccessible(true);
79
80         Field modifiersField = Field.class.getDeclaredField("modifiers");
81         modifiersField.setAccessible(true);
82         modifiersField.setInt(configField, configField.getModifiers() & ~Modifier.FINAL);
83
84         configField.set(null, fieldValue);
85     }
86 }