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.acl.basic;
017:
018: import junit.framework.TestCase;
019:
020: /**
021: * Tests {@link NamedEntityObjectIdentity}.
022: *
023: * @author Ben Alex
024: * @version $Id: NamedEntityObjectIdentityTests.java 1496 2006-05-23 13:38:33Z benalex $
025: */
026: public class NamedEntityObjectIdentityTests extends TestCase {
027: //~ Constructors ===================================================================================================
028:
029: public NamedEntityObjectIdentityTests() {
030: super ();
031: }
032:
033: public NamedEntityObjectIdentityTests(String arg0) {
034: super (arg0);
035: }
036:
037: //~ Methods ========================================================================================================
038:
039: public static void main(String[] args) {
040: junit.textui.TestRunner
041: .run(NamedEntityObjectIdentityTests.class);
042: }
043:
044: public final void setUp() throws Exception {
045: super .setUp();
046: }
047:
048: public void testConstructionViaReflection() throws Exception {
049: SomeDomain domainObject = new SomeDomain();
050: domainObject.setId(34);
051:
052: NamedEntityObjectIdentity name = new NamedEntityObjectIdentity(
053: domainObject);
054: assertEquals("34", name.getId());
055: assertEquals(domainObject.getClass().getName(), name
056: .getClassname());
057: name.toString();
058: }
059:
060: public void testConstructionViaReflectionFailsIfNoGetIdMethod()
061: throws Exception {
062: try {
063: new NamedEntityObjectIdentity(new Integer(45));
064: fail("Should have thrown IllegalArgumentException");
065: } catch (IllegalArgumentException expected) {
066: assertTrue(true);
067: }
068: }
069:
070: public void testConstructionViaReflectionFailsIfNullPassed()
071: throws Exception {
072: try {
073: new NamedEntityObjectIdentity(null);
074: fail("Should have thrown IllegalArgumentException");
075: } catch (IllegalArgumentException expected) {
076: assertTrue(true);
077: }
078: }
079:
080: public void testEquality() {
081: NamedEntityObjectIdentity original = new NamedEntityObjectIdentity(
082: "foo", "12");
083: assertFalse(original.equals(null));
084: assertFalse(original.equals(new Integer(354)));
085: assertFalse(original.equals(new NamedEntityObjectIdentity(
086: "foo", "23232")));
087: assertTrue(original.equals(new NamedEntityObjectIdentity("foo",
088: "12")));
089: assertTrue(original.equals(original));
090: }
091:
092: public void testNoArgConstructorDoesntExist() {
093: Class clazz = NamedEntityObjectIdentity.class;
094:
095: try {
096: clazz.getDeclaredConstructor((Class[]) null);
097: fail("Should have thrown NoSuchMethodException");
098: } catch (NoSuchMethodException expected) {
099: assertTrue(true);
100: }
101: }
102:
103: public void testNormalConstructionRejectedIfInvalidArguments()
104: throws Exception {
105: try {
106: new NamedEntityObjectIdentity(null, "12");
107: fail("Should have thrown IllegalArgumentException");
108: } catch (IllegalArgumentException expected) {
109: assertTrue(true);
110: }
111:
112: try {
113: new NamedEntityObjectIdentity("classname", null);
114: fail("Should have thrown IllegalArgumentException");
115: } catch (IllegalArgumentException expected) {
116: assertTrue(true);
117: }
118:
119: try {
120: new NamedEntityObjectIdentity("", "12");
121: fail("Should have thrown IllegalArgumentException");
122: } catch (IllegalArgumentException expected) {
123: assertTrue(true);
124: }
125:
126: try {
127: new NamedEntityObjectIdentity("classname", "");
128: fail("Should have thrown IllegalArgumentException");
129: } catch (IllegalArgumentException expected) {
130: assertTrue(true);
131: }
132: }
133:
134: public void testNormalOperation() {
135: NamedEntityObjectIdentity name = new NamedEntityObjectIdentity(
136: "domain", "id");
137: assertEquals("domain", name.getClassname());
138: assertEquals("id", name.getId());
139: }
140: }
|