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.hamcrest.CoreMatchers.is;
26 import static org.junit.Assert.assertThat;
28 import java.io.IOException;
30 import org.junit.Test;
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.LifeForm;
35 import org.onap.aaf.cadi.principal.TaggedPrincipal;
36 import org.onap.aaf.cadi.taf.EpiTaf;
37 import org.onap.aaf.cadi.taf.NullTaf;
38 import org.onap.aaf.cadi.taf.TafResp;
39 import org.onap.aaf.cadi.taf.TafResp.RESP;
41 public class JU_EpiTaf {
43 @Test(expected = CadiException.class)
44 @SuppressWarnings("unused")
45 public void constructorTest() throws CadiException {
46 EpiTaf et = new EpiTaf();
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));
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));
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));
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 Access.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";}
85 class TryAnotherTaf implements Taf {
86 @Override public TafResp validate(LifeForm reading, String ... info) { return new TryAnotherTafResp(); }
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 Access.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";}
102 class TryAuthenticatingTaf implements Taf {
103 @Override public TafResp validate(LifeForm reading, String ... info) { return new TryAuthenticatingResp(); }
106 class EpiTafStub extends EpiTaf {
107 public EpiTafStub() throws CadiException { }