Advertisement
Guest User

Untitled

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