View Javadoc

1   package gov.nasa.pds.ltdt.testLabel;
2   
3   import gov.nasa.pds.ltdt.gui.util.Utility;
4   import gov.nasa.pds.tools.dict.ElementDefinition;
5   import gov.nasa.pds.tools.dict.type.AlphaNumericChecker;
6   import gov.nasa.pds.tools.dict.type.InvalidLengthException;
7   import gov.nasa.pds.tools.dict.type.InvalidTypeException;
8   
9   public class AlphaNumericTestValue implements TestValue {
10  
11  	public Object getTestValue(ElementDefinition element) throws InvalidTypeException {
12  		AlphaNumericChecker checker = new AlphaNumericChecker();
13  		String value = new String("TEST123");
14  		try {
15  			checker.checkMinLength(value, element.getMinLength());
16  		} catch(InvalidLengthException e) {
17  			String biggerString = value + Utility.makeTestString(element.getMinLength() - value.length());
18  			return checker.cast(biggerString);
19  		}
20  		
21  		try {
22  			checker.checkMaxLength(value, element.getMaxLength());
23  		} catch(InvalidLengthException e) {
24  			String smallerString = Utility.makeTestString(element.getMaxLength());
25  			return checker.cast(smallerString);
26  		}
27  		
28  		return checker.cast(value);
29  	}
30  	
31  }