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.DataSetChecker;
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 DataSetTestValue implements TestValue {
16  
17  	public Object getTestValue(ElementDefinition element) throws InvalidTypeException {
18  		DataSetChecker checker = new DataSetChecker();
19  		String value = new String("TEST STRING");
20  		
21  		try {
22  			checker.checkMinLength(value, element.getMinLength());
23  		} catch(InvalidLengthException e) {
24  			String biggerString = value + Utility.makeTestString(element.getMinLength() - value.length());
25  			return checker.cast(biggerString);
26  		}
27  		
28  		try {
29  			checker.checkMaxLength(value, element.getMaxLength());
30  		} catch(InvalidLengthException e) {
31  			String smallerString = Utility.makeTestString(element.getMaxLength());
32  			return checker.cast(smallerString);
33  		}
34  		
35  		return checker.cast(value);
36  	}
37  
38  }