portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wea...@apache.org
Subject cvs commit: jakarta-jetspeed-2/components/id-generator/src/test/org/apache/jetspeed/idgenerator TestIdGenerator.java
Date Wed, 19 May 2004 19:14:22 GMT
weaver      2004/05/19 12:14:22

  Added:       components/id-generator project.xml project.properties
                        maven.xml .cvsignore
               components/id-generator/src/java/org/apache/jetspeed/idgenerator
                        JetspeedIdGenerator.java
               components/id-generator/src/test/org/apache/jetspeed/idgenerator
                        TestIdGenerator.java
  Log:
  - Id Generator moved to its own component sub-project
  - IdGenerator interface moved to commons
  - Test case is now a straight test case.  No need to go through
     all that trouble to build up a container for just one component.
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed-2/components/id-generator/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!--
  Copyright 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.
  -->
  <project>
  <extend>${basedir}/../../project.xml</extend>
    <pomVersion>3</pomVersion>
    <id>jetspeed-id-generator</id>
    <groupId>jetspeed2</groupId>
    <name>Jetspeed-2 ID Generator</name>
    <currentVersion>2.0-a1-dev</currentVersion>
    <package>org.apache.jetspeed</package>
    <description>
  	  Jetspeed ID Generator
    </description>
    <shortDescription>ID Generator</shortDescription>
  
    <repository>                 
      <connection>scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:jakarta-jetspeed-2/components/jetspeed</connection>
      <url>http://cvs.apache.org/viewcvs/jakarta-jetspeed-2/components/jetspeed/</url>
    </repository>
  
    <dependencies>
    	<dependency>
        <id>jetspeed2:jetspeed-commons</id>
        <version>2.0-a1-dev</version>
      </dependency>
      <dependency>
       <id>picocontainer</id>
        <version>1.0-beta-5</version>
      </dependency>
      <dependency>
        <id>commons-logging</id>
        <version>1.0.3</version>
      </dependency>
      <dependency>
        <id>junit</id>
        <version>3.8.1</version>
      </dependency>
      <dependency>
        <id>log4j</id>
        <version>1.2.6</version>
      </dependency>y> 
    </dependencies>
    <build>
      <sourceDirectory>src/java</sourceDirectory>
       <resources>
        <resource>
          <directory>${basedir}/src/java</directory>
          <excludes>
            <exclude>**/*.java</exclude>
          </excludes>
        </resource>
      </resources>
      <unitTestSourceDirectory>src/test</unitTestSourceDirectory>
      <unitTest>
         <includes>
          <include>**/Test*.java</include>
        </includes>
        <excludes>
        </excludes>
        <resources>
          <resource>
            <directory>${basedir}/src/test</directory>
            <excludes>
             <exclude>**/*.java</exclude>
            </excludes>
          </resource>
        </resources>
      </unitTest>
      
    </build>
  
    <reports>
      <report>maven-jdepend-plugin</report>
  <!--
      <report>maven-checkstyle-plugin</report>
  -->
  <!--
      <report>maven-pmd-plugin</report>
      <report>maven-changelog-plugin</report>
      <report>maven-file-activity-plugin</report>
      <report>maven-developer-activity-plugin</report>
      <report>maven-license-plugin</report>
      <report>maven-javadoc-plugin</report>
      <report>maven-jxr-plugin</report>
      <report>maven-junit-report-plugin</report>
      <report>maven-linkcheck-plugin</report>
      <report>maven-tasklist-plugin</report>
  -->
    </reports>  
  </project>
  
  
  
  1.1                  jakarta-jetspeed-2/components/id-generator/project.properties
  
  Index: project.properties
  ===================================================================
  # Copyright 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.
  
  # Remote repos
  maven.repo.remote = http://www.bluesunrise.com/maven/, http://www.ibiblio.org/maven/,http://dist.codehaus.org
  
  # Display the date on the Maven web site
  maven.xdoc.date = left
  
  # Display the maven version the web site is documenting
  maven.xdoc.version = ${pom.currentVersion}
  
  maven.checkstyle.header.file=${basedir}/../../checkstyle.license
  maven.checkstyle.properties=${basedir}/../../checkstyle.xml
  
  maven.license.licenseFile=${basedir}/../../LICENSE.TXT
  
  maven.compile.deprecation=on
  
  # Include private method and field in Javadoc.
  maven.javadoc.private=true
  
  # Removed the rule ${plugin.resources}/rulesets/naming.xml from the default
  # maven.pmd.rulesetfiles.  This is because the LongVariableName rule is to
  # restrictive.  We need to increase the limit from 12 to 20
  maven.pmd.rulesetfiles=${plugin.resources}/rulesets/strings.xml,${plugin.resources}/rulesets/junit.xml,${plugin.resources}/rulesets/braces.xml,${plugin.resources}/rulesets/basic.xml,${plugin.resources}/rulesets/unusedcode.xml,${plugin.resources}/rulesets/design.xml,${plugin.resources}/rulesets/imports.xml,${plugin.resources}/rulesets/codesize.xml
  
  # Include private method and field in Javadoc.
  maven.multiproject.type=jar
  
  maven.junit.fork=true
  
  
  
  
  1.1                  jakarta-jetspeed-2/components/id-generator/maven.xml
  
  Index: maven.xml
  ===================================================================
  <!--
  Copyright 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.
  -->
  <project default="java:jar"
           xmlns:j="jelly:core" 
           xmlns:define="jelly:define"
           xmlns:reactor="reactor">
  
    <!-- Target of maven test:single test -->
    <property name='testcase' value='org.apache.jetspeed.idgenerator.TestIdGenerator'/>

    
     <goal name="deployJar">
    	<attainGoal name="jar:install"/>
    	<copy file="${basedir}/target/${maven.final.name}.jar" todir="${deploy.war.dir}/jetspeed/WEB-INF/lib"/>
    </goal>
  
  </project>
  
  
  
  1.1                  jakarta-jetspeed-2/components/id-generator/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  *.log
  target
  
  
  
  1.1                  jakarta-jetspeed-2/components/id-generator/src/java/org/apache/jetspeed/idgenerator/JetspeedIdGenerator.java
  
  Index: JetspeedIdGenerator.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.idgenerator;
  
  
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.picocontainer.Startable;
  
  /**
   * Simple implementation of the IdGeneratorService.
   *
   * @author <a href="mailto:paulsp@apache.org">Paul Spencer</a>
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: JetspeedIdGenerator.java,v 1.1 2004/05/19 19:14:22 weaver Exp $
   */
  public class JetspeedIdGenerator implements IdGenerator, Startable
  {
      private final static Log log = LogFactory.getLog(JetspeedIdGenerator.class);
  
      // default configuration values
      private final static long DEFAULT_CONFIG_COUNTER_START = 0x10000;
      private final static String DEFAULT_CONFIG_PEID_PREFIX = "P-";
      private final static String DEFAULT_CONFIG_PEID_SUFFIX = "";
  
      // configuration parameters
      private String peidPrefix = null;
      private String peidSuffix = null;
      protected long idCounter;
  
      public JetspeedIdGenerator()
      {
          this.idCounter = DEFAULT_CONFIG_COUNTER_START;
          this.peidPrefix = DEFAULT_CONFIG_PEID_PREFIX;
          this.peidSuffix = DEFAULT_CONFIG_PEID_SUFFIX;         
      }
  
      public JetspeedIdGenerator(long counterStart)
      {
          this.idCounter = counterStart;
          this.peidPrefix = DEFAULT_CONFIG_PEID_PREFIX;
          this.peidSuffix = DEFAULT_CONFIG_PEID_SUFFIX; 
      }
  
      public JetspeedIdGenerator(long counterStart, String prefix, String suffix)
      {
          this.idCounter = counterStart;
          this.peidPrefix = prefix;
          this.peidSuffix = suffix; 
      }
      
      public void start() 
      {
          log.info( "Start JetspeedIdGenerator");        
       }
  
      public void stop() 
      {
          log.info( "Shutdown for JetspeedIdGenerator called. idCounter = "
               + idCounter + " (" + Long.toHexString(idCounter) + ")" ); 
      }
  
      /**
       * Generate a Unique PEID
       * @return Unique PEID
       */
      public String getNextPeid()
      {
          long newid;
  
          synchronized(JetspeedIdGenerator.class)
          {
              newid = idCounter++;
          }
          
          return peidPrefix + Long.toHexString(System.currentTimeMillis()) + "-" 
                 + Long.toHexString(newid) + peidSuffix;
      }
      
  }
  
  
  
  1.1                  jakarta-jetspeed-2/components/id-generator/src/test/org/apache/jetspeed/idgenerator/TestIdGenerator.java
  
  Index: TestIdGenerator.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.idgenerator;
  
  // Java imports
  import java.util.HashMap;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  /**
   * TestIdGenerator
   *
   * @author <a href="paulsp@apache.org">Paul Spencer</a>
   * @version $Id: TestIdGenerator.java,v 1.1 2004/05/19 19:14:22 weaver Exp $
   */
  public class TestIdGenerator extends TestCase
  {
      
      private static int ID_TEST_TRIES = 10000;
      
     
      /**
       * Start the tests.
       *
       * @param args the arguments. Not used
       */
      public static void main(String args[]) 
      {
          junit.awtui.TestRunner.main( new String[] { TestIdGenerator.class.getName() } );
      }
   
      /**
       * 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( TestIdGenerator.class );
      }
      
      /**
       * Simple test that verify the PEID are unique.  This test will generate
       * <CODE>ID_TEST_TRIES<CODE> PEIDs.  It will test for a NULL PEID.
       *
       * Granted, passing this test does <B>not</B> guarantee that a duplicate
       * PEID will not be generated.
       *
       * @throws Exception
       */
      public void testVerifyUniquePeid() throws Exception
      {
          IdGenerator generator = new JetspeedIdGenerator(65536, "P-", "");
          
          HashMap generatedIds = new HashMap( ID_TEST_TRIES + 1);
          String  newId;
          
          // Add a NULL  to verify a NULL is not being generated.
          generatedIds.put(null, null);
          
          for (int counter = 1; counter <= ID_TEST_TRIES; counter++)
          {
              newId = generator.getNextPeid();
              assertTrue( "PEID already generated. PEID = " + newId, !generatedIds.containsKey(newId));
              generatedIds.put(newId, null);
          }
      }
  
      /**
       * Simple test that verify the PEIDs are increasing. Although this is not a 
       * requirement of the IdGenerator, it is recommended
       *
       * @throws Exception
       */
      public void testVerifyIncreasingPeid() throws Exception
      {
          IdGenerator generator = new JetspeedIdGenerator(65536, "P-", "");
          assertNotNull("idgenerator service is null", generator);            
          
          String  newId;
          String  lastId = null;
          
          for (int counter = 1; counter <= ID_TEST_TRIES; counter++)
          {
              newId = generator.getNextPeid();
              if (lastId == null)
              {
                  lastId = newId;
                  continue;
              }
              assertTrue( "PEID is not greater then last generated PEID. PEID = " + newId,
(lastId.compareTo(newId)<0));
              lastId = newId;
          }
      }
  }
  
  
  

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


Mime
View raw message