]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-534: Replaced inappropriate references to IllegalArgumentExceptions with BadRe...
authorAron Roberts <aron@socrates.berkeley.edu>
Thu, 5 Nov 2009 03:55:01 +0000 (03:55 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Thu, 5 Nov 2009 03:55:01 +0000 (03:55 +0000)
16 files changed:
services/id/service/src/main/java/org/collectionspace/services/id/AlphabeticIDGeneratorPart.java
services/id/service/src/main/java/org/collectionspace/services/id/IDGeneratorPart.java
services/id/service/src/main/java/org/collectionspace/services/id/IDGeneratorSerializer.java
services/id/service/src/main/java/org/collectionspace/services/id/IDServiceJdbcImpl.java
services/id/service/src/main/java/org/collectionspace/services/id/NumericIDGeneratorPart.java
services/id/service/src/main/java/org/collectionspace/services/id/SettableIDGenerator.java
services/id/service/src/main/java/org/collectionspace/services/id/StringIDGeneratorPart.java
services/id/service/src/main/java/org/collectionspace/services/id/UUIDGeneratorPart.java
services/id/service/src/main/java/org/collectionspace/services/id/YearIDGeneratorPart.java
services/id/service/src/test/java/org/collectionspace/services/id/test/AlphabeticIDGeneratorPartTest.java
services/id/service/src/test/java/org/collectionspace/services/id/test/BaseIDGeneratorTest.java
services/id/service/src/test/java/org/collectionspace/services/id/test/IDGeneratorSerializerTest.java
services/id/service/src/test/java/org/collectionspace/services/id/test/IDServiceJdbcImplTest.java
services/id/service/src/test/java/org/collectionspace/services/id/test/NumericIDGeneratorPartTest.java
services/id/service/src/test/java/org/collectionspace/services/id/test/StringIDGeneratorPartTest.java
services/id/service/src/test/java/org/collectionspace/services/id/test/YearIDGeneratorPartTest.java

index 83a1aab6d876f0e0d5c87e0bb93a43ed58389bf8..f23a3055071f7ee88684688e289a3d643c07fe81 100644 (file)
 package org.collectionspace.services.id;
 
 import java.util.Vector;
-
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.collectionspace.services.common.repository.BadRequestException;
+
 /**
  * AlphabeticIDGeneratorPart
  *
@@ -90,7 +91,7 @@ public class AlphabeticIDGeneratorPart implements SequenceIDGeneratorPart {
     *
     * Additionally defaults to an initial value of "a".
     */
-    public AlphabeticIDGeneratorPart() throws IllegalArgumentException {
+    public AlphabeticIDGeneratorPart() throws BadRequestException {
       this(DEFAULT_START_CHAR, DEFAULT_END_CHAR, DEFAULT_INITIAL_VALUE);
     }
 
@@ -106,7 +107,7 @@ public class AlphabeticIDGeneratorPart implements SequenceIDGeneratorPart {
     *                 member of the valid alphabetic sequence.
     */
     public AlphabeticIDGeneratorPart(String initial)
-        throws IllegalArgumentException {
+        throws BadRequestException {
       this(DEFAULT_START_CHAR, DEFAULT_END_CHAR, initial);
     }
     
@@ -121,12 +122,12 @@ public class AlphabeticIDGeneratorPart implements SequenceIDGeneratorPart {
     *                 member of the valid aphabetic sequence.
     */
     public AlphabeticIDGeneratorPart(String sequenceStart, String sequenceEnd,
-        String initial) throws IllegalArgumentException {
+        String initial) throws BadRequestException {
       
         // Validate and store the start character in the character sequence.
       
         if (sequenceStart == null || sequenceStart.equals("")) {
-            throw new IllegalArgumentException(
+            throw new BadRequestException(
               "Start character in the character sequence must not be " +
               "null or empty");
         }
@@ -136,7 +137,7 @@ public class AlphabeticIDGeneratorPart implements SequenceIDGeneratorPart {
         } else if (false) {
           // Handle representations of Unicode code points here
         } else {
-            throw new IllegalArgumentException(
+            throw new BadRequestException(
               "Start character must be one character in length");
               // "Start character must be one character in length or
               // a Unicode value such as '\u0000'");
@@ -145,7 +146,7 @@ public class AlphabeticIDGeneratorPart implements SequenceIDGeneratorPart {
         // Validate and store the end character in the character sequence.
         
         if (sequenceEnd == null || sequenceEnd.equals("")) {
-            throw new IllegalArgumentException(
+            throw new BadRequestException(
                 "End character in the character sequence must not be " +
                 "null or empty");
         }
@@ -155,14 +156,14 @@ public class AlphabeticIDGeneratorPart implements SequenceIDGeneratorPart {
         } else if (false) {
           // Handle representations of Unicode code points here
         } else {
-            throw new IllegalArgumentException(
+            throw new BadRequestException(
               "End character must be one character in length");
               // "End character must be one character in length or
               // a Unicode value such as '\u0000'");
         }
     
         if (this.endChar <= this.startChar) {
-            throw new IllegalArgumentException(
+            throw new BadRequestException(
               "End (last) character in the character sequence must be " +
               "greater than the start character");
         }
@@ -170,7 +171,7 @@ public class AlphabeticIDGeneratorPart implements SequenceIDGeneratorPart {
         // Validate and store the initial value of this identifier.
 
         if (initial == null || initial.equals("")) {
-            throw new IllegalArgumentException("Initial value must not be " +
+            throw new BadRequestException("Initial value must not be " +
                 "null or empty");
         }
         
@@ -193,7 +194,7 @@ public class AlphabeticIDGeneratorPart implements SequenceIDGeneratorPart {
                 this.initialValue.add(new Character(ch));
             // Otherwise, we've detected a character not in the sequence.
             } else {
-                throw new IllegalArgumentException(
+                throw new BadRequestException(
                     "character " + "\'" + ch + "\'" + " is not valid");
             }
           
@@ -207,13 +208,13 @@ public class AlphabeticIDGeneratorPart implements SequenceIDGeneratorPart {
     }
 
     @Override
-    public void setCurrentID(String value) throws IllegalArgumentException {
+    public void setCurrentID(String value) throws BadRequestException {
     
         // @TODO Much of this code is copied from the main constructor,
         // and may be ripe for refactoring.
       
         if (value == null || value.equals("")) {
-            throw new IllegalArgumentException("Initial value must not be " +
+            throw new BadRequestException("Initial value must not be " +
                 "null or empty");
         }
         
@@ -237,7 +238,7 @@ public class AlphabeticIDGeneratorPart implements SequenceIDGeneratorPart {
                 v.add(new Character(ch));
             // Otherwise, we've detected a character not in the sequence.
             } else {
-                throw new IllegalArgumentException(
+                throw new BadRequestException(
                     "character " + "\'" + ch + "\'" + " is not valid");
             }
           
index 4193c4eb101f821e4a90e257e09daed8216ce808..901fbb01a343c28edb1daf792f5b0570a3a49869 100644 (file)
@@ -29,6 +29,8 @@
  */
 package org.collectionspace.services.id;
 
+import org.collectionspace.services.common.repository.BadRequestException;
+
 public interface IDGeneratorPart {
     
     /**
@@ -45,7 +47,7 @@ public interface IDGeneratorPart {
      *
      * @return  The current value of the ID.
      */
-       public void setCurrentID(String value) throws IllegalArgumentException;
+       public void setCurrentID(String value) throws BadRequestException;
 
     /**
      * Returns a new ID.
index eb14b3008666171d77a94d851881b48c0abafdff..d03faa99273d597bf5c5bc2f9f68eb997b1e1d9a 100644 (file)
@@ -27,6 +27,9 @@ import com.thoughtworks.xstream.XStream;
 import com.thoughtworks.xstream.XStreamException;
 import com.thoughtworks.xstream.io.xml.DomDriver;
 
+import org.collectionspace.services.common.repository.BadRequestException;
+
+
 /**
  * IDGeneratorSerializer
  *
@@ -53,13 +56,13 @@ public class IDGeneratorSerializer {
    *
    * @return  A serialized representation of that ID generator.
    *
-   * @throws  IllegalArgumentException if the ID generator cannot be serialized.
+   * @throws  BadRequestException if the ID generator cannot be serialized.
    */
        public static String serialize(SettableIDGenerator generator)
-           throws IllegalArgumentException {
+           throws BadRequestException {
        
          if (generator == null) {
-           throw new IllegalArgumentException("ID generator cannot be null.");
+           throw new BadRequestException("ID generator cannot be null.");
          }
   
     XStream xstream = new XStream(new DomDriver()); 
@@ -68,7 +71,7 @@ public class IDGeneratorSerializer {
     try {
       serializedGenerator = xstream.toXML(generator);
     } catch (XStreamException e) {
-           throw new IllegalArgumentException(
+           throw new BadRequestException(
              "Could not convert ID generator to XML for storage in database.");
     }
     
@@ -85,13 +88,13 @@ public class IDGeneratorSerializer {
    *
    * @return  The ID generator deserialized as a Java object.
    *
-   * @throws  IllegalArgumentException if the ID generator cannot be deserialized.
+   * @throws  BadRequestException if the ID generator cannot be deserialized.
    */
        public static SettableIDGenerator deserialize(String serializedGenerator)
-         throws IllegalArgumentException {
+         throws BadRequestException {
 
          if (serializedGenerator == null || serializedGenerator.equals("")) {
-           throw new IllegalArgumentException("ID generator cannot be null or empty.");
+           throw new BadRequestException("ID generator cannot be null or empty.");
          }
 
     XStream xstream = new XStream(new DomDriver());
@@ -100,7 +103,7 @@ public class IDGeneratorSerializer {
     try {
       generator = (SettableIDGenerator) xstream.fromXML(serializedGenerator);
     } catch (XStreamException e) {
-           throw new IllegalArgumentException(
+           throw new BadRequestException(
              "Could not understand or parse this representation of an ID generator.");
     }
 
index d63e2d552252f2f0d314a6bd46729824d1bda238..5355526555ff8970e422e681369f363b1299044f 100644 (file)
@@ -86,9 +86,7 @@ import java.sql.Statement;
 
 // May at some point instead use
 // org.jboss.resteasy.spi.NotFoundException
-import java.util.ArrayList;
 import java.util.LinkedHashMap;
-import java.util.List;
 import java.util.Map;
 import org.collectionspace.services.common.repository.BadRequestException;
 import org.collectionspace.services.common.repository.DocumentNotFoundException;
@@ -430,8 +428,8 @@ public class IDServiceJdbcImpl implements IDService {
                String serializedGenerator = "";
                try {
                        serializedGenerator = IDGeneratorSerializer.serialize(generator);
-               } catch (IllegalArgumentException e) {
-                       throw new BadRequestException(e);
+               } catch (BadRequestException e) {
+                       throw e;
                }
                
                try {
@@ -726,8 +724,8 @@ public class IDServiceJdbcImpl implements IDService {
                String serializedGenerator = "";
                try {
                        serializedGenerator = IDGeneratorSerializer.serialize(generator);
-               } catch (IllegalArgumentException e) {
-                       throw new BadRequestException(e);
+               } catch (BadRequestException e) {
+                       throw e;
                }
        
                try {
index d5a1a6fd3bc7065c38621ef361bd22fa55f84445..38621cbea3a81499f1a57d786a39566fec55c8c7 100644 (file)
@@ -30,6 +30,8 @@ package org.collectionspace.services.id;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.collectionspace.services.common.repository.BadRequestException;
+
 /**  
  * NumericIDGeneratorPart
  *
@@ -52,7 +54,7 @@ public class NumericIDGeneratorPart implements SequenceIDGeneratorPart {
     /**
      * Constructor using defaults for initial value and maximum length.
      */
-    public NumericIDGeneratorPart() throws IllegalArgumentException {
+    public NumericIDGeneratorPart() throws BadRequestException {
         this(Long.toString(DEFAULT_INITIAL_VALUE),
             Long.toString(DEFAULT_MAX_LENGTH));
     }
@@ -63,7 +65,7 @@ public class NumericIDGeneratorPart implements SequenceIDGeneratorPart {
      * @param initialValue  The initial value of the numeric ID.
      */
     public NumericIDGeneratorPart(String initialValue)
-        throws IllegalArgumentException {
+        throws BadRequestException {
         this(initialValue, Long.toString(DEFAULT_MAX_LENGTH));
     }
 
@@ -75,27 +77,27 @@ public class NumericIDGeneratorPart implements SequenceIDGeneratorPart {
      * @param maxLength  The maximum String length for generated IDs.
      */
     public NumericIDGeneratorPart(String initialValue, String maxLength)
-        throws IllegalArgumentException {
+        throws BadRequestException {
 
         if (maxLength == null || maxLength.equals("")) {
-            throw new IllegalArgumentException(
+            throw new BadRequestException(
                 "Initial ID value must not be null or empty");
         }
         try {
             this.maxLength = Long.parseLong(maxLength);
         } catch (NumberFormatException e) {
-            throw new IllegalArgumentException(
+            throw new BadRequestException(
                 "Maximum ID length must be parseable as a number");
         }
         if (initialValue == null || initialValue.equals("")) {
-            throw new IllegalArgumentException(
+            throw new BadRequestException(
                 "Initial ID value must not be null or empty");
         }
         
         try {
             long initVal = Long.parseLong(initialValue.trim());
             if ( initVal < 0 ) {
-                throw new IllegalArgumentException(
+                throw new BadRequestException(
                     "Initial ID value should be zero (0) or greater");
             }
             String initValStr = Long.toString(initVal);
@@ -106,10 +108,10 @@ public class NumericIDGeneratorPart implements SequenceIDGeneratorPart {
             }
             this.initialValue = initVal;
         } catch (NullPointerException e) {
-            throw new IllegalArgumentException(
+            throw new BadRequestException(
                 "Initial ID value should not be null");
         } catch (NumberFormatException e) {
-            throw new IllegalArgumentException(
+            throw new BadRequestException(
                 "Initial ID value must be parseable as a number");
         }
 
@@ -121,20 +123,20 @@ public class NumericIDGeneratorPart implements SequenceIDGeneratorPart {
     }
 
     @Override
-    public void setCurrentID(String value) throws IllegalArgumentException {
+    public void setCurrentID(String value) throws BadRequestException {
 
       // @TODO Much of this code is copied from the main constructor,
       // and may be ripe for refactoring.
 
         if (value == null || value.equals("")) {
-            throw new IllegalArgumentException(
+            throw new BadRequestException(
                 "ID value must not be null or empty");
         }
         
         try {
             long currVal = Long.parseLong(value.trim());
             if ( currVal < 0 ) {
-                throw new IllegalArgumentException(
+                throw new BadRequestException(
                     "ID value should be zero (0) or greater");
             }
             String currValStr = Long.toString(currVal);
@@ -145,10 +147,10 @@ public class NumericIDGeneratorPart implements SequenceIDGeneratorPart {
             }
             this.currentValue = currVal;
         } catch (NullPointerException e) {
-            throw new IllegalArgumentException(
+            throw new BadRequestException(
                 "ID value should not be null");
         } catch (NumberFormatException e) {
-            throw new IllegalArgumentException(
+            throw new BadRequestException(
                 "ID value must be parseable as a number");
         }
     }
index bf70510d77e661775b3fa9b9d213f900d19b110f..05bd355f492af36ef6692a936527f583499e69bc 100644 (file)
 package org.collectionspace.services.id;
 
 import java.util.Vector;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import org.collectionspace.services.common.repository.BadRequestException;
 
 /**
  * SettableIDGenerator
@@ -91,7 +94,7 @@ public class SettableIDGenerator extends BaseIDGenerator {
      * @return  The current value of this ID.
      */
     public String getCurrentID(String value)
-        throws IllegalArgumentException {
+        throws BadRequestException {
 
       if (value == null) return value;
       
@@ -125,7 +128,7 @@ public class SettableIDGenerator extends BaseIDGenerator {
         // If the supplied ID doesn't partly match the pattern,
         // throw an Exception.
         if (matchedParts == 0) {
-            throw new IllegalArgumentException("Supplied ID does not match " +
+            throw new BadRequestException("Supplied ID does not match " +
                 "this ID pattern.");
         }
 
@@ -136,7 +139,7 @@ public class SettableIDGenerator extends BaseIDGenerator {
         // throw an Exception.  (This error condition should likely
         // never be reached, but it's here as a guard.)
         if (! matcher.matches()) {
-            throw new IllegalArgumentException("Supplied ID does not match " +
+            throw new BadRequestException("Supplied ID does not match " +
                 "this ID pattern.");
         }
         
@@ -146,7 +149,11 @@ public class SettableIDGenerator extends BaseIDGenerator {
         IDGeneratorPart currentPart;
         for (int i = 1; i <= matchedParts; i++) {
             currentPart = this.parts.get(i - 1);
-            currentPart.setCurrentID(matcher.group(i));
+            try {
+                currentPart.setCurrentID(matcher.group(i));
+            } catch (BadRequestException ex) {
+                throw new BadRequestException("Error setting current ID in ID part.");
+            }
         }
 
         // Obtain the initial value of the next IDGeneratorPart, and
@@ -189,10 +196,10 @@ public class SettableIDGenerator extends BaseIDGenerator {
      * @return  An new ID. 
      */
     public String newID(String value)
-        throws IllegalStateException, IllegalArgumentException {
+        throws IllegalStateException, BadRequestException {
 
         if (value == null) { 
-            throw new IllegalArgumentException("Supplied ID cannot be null.");
+            throw new BadRequestException("Supplied ID cannot be null.");
         }
         
         Pattern pattern = Pattern.compile(getRegex());
@@ -201,7 +208,7 @@ public class SettableIDGenerator extends BaseIDGenerator {
         // If the supplied ID doesn't entirely match the pattern,
         // throw an Exception.
         if (! matcher.matches()) {
-            throw new IllegalArgumentException(
+            throw new BadRequestException(
                 "Supplied ID does not match this ID pattern.");
         }
         
index c7abc67ed56b3df517227d4074f86c9579df4c12..fc2e5179d375339c969537122f4303b1e7dc3aea 100644 (file)
@@ -30,6 +30,7 @@ package org.collectionspace.services.id;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
+import org.collectionspace.services.common.repository.BadRequestException;
 
 /**
  * StringIDGeneratorPart
@@ -46,10 +47,10 @@ public class StringIDGeneratorPart implements IDGeneratorPart,
     private String currentValue = null;
     
     public StringIDGeneratorPart(String initialValue)
-        throws IllegalArgumentException {
+        throws BadRequestException {
 
         if (initialValue == null || initialValue.equals("")) {
-            throw new IllegalArgumentException(
+            throw new BadRequestException(
                 "Initial ID value must not be null or empty");
         }
         
@@ -68,9 +69,9 @@ public class StringIDGeneratorPart implements IDGeneratorPart,
         return this.currentValue;
     }
 
-    public void setCurrentID(String value) throws IllegalArgumentException {
+    public void setCurrentID(String value) throws BadRequestException {
         if (value == null || value.equals("")) {
-            throw new IllegalArgumentException(
+            throw new BadRequestException(
             "ID value must not be null or empty");
         }
         this.currentValue = value;
index 83ec2c7a280a01e378dc3ce36fbd1ca25f574a9c..80a3f94fa6053632110b727cf2b33017a92f1e41 100644 (file)
 package org.collectionspace.services.id;
 
 import java.util.UUID;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import org.collectionspace.services.common.repository.BadRequestException;
 
 /**
  * UUIDGeneratorPart
@@ -65,13 +68,13 @@ public class UUIDGeneratorPart implements IDGeneratorPart {
     }
 
     @Override
-    public void setCurrentID(String idValue) throws IllegalArgumentException {
+    public void setCurrentID(String idValue) throws BadRequestException {
                if (idValue == null || idValue.equals("")) {
-                       throw new IllegalArgumentException(
+                       throw new BadRequestException(
                            "Supplied UUID must not be null or empty");
                }
                if (! isValidID(idValue)) {
-                       throw new IllegalArgumentException(
+                       throw new BadRequestException(
                            "Supplied UUID '" + idValue + "' is not valid.");
         }
         this.currentValue = idValue;
@@ -89,7 +92,12 @@ public class UUIDGeneratorPart implements IDGeneratorPart {
     @Override
     public String newID() {
         String newID = UUID.randomUUID().toString();
-        setCurrentID(newID);
+        try {
+            setCurrentID(newID);
+        } catch (BadRequestException ex) {
+            // Do nothing.  There will be no adverse consequences if we
+            // can't set the current ID here.
+        }
         return newID;
     }
 
index f5ec3d036ffb9bdb9b07761f12df30f0a70f91ca..d036e490abcb3c409971f005e03182bb80b250ce 100644 (file)
@@ -43,10 +43,13 @@ package org.collectionspace.services.id;
 
 import java.util.Calendar;
 import java.util.GregorianCalendar;
-
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.collectionspace.services.common.repository.BadRequestException;
+
 /**
  * YearIDGeneratorPart
  *
@@ -64,25 +67,23 @@ public class YearIDGeneratorPart implements IDGeneratorPart {
     // four-digit Gregorian Calendar year dates.
     final static String REGEX_PATTERN = "(\\d{4})";
 
-       public YearIDGeneratorPart() throws IllegalArgumentException {
-               this.currentValue = getCurrentYear();
+       public YearIDGeneratorPart() {
        }
        
-       public YearIDGeneratorPart(String yearValue)
-           throws IllegalArgumentException {
+       public YearIDGeneratorPart(String yearValue) throws BadRequestException {
         setCurrentID(yearValue);
        }
 
     @Override
-       public void setCurrentID(String yearValue) throws IllegalArgumentException {
+       public void setCurrentID(String yearValue) throws BadRequestException {
                if (yearValue == null || yearValue.equals("")) {
-                       throw new IllegalArgumentException(
+                       throw new BadRequestException(
                            "Supplied year must not be null or empty");
                }
                // NOTE: Validation currently is based on a
                // hard coded year format and calendar system.
                if (! isValidID(yearValue)) {
-                       throw new IllegalArgumentException(
+                       throw new BadRequestException(
                            "Supplied year '" + yearValue + "' is not valid.");
                }
                this.currentValue = yearValue;
@@ -90,15 +91,17 @@ public class YearIDGeneratorPart implements IDGeneratorPart {
 
     @Override
        public String getCurrentID() {
-        if (this.currentValue == null || this.currentValue.equals("")) {
-            setCurrentID(getCurrentYear());
+        String currentYear = "";
+        if (this.currentValue == null || this.currentValue.trim().isEmpty()) {
+            currentYear = getCurrentYear();
+        } else {
+            currentYear = this.currentValue;
         }
-               return this.currentValue;
+               return currentYear;
        }
 
     @Override
     public String newID() {
-        setCurrentID(getCurrentYear());
                return getCurrentID();
     }
 
index 9fffb9d7027c370271023c0fbdbbb7725d469374..594f9181716ae217340b448e9bd9a72782720b49 100644 (file)
@@ -23,6 +23,7 @@
 
 package org.collectionspace.services.id.test;
 
+import org.collectionspace.services.common.repository.BadRequestException;
 import org.collectionspace.services.id.AlphabeticIDGeneratorPart;
 import org.collectionspace.services.id.SequenceIDGeneratorPart;
 
@@ -41,7 +42,7 @@ public class AlphabeticIDGeneratorPartTest extends TestCase {
 
        SequenceIDGeneratorPart part;
        
-       public void testNextIDLowercase() {
+       public void testNextIDLowercase() throws BadRequestException {
 
                part = new AlphabeticIDGeneratorPart("a");
                assertEquals("a", part.newID());
@@ -55,7 +56,7 @@ public class AlphabeticIDGeneratorPartTest extends TestCase {
 
 }
 
-       public void testnewIDLowercase2Chars() {
+       public void testnewIDLowercase2Chars() throws BadRequestException {
 
                part = new AlphabeticIDGeneratorPart("aa");
                assertEquals("aa", part.newID());
@@ -69,7 +70,7 @@ public class AlphabeticIDGeneratorPartTest extends TestCase {
 
        }
 
-       public void testnewIDLowercase2CharsRolloverFirst() {
+       public void testnewIDLowercase2CharsRolloverFirst() throws BadRequestException {
 
                part = new AlphabeticIDGeneratorPart("ay");
                assertEquals("ay", part.newID());
@@ -79,7 +80,7 @@ public class AlphabeticIDGeneratorPartTest extends TestCase {
 
     }
        
-       public void testnewIDUppercase() {
+       public void testnewIDUppercase() throws BadRequestException {
                
                part = new AlphabeticIDGeneratorPart("A", "Z", "A");
                assertEquals("A", part.newID());
@@ -93,7 +94,7 @@ public class AlphabeticIDGeneratorPartTest extends TestCase {
 
     }
 
-       public void testnewIDUppercase2Chars() {
+       public void testnewIDUppercase2Chars() throws BadRequestException {
 
                part = new AlphabeticIDGeneratorPart("A", "Z", "AA");
                assertEquals("AA", part.newID());
@@ -107,7 +108,7 @@ public class AlphabeticIDGeneratorPartTest extends TestCase {
                        
        }
 
-       public void testnewIDUppercase2CharsRolloverFirst() {
+       public void testnewIDUppercase2CharsRolloverFirst() throws BadRequestException {
 
                part = new AlphabeticIDGeneratorPart("A", "Z", "AY");
                assertEquals("AY", part.newID());
@@ -117,21 +118,21 @@ public class AlphabeticIDGeneratorPartTest extends TestCase {
 
   }
 
-       public void testInitialLowercase() {
+       public void testInitialLowercase() throws BadRequestException {
                
                part = new AlphabeticIDGeneratorPart("aaa");
                assertEquals("aaa", part.getInitialID());
                
        }
 
-       public void testInitialUppercase() {
+       public void testInitialUppercase() throws BadRequestException {
                
                part = new AlphabeticIDGeneratorPart("A", "Z", "AZ");
                assertEquals("AZ", part.getInitialID());
                
        }
 
-       public void testCurrentLowercase() {
+       public void testCurrentLowercase() throws BadRequestException {
                
                part = new AlphabeticIDGeneratorPart("aaa");
                assertEquals("aaa", part.getCurrentID());
@@ -143,7 +144,7 @@ public class AlphabeticIDGeneratorPartTest extends TestCase {
                
        }
 
-       public void testCurrentUppercase() {
+       public void testCurrentUppercase() throws BadRequestException {
                
                part = new AlphabeticIDGeneratorPart("A", "Z", "A");
                assertEquals("A", part.getCurrentID());
@@ -155,7 +156,7 @@ public class AlphabeticIDGeneratorPartTest extends TestCase {
                
        }       
 
-       public void testOverflowLowercase() {
+       public void testOverflowLowercase() throws BadRequestException {
        
         part = new AlphabeticIDGeneratorPart("zx");
         assertEquals("zx", part.newID());
@@ -165,7 +166,7 @@ public class AlphabeticIDGeneratorPartTest extends TestCase {
                
        }
 
-       public void testOverflowUppercase() {
+       public void testOverflowUppercase() throws BadRequestException {
        
         part = new AlphabeticIDGeneratorPart("A", "Z", "X");
         assertEquals("X", part.newID());
@@ -178,8 +179,8 @@ public class AlphabeticIDGeneratorPartTest extends TestCase {
        public void testNonAlphabeticInitialValue() {
                try {
                        part = new AlphabeticIDGeneratorPart("&*432");
-                       fail("Should have thrown IllegalArgumentException here");
-               } catch (IllegalArgumentException expected) {
+                       fail("Should have thrown BadRequestException here");
+               } catch (BadRequestException expected) {
                        // This Exception should be thrown, and thus the test should pass.
                }
        }
@@ -187,8 +188,8 @@ public class AlphabeticIDGeneratorPartTest extends TestCase {
        public void testNullInitialValue() {
                try {
                        part = new AlphabeticIDGeneratorPart(null);
-                       fail("Should have thrown IllegalArgumentException here");
-               } catch (IllegalArgumentException expected) {
+                       fail("Should have thrown BadRequestException here");
+               } catch (BadRequestException expected) {
                        // This Exception should be thrown, and thus the test should pass.
                }
        }
@@ -196,8 +197,8 @@ public class AlphabeticIDGeneratorPartTest extends TestCase {
        public void testEmptyStringInitialValue() {
                try {
                        part = new AlphabeticIDGeneratorPart("");
-                       fail("Should have thrown IllegalArgumentException here");
-               } catch (IllegalArgumentException expected) {
+                       fail("Should have thrown BadRequestException here");
+               } catch (BadRequestException expected) {
                        // This Exception should be thrown, and thus the test should pass.
                }
        }
@@ -205,13 +206,13 @@ public class AlphabeticIDGeneratorPartTest extends TestCase {
        public void testAllSpaceCharsInitialValue() {
                try {
                        part = new AlphabeticIDGeneratorPart("  ");
-                       fail("Should have thrown IllegalArgumentException here");
-               } catch (IllegalArgumentException expected) {
+                       fail("Should have thrown BadRequestException here");
+               } catch (BadRequestException expected) {
                        // This Exception should be thrown, and thus the test should pass.
                }
        }
 
-       public void testIsValidIDDefaultSeries() {
+       public void testIsValidIDDefaultSeries() throws BadRequestException {
        
                part = new AlphabeticIDGeneratorPart();
 
@@ -223,7 +224,7 @@ public class AlphabeticIDGeneratorPartTest extends TestCase {
                
        }
 
-       public void testIsValidIDConstrainedLowerCaseSeries() {
+       public void testIsValidIDConstrainedLowerCaseSeries() throws BadRequestException {
        
                part = new AlphabeticIDGeneratorPart("a", "f", "a");
                
@@ -238,7 +239,7 @@ public class AlphabeticIDGeneratorPartTest extends TestCase {
                
        }
 
-       public void testIsValidIDConstrainedUppercaseSeries() {
+       public void testIsValidIDConstrainedUppercaseSeries() throws BadRequestException {
        
                part = new AlphabeticIDGeneratorPart("A", "F", "A");
 
index 9383955fc8d7e582d7d20c1d229a78db581eb989..7e218d492aac06908c54e6c4d0be1ac582bb6c89 100644 (file)
@@ -25,6 +25,7 @@ package org.collectionspace.services.id.test;
 
 import java.util.Vector;
 import junit.framework.TestCase;
+import org.collectionspace.services.common.repository.BadRequestException;
 import org.collectionspace.services.id.*;
 
 /**    
@@ -40,7 +41,7 @@ public class BaseIDGeneratorTest extends TestCase {
     
     final static String CURRENT_YEAR = YearIDGeneratorPart.getCurrentYear();
 
-    // Note: tests may fail with IllegalArgumentException
+    // Note: tests may fail with BadRequestException
     // if any initialization of new IDParts fails
     // due to invalid arguments passed to their constructors.
 
@@ -56,7 +57,7 @@ public class BaseIDGeneratorTest extends TestCase {
     
     // Test adding parts and retrieving current IDs
 
-    public void testCurrentIDViaVector() {
+    public void testCurrentIDViaVector() throws BadRequestException {
         Vector parts = new Vector();
         BaseIDGenerator gen;
 
@@ -98,7 +99,7 @@ public class BaseIDGeneratorTest extends TestCase {
         assertEquals("2009.1-a", gen.getCurrentID());
     }
 
-    public void testCurrentIDViaAdd() {
+    public void testCurrentIDViaAdd() throws BadRequestException {
         generator.clear();
         generator.add(new YearIDGeneratorPart("2009"));
         generator.add(new StringIDGeneratorPart("."));
@@ -118,7 +119,7 @@ public class BaseIDGeneratorTest extends TestCase {
     
     // Test generating new IDs from a single part
 
-    public void testNewAlphabeticLowercaseID() {
+    public void testNewAlphabeticLowercaseID() throws BadRequestException {
         generator.clear();
         generator.add(new AlphabeticIDGeneratorPart("a"));
         assertEquals("a", generator.newID());
@@ -145,7 +146,7 @@ public class BaseIDGeneratorTest extends TestCase {
         assertEquals("aza", generator.newID());
     }
 
-    public void testNewAlphabeticUppercaseID() {
+    public void testNewAlphabeticUppercaseID() throws BadRequestException {
         generator.clear();
         generator.add(new AlphabeticIDGeneratorPart("A", "Z", "A"));
         assertEquals("A", generator.newID());
@@ -172,7 +173,7 @@ public class BaseIDGeneratorTest extends TestCase {
         assertEquals("AZA", generator.newID());
     }
 
-    public void testNewNumericID() {
+    public void testNewNumericID() throws BadRequestException {
         generator.clear();
         generator.add(new NumericIDGeneratorPart("1"));
         assertEquals("1", generator.newID());
@@ -180,7 +181,7 @@ public class BaseIDGeneratorTest extends TestCase {
         assertEquals("3", generator.newID());
     }
 
-    public void testNewStringID() {
+    public void testNewStringID() throws BadRequestException {
         generator.clear();
         generator.add(new StringIDGeneratorPart("PREFIX"));
         assertEquals("PREFIX", generator.newID());
@@ -216,7 +217,7 @@ public class BaseIDGeneratorTest extends TestCase {
     
     // Test generating new IDs from multiple, mixed parts
 
-    public void testNewMixedID() {
+    public void testNewMixedID() throws BadRequestException {
         generator.clear();
         generator.add(new YearIDGeneratorPart());
         generator.add(new StringIDGeneratorPart("."));
@@ -253,7 +254,7 @@ public class BaseIDGeneratorTest extends TestCase {
         assertEquals(CURRENT_YEAR + ".1.3", generator.newID()); 
     }
 
-    public void testNewMixedIDWithTrailingConstantStringID() {
+    public void testNewMixedIDWithTrailingConstantStringID() throws BadRequestException {
         generator.clear();
         generator.add(new YearIDGeneratorPart());
         generator.add(new StringIDGeneratorPart("."));
@@ -288,7 +289,7 @@ public class BaseIDGeneratorTest extends TestCase {
         assertFalse(generator.isValidID("10000"));
     }
 
-    public void testValidMixedID() {
+    public void testValidMixedID() throws BadRequestException {
         generator.clear();
         generator.add(new YearIDGeneratorPart("2009"));
         generator.add(new StringIDGeneratorPart("."));
@@ -309,7 +310,7 @@ public class BaseIDGeneratorTest extends TestCase {
         assertFalse(generator.isValidID("2009ZZ-AND-1"));
     }
 
-    public void testGetRegex() {
+    public void testGetRegex() throws BadRequestException {
         generator.clear();
         generator.add(new YearIDGeneratorPart("2009"));
         generator.add(new StringIDGeneratorPart("."));
index 1231518ed81b79ec57a7817d240e13d5a4614758..156d36894a051b9a577cac2ac7f2d8462152475f 100644 (file)
@@ -25,6 +25,8 @@ package org.collectionspace.services.id.test;
 
 import org.collectionspace.services.id.*;
 
+import org.collectionspace.services.common.repository.BadRequestException; 
+
 import junit.framework.TestCase;
 import static org.junit.Assert.*;
 
@@ -51,7 +53,7 @@ public class IDGeneratorSerializerTest extends TestCase {
     // @TODO We may want to canonicalize (or otherwise normalize) the
     // expected and actual XML in these tests, to avoid failures resulting
     // from differences in whitespace, etc.
-    public void testSerializeIDGenerator() {
+    public void testSerializeIDGenerator() throws BadRequestException {
       SettableIDGenerator tempGenerator = new SettableIDGenerator();
         assertEquals(DEFAULT_SERIALIZED_ID_GENERATOR,
             IDGeneratorSerializer.serialize(tempGenerator));
@@ -60,8 +62,8 @@ public class IDGeneratorSerializerTest extends TestCase {
     public void testSerializeNullIDGenerator() {
       try {
         String serializedPattern = IDGeneratorSerializer.serialize(null);
-            fail("Should have thrown IllegalArgumentException here");
-        } catch (IllegalArgumentException expected) {
+            fail("Should have thrown BadRequestException here");
+        } catch (BadRequestException expected) {
             // This Exception should be thrown, and thus the test should pass.
         }
     }
@@ -80,8 +82,8 @@ public class IDGeneratorSerializerTest extends TestCase {
       try {
         SettableIDGenerator tempGenerator =
             IDGeneratorSerializer.deserialize(null);
-            fail("Should have thrown IllegalArgumentException here");
-        } catch (IllegalArgumentException expected) {
+            fail("Should have thrown BadRequestException here");
+        } catch (BadRequestException expected) {
             // This Exception should be thrown, and thus the test should pass.
         }
     }
@@ -90,8 +92,8 @@ public class IDGeneratorSerializerTest extends TestCase {
       try {
         IDGenerator tempGenerator =
             IDGeneratorSerializer.deserialize("<invalid_serialized_generator/>");
-            fail("Should have thrown IllegalArgumentException here");
-        } catch (IllegalArgumentException expected) {
+            fail("Should have thrown BadRequestException here");
+        } catch (BadRequestException expected) {
             // This Exception should be thrown, and thus the test should pass.
         }
     }
index 6d9ce14e3ae84a16babc6dea0331ce3aaff3f0f5..b3f7e3c57a546e7406d1dd85655a8a1ce1cb0c1e 100644 (file)
@@ -80,7 +80,7 @@ public class IDServiceJdbcImplTest {
 
     @Test(dependsOnMethods = {"hasRequiredDatabaseTable", "createIDGenerator"})
     public void readIDGenerator() throws DocumentNotFoundException,
-        IllegalArgumentException, IllegalStateException {
+        BadRequestException, IllegalStateException {
 
         instance = jdbc.readIDGenerator(DEFAULT_CSID);
         Assert.assertTrue(instance != null);
@@ -204,7 +204,7 @@ public class IDServiceJdbcImplTest {
 
     // @TODO Read test patterns from external configuration.
     
-    public String getSpectrumEntryNumberGenerator() {
+    public String getSpectrumEntryNumberGenerator() throws BadRequestException {
         
         generator = new SettableIDGenerator();
         generator.add(new StringIDGeneratorPart("E"));
@@ -214,7 +214,7 @@ public class IDServiceJdbcImplTest {
         
     }
 
-    public String getChinAccessionNumberGenerator() {
+    public String getChinAccessionNumberGenerator() throws BadRequestException {
 
         generator = new SettableIDGenerator();
         generator.add(new YearIDGeneratorPart());
index caa2ab9ba4949f2de60c272f418c6ebc4b560836..c21bbf9a3658aa3288b4efb01dc397a7a5fffa7e 100644 (file)
@@ -27,6 +27,7 @@
 
 package org.collectionspace.services.id.test;
 
+import org.collectionspace.services.common.repository.BadRequestException;
 import static org.junit.Assert.fail;
 import junit.framework.TestCase;
 import org.collectionspace.services.id.NumericIDGeneratorPart;
@@ -45,7 +46,7 @@ public class NumericIDGeneratorPartTest extends TestCase {
 
     SequenceIDGeneratorPart part;
 
-    public void testInitialID() {
+    public void testInitialID() throws BadRequestException {
         part = new NumericIDGeneratorPart("0");
         assertEquals("0", part.getInitialID());
 
@@ -56,8 +57,8 @@ public class NumericIDGeneratorPartTest extends TestCase {
     public void testNullInitialValue() {
         try {
             part = new NumericIDGeneratorPart(null);
-            fail("Should have thrown IllegalArgumentException here");
-        } catch (IllegalArgumentException expected) {
+            fail("Should have thrown BadRequestException here");
+        } catch (BadRequestException expected) {
             // This Exception should be thrown, and thus the test should pass.
         }
     }
@@ -65,8 +66,8 @@ public class NumericIDGeneratorPartTest extends TestCase {
     public void testNonLongParseableInitialValue() {
         try {
             part = new NumericIDGeneratorPart("not a long parseable value");
-            fail("Should have thrown IllegalArgumentException here");
-        } catch (IllegalArgumentException expected) {
+            fail("Should have thrown BadRequestException here");
+        } catch (BadRequestException expected) {
             // This Exception should be thrown, and thus the test should pass.
         }
     }
@@ -74,8 +75,8 @@ public class NumericIDGeneratorPartTest extends TestCase {
     public void testNonLongParseableMaxLength() {
         try {
             part = new NumericIDGeneratorPart("1", "not an int parseable value");
-            fail("Should have thrown IllegalArgumentException here");
-        } catch (IllegalArgumentException expected) {
+            fail("Should have thrown BadRequestException here");
+        } catch (BadRequestException expected) {
             // This Exception should be thrown, and thus the test should pass.
         }
     }
@@ -83,13 +84,13 @@ public class NumericIDGeneratorPartTest extends TestCase {
     public void testNegativeInitialValue() {
        try {
             part = new NumericIDGeneratorPart("-1");
-            fail("Should have thrown IllegalArgumentException here");
-        } catch (IllegalArgumentException expected) {
+            fail("Should have thrown BadRequestException here");
+        } catch (BadRequestException expected) {
             // This Exception should be thrown, and thus the test should pass.
         }
     }
 
-    public void testGetCurrentID() {
+    public void testGetCurrentID() throws BadRequestException {
         part = new NumericIDGeneratorPart("0");
         assertEquals("0", part.getCurrentID());
         assertEquals("0", part.newID());
@@ -102,7 +103,7 @@ public class NumericIDGeneratorPartTest extends TestCase {
         assertEquals("25", part.getCurrentID());
     }
 
-    public void testNewID() {
+    public void testNewID() throws BadRequestException {
         part = new NumericIDGeneratorPart("0");        
         assertEquals("0", part.newID());
         assertEquals("1", part.newID());
@@ -121,7 +122,7 @@ public class NumericIDGeneratorPartTest extends TestCase {
         assertEquals("3", part.newID());
     }
 
-    public void testNewIDOverflow() {
+    public void testNewIDOverflow() throws BadRequestException {
 
         try {
             part = new NumericIDGeneratorPart("997", "3");        
@@ -148,7 +149,7 @@ public class NumericIDGeneratorPartTest extends TestCase {
             
     }
 
-    public void testIsValidID() {
+    public void testIsValidID() throws BadRequestException {
         part = new NumericIDGeneratorPart("1");
         assertTrue(part.isValidID("1"));
         part = new NumericIDGeneratorPart("1");
index 5cdbe788be48f42a591bbec3d175a6ea11eced80..9a14be2c4e78035c4751d41b7ed2b361af484f00 100644 (file)
@@ -24,6 +24,7 @@
 package org.collectionspace.services.id.test;
 
 import junit.framework.TestCase;
+import org.collectionspace.services.common.repository.BadRequestException;
 import org.collectionspace.services.id.StoredValueIDGeneratorPart;
 import org.collectionspace.services.id.StringIDGeneratorPart;
 
@@ -42,8 +43,8 @@ public class StringIDGeneratorPartTest extends TestCase {
        public void testNullInitialValue() {
                try {
                        part = new StringIDGeneratorPart(null);
-                       fail("Should have thrown IllegalArgumentException here");
-               } catch (IllegalArgumentException expected) {
+                       fail("Should have thrown BadRequestException here");
+               } catch (BadRequestException expected) {
                        // This Exception should be thrown, and thus the test should pass.
                }
        }
@@ -51,30 +52,30 @@ public class StringIDGeneratorPartTest extends TestCase {
        public void testEmptyInitialValue() {
                try {
                        part = new StringIDGeneratorPart("");
-                       fail("Should have thrown IllegalArgumentException here");
-               } catch (IllegalArgumentException expected) {
+                       fail("Should have thrown BadRequestException here");
+               } catch (BadRequestException expected) {
                        // This Exception should be thrown, and thus the test should pass.
                }
        }
 
-       public void testGetInitialID() {
+       public void testGetInitialID() throws BadRequestException {
                part = new StringIDGeneratorPart("-");
                assertEquals("-", part.getInitialID());
        }
 
-       public void testGetCurrentID() {
+       public void testGetCurrentID() throws BadRequestException {
                part = new StringIDGeneratorPart("- -");
                assertEquals("- -", part.getCurrentID());
        }
        
-       public void testNewID() {
+       public void testNewID() throws BadRequestException {
                part = new StringIDGeneratorPart("E");          
                assertEquals("E", part.newID());        
                part = new StringIDGeneratorPart("XYZ");                
                assertEquals("XYZ", part.newID());              
        }
 
-       public void testIsValidID() {
+       public void testIsValidID() throws BadRequestException, BadRequestException {
                part = new StringIDGeneratorPart("-");
                assertTrue(part.isValidID("-"));
                part = new StringIDGeneratorPart("TE");
index 40b03cb17c2d3c53ec3ce6bf7fd5f2994e330f02..3073dc66786164080bad7114a753bdf32fa3abe5 100644 (file)
@@ -23,6 +23,7 @@
 
 package org.collectionspace.services.id.test;
 
+import org.collectionspace.services.common.repository.BadRequestException;
 import static org.junit.Assert.fail;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
@@ -50,7 +51,7 @@ public class YearIDGeneratorPartTest extends TestCase {
     }
 
 
-    public void testCurrentID() {
+    public void testCurrentID() throws BadRequestException {
 
         part = new YearIDGeneratorPart();
         assertEquals(getCurrentYear(), part.getCurrentID());
@@ -60,7 +61,7 @@ public class YearIDGeneratorPartTest extends TestCase {
 
     }
 
-    public void testSetCurrentID() {
+    public void testSetCurrentID() throws BadRequestException {
 
         part = new YearIDGeneratorPart("1999");
         part.setCurrentID("1999");
@@ -76,15 +77,15 @@ public class YearIDGeneratorPartTest extends TestCase {
 
         try {
           part.setCurrentID(null);
-            fail("Should have thrown IllegalArgumentException here");
-        } catch (IllegalArgumentException expected) {
+            fail("Should have thrown BadRequestException here");
+        } catch (BadRequestException expected) {
             // This Exception should be thrown, and thus the test should pass.
         }
 
         try {
           part.setCurrentID("");
-            fail("Should have thrown IllegalArgumentException here");
-        } catch (IllegalArgumentException expected) {
+            fail("Should have thrown BadRequestException here");
+        } catch (BadRequestException expected) {
             // This Exception should be thrown, and thus the test should pass.
         }
 
@@ -126,12 +127,12 @@ public class YearIDGeneratorPartTest extends TestCase {
     }
 */
 
-    public void testNullInitialValue() {
+    public void testNullInitialValue() throws BadRequestException {
     
         try {
             part = new YearIDGeneratorPart(null);
-            fail("Should have thrown IllegalArgumentException here");
-        } catch (IllegalArgumentException expected) {
+            fail("Should have thrown BadRequestException here");
+        } catch (BadRequestException expected) {
             // This Exception should be thrown, and thus the test should pass.
         }
         
@@ -141,8 +142,8 @@ public class YearIDGeneratorPartTest extends TestCase {
     
         try {
             part = new YearIDGeneratorPart("");
-            fail("Should have thrown IllegalArgumentException here");
-        } catch (IllegalArgumentException expected) {
+            fail("Should have thrown BadRequestException here");
+        } catch (BadRequestException expected) {
             // This Exception should be thrown, and thus the test should pass.
         }