Created
September 2, 2011 13:45
-
-
Save jsnikeris/1188620 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FieldLengthIT extends BaseTest { | |
@Factory(dataProvider = "fieldLengths") | |
public Object[] createTest(String fieldName, Integer length) { | |
return new Object[] { | |
new FieldLengthTst<EntityCollection>(fieldName, length, | |
client, ecBuilder.build()) | |
}; | |
} | |
@DataProvider | |
public Object[][] fieldLengths() { | |
return new Object[][] { | |
{"title", 1000}, | |
{"type", 32}, | |
{"subtype", 32} | |
}; | |
} | |
} | |
public class FieldLengthTst<T extends DataObject> { | |
private final String fieldName; | |
private final int maxLength; | |
private final DataServiceClient<T> client; | |
private final T dataObject; | |
public FieldLengthTst(String fieldName, int maxLength, | |
DataServiceClient<T> client, T validDataObject) { | |
this.fieldName = fieldName; | |
this.maxLength = maxLength; | |
this.client = client; | |
this.dataObject = validDataObject; | |
} | |
@Test | |
public void maxLength() { | |
create(fieldName, maxLength); | |
} | |
@Test(expectedExceptions = ValidationException.class) | |
public void overMaxLength() { | |
create(fieldName, maxLength + 1); | |
} | |
private void create(String fieldName, int length) { | |
String value = StringUtils.repeat("a", length); | |
try {BeanUtils.setProperty(dataObject, fieldName, value);} | |
catch (Exception e) {throw new RuntimeException(e);} | |
client.create(dataObject); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment