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.CharacterChecker;
6   import gov.nasa.pds.tools.dict.type.InvalidLengthException;
7   import gov.nasa.pds.tools.dict.type.InvalidTypeException;
8   
9   /***
10   * Returns a quoted test value.
11   * 
12   * @author mcayanan
13   *
14   */
15  public class CharacterTestValue implements TestValue {
16  
17  	public Object getTestValue(ElementDefinition element) throws InvalidTypeException {
18  		CharacterChecker checker = new CharacterChecker();
19  		String value = new String("TEST STRING");
20  		try {
21  			checker.checkMinLength(value, element.getMinLength());
22  		} catch(InvalidLengthException e) {
23  			String biggerString = value + Utility.makeTestString(element.getMinLength() - value.length());
24  			return checker.cast(biggerString);
25  		}
26  		
27  		try {
28  			checker.checkMaxLength(value, element.getMaxLength());
29  		} catch(InvalidLengthException e) {
30  			String smallerString = Utility.makeTestString(element.getMaxLength());
31  			return checker.cast(smallerString);
32  		}
33  		
34  		return checker.cast(value);	
35  	}
36  
37  }