1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18/**
19* @author Aleksei Y. Semenov
20*/
21
22package org.apache.harmony.security.tests.java.security;
23import java.security.*;
24import org.apache.harmony.security.tests.support.IdentityScopeStub;
25
26import junit.framework.TestCase;
27
28
29/**
30 * Tests for <code>IdentityScope</code>
31 *
32 */
33
34public class IdentityScopeTest extends TestCase {
35
36    IdentityScope is;
37
38    /**
39     * Constructor for IdentityScopeTest.
40     * @param arg0
41     */
42    public IdentityScopeTest(String arg0) {
43        super(arg0);
44    }
45
46    /**
47     * Class under test for String toString()
48     */
49    public final void testToString() {
50        assertNotNull(new IdentityScopeStub("Aleksei Semenov").toString());
51    }
52
53    /**
54     * test default constructor void IdentityScope()
55     */
56    public final void testIdentityScope() {
57        assertNotNull(new IdentityScopeStub());
58    }
59
60    /**
61     * check that void IdentityScope(String) creates instance with given name
62     */
63    public final void testIdentityScopeString() {
64        is = new IdentityScopeStub("Aleksei Semenov");
65        assertNotNull(is);
66        assertEquals("Aleksei Semenov", is.getName());
67    }
68
69    /**
70     * check that void IdentityScope(String, IdentityScope) creates instance with given name and within given scope
71     */
72    public final void testIdentityScopeStringIdentityScope() throws Exception {
73        IdentityScope scope = new IdentityScopeStub("my scope");
74        is = new IdentityScopeStub("Aleksei Semenov", scope);
75        assertNotNull(is);
76        assertEquals("Aleksei Semenov", is.getName());
77        assertEquals(scope.getName(), is.getScope().getName());
78    }
79
80    /**
81     * just call IdentityScope.getSystemScope()
82     */
83    public final void testGetSystemScope() {
84        String name = Security.getProperty("system.scope");
85        assertNotNull(name);
86        IdentityScope scope = IdentityScope.getSystemScope();
87        assertNotNull(scope);
88        assertEquals(name, scope.getClass().getName());
89    }
90
91    /**
92     * Class under test for Identity getIdentity(Principal)
93     */
94    public final void testGetIdentityPrincipal() {
95        is = new IdentityScopeStub("Aleksei Semenov");
96        IdentityScope sc2 = new IdentityScopeStub("aaa");
97        assertSame(is, is.getIdentity(sc2));
98    }
99
100}
101