Advertisement
Guest User

Untitled

a guest
Jan 4th, 2013
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. /**
  2. * The contents of this file are subject to the OpenMRS Public License
  3. * Version 1.0 (the "License"); you may not use this file except in
  4. * compliance with the License. You may obtain a copy of the License at
  5. *
  6. * Software distributed under the License is distributed on an "AS IS"
  7. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  8. * License for the specific language governing rights and limitations
  9. * under the License.
  10. *
  11. * Copyright (C) OpenMRS, LLC. All Rights Reserved.
  12. */
  13. package org.openmrs.validator;
  14.  
  15. import org.junit.Assert;
  16. import org.junit.Test;
  17. import org.openmrs.RelationshipType;
  18. import org.springframework.validation.BindException;
  19. import org.springframework.validation.Errors;
  20.  
  21. /**
  22. * Tests method called validate on the {@link RelationshipTypeValidator} class.
  23. * @since 1.10
  24. */
  25. public class RelationshipTypeValidatorTest {
  26.  
  27. /**
  28. * @see RelationshipTypeValidator#validate(Object,Errors)
  29. * @verifies fail validation if aIsToB(or A is To B) is null or empty or whitespace
  30. */
  31. @Test
  32. public void validate_shouldFailValidationIfaIsToBIsNullOrEmptyOrWhitespace()
  33. throws Exception {
  34. RelationshipType type = new RelationshipType();
  35. type.setaIsToB(null);
  36.  
  37. Errors errors = new BindException(type, "type");
  38. new RelationshipTypeValidator().validate(type, errors);
  39. Assert.assertTrue(errors.hasFieldErrors("aIsToB"));
  40.  
  41. type.setaIsToB("");
  42. errors = new BindException(type, "type");
  43. new RelationshipTypeValidator().validate(type, errors);
  44. Assert.assertTrue(errors.hasFieldErrors("aIsToB"));
  45.  
  46. type.setaIsToB(" ");
  47. errors = new BindException(type, "type");
  48. new RelationshipTypeValidator().validate(type, errors);
  49. Assert.assertTrue(errors.hasFieldErrors("aIsToB"));
  50. }
  51.  
  52. /**
  53. * @see RelationshipTypeValidator#validate(Object,Errors)
  54. * @verifies fail validation if bIsToA(or B is To A) is null or empty or whitespace
  55. */
  56. @Test
  57. public void validate_shouldFailValidationIfbIsToAIsNullOrEmptyOrWhitespace()
  58. throws Exception {
  59. RelationshipType type = new RelationshipType();
  60. type.setbIsToA(null);
  61.  
  62. Errors errors = new BindException(type, "type");
  63. new RelationshipTypeValidator().validate(type, errors);
  64. Assert.assertTrue(errors.hasFieldErrors("bIsToA"));
  65.  
  66. type.setbIsToA("");
  67. errors = new BindException(type, "type");
  68. new RelationshipTypeValidator().validate(type, errors);
  69. Assert.assertTrue(errors.hasFieldErrors("bIsToA"));
  70.  
  71. type.setbIsToA(" ");
  72. errors = new BindException(type, "type");
  73. new RelationshipTypeValidator().validate(type, errors);
  74. Assert.assertTrue(errors.hasFieldErrors("bIsToA"));
  75. }
  76.  
  77. /**
  78. * @see RelationshipTypeValidator#validate(Object,Errors)
  79. * @verifies fail validation if description is null or empty or whitespace
  80. */
  81. @Test
  82. public void validate_shouldFailValidationIfDescriptionIsNullOrEmptyOrWhitespace()
  83. throws Exception {
  84. RelationshipType type = new RelationshipType();
  85. type.setDescription(null);
  86.  
  87. Errors errors = new BindException(type, "type");
  88. new RelationshipTypeValidator().validate(type, errors);
  89. Assert.assertFalse(errors.hasFieldErrors("description"));
  90.  
  91. type.setDescription("");
  92. errors = new BindException(type, "type");
  93. new RelationshipTypeValidator().validate(type, errors);
  94. Assert.assertFalse(errors.hasFieldErrors("description"));
  95.  
  96. type.setDescription(" ");
  97. errors = new BindException(type, "type");
  98. new RelationshipTypeValidator().validate(type, errors);
  99. Assert.assertFalse(errors.hasFieldErrors("description"));
  100. }
  101.  
  102. /**
  103. * Test for all the field being set to some values
  104. * @see RelationshipTypeValidator#validate(Object,Errors)
  105. * @verifies pass validation if all required fields are set
  106. */
  107. @Test
  108. public void validate_shouldPassValidationIfAllRequiredFieldsAreSet()
  109. throws Exception {
  110. RelationshipType type = new RelationshipType();
  111. type.setaIsToB("A is To B");
  112. type.setbIsToA("B is To A");
  113. type.setDescription("description");
  114.  
  115. Errors errors = new BindException(type, "type");
  116. new RelationshipTypeValidator().validate(type, errors);
  117. Assert.assertFalse(errors.hasErrors());
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement