2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package org.onap.aaf.cadi.taf.test;
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;
29 import java.io.ByteArrayOutputStream;
30 import java.io.IOException;
31 import java.io.PrintStream;
33 import java.net.URISyntaxException;
34 import java.util.ArrayList;
35 import java.util.List;
37 import javax.servlet.http.HttpServletResponse;
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;
53 public class JU_LoginPageTafResp {
55 private static final String uriString = "example.com";
58 private Access access;
59 private List<Redirectable> redirectables;
61 @Mock private HttpServletResponse respMock;
62 @Mock private Locator<URI> locatorMock;
63 @Mock private Redirectable redirMock;
66 public void setup() throws URISyntaxException {
67 MockitoAnnotations.initMocks(this);
69 access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
71 redirectables = new ArrayList<>();
72 uri = new URI(uriString);
76 public void test() throws LocatorException, IOException {
78 resp = LoginPageTafResp.create(access, null, respMock, redirectables);
79 assertThat(resp.desc(), is("All Authentication denied"));
81 redirectables.add(redirMock);
82 redirectables.add(redirMock);
83 resp = LoginPageTafResp.create(access, null, respMock, redirectables);
84 assertThat((Redirectable)resp, is(redirMock));
86 resp = LoginPageTafResp.create(access, locatorMock, respMock, redirectables);
87 assertThat(resp.desc(), is("All Authentication denied"));
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));
95 redirectables = new ArrayList<>();
96 resp = LoginPageTafResp.create(access, locatorMock, respMock, redirectables);
97 assertThat(resp.desc(), is("All Authentication denied"));