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.sourcemodel;
038:
039: import com.sun.xml.ws.policy.Policy;
040: import com.sun.xml.ws.policy.testutils.PolicyResourceLoader;
041: import java.util.Collections;
042: import java.util.HashMap;
043: import java.util.Map;
044: import junit.framework.TestCase;
045:
046: /**
047: *
048: * @author Marek Potociar
049: */
050: public class PolicyModelTranslatorTest extends TestCase {
051: private static final String COMPACT_MODEL_SUFFIX = ".xml";
052: private static final String NORMALIZED_MODEL_SUFFIX = "_normalized.xml";
053: private static final Map<String, Integer> COMPLEX_POLICIES;
054:
055: static {
056: Map<String, Integer> tempMap = new HashMap<String, Integer>();
057: tempMap
058: .put(
059: "complex_policy/nested_assertions_with_alternatives",
060: 3);
061: tempMap.put("complex_policy/single_choice1", 3);
062: tempMap.put("complex_policy/single_choice2", 5);
063: tempMap.put("complex_policy/nested_choice1", 3);
064: tempMap.put("complex_policy/nested_choice2", 3);
065: tempMap.put("complex_policy/assertion_parameters1", 1);
066: COMPLEX_POLICIES = Collections.unmodifiableMap(tempMap);
067: }
068:
069: private PolicyModelTranslator translator;
070:
071: public PolicyModelTranslatorTest(String testName) {
072: super (testName);
073: }
074:
075: protected void setUp() throws Exception {
076: translator = PolicyModelTranslator.getTranslator();
077: }
078:
079: protected void tearDown() throws Exception {
080: }
081:
082: /**
083: * Test of getTranslator method, of class com.sun.xml.ws.policy.PolicyModelTranslator.
084: */
085: public void testGetTranslator() throws Exception {
086: PolicyModelTranslator result = PolicyModelTranslator
087: .getTranslator();
088: assertNotNull(result);
089: }
090:
091: /**
092: * Test of translate method, of class com.sun.xml.ws.policy.PolicyModelTranslator.
093: */
094: public void testTranslateComplexPoliciesWithMultipleNestedPolicyAlternatives()
095: throws Exception {
096: int index = 0;
097: for (Map.Entry<String, Integer> entry : COMPLEX_POLICIES
098: .entrySet()) {
099: String compactResourceName = entry.getKey()
100: + COMPACT_MODEL_SUFFIX;
101: String normalizedResouceName = entry.getKey()
102: + NORMALIZED_MODEL_SUFFIX;
103: int expectedNumberOfAlternatives = entry.getValue();
104:
105: PolicySourceModel compactModel = PolicyResourceLoader
106: .unmarshallModel(compactResourceName);
107: PolicySourceModel normalizedModel = PolicyResourceLoader
108: .unmarshallModel(normalizedResouceName);
109:
110: // System.out.println(index + ". compact model: " + compactModel);
111: // System.out.println("===========================================================");
112: // System.out.println(index + ". normalized model: " + normalizedModel);
113: // System.out.println("===========================================================");
114:
115: Policy compactModelPolicy = translator
116: .translate(compactModel);
117: Policy normalizedModelPolicy = translator
118: .translate(normalizedModel);
119:
120: assertEquals(
121: "Normalized and compact model policy instances should contain equal number of alternatives",
122: normalizedModelPolicy.getNumberOfAssertionSets(),
123: compactModelPolicy.getNumberOfAssertionSets());
124: assertEquals("This policy should contain '"
125: + expectedNumberOfAlternatives + "' alternatives",
126: expectedNumberOfAlternatives, compactModelPolicy
127: .getNumberOfAssertionSets());
128: assertEquals(
129: "Normalized and compact policy expression should form equal Policy instances",
130: normalizedModelPolicy, compactModelPolicy);
131:
132: // System.out.println(index + ". compact model policy: " + compactModelPolicy);
133: // System.out.println("===========================================================");
134: // System.out.println(index + ". normalized model policy: " + normalizedModelPolicy);
135:
136: index++;
137: }
138:
139: }
140: }
|