1 /* 2 * Copyright (C) The Spice Group. All rights reserved. 3 * 4 * This software is published under the terms of the Spice 5 * Software License version 1.1, a copy of which has been included 6 * with this distribution in the LICENSE.txt file. 7 */ 8 package org.codehaus.spice.xmlpolicy.test; 9 10 import java.io.InputStream; 11 import javax.xml.parsers.DocumentBuilder; 12 import javax.xml.parsers.DocumentBuilderFactory; 13 import junit.framework.TestCase; 14 import org.codehaus.spice.xmlpolicy.metadata.PolicyMetaData; 15 import org.codehaus.spice.xmlpolicy.reader.PolicyReader; 16 import org.w3c.dom.Document; 17 18 /*** 19 * An abstract testcase to test policys. 20 * 21 * @author Peter Donald 22 * @version $Revision: 1.1 $ $Date: 2003/12/02 09:16:08 $ 23 */ 24 public class AbstractPolicyTestCase 25 extends TestCase 26 { 27 protected PolicyMetaData buildFromStream( final InputStream stream ) 28 throws Exception 29 { 30 try 31 { 32 final PolicyReader builder = new PolicyReader(); 33 final Document config = load( stream ); 34 return builder.readPolicy( config.getDocumentElement() ); 35 } 36 catch( final Exception e ) 37 { 38 fail( "Error building Policy: " + e ); 39 return null; 40 } 41 } 42 43 protected Document load( final InputStream stream ) 44 throws Exception 45 { 46 final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 47 //factory.setValidating(true); 48 //factory.setNamespaceAware(true); 49 final DocumentBuilder builder = factory.newDocumentBuilder(); 50 return builder.parse( stream ); 51 } 52 53 protected PolicyMetaData buildFromResource( final String resource ) 54 throws Exception 55 { 56 final InputStream stream = getClass().getResourceAsStream( resource ); 57 if( null == stream ) 58 { 59 fail( "Missing resource " + resource ); 60 } 61 return buildFromStream( stream ); 62 } 63 64 public AbstractPolicyTestCase( String name ) 65 { 66 super( name ); 67 } 68 }

This page was automatically generated by Maven