01: package nl.knowlogy.validation.annotations;
02:
03: import junit.framework.TestCase;
04: import nl.knowlogy.validation.ErrorCodes;
05: import nl.knowlogy.validation.Message;
06: import nl.knowlogy.validation.Messages;
07: import nl.knowlogy.validation.MessagesImpl;
08: import nl.knowlogy.validation.ValidationEngine;
09: import nl.knowlogy.validation.annotations.beans.MaxLengthBean;
10:
11: public class ValidateLengthTest extends TestCase {
12:
13: public void testValidateErrorStringLength() {
14:
15: MaxLengthBean maxLengthBean = new MaxLengthBean();
16: maxLengthBean.setTestString(createString(21));
17:
18: Messages messages = new MessagesImpl();
19: ValidationEngine.validate(maxLengthBean, messages);
20:
21: Message errorMessage = messages.getMessage(maxLengthBean,
22: "testString");
23: assertNotNull(errorMessage);
24: assertEquals(ErrorCodes.INVALID_MAX_LENGTH, errorMessage
25: .getMessageCode());
26: }
27:
28: private String createString(int length) {
29: String result = "";
30: for (int i = 0; i < length; i++) {
31: result = result + "a";
32: }
33: return result;
34: }
35:
36: }
|