2bbfee23b212734a849b17d2d7350bac09e0a7dd
[aaf/authz.git] / cadi / core / src / test / java / org / onap / aaf / cadi / principal / test / JU_TaggedPrincipal.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.principal.test;
24
25 import static org.junit.Assert.*;
26 import static org.hamcrest.CoreMatchers.*;
27 import org.junit.*;
28
29 import org.onap.aaf.cadi.principal.TaggedPrincipal;
30 import org.onap.aaf.cadi.principal.TaggedPrincipal.TagLookup;
31 import org.onap.aaf.cadi.CadiException;
32 import org.onap.aaf.cadi.principal.StringTagLookup;
33
34 public class JU_TaggedPrincipal {
35
36         private final String name = "stubbedName";
37         private final String tag = "tag";
38
39         private class TaggedPrincipalStub extends TaggedPrincipal {
40                 public TaggedPrincipalStub() { super(); }
41                 public TaggedPrincipalStub(final TagLookup tl) { super(tl); }
42                 @Override public String getName() { return name; }
43                 @Override public String tag() { return null; }
44         }
45
46         private class WhinyTagLookup implements TagLookup {
47                 public WhinyTagLookup(final String tag) { }
48                 @Override
49                 public String lookup() throws CadiException {
50                         throw new CadiException();
51                 }
52         }
53
54         @Test
55         public void personalNameTest() {
56                 TaggedPrincipal tp = new TaggedPrincipalStub();
57                 assertThat(tp.personalName(), is(name));
58
59                 StringTagLookup stl = new StringTagLookup(tag);
60                 tp = new TaggedPrincipalStub(stl);
61                 assertThat(tp.personalName(), is(tag));
62
63                 WhinyTagLookup wtl = new WhinyTagLookup(tag);
64                 tp.setTagLookup(wtl);
65                 assertThat(tp.personalName(), is(name));
66         }
67
68 }