CADI AAF Integration and merging the code
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / utils / MusicCookieCsrfTokenRepositoryTest.java
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright © 2018 IBM.
7  * ===================================================================
8  *
9  * Unless otherwise specified, all software contained herein is licensed
10  * under the Apache License, Version 2.0 (the "License");
11  * you may not use this software except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *             http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  * Unless otherwise specified, all documentation contained herein is licensed
23  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
24  * you may not use this documentation except in compliance with the License.
25  * You may obtain a copy of the License at
26  *
27  *             https://creativecommons.org/licenses/by/4.0/
28  *
29  * Unless required by applicable law or agreed to in writing, documentation
30  * distributed under the License is distributed on an "AS IS" BASIS,
31  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32  * See the License for the specific language governing permissions and
33  * limitations under the License.
34  *
35  * ============LICENSE_END============================================
36  *
37  * 
38  */
39 package org.onap.portalapp.portal.utils;
40
41 import javax.servlet.http.HttpServletRequest;
42
43 import org.junit.Assert;
44 import org.junit.Before;
45 import org.junit.Test;
46 import org.mockito.Mockito;
47 import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
48 import org.springframework.security.web.csrf.CsrfToken;
49
50 public class MusicCookieCsrfTokenRepositoryTest {
51     
52     MusicCookieCsrfTokenRepository repo;
53     
54     CookieCsrfTokenRepository cookieRepo;
55     
56     @Before
57     public void setup() {
58         cookieRepo = new CookieCsrfTokenRepository();
59         repo = new MusicCookieCsrfTokenRepository(cookieRepo);
60     }
61
62     @Test
63     public void  generateTokenTest(){
64         HttpServletRequest requestMock = Mockito.mock(HttpServletRequest.class);
65         CsrfToken expected = cookieRepo.generateToken(requestMock);
66         
67         CsrfToken actual = repo.generateToken(requestMock);
68         
69         Assert.assertEquals(expected.getHeaderName(), actual.getHeaderName());
70         Assert.assertEquals(expected.getParameterName(), actual.getParameterName());
71     }
72 }