01: package nl.knowlogy.validation.annotations;
02:
03: import junit.framework.TestCase;
04: import nl.knowlogy.validation.Message;
05: import nl.knowlogy.validation.MessageType;
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.Address;
10: import nl.knowlogy.validation.annotations.beans.Customer;
11: import nl.knowlogy.validation.annotations.beans.EmailSupport;
12:
13: public class ValidatedClassAnnotationsTest extends TestCase {
14:
15: public void testCorrectValidateOfStreet() {
16:
17: Address address = new Address();
18:
19: Messages messages = new MessagesImpl();
20:
21: ValidationEngine.validate(address, messages);
22:
23: assertTrue(messages.getNumberOfMessages(MessageType.ERROR) > 0);
24: Message streetMessage = messages.getMessage(address, "street");
25: assertNotNull(streetMessage);
26: assertEquals("street.isrequired", streetMessage
27: .getMessageCode());
28:
29: }
30:
31: public void testRetrieveValidateClassAnnotation() {
32:
33: Address diephuistraat38B = new Address();
34: diephuistraat38B.setHouseNumber(new Integer(1000));
35: diephuistraat38B.setZipCode("12QW");
36:
37: // outside validation
38: Messages messages = new MessagesImpl();
39: ValidationEngine.validate(diephuistraat38B, messages);
40:
41: Message streetMessage = messages.getMessage(diephuistraat38B,
42: "street");
43: assertNotNull(streetMessage);
44: assertEquals(streetMessage.getMessageCode(),
45: "street.isrequired");
46:
47: assertNotNull(messages.getMessage(diephuistraat38B,
48: "houseNumber"));
49: assertNotNull(messages.getMessage(diephuistraat38B, "zipCode"));
50:
51: // inside validation
52: // messages = new MessagesImpl();
53: // diephuistraat38B.validate(messages);
54: // assertNotNull( messages.getMessage(diephuistraat38B, "street"));
55: // assertNotNull( messages.getMessage(diephuistraat38B, "houseNumber"));
56: // assertNotNull( messages.getMessage(diephuistraat38B, "zipCode"));
57:
58: }
59:
60: public void testValidateCustomerEmail() {
61:
62: Customer customer = new Customer();
63: customer.setEmail("bla");
64:
65: EmailSupport aEmailSupport = new EmailSupport();
66: customer.getEmailAddresses().add(aEmailSupport);
67:
68: Messages messages = new MessagesImpl();
69: ValidationEngine.validate(customer, messages);
70: //assertNotNull( messages.getMessage(aEmailSupport, "email"));
71: assertNotNull(messages.getMessage(customer, "email"));
72: }
73:
74: public void testValidateCustomerLastname() {
75:
76: }
77:
78: }
|