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
*
*
* 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);
}
* member of the valid alphabetic sequence.
*/
public AlphabeticIDGeneratorPart(String initial)
- throws IllegalArgumentException {
+ throws BadRequestException {
this(DEFAULT_START_CHAR, DEFAULT_END_CHAR, initial);
}
* 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");
}
} 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'");
// 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");
}
} 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");
}
// 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");
}
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");
}
}
@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");
}
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");
}
*/
package org.collectionspace.services.id;
+import org.collectionspace.services.common.repository.BadRequestException;
+
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.
import com.thoughtworks.xstream.XStreamException;
import com.thoughtworks.xstream.io.xml.DomDriver;
+import org.collectionspace.services.common.repository.BadRequestException;
+
+
/**
* 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());
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.");
}
*
* @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());
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.");
}
// 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;
String serializedGenerator = "";
try {
serializedGenerator = IDGeneratorSerializer.serialize(generator);
- } catch (IllegalArgumentException e) {
- throw new BadRequestException(e);
+ } catch (BadRequestException e) {
+ throw e;
}
try {
String serializedGenerator = "";
try {
serializedGenerator = IDGeneratorSerializer.serialize(generator);
- } catch (IllegalArgumentException e) {
- throw new BadRequestException(e);
+ } catch (BadRequestException e) {
+ throw e;
}
try {
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.collectionspace.services.common.repository.BadRequestException;
+
/**
* NumericIDGeneratorPart
*
/**
* 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));
}
* @param initialValue The initial value of the numeric ID.
*/
public NumericIDGeneratorPart(String initialValue)
- throws IllegalArgumentException {
+ throws BadRequestException {
this(initialValue, Long.toString(DEFAULT_MAX_LENGTH));
}
* @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);
}
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");
}
}
@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);
}
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");
}
}
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
* @return The current value of this ID.
*/
public String getCurrentID(String value)
- throws IllegalArgumentException {
+ throws BadRequestException {
if (value == null) return value;
// 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.");
}
// 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.");
}
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
* @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());
// 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.");
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
+import org.collectionspace.services.common.repository.BadRequestException;
/**
* StringIDGeneratorPart
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");
}
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;
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
}
@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;
@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;
}
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
*
// 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;
@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();
}
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;
SequenceIDGeneratorPart part;
- public void testNextIDLowercase() {
+ public void testNextIDLowercase() throws BadRequestException {
part = new AlphabeticIDGeneratorPart("a");
assertEquals("a", part.newID());
}
- public void testnewIDLowercase2Chars() {
+ public void testnewIDLowercase2Chars() throws BadRequestException {
part = new AlphabeticIDGeneratorPart("aa");
assertEquals("aa", part.newID());
}
- public void testnewIDLowercase2CharsRolloverFirst() {
+ public void testnewIDLowercase2CharsRolloverFirst() throws BadRequestException {
part = new AlphabeticIDGeneratorPart("ay");
assertEquals("ay", part.newID());
}
- public void testnewIDUppercase() {
+ public void testnewIDUppercase() throws BadRequestException {
part = new AlphabeticIDGeneratorPart("A", "Z", "A");
assertEquals("A", part.newID());
}
- public void testnewIDUppercase2Chars() {
+ public void testnewIDUppercase2Chars() throws BadRequestException {
part = new AlphabeticIDGeneratorPart("A", "Z", "AA");
assertEquals("AA", part.newID());
}
- public void testnewIDUppercase2CharsRolloverFirst() {
+ public void testnewIDUppercase2CharsRolloverFirst() throws BadRequestException {
part = new AlphabeticIDGeneratorPart("A", "Z", "AY");
assertEquals("AY", part.newID());
}
- 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());
}
- public void testCurrentUppercase() {
+ public void testCurrentUppercase() throws BadRequestException {
part = new AlphabeticIDGeneratorPart("A", "Z", "A");
assertEquals("A", part.getCurrentID());
}
- public void testOverflowLowercase() {
+ public void testOverflowLowercase() throws BadRequestException {
part = new AlphabeticIDGeneratorPart("zx");
assertEquals("zx", part.newID());
}
- public void testOverflowUppercase() {
+ public void testOverflowUppercase() throws BadRequestException {
part = new AlphabeticIDGeneratorPart("A", "Z", "X");
assertEquals("X", part.newID());
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.
}
}
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.
}
}
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.
}
}
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();
}
- public void testIsValidIDConstrainedLowerCaseSeries() {
+ public void testIsValidIDConstrainedLowerCaseSeries() throws BadRequestException {
part = new AlphabeticIDGeneratorPart("a", "f", "a");
}
- public void testIsValidIDConstrainedUppercaseSeries() {
+ public void testIsValidIDConstrainedUppercaseSeries() throws BadRequestException {
part = new AlphabeticIDGeneratorPart("A", "F", "A");
import java.util.Vector;
import junit.framework.TestCase;
+import org.collectionspace.services.common.repository.BadRequestException;
import org.collectionspace.services.id.*;
/**
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.
// Test adding parts and retrieving current IDs
- public void testCurrentIDViaVector() {
+ public void testCurrentIDViaVector() throws BadRequestException {
Vector parts = new Vector();
BaseIDGenerator gen;
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("."));
// 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());
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());
assertEquals("AZA", generator.newID());
}
- public void testNewNumericID() {
+ public void testNewNumericID() throws BadRequestException {
generator.clear();
generator.add(new NumericIDGeneratorPart("1"));
assertEquals("1", generator.newID());
assertEquals("3", generator.newID());
}
- public void testNewStringID() {
+ public void testNewStringID() throws BadRequestException {
generator.clear();
generator.add(new StringIDGeneratorPart("PREFIX"));
assertEquals("PREFIX", generator.newID());
// 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("."));
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("."));
assertFalse(generator.isValidID("10000"));
}
- public void testValidMixedID() {
+ public void testValidMixedID() throws BadRequestException {
generator.clear();
generator.add(new YearIDGeneratorPart("2009"));
generator.add(new StringIDGeneratorPart("."));
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("."));
import org.collectionspace.services.id.*;
+import org.collectionspace.services.common.repository.BadRequestException;
+
import junit.framework.TestCase;
import static org.junit.Assert.*;
// @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));
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.
}
}
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.
}
}
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.
}
}
@Test(dependsOnMethods = {"hasRequiredDatabaseTable", "createIDGenerator"})
public void readIDGenerator() throws DocumentNotFoundException,
- IllegalArgumentException, IllegalStateException {
+ BadRequestException, IllegalStateException {
instance = jdbc.readIDGenerator(DEFAULT_CSID);
Assert.assertTrue(instance != null);
// @TODO Read test patterns from external configuration.
- public String getSpectrumEntryNumberGenerator() {
+ public String getSpectrumEntryNumberGenerator() throws BadRequestException {
generator = new SettableIDGenerator();
generator.add(new StringIDGeneratorPart("E"));
}
- public String getChinAccessionNumberGenerator() {
+ public String getChinAccessionNumberGenerator() throws BadRequestException {
generator = new SettableIDGenerator();
generator.add(new YearIDGeneratorPart());
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;
SequenceIDGeneratorPart part;
- public void testInitialID() {
+ public void testInitialID() throws BadRequestException {
part = new NumericIDGeneratorPart("0");
assertEquals("0", part.getInitialID());
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.
}
}
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.
}
}
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.
}
}
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());
assertEquals("25", part.getCurrentID());
}
- public void testNewID() {
+ public void testNewID() throws BadRequestException {
part = new NumericIDGeneratorPart("0");
assertEquals("0", part.newID());
assertEquals("1", part.newID());
assertEquals("3", part.newID());
}
- public void testNewIDOverflow() {
+ public void testNewIDOverflow() throws BadRequestException {
try {
part = new NumericIDGeneratorPart("997", "3");
}
- public void testIsValidID() {
+ public void testIsValidID() throws BadRequestException {
part = new NumericIDGeneratorPart("1");
assertTrue(part.isValidID("1"));
part = new NumericIDGeneratorPart("1");
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;
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.
}
}
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");
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;
}
- public void testCurrentID() {
+ public void testCurrentID() throws BadRequestException {
part = new YearIDGeneratorPart();
assertEquals(getCurrentYear(), part.getCurrentID());
}
- public void testSetCurrentID() {
+ public void testSetCurrentID() throws BadRequestException {
part = new YearIDGeneratorPart("1999");
part.setCurrentID("1999");
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.
}
}
*/
- 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.
}
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.
}