[gatein-commits] gatein SVN: r6079 - in components/wsrp/trunk/producer/src: test/java/org/gatein/registration and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Mar 17 13:22:19 EDT 2011


Author: chris.laprun at jboss.com
Date: 2011-03-17 13:22:19 -0400 (Thu, 17 Mar 2011)
New Revision: 6079

Added:
   components/wsrp/trunk/producer/src/test/java/org/gatein/registration/RegistrationUtilsTestCase.java
Modified:
   components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationUtils.java
Log:
- GTNWSRP-211: fixed improper implementation of RegistrationUtils.validateConsumerAgent and added test case.

Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationUtils.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationUtils.java	2011-03-17 15:49:58 UTC (rev 6078)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationUtils.java	2011-03-17 17:22:19 UTC (rev 6079)
@@ -44,23 +44,37 @@
    }
 
    /**
+    * Per the specification (http://www.oasis-open.org/committees/download.php/18617/wsrp-2.0-spec-pr-01.html#_RegistrationData):
+    * The consumerAgent value MUST start with "productName.majorVersion.minorVersion" where "productName" identifies the
+    * product the Consumer installed for its deployment, and majorVersion and minorVersion are vendor-defined
+    * indications of the version of its product. This string can then contain any additional characters/words the
+    * product or Consumer wish to supply.
+    *
     * @param consumerAgent
     * @throws IllegalArgumentException
     * @since 2.6
     */
-   public static void validateConsumerAgent(String consumerAgent) throws IllegalArgumentException
+   public static void validateConsumerAgent(final String consumerAgent) throws IllegalArgumentException
    {
       ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerAgent, "consumer agent", null);
       char periodChar = '.';
-      int period = consumerAgent.indexOf(periodChar);
+
+      String tmp = consumerAgent.trim();
+
+      int period = tmp.indexOf(periodChar);
       if (period != -1)
       {
-         consumerAgent = consumerAgent.substring(period);
-         period = consumerAgent.indexOf(periodChar);
+         tmp = tmp.substring(period + 1);
+         period = tmp.indexOf(periodChar);
 
          if (period != -1)
          {
-            return;
+            tmp = tmp.substring(period + 1);
+
+            if (tmp.length() > 0)
+            {
+               return;
+            }
          }
       }
 

Added: components/wsrp/trunk/producer/src/test/java/org/gatein/registration/RegistrationUtilsTestCase.java
===================================================================
--- components/wsrp/trunk/producer/src/test/java/org/gatein/registration/RegistrationUtilsTestCase.java	                        (rev 0)
+++ components/wsrp/trunk/producer/src/test/java/org/gatein/registration/RegistrationUtilsTestCase.java	2011-03-17 17:22:19 UTC (rev 6079)
@@ -0,0 +1,74 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.gatein.registration;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class RegistrationUtilsTestCase extends TestCase
+{
+   public void testValidateConsumerAgentStrict()
+   {
+      RegistrationUtils.setStrict(true);
+
+      RegistrationUtils.validateConsumerAgent("foo.bar.baz");
+      RegistrationUtils.validateConsumerAgent("foo.bar.baz.");
+      RegistrationUtils.validateConsumerAgent("foo.bar.baz. ");
+      RegistrationUtils.validateConsumerAgent("foo.bar.baz. dasfsafads");
+
+      checkValidateProperlyRejects("goo");
+      checkValidateProperlyRejects("goo.");
+      checkValidateProperlyRejects("goo.boo");
+      checkValidateProperlyRejects("goo.boo.");
+      checkValidateProperlyRejects("goo.boo. ");
+   }
+
+   private void checkValidateProperlyRejects(String consumerAgent)
+   {
+      try
+      {
+         RegistrationUtils.validateConsumerAgent(consumerAgent);
+         fail("Should have rejected '" + consumerAgent + "' as an invalid Consumer Agent string");
+      }
+      catch (IllegalArgumentException e)
+      {
+         // expected
+      }
+   }
+
+   public void testValidateConsumerAgentLenient()
+   {
+      RegistrationUtils.setStrict(false);
+
+      RegistrationUtils.validateConsumerAgent("foo.bar.baz");
+
+      RegistrationUtils.validateConsumerAgent("goo");
+      RegistrationUtils.validateConsumerAgent("goo.");
+      RegistrationUtils.validateConsumerAgent("goo.boo");
+      RegistrationUtils.validateConsumerAgent("goo.boo.");
+      RegistrationUtils.validateConsumerAgent("goo.boo. ");
+   }
+}



More information about the gatein-commits mailing list