ed1ae4c9d610c3b0854fd0a590ae99893e96e2ce
[aaf/authz.git] / cadi / core / src / test / java / org / onap / aaf / cadi / principal / test / JU_TrustPrincipal.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 java.security.Principal;
30
31 import org.onap.aaf.cadi.UserChain;
32 import org.onap.aaf.cadi.principal.TaggedPrincipal;
33 import org.onap.aaf.cadi.principal.TrustPrincipal;
34
35 public class JU_TrustPrincipal {
36
37     private final String ucName = "UserChain";
38     private final String uc = "This is a UserChain";
39     private final String taggedName = "TaggedPrincipal";
40     private final String tag = "tag";
41     private final String pName = "Principal";
42
43     private class UserChainPrincipalStub implements Principal, UserChain {
44         @Override public String userChain() { return uc; }
45         @Override public String getName() { return ucName; }
46     }
47
48     private class TaggedPrincipalStub extends TaggedPrincipal {
49         public TaggedPrincipalStub() { super(); }
50         @Override public String getName() { return taggedName; }
51         @Override public String tag() { return tag; }
52     }
53
54     private class PrincipalStub implements Principal {
55         @Override public String getName() { return pName; }
56     }
57
58     @Test
59     public void userChainConstructorTest() {
60         UserChainPrincipalStub ucps = new UserChainPrincipalStub();
61         TrustPrincipal tp = new TrustPrincipal(ucps, taggedName);
62         assertThat(tp.getName(), is(taggedName));
63         assertThat(tp.userChain(), is(uc));
64         assertSame(tp.original(), ucps);
65         assertThat(tp.tag(), is(uc));
66         assertThat(tp.personalName(), is(ucName + '[' + uc + ']'));
67     }
68
69     @Test
70     public void taggedPrincipalConstructorTest() {
71         TaggedPrincipal tagged = new TaggedPrincipalStub();
72         TrustPrincipal tp = new TrustPrincipal(tagged, taggedName);
73         assertThat(tp.getName(), is(taggedName));
74         assertThat(tp.userChain(), is(tag));
75         assertSame(tp.original(), tagged);
76         assertThat(tp.tag(), is(tag));
77         assertThat(tp.personalName(), is(taggedName + '[' + tag + ']'));
78     }
79
80     @Test
81     public void principalConstructorTest() {
82         Principal principal = new PrincipalStub();
83         TrustPrincipal tp = new TrustPrincipal(principal, pName);
84         assertThat(tp.getName(), is(pName));
85         assertThat(tp.userChain(), is(principal.getClass().getSimpleName()));
86         assertSame(tp.original(), principal);
87         assertThat(tp.tag(), is(principal.getClass().getSimpleName()));
88         assertThat(tp.personalName(), is(pName + '[' + principal.getClass().getSimpleName() + ']'));
89     }
90
91 }