001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.ws.policy.builder.primitive;
019:
020: import javax.xml.namespace.QName;
021:
022: import org.apache.neethi.Assertion;
023: import org.apache.neethi.ExactlyOne;
024: import org.apache.neethi.Policy;
025: import org.junit.Assert;
026: import org.junit.Before;
027: import org.junit.Test;
028:
029: /**
030: *
031: */
032: public class NestedPrimitiveAssertionTest extends Assert {
033:
034: private static final String TEST_NAMESPACE = "http://www.w3.org/2007/01/addressing/metadata";
035: private static final QName TEST_NAME1 = new QName(TEST_NAMESPACE,
036: "Addressing");
037: private static final QName TEST_NAME2 = new QName(TEST_NAMESPACE,
038: "AnonymousResponses");
039: private static final QName TEST_NAME3 = new QName(TEST_NAMESPACE,
040: "NonAnonymousResponses");
041:
042: private Policy[] policies;
043:
044: @Before
045: public void setUp() {
046: policies = buildTestPolicies();
047: }
048:
049: @Test
050: public void testEqual() {
051: Assertion other = new PrimitiveAssertion(new QName("abc"));
052: for (int i = 0; i < policies.length; i++) {
053: Assertion a = (Assertion) policies[i]
054: .getFirstPolicyComponent();
055: assertTrue("Assertion " + i + " should equal itself.", a
056: .equal(a));
057: assertTrue("Assertion " + i + " should not equal other.",
058: !a.equal(other));
059: for (int j = i + 1; j < policies.length; j++) {
060: Assertion b = (Assertion) policies[j]
061: .getFirstPolicyComponent();
062: if (j == 1) {
063: assertTrue("Assertion " + i + " should equal " + j
064: + ".", a.equal(b));
065: } else {
066: assertTrue("Assertion " + i
067: + " unexpectedly equals assertion " + j
068: + ".", !a.equal(b));
069: }
070: }
071: }
072: }
073:
074: protected static Policy[] buildTestPolicies() {
075: Policy[] p = new Policy[5];
076: int i = 0;
077:
078: p[i] = new Policy();
079: NestedPrimitiveAssertion a = new NestedPrimitiveAssertion(
080: TEST_NAME1, true);
081: Policy nested = new Policy();
082: a.setNested(nested);
083: p[i++].addPolicyComponent(a);
084:
085: p[i] = new Policy();
086: a = new NestedPrimitiveAssertion(TEST_NAME1, false);
087: nested = new Policy();
088: a.setNested(nested);
089: p[i++].addPolicyComponent(a);
090:
091: p[i] = new Policy();
092: a = new NestedPrimitiveAssertion(TEST_NAME1, false);
093: nested = new Policy();
094: a.setNested(nested);
095: nested.addPolicyComponent(new PrimitiveAssertion(TEST_NAME2,
096: true));
097: nested.addPolicyComponent(new PrimitiveAssertion(TEST_NAME3,
098: true));
099: p[i++].addPolicyComponent(a);
100:
101: p[i] = new Policy();
102: a = new NestedPrimitiveAssertion(TEST_NAME1, false);
103: nested = new Policy();
104: a.setNested(nested);
105: ExactlyOne eo = new ExactlyOne();
106: nested.addPolicyComponent(eo);
107: eo.addPolicyComponent(new PrimitiveAssertion(TEST_NAME2));
108: eo.addPolicyComponent(new PrimitiveAssertion(TEST_NAME3));
109: p[i++].addPolicyComponent(a);
110:
111: p[i] = new Policy();
112: a = new NestedPrimitiveAssertion(TEST_NAME1, false);
113: nested = new Policy();
114: a.setNested(nested);
115: nested.addPolicyComponent(new PrimitiveAssertion(TEST_NAME3));
116: p[i++].addPolicyComponent(a);
117:
118: return p;
119: }
120: }
|