You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2004/07/14 00:54:35 UTC

cvs commit: jakarta-jetspeed/src/test/org/apache/jetspeed/services/registry TestHybridRegistryService.java

taylor      2004/07/13 15:54:35

  Added:       src/test/org/apache/jetspeed/services/registry
                        TestHybridRegistryService.java
  Log:
  test for Hybrid Registry service specific for security right now
  
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed/src/test/org/apache/jetspeed/services/registry/TestHybridRegistryService.java
  
  Index: TestHybridRegistryService.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.services.registry;
  
  import java.util.Enumeration;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.jetspeed.om.registry.PortletEntry;
  import org.apache.jetspeed.om.registry.PortletRegistry;
  import org.apache.jetspeed.om.registry.RegistryEntry;
  import org.apache.jetspeed.om.registry.SecurityEntry;
  import org.apache.jetspeed.services.Registry;
  import org.apache.jetspeed.test.JetspeedTestCase;
  import org.apache.turbine.util.StringUtils;
  import org.apache.turbine.util.TurbineConfig;
  
  
  /**
   * TestHybridRegistryService
   *
   * @author <a href="taylor@apache.org">David Sean Taylor</a>
   * @version $Id: TestHybridRegistryService.java,v 1.1 2004/07/13 22:54:35 taylor Exp $
   */
  public class TestHybridRegistryService extends JetspeedTestCase
  {
      /**
       * Defines the testcase name for JUnit.
       *
       * @param name the testcase's name.
       */
      public TestHybridRegistryService( String name ) 
      {
          super( name );
      }
      
      /**
       * Start the tests.
       *
       * @param args the arguments. Not used
       */
      public static void main(String args[]) 
      {
          junit.awtui.TestRunner.main( new String[] { TestHybridRegistryService.class.getName() } );
      }
   
      public void setup() 
      {
          System.out.println("Setup: Testing Hybrid Database Registry");
      }
      
      /**
       * Creates the test suite.
       *
       * @return a test suite (<code>TestSuite</code>) that includes all methods
       *         starting with "test"
       */
      public static Test suite() {
          // All methods starting with "test" will be executed in the test suite.
          return new TestSuite( TestHybridRegistryService.class );
      }
  
      /**
       * Tests categories
       * @throws Exception
       */
      public void testHybrid() throws Exception 
      {
          try
          {
              System.out.println("Testing Startup");
              PortletRegistry registry = (PortletRegistry)Registry.get(Registry.PORTLET);
  
              PortletEntry pe = (PortletEntry)registry.getEntry("RSS");
              assertNotNull(pe);
              
              Enumeration names = Registry.getNames();
              while (names.hasMoreElements())
              {
                  System.out.println("debug name  = " + names.nextElement());
              }
              boolean testAdd = true;
              if (testAdd)
              {            
                  SecurityEntry entry = (SecurityEntry)Registry.createEntry(Registry.SECURITY);
                  entry.setName("test");
                  entry.setDescription("description");
                  entry.setTitle("The Title");
                  entry.grantRoleAccess("*", "admin");
                  entry.grantGroupAccess("view", "sales");
                  entry.grantGroupAccess("edit", "sales");
                  entry.grantGroupAccess("edit", "marketing");
                  entry.grantGroupAccess("edit", "accounting");
  
                  assertSimpleConstraints(entry);
                      
                  Registry.addEntry(Registry.SECURITY, (RegistryEntry)entry);
              }
              SecurityEntry se = (SecurityEntry)Registry.getEntry(Registry.SECURITY, "test");
              assertSimpleConstraints(se);
              
              SecurityEntry se2 = (SecurityEntry)Registry.getEntry(Registry.SECURITY, "test");
              assertSimpleConstraints(se2);
              se2.revokeGroupAccess("edit", "accounting");
              se2.grantGroupAccess("view", "accounting");
              
              Registry.saveEntry(Registry.SECURITY, (RegistryEntry)se2);
              Registry.removeEntry(Registry.SECURITY, "test");
              
          }
          catch (Exception e)
          {
              String errmsg = "Error in database test: " + e.toString();
             // e.printStackTrace();
             assertNotNull(errmsg, null);
          }
      }
  
      private void assertSimpleConstraints(SecurityEntry se)
      {
          assertNotNull("result", se);
          assertTrue(se.getName().equals("test"));
          assertTrue(se.getTitle().equals("The Title"));            
          assertTrue(se.getDescription().equals("description"));
          assertTrue(se.allowsRole("admin", "view"));
          
          assertTrue(!se.allowsRole("nobody", "view"));
          
          assertTrue(se.allowsGroup("marketing", "edit"));
          assertTrue(se.allowsGroup("sales", "edit"));        
          assertTrue(!se.allowsGroup("marketing", "print"));        
          
      }
      
      /*
      Configuration object to run Turbine outside a servlet container
      ( uses turbine.properties )
    */
    private static TurbineConfig config = null;
    
    /*    
      Sets up TurbineConfig using the system property:
      <pre>turbine.properties</pre>
    */
    static
    {
        try
        {
           config = new TurbineConfig( "webapp", "/WEB-INF/conf/TurbineResources.properties");
           config.initialize();
        }
        catch (Exception e)
        {
            fail(StringUtils.stackTrace(e));
        }
    }
      
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org