Allow plugging-in any provided LoginStrategy
[vid.git] / epsdk-app-onap / src / test / java / org / onap / portalapp / conf / ExternalAppConfigTest.java
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software 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  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalapp.conf;
39
40 import static org.hamcrest.CoreMatchers.instanceOf;
41 import static org.hamcrest.CoreMatchers.is;
42 import static org.junit.Assert.assertThat;
43
44 import java.util.List;
45
46 import javax.servlet.http.HttpServletRequest;
47 import javax.servlet.http.HttpServletResponse;
48 import org.junit.Assert;
49 import org.junit.Test;
50 import org.onap.portalapp.login.LoginStrategyImpl;
51 import org.onap.portalapp.scheduler.RegistryAdapter;
52 import org.onap.portalsdk.core.auth.LoginStrategy;
53 import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
54 import org.onap.portalsdk.core.service.DataAccessService;
55 import org.springframework.web.servlet.ModelAndView;
56 import org.springframework.web.servlet.ViewResolver;
57
58 public class ExternalAppConfigTest {
59
60     private ExternalAppConfig createTestSubject() {
61         return new ExternalAppConfig();
62     }
63
64     @Test
65     public void testViewResolver() throws Exception {
66         ExternalAppConfig testSubject;
67         ViewResolver result;
68
69         // default test
70         testSubject = createTestSubject();
71         result = testSubject.viewResolver();
72     }
73
74
75
76     @Test
77     public void testDataAccessService() throws Exception {
78         ExternalAppConfig testSubject;
79         DataAccessService result;
80
81         // default test
82         testSubject = createTestSubject();
83         result = testSubject.dataAccessService();
84     }
85
86     @Test
87     public void testAddTileDefinitions() throws Exception {
88         ExternalAppConfig testSubject;
89         List<String> result;
90
91         // default test
92         testSubject = createTestSubject();
93         result = testSubject.addTileDefinitions();
94     }
95
96    
97
98     @Test
99     public void testCacheManager() throws Exception {
100         ExternalAppConfig testSubject;
101         //AbstractCacheManager result;
102
103         // default test
104         testSubject = createTestSubject();
105         testSubject.cacheManager();
106     }
107    
108
109
110     @Test
111     public void testSetSchedulerRegistryAdapter() throws Exception {
112         ExternalAppConfig testSubject;
113         RegistryAdapter schedulerRegistryAdapter = null;
114
115         // default test
116         testSubject = createTestSubject();
117     }
118
119     @Test
120     public void loginStrategy_givenEmptyString_yieldDefault() throws Exception {
121         assertThat(new ExternalAppConfig().loginStrategy(""),
122             is(instanceOf(LoginStrategyImpl.class)));
123     }
124
125     @Test
126     public void loginStrategy_givenNullString_yieldDefault() throws Exception {
127         assertThat(new ExternalAppConfig().loginStrategy(null),
128             is(instanceOf(LoginStrategyImpl.class)));
129     }
130
131     public static class DummyLoginStrategy extends LoginStrategy {
132         @Override
133         public ModelAndView doLogin(HttpServletRequest request, HttpServletResponse response) {
134             return null;
135         }
136
137         @Override
138         public String getUserId(HttpServletRequest request) {
139             return null;
140         }
141     }
142
143     @Test
144     public void loginStrategy_givenClassname_yieldClassInstance() throws Exception {
145         assertThat(
146             new ExternalAppConfig().loginStrategy("org.onap.portalapp.conf.ExternalAppConfigTest$DummyLoginStrategy"),
147             is(instanceOf(DummyLoginStrategy.class)));
148     }
149
150     @Test(expected = ClassNotFoundException.class)
151     public void loginStrategy_givenMissingClassname_throwsException() throws Exception {
152         new ExternalAppConfig().loginStrategy("no.real.classname");
153         Assert.fail("should throw");
154     }
155 }