/** * @see org.openmrs.api.PersonService#voidRelationship(org.openmrs.Relationship, * java.lang.String) */ @Override public Relationship voidRelationship(Relationship relationship, String voidReason) throws APIException { if (relationship.getVoided()) { return relationship; } relationship.setVoided(true); if (relationship.getVoidedBy() == null) { relationship.setVoidedBy(Context.getAuthenticatedUser()); } if (voidReason != null) { relationship.setVoidReason(voidReason); } relationship.setDateVoided(new Date()); return Context.getPersonService().saveRelationship(relationship); }
/** * The purpose of this method is to allow subclasses of Relationship to delegate a portion of * their copy() method back to the superclass, in case the base class implementation changes. * * @param target a Relationship that will have the state of <code>this</code> copied into it * @return the Relationship that was passed in, with state copied into it */ protected Relationship copyHelper(Relationship target) { target.personA = getPersonA(); target.relationshipType = getRelationshipType(); target.personB = getPersonB(); target.setCreator(getCreator()); target.setDateCreated(getDateCreated()); target.setVoided(getVoided()); target.setVoidedBy(getVoidedBy()); target.setDateVoided(getDateVoided()); target.setVoidReason(getVoidReason()); return target; }
@Test public void voidRelationship_shouldVoidRelationshipIfGivenRelationshipIsNotVoided() { Relationship relationship = personService.getRelationship(1); assertFalse("We need an unvoided relationship to test the method", relationship.getVoided()); String voidReason = "Something"; // TODO - voiding is done by the BaseVoidHandler called via AOP before voidRelationship // is executed. Coverage of voidRelationship is low because relationship.getVoided() is true // when entering voidRelationship // Documented at TRUNK-5151 personService.voidRelationship(relationship, voidReason); Relationship voidedRelationship = personService.getRelationship(1); assertTrue(voidedRelationship.getVoided()); assertThat(voidedRelationship.getVoidReason(), is(voidReason)); assertNotNull(voidedRelationship.getDateVoided()); assertEquals(voidedRelationship.getVoidedBy(), Context.getAuthenticatedUser()); }
@Test public void voidRelationship_shouldVoidRelationshipWithVoidReasonNullIfGivenRelationshipIsNotVoided() { Relationship relationship = personService.getRelationship(1); assertFalse("We need an unvoided relationship to test the method", relationship.getVoided()); String voidReason = null; // TODO - voiding is done by the BaseVoidHandler called via AOP before voidRelationship // is executed. Coverage of voidRelationship is low because relationship.getVoided() is true // when entering voidRelationship // Documented at TRUNK-5151 personService.voidRelationship(relationship, voidReason); Relationship voidedRelationship = personService.getRelationship(1); assertTrue(voidedRelationship.getVoided()); assertThat(voidedRelationship.getVoidReason(), is(voidReason)); assertNotNull(voidedRelationship.getDateVoided()); assertEquals(voidedRelationship.getVoidedBy(), Context.getAuthenticatedUser()); }
/** * @see PersonService#unvoidRelationship(Relationship) */ @Test public void unvoidRelationship_shouldUnvoidVoidedRelationship() throws Exception { Relationship relationship = Context.getPersonService().getRelationship(1); Relationship voidedRelationship = Context.getPersonService().voidRelationship(relationship, "Test Voiding Relationship"); assertTrue(voidedRelationship.getVoided()); Assert.assertNotNull(voidedRelationship.getVoidedBy()); Assert.assertNotNull(voidedRelationship.getVoidReason()); Assert.assertNotNull(voidedRelationship.getDateVoided()); Relationship unvoidedRelationship = Context.getPersonService().unvoidRelationship(voidedRelationship); Assert.assertFalse(unvoidedRelationship.getVoided()); Assert.assertNull(unvoidedRelationship.getVoidedBy()); Assert.assertNull(unvoidedRelationship.getVoidReason()); Assert.assertNull(unvoidedRelationship.getDateVoided()); }
@Test public void voidRelationship_shouldVoidRelationshipAndSetVoidedByToGivenUserIfGivenRelationshipIsNotVoided() { Relationship relationship = personService.getRelationship(1); assertFalse("We need an unvoided relationship to test the method", relationship.getVoided()); String voidReason = "Something"; User user = Context.getUserService().getUser(501); assertNotNull("need a user to void", user); relationship.setVoidedBy(user); // TODO - voiding is done by the BaseVoidHandler called via AOP before voidRelationship // is executed. Coverage of voidRelationship is low because relationship.getVoided() is true // when entering voidRelationship // Documented at TRUNK-5151 personService.voidRelationship(relationship, voidReason); Relationship voidedRelationship = personService.getRelationship(1); assertTrue(voidedRelationship.getVoided()); assertThat(voidedRelationship.getVoidReason(), is(voidReason)); assertNotNull(voidedRelationship.getDateVoided()); assertEquals(voidedRelationship.getVoidedBy(), user); }