1 /*******************************************************************************
2 * ============LICENSE_START====================================================
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
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====================================================
21 ******************************************************************************/
23 package org.onap.aaf.cadi.taf.test;
25 import static org.junit.Assert.*;
26 import static org.hamcrest.CoreMatchers.*;
29 import java.io.IOException;
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;
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;
42 public class JU_EpiTaf {
44 @Test(expected = CadiException.class)
45 @SuppressWarnings("unused")
46 public void constructorTest() throws CadiException {
47 EpiTaf et = new EpiTaf();
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));
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));
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));
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";}
86 class TryAnotherTaf implements Taf {
87 @Override public TafResp validate(LifeForm reading, String ... info) { return new TryAnotherTafResp(); }
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";}
103 class TryAuthenticatingTaf implements Taf {
104 @Override public TafResp validate(LifeForm reading, String ... info) { return new TryAuthenticatingResp(); }
107 class EpiTafStub extends EpiTaf {
108 public EpiTafStub() throws CadiException { }