f8e20cbfaf146b0f891ea8d9a9b89a471e339308
[aaf/authz.git] / cadi / core / src / test / java / org / onap / aaf / cadi / taf / test / JU_EpiTaf.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 package org.onap.aaf.cadi.taf.test;
23
24 import static org.junit.Assert.*;
25 import static org.hamcrest.CoreMatchers.*;
26 import org.junit.*;
27
28 import java.io.IOException;
29
30 import org.onap.aaf.cadi.Access;
31 import org.onap.aaf.cadi.CadiException;
32 import org.onap.aaf.cadi.Taf;
33 import org.onap.aaf.cadi.taf.TafResp;
34 import org.onap.aaf.cadi.taf.TafResp.RESP;
35
36 import org.onap.aaf.cadi.taf.EpiTaf;
37 import org.onap.aaf.cadi.taf.NullTaf;
38 import org.onap.aaf.cadi.Taf.LifeForm;
39 import org.onap.aaf.cadi.principal.TaggedPrincipal;
40
41 public class JU_EpiTaf {
42
43         @Test(expected = CadiException.class)
44         @SuppressWarnings("unused")
45         public void constructorTest() throws CadiException {
46                 EpiTaf et = new EpiTaf();
47         }
48
49         @Test
50         public void validateTryAnotherTest() throws CadiException {
51                 EpiTaf et = new EpiTaf(new TryAnotherTaf());
52                 TafResp output = et.validate(LifeForm.CBLF);
53                 assertThat(output.isAuthenticated(), is(RESP.NO_FURTHER_PROCESSING));
54         }
55
56         @Test
57         public void validateTryAuthenticatingTest() throws CadiException {
58                 EpiTaf et = new EpiTaf(new TryAuthenticatingTaf(), new TryAuthenticatingTaf());
59                 TafResp output = et.validate(LifeForm.CBLF);
60                 assertThat(output.isAuthenticated(), is(RESP.TRY_AUTHENTICATING));
61                 output = et.validate(LifeForm.CBLF);
62                 assertThat(output.isAuthenticated(), is(RESP.TRY_AUTHENTICATING));
63         }
64
65         @Test
66         public void validateDefaultCaseTest() throws CadiException {
67                 EpiTaf et = new EpiTaf(new NullTaf());
68                 TafResp output = et.validate(LifeForm.CBLF);
69                 assertThat(output.isAuthenticated(), is(RESP.NO_FURTHER_PROCESSING));
70         }
71
72         class TryAnotherTafResp implements TafResp {
73                 @Override public boolean isValid() { return false; } 
74                 @Override public String desc() { return null; } 
75                 @Override public RESP isAuthenticated() { return RESP.TRY_ANOTHER_TAF; } 
76                 @Override public RESP authenticate() throws IOException { return null; } 
77                 @Override public TaggedPrincipal getPrincipal() { return null; } 
78                 @Override public Access getAccess() { return null; } 
79                 @Override public boolean isFailedAttempt() { return false; }
80                 @Override public float timing() { return 0; }
81                 @Override public void timing(long start) {} 
82                 @Override public String taf() {return "JUnit";}
83         }
84
85         class TryAnotherTaf implements Taf {
86                 @Override public TafResp validate(LifeForm reading, String ... info) { return new TryAnotherTafResp(); }
87         }
88
89         class TryAuthenticatingResp implements TafResp {
90                 @Override public boolean isValid() { return false; } 
91                 @Override public String desc() { return null; } 
92                 @Override public RESP isAuthenticated() { return RESP.TRY_AUTHENTICATING; } 
93                 @Override public RESP authenticate() throws IOException { return null; } 
94                 @Override public TaggedPrincipal getPrincipal() { return null; } 
95                 @Override public Access getAccess() { return null; } 
96                 @Override public boolean isFailedAttempt() { return false; } 
97                 @Override public float timing() { return 0; }
98                 @Override public void timing(long start) {} 
99                 @Override public String taf() {return "JUnit";}
100         }
101
102         class TryAuthenticatingTaf implements Taf {
103                 @Override public TafResp validate(LifeForm reading, String ... info) { return new TryAuthenticatingResp(); }
104         }
105
106         class EpiTafStub extends EpiTaf {
107                 public EpiTafStub() throws CadiException { }
108         }
109
110 }