Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2013
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. package org.openmrs.validator;
  2.  
  3. import org.junit.Assert;
  4. import org.junit.Test;
  5. import org.openmrs.RelationshipType;
  6. import org.springframework.validation.BindException;
  7. import org.springframework.validation.Errors;
  8.  
  9. public class RelationshipTypeValidatorTest {
  10.  
  11. /**
  12. * @see RelationshipTypeValidator#validate(Object,Errors)
  13. * @verifies fail validation if aIsToB(or A is To B) is null or empty or whitespace
  14. */
  15. @Test
  16. public void validate_shouldFailValidationIfaIsToBIsNullOrEmptyOrWhitespace() throws Exception {
  17. RelationshipType type = new RelationshipType();
  18. type.setaIsToB(null);
  19. type.setDescription("A is To B");
  20.  
  21. Errors errors = new BindException(type, "type");
  22. new RelationshipTypeValidator().validate(type, errors);
  23. Assert.assertTrue(errors.hasFieldErrors("aIsToB"));
  24.  
  25. type.setaIsToB("");
  26. errors = new BindException(type, "type");
  27. new RelationshipTypeValidator().validate(type, errors);
  28. Assert.assertTrue(errors.hasFieldErrors("aIsToB"));
  29.  
  30. type.setaIsToB(" ");
  31. errors = new BindException(type, "type");
  32. new RelationshipTypeValidator().validate(type, errors);
  33. Assert.assertTrue(errors.hasFieldErrors("aIsToB"));
  34.  
  35. }
  36.  
  37. /**
  38. * @see RelationshipTypeValidator#validate(Object,Errors)
  39. * @verifies fail validation if bIsToA(or B is To A) is null or empty or whitespace
  40. */
  41. @Test
  42. public void validate_shouldFailValidationIfbIsToAIsNullOrEmptyOrWhitespace() throws Exception {
  43. RelationshipType type = new RelationshipType();
  44. type.setbIsToA(null);
  45. type.setDescription("B is To A");
  46.  
  47. Errors errors = new BindException(type, "type");
  48. new RelationshipTypeValidator().validate(type, errors);
  49. Assert.assertTrue(errors.hasFieldErrors("bIsToA"));
  50.  
  51. type.setbIsToA("");
  52. errors = new BindException(type, "type");
  53. new RelationshipTypeValidator().validate(type, errors);
  54. Assert.assertTrue(errors.hasFieldErrors("bIsToA"));
  55.  
  56. type.setbIsToA(" ");
  57. errors = new BindException(type, "type");
  58. new RelationshipTypeValidator().validate(type, errors);
  59. Assert.assertTrue(errors.hasFieldErrors("bIsToA"));
  60.  
  61. }
  62.  
  63. /**
  64. * @see RelationshipTypeValidator#validate(Object,Errors)
  65. * @verifies fail validation if description is null or empty or whitespace
  66. */
  67. @Test
  68. public void validate_shouldFailValidationIfDescriptionIsNullOrEmptyOrWhitespace() throws Exception {
  69. RelationshipType type = new RelationshipType();
  70. type.setName("name");
  71. type.setDescription(null);
  72.  
  73. Errors errors = new BindException(type, "type");
  74. new RelationshipTypeValidator().validate(type, errors);
  75. Assert.assertFalse(errors.hasFieldErrors("description"));
  76.  
  77. type.setDescription("");
  78. errors = new BindException(type, "type");
  79. new RelationshipTypeValidator().validate(type, errors);
  80. Assert.assertFalse(errors.hasFieldErrors("description"));
  81.  
  82. type.setDescription(" ");
  83. errors = new BindException(type, "type");
  84. new RelationshipTypeValidator().validate(type, errors);
  85. Assert.assertFalse(errors.hasFieldErrors("description"));
  86.  
  87. }
  88.  
  89. /**
  90. * @see RelationshipTypeValidator#validate(Object,Errors)
  91. * @verifies pass validation if all required fields are set
  92. */
  93. @Test
  94. public void validate_shouldPassValidationIfAllRequiredFieldsAreSet() throws Exception {
  95. RelationshipType type = new RelationshipType();
  96. type.setaIsToB("A is To B");
  97. type.setbIsToA("B is To A");
  98. type.setDescription("name");
  99.  
  100. Errors errors = new BindException(type, "type");
  101. new RelationshipTypeValidator().validate(type, errors);
  102.  
  103. Assert.assertFalse(errors.hasErrors());
  104.  
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement