Update for more Logging Info
[aaf/authz.git] / cadi / core / src / test / java / org / onap / aaf / cadi / taf / test / JU_AbsTafResp.java
1 /*******************************************************************************
2 * ============LICENSE_START====================================================
3 * * org.onap.aaf
4 * * ===========================================================================
5 * * Copyright © 2017 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
23 package org.onap.aaf.cadi.taf.test;
24
25 import static org.hamcrest.CoreMatchers.is;
26 import static org.hamcrest.CoreMatchers.nullValue;
27 import static org.junit.Assert.assertThat;
28
29 import java.io.ByteArrayOutputStream;
30 import java.io.IOException;
31 import java.io.PrintStream;
32
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.aaf.cadi.Access;
36 import org.onap.aaf.cadi.PropAccess;
37 import org.onap.aaf.cadi.principal.TaggedPrincipal;
38 import org.onap.aaf.cadi.taf.AbsTafResp;
39 import org.onap.aaf.cadi.taf.TafResp.RESP;
40
41 public class JU_AbsTafResp {
42     
43     private static final String JUNIT = "Junit";
44     private static final String name = "name";
45     private static final String tag = "tag";
46     private static final String description = "description";
47     
48     private Access access;
49     private TaggedPrincipal taggedPrinc;
50     
51     @Before
52     public void setup() {
53         access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
54         taggedPrinc = new TaggedPrincipal() {
55             @Override public String getName() { return name; }
56             @Override public String tag() { return tag; }
57         };
58     }
59
60     @Test
61     public void test() {
62         AbsTafResp tafResp = new AbsTafResp(access, JUNIT, taggedPrinc, description) {
63             @Override public RESP authenticate() throws IOException {
64                 return null;
65             }
66         };
67
68         assertThat(tafResp.isValid(), is(true));
69         assertThat(tafResp.desc(), is(description));
70         assertThat(tafResp.taf(), is(JUNIT));
71         assertThat(tafResp.isAuthenticated(), is(RESP.IS_AUTHENTICATED));
72         assertThat(tafResp.getPrincipal(), is(taggedPrinc));
73         assertThat(tafResp.getAccess(), is(access));
74         assertThat(tafResp.isFailedAttempt(), is(false));
75
76         tafResp = new AbsTafResp(null, JUNIT, "unknown", null) {
77             @Override public RESP authenticate() throws IOException {
78                 return null;
79             }
80         };
81
82         assertThat(tafResp.isValid(), is(false));
83         assertThat(tafResp.isAuthenticated(), is(RESP.TRY_ANOTHER_TAF));
84         assertThat(tafResp.getPrincipal(), is(nullValue()));
85         assertThat(tafResp.getTarget(), is("unknown"));
86         assertThat(tafResp.getAccess(), is(nullValue()));
87         assertThat(tafResp.taf(), is(JUNIT));
88         assertThat(tafResp.isFailedAttempt(), is(false));
89     }
90
91 }