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