FileDocCategorySizeDatePackage
PolicyModelGeneratorTest.javaAPI DocExample6299Tue May 29 16:57:40 BST 2007com.sun.xml.ws.policy.sourcemodel

PolicyModelGeneratorTest

public class PolicyModelGeneratorTest extends TestCase

Fields Summary
private static final String
COMPACT_MODEL_SUFFIX
private static final String
NORMALIZED_MODEL_SUFFIX
private static final Map
COMPLEX_POLICIES
private PolicyModelGenerator
generator
private PolicyModelTranslator
translator
Constructors Summary
public PolicyModelGeneratorTest(String testName)

        super(testName);
    
Methods Summary
protected voidsetUp()

        translator = PolicyModelTranslator.getTranslator();
        generator = PolicyModelGenerator.getGenerator();
    
protected voidtearDown()

    
public voidtestGenerate()

        for (Map.Entry<String, Integer> entry : COMPLEX_POLICIES.entrySet()) {
            String compactResourceName = entry.getKey() + COMPACT_MODEL_SUFFIX;
            String normalizedResouceName = entry.getKey() + NORMALIZED_MODEL_SUFFIX;
            int expectedNumberOfAlternatives = entry.getValue();
            
            PolicySourceModel compactModel = PolicyResourceLoader.unmarshallModel(compactResourceName);
            PolicySourceModel normalizedModel = PolicyResourceLoader.unmarshallModel(normalizedResouceName);
            Policy compactModelPolicy = translator.translate(compactModel);
            Policy normalizedModelPolicy = translator.translate(normalizedModel);
            
            PolicySourceModel generatedCompactModel = generator.translate(compactModelPolicy);
            PolicySourceModel generatedNormalizedModel = generator.translate(normalizedModelPolicy);

            Policy generatedCompactModelPolicy = translator.translate(generatedCompactModel);
            Policy generatedNormalizedModelPolicy = translator.translate(generatedNormalizedModel);
            
            assertEquals("Generated compact policy should contain '" + expectedNumberOfAlternatives + "' alternatives", expectedNumberOfAlternatives,generatedCompactModelPolicy.getNumberOfAssertionSets());
            assertEquals("Generated and translated compact model policy instances should contain equal number of alternatives", compactModelPolicy.getNumberOfAssertionSets(), generatedCompactModelPolicy.getNumberOfAssertionSets());
            assertEquals("Generated and translated compact policy expression should form equal Policy instances", compactModelPolicy, generatedCompactModelPolicy);

            assertEquals("Generated normalized policy should contain '" + expectedNumberOfAlternatives + "' alternatives", expectedNumberOfAlternatives, generatedNormalizedModelPolicy.getNumberOfAssertionSets());
            assertEquals("Generated and translated normalized model policy instances should contain equal number of alternatives", normalizedModelPolicy.getNumberOfAssertionSets(), generatedNormalizedModelPolicy.getNumberOfAssertionSets());
            assertEquals("Generated and translated normalized policy expression should form equal Policy instances", normalizedModelPolicy, generatedNormalizedModelPolicy);
            
            // TODO: somehow compare models, because now the test only checks if the translation does not end in some exception...
        }
    
public voidtestGetTranslator()

        PolicyModelGenerator result = PolicyModelGenerator.getGenerator();
        assertNotNull(result);