Mass removal of all Tabs (Style Warnings)
[aaf/authz.git] / cadi / core / src / test / java / org / onap / aaf / cadi / taf / test / JU_LoginPageTafResp.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 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  */
21
22 package org.onap.aaf.cadi.taf.test;
23
24 import static org.hamcrest.CoreMatchers.is;
25 import static org.junit.Assert.assertThat;
26 import static org.mockito.Matchers.any;
27 import static org.mockito.Mockito.when;
28
29 import java.io.ByteArrayOutputStream;
30 import java.io.IOException;
31 import java.io.PrintStream;
32 import java.net.URI;
33 import java.net.URISyntaxException;
34 import java.util.ArrayList;
35 import java.util.List;
36
37 import javax.servlet.http.HttpServletResponse;
38
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.mockito.Mock;
42 import org.mockito.MockitoAnnotations;
43 import org.onap.aaf.cadi.Access;
44 import org.onap.aaf.cadi.Locator;
45 import org.onap.aaf.cadi.Locator.Item;
46 import org.onap.aaf.cadi.LocatorException;
47 import org.onap.aaf.cadi.PropAccess;
48 import org.onap.aaf.cadi.taf.LoginPageTafResp;
49 import org.onap.aaf.cadi.taf.Redirectable;
50 import org.onap.aaf.cadi.taf.TafResp;
51 import org.onap.aaf.cadi.taf.TafResp.RESP;
52
53 public class JU_LoginPageTafResp {
54
55     private static final String uriString = "example.com";
56
57     private URI uri;
58     private Access access;
59     private List<Redirectable> redirectables;
60
61     @Mock private HttpServletResponse respMock;
62     @Mock private Locator<URI> locatorMock;
63     @Mock private Redirectable redirMock;
64
65     @Before
66     public void setup() throws URISyntaxException {
67         MockitoAnnotations.initMocks(this);
68
69         access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
70
71         redirectables = new ArrayList<>();
72         uri = new URI(uriString);
73     }
74
75     @Test
76     public void test() throws LocatorException, IOException {
77         TafResp resp;
78         resp = LoginPageTafResp.create(access, null, respMock, redirectables);
79         assertThat(resp.desc(), is("All Authentication denied"));
80
81         redirectables.add(redirMock);
82         redirectables.add(redirMock);
83         resp = LoginPageTafResp.create(access, null, respMock, redirectables);
84         assertThat((Redirectable)resp, is(redirMock));
85
86         resp = LoginPageTafResp.create(access, locatorMock, respMock, redirectables);
87         assertThat(resp.desc(), is("All Authentication denied"));
88
89         when(locatorMock.get((Item)any())).thenReturn(uri);
90         resp = LoginPageTafResp.create(access, locatorMock, respMock, redirectables);
91         assertThat(resp.desc(), is("Multiple Possible HTTP Logins available.  Redirecting to Login Choice Page"));
92         assertThat(resp.authenticate(), is(RESP.HTTP_REDIRECT_INVOKED));
93         assertThat(resp.isAuthenticated(), is(RESP.TRY_AUTHENTICATING));
94
95         redirectables = new ArrayList<>();
96         resp = LoginPageTafResp.create(access, locatorMock, respMock, redirectables);
97         assertThat(resp.desc(), is("All Authentication denied"));
98
99     }
100
101 }