avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/policy/reader/test ReaderTestCase.java config1.xml config2.xml config3.xml
Date Fri, 20 Sep 2002 16:38:14 GMT
donaldp     2002/09/20 09:38:14

  Added:       loader/src/test/org/apache/excalibur/policy/reader/test
                        ReaderTestCase.java config1.xml config2.xml
                        config3.xml
  Log:
  Add some unit tests for Policy parser/reader
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/policy/reader/test/ReaderTestCase.java
  
  Index: ReaderTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.policy.reader.test;
  
  import org.apache.excalibur.policy.metadata.GrantMetaData;
  import org.apache.excalibur.policy.metadata.KeyStoreMetaData;
  import org.apache.excalibur.policy.metadata.PermissionMetaData;
  import org.apache.excalibur.policy.metadata.PolicyMetaData;
  import org.apache.excalibur.policy.test.AbstractPolicyTestCase;
  
  /**
   * TestCase for {@link org.apache.excalibur.policy.reader.PolicyReader}.
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   */
  public class ReaderTestCase
      extends AbstractPolicyTestCase
  {
      public ReaderTestCase( final String name )
      {
          super( name );
      }
  
      public void testConfig1()
          throws Exception
      {
          final PolicyMetaData policy = buildFromResource( "config1.xml" );
  
          assertEquals( "Policy KeyStore Count",
                        1,
                        policy.getKeyStores().length );
  
          final KeyStoreMetaData keyStore = policy.getKeyStores()[ 0 ];
          assertEquals( "KeyStore Name",
                        "myKeystore",
                        keyStore.getName() );
          assertEquals( "KeyStore Location",
                        "sar:/conf/keystore",
                        keyStore.getLocation() );
          assertEquals( "KeyStore Type",
                        "JKS",
                        keyStore.getType() );
  
          assertEquals( "Policy Grant Count",
                        2,
                        policy.getGrants().length );
  
          final GrantMetaData grant1 = policy.getGrants()[ 0 ];
          final GrantMetaData grant2 = policy.getGrants()[ 1 ];
  
          assertEquals( "grant1.getCodebase()",
                        "myCodeBase",
                        grant1.getCodebase() );
          assertEquals( "grant1.getKeyStore()",
                        null,
                        grant1.getKeyStore() );
          assertEquals( "grant1.getSignedBy()",
                        null,
                        grant1.getSignedBy() );
  
          assertEquals( "grant1.getPermissions().length",
                        1,
                        grant1.getPermissions().length );
  
          final PermissionMetaData permission1 = grant1.getPermissions()[ 0 ];
          assertEquals( "permission1.getClassname()",
                        "java.io.FilePermission",
                        permission1.getClassname() );
          assertEquals( "permission1.getAction()",
                        "read,write",
                        permission1.getAction() );
          assertEquals( "permission1.getTarget()",
                        "${/}tmp${/}*",
                        permission1.getTarget() );
  
          assertEquals( "grant2.getCodebase()",
                        "sar:/SAR-INF/lib/*",
                        grant2.getCodebase() );
          assertEquals( "grant2.getKeyStore()",
                        "myKeystore",
                        grant2.getKeyStore() );
          assertEquals( "grant2.getSignedBy()",
                        "Bob",
                        grant2.getSignedBy() );
  
          assertEquals( "grant2.getPermissions().length",
                        1,
                        grant2.getPermissions().length );
  
          final PermissionMetaData permission2 = grant2.getPermissions()[ 0 ];
          assertEquals( "permission2.getClassname()",
                        "java.io.FilePermission",
                        permission2.getClassname() );
          assertEquals( "permission2.getAction()",
                        null,
                        permission2.getAction() );
          assertEquals( "permission2.getTarget()",
                        null,
                        permission2.getTarget() );
      }
  
      public void testConfig2()
          throws Exception
      {
          try
          {
              buildFromResource( "config2.xml" );
          }
          catch( final Throwable t )
          {
              return;
          }
          fail( "Should have failed as loaded a " +
                "configuration with no version" );
      }
  
      public void testConfig3()
          throws Exception
      {
          try
          {
              buildFromResource( "config3.xml" );
          }
          catch( final Throwable t )
          {
              return;
          }
          fail( "Should have failed as loaded a " +
                "configuration with bad version set" );
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/policy/reader/test/config1.xml
  
  Index: config1.xml
  ===================================================================
  <policy version="1.0">
      <keystore name="myKeystore"
          location="sar:/conf/keystore"
          type="JKS"/>
  
      <grant code-base="myCodeBase">
          <permission class="java.io.FilePermission"
              target="${/}tmp${/}*"
              action="read,write"/>
      </grant>
  
      <grant signed-by="Bob" key-store="myKeystore" code-base="sar:/SAR-INF/lib/*">
          <permission class="java.io.FilePermission"/>
      </grant>
  </policy>
  
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/policy/reader/test/config2.xml
  
  Index: config2.xml
  ===================================================================
  <policy>
  </policy>
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/policy/reader/test/config3.xml
  
  Index: config3.xml
  ===================================================================
  <policy version="3.2">
  </policy>
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message