001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.policy;
038:
039: import com.sun.xml.ws.policy.testutils.PolicyResourceLoader;
040: import java.util.ArrayList;
041: import java.util.Collection;
042: import java.util.LinkedList;
043: import junit.framework.TestCase;
044:
045: /**
046: *
047: * @author Marek Potociar (marek.potociar@sun.com)
048: */
049: public class PolicySubjectTest extends TestCase {
050: private Object subject = new Object();
051: private PolicyMerger merger = PolicyMerger.getMerger();
052:
053: public PolicySubjectTest(String testName) {
054: super (testName);
055: }
056:
057: protected void setUp() throws Exception {
058: }
059:
060: protected void tearDown() throws Exception {
061: }
062:
063: public void testCreatePolicySubjectWithNullSubjectMustThrowIAE()
064: throws Exception {
065: try {
066: new PolicySubject(null, Policy.createNullPolicy());
067: fail("PolicySubject creation must throw IllegalArgumentException on 'null' subject");
068: } catch (IllegalArgumentException e) {
069: // ok.
070: }
071: }
072:
073: public void testCreatePolicySubjectWithNullPolicyMustThrowIAE()
074: throws Exception {
075: try {
076: Policy p = null;
077: new PolicySubject(subject, p);
078: fail("PolicySubject creation must throw IllegalArgumentException on 'null' policy");
079: } catch (IllegalArgumentException e) {
080: // ok.
081: }
082: }
083:
084: public void testCreatePolicySubjectWithNullPolicyCollcetionMustThrowIAE()
085: throws Exception {
086: try {
087: Collection<Policy> c = null;
088: new PolicySubject(subject, c);
089: fail("PolicySubject creation must throw IllegalArgumentException on 'null' policy collection");
090: } catch (IllegalArgumentException e) {
091: // ok.
092: }
093: }
094:
095: public void testCreatePolicySubjectWithEmptyPolicyCollectionMustThrowIAE()
096: throws Exception {
097: try {
098: Collection<Policy> c = new ArrayList<Policy>();
099: new PolicySubject(subject, c);
100: fail("PolicySubject creation must throw IllegalArgumentException on empty policy collection");
101: } catch (IllegalArgumentException e) {
102: // ok.
103: }
104: }
105:
106: public void testGetSubjectReturnsCorrectSubject() throws Exception {
107: PolicySubject ps = new PolicySubject(subject, Policy
108: .createNullPolicy());
109: assertEquals(
110: "Subject used in constructor must equal to subject returned from getter.",
111: subject, ps.getSubject());
112: }
113:
114: public void testGetSubjectReturnsCorrectReference()
115: throws Exception {
116: StringBuffer subject = new StringBuffer('a');
117: PolicySubject ps = new PolicySubject(subject, Policy
118: .createNullPolicy());
119: subject.append('b');
120: assertEquals(
121: "Subject used in constructor must equal to subject returned from getter.",
122: subject, ps.getSubject());
123: }
124:
125: public void testAttachingNullPolicyThrowsIAE() throws Exception {
126: PolicySubject ps = new PolicySubject(subject, Policy
127: .createNullPolicy());
128: try {
129: ps.attach(null);
130: fail("Attaching a 'null' policy to the policyt subject must throw IllegalArgumentException");
131: } catch (IllegalArgumentException e) {
132: // ok.
133: }
134: }
135:
136: public void testAttachingNoPolicyToAnyPolicyResultsInNoEffectivePolicy()
137: throws Exception {
138: PolicySubject ps = new PolicySubject(subject, Policy
139: .createEmptyPolicy());
140: Policy noPolicy = Policy.createNullPolicy();
141: ps.attach(noPolicy);
142:
143: assertEquals(noPolicy, ps.getEffectivePolicy(merger));
144: }
145:
146: }
|