001: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
002: *
003: * Licensed under the Apache License, Version 2.0 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at
006: *
007: * http://www.apache.org/licenses/LICENSE-2.0
008: *
009: * Unless required by applicable law or agreed to in writing, software
010: * distributed under the License is distributed on an "AS IS" BASIS,
011: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: * See the License for the specific language governing permissions and
013: * limitations under the License.
014: */
015:
016: package org.acegisecurity;
017:
018: import junit.framework.TestCase;
019:
020: /**
021: * Tests {@link SecurityConfig}.
022: *
023: * @author Ben Alex
024: * @version $Id: SecurityConfigTests.java 1669 2006-09-15 03:09:05Z benalex $
025: */
026: public class SecurityConfigTests extends TestCase {
027: //~ Constructors ===================================================================================================
028:
029: public SecurityConfigTests() {
030: super ();
031: }
032:
033: public SecurityConfigTests(String arg0) {
034: super (arg0);
035: }
036:
037: //~ Methods ========================================================================================================
038:
039: public static void main(String[] args) {
040: junit.textui.TestRunner.run(SecurityConfigTests.class);
041: }
042:
043: public final void setUp() throws Exception {
044: super .setUp();
045: }
046:
047: public void testHashCode() {
048: SecurityConfig config = new SecurityConfig("TEST");
049: assertEquals("TEST".hashCode(), config.hashCode());
050: }
051:
052: public void testNoArgConstructorDoesntExist() {
053: Class clazz = SecurityConfig.class;
054:
055: try {
056: clazz.getDeclaredConstructor((Class[]) null);
057: fail("Should have thrown NoSuchMethodException");
058: } catch (NoSuchMethodException expected) {
059: assertTrue(true);
060: }
061: }
062:
063: public void testObjectEquals() throws Exception {
064: SecurityConfig security1 = new SecurityConfig("TEST");
065: SecurityConfig security2 = new SecurityConfig("TEST");
066: assertEquals(security1, security2);
067:
068: // SEC-311: Must observe symmetry requirement of Object.equals(Object) contract
069: String securityString1 = "TEST";
070: assertNotSame(security1, securityString1);
071:
072: String securityString2 = "NOT_EQUAL";
073: assertTrue(!security1.equals(securityString2));
074:
075: SecurityConfig security3 = new SecurityConfig("NOT_EQUAL");
076: assertTrue(!security1.equals(security3));
077:
078: MockConfigAttribute mock1 = new MockConfigAttribute("TEST");
079: assertEquals(security1, mock1);
080:
081: MockConfigAttribute mock2 = new MockConfigAttribute("NOT_EQUAL");
082: assertTrue(!security1.equals(mock2));
083:
084: Integer int1 = new Integer(987);
085: assertTrue(!security1.equals(int1));
086: }
087:
088: public void testToString() {
089: SecurityConfig config = new SecurityConfig("TEST");
090: assertEquals("TEST", config.toString());
091: }
092:
093: //~ Inner Classes ==================================================================================================
094:
095: private class MockConfigAttribute implements ConfigAttribute {
096: private String attribute;
097:
098: public MockConfigAttribute(String configuration) {
099: this .attribute = configuration;
100: }
101:
102: private MockConfigAttribute() {
103: super ();
104: }
105:
106: public String getAttribute() {
107: return this.attribute;
108: }
109: }
110: }
|