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.principal.test;
25 import static org.junit.Assert.*;
26 import static org.hamcrest.CoreMatchers.*;
29 import java.security.Principal;
31 import org.onap.aaf.cadi.UserChain;
32 import org.onap.aaf.cadi.principal.TaggedPrincipal;
33 import org.onap.aaf.cadi.principal.TrustPrincipal;
35 public class JU_TrustPrincipal {
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";
43 private class UserChainPrincipalStub implements Principal, UserChain {
44 @Override public String userChain() { return uc; }
45 @Override public String getName() { return ucName; }
48 private class TaggedPrincipalStub extends TaggedPrincipal {
49 public TaggedPrincipalStub() { super(); }
50 @Override public String getName() { return taggedName; }
51 @Override public String tag() { return tag; }
54 private class PrincipalStub implements Principal {
55 @Override public String getName() { return pName; }
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 + ']'));
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 + ']'));
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() + ']'));