6d0c04b7388c428f4d20a9e553dd1bd73bd6948a
[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 name = "name";
44         private static final String tag = "tag";
45         private static final String description = "description";
46         
47         private Access access;
48         private TaggedPrincipal taggedPrinc;
49         
50         @Before
51         public void setup() {
52                 access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
53                 taggedPrinc = new TaggedPrincipal() {
54                         @Override public String getName() { return name; }
55                         @Override public String tag() { return tag; }
56                 };
57         }
58
59         @Test
60         public void test() {
61                 AbsTafResp tafResp = new AbsTafResp(access, taggedPrinc, description) {
62                         @Override public RESP authenticate() throws IOException {
63                                 return null;
64                         }
65                 };
66
67                 assertThat(tafResp.isValid(), is(true));
68                 assertThat(tafResp.desc(), is(description));
69                 assertThat(tafResp.isAuthenticated(), is(RESP.IS_AUTHENTICATED));
70                 assertThat(tafResp.getPrincipal(), is(taggedPrinc));
71                 assertThat(tafResp.getAccess(), is(access));
72                 assertThat(tafResp.isFailedAttempt(), is(false));
73
74                 tafResp = new AbsTafResp(null, null, null) {
75                         @Override public RESP authenticate() throws IOException {
76                                 return null;
77                         }
78                 };
79
80                 assertThat(tafResp.isValid(), is(false));
81                 assertThat(tafResp.isAuthenticated(), is(RESP.TRY_ANOTHER_TAF));
82                 assertThat(tafResp.getPrincipal(), is(nullValue()));
83                 assertThat(tafResp.getAccess(), is(nullValue()));
84                 assertThat(tafResp.isFailedAttempt(), is(false));
85         }
86
87 }