/** * @see Person#getAttribute(String) */ @Test public void getAttribute_shouldReturnNullIfAttributeNameIsVoided() { Person person = personHelper(true, 1, 2, 3, "name1", "name2", "name3", "value1", "value2", "value3"); Assert.assertNull(person.getAttribute("name3")); }
/** * @see Person#getAttribute(Integer) */ @Test public void getAttribute_shouldReturnNullWhenExistingPersonAttributeWithMatchingAttributeTypeIdIsVoided() { Person person = personHelper(true, 1, 2, 3, "name1", "name2", "name3", "value1", "value2", "value3"); Assert.assertNull(person.getAttribute(3)); }
/** * @see Person#getAttribute(Integer) */ @Test public void getAttribute_shouldreturnPersonAttributeBasedOnAttributeTypeId() { Person person = personHelper(false, 1, 2, 3, "name1", "name2", "name3", "value1", "value2", "value3"); Assert.assertEquals(new Integer(3), person.getAttribute(3).getAttributeType().getId()); }
/** * @see Person#getAttribute(String) */ @Test public void getAttribute_shouldPersonAttributeBasedOnAttributeName() { Person person = personHelper(false, 1, 2, 3, "name1", "name2", "name3", "value1", "value2", "value3"); Assert.assertEquals("name3", person.getAttribute("name3").getAttributeType().getName()); }
/** * @see Person#getAttribute(PersonAttributeType) */ @Test public void getAttribute_shouldReturnNullWhenExistingPersonAttributeTypeIsVoided() { Person person = personHelper(true, 1, 2, 3, "name1", "name2", "name3", "value1", "value2", "value3"); PersonAttributeType type = new PersonAttributeType(3); type.setName("name3"); Assert.assertNull(person.getAttribute(type)); }
@Test public void shouldCreateAPersonWithAttributes() throws Exception { long originalCount = service.getPeople("", false).size(); final String birthPlace = "Nsambya"; String json = "{ \"names\": [{ \"givenName\":\"Helen\", \"familyName\":\"of Troy\" }], " + "\"birthdate\":\"2003-01-01\", \"gender\":\"F\", \"attributes\":" + "[{\"attributeType\":\"54fc8400-1683-4d71-a1ac-98d40836ff7c\",\"value\": \"" + birthPlace + "\"}] }"; SimpleObject newPerson = deserialize(handle(newPostRequest(getURI(), json))); String uuid = PropertyUtils.getProperty(newPerson, "uuid").toString(); Person person = Context.getPersonService().getPersonByUuid(uuid); assertEquals(++originalCount, service.getPeople("", false).size()); assertEquals(birthPlace, person.getAttribute("Birthplace").getValue()); }
/** * Sets attributes on the given person. * * @param instance * @param attrs */ @PropertySetter("attributes") public static void setAttributes(Person instance, List<PersonAttribute> attrs) { for (PersonAttribute attr : attrs) { PersonAttribute existingAttribute = instance.getAttribute(Context.getPersonService() .getPersonAttributeTypeByUuid(attr.getAttributeType().getUuid())); if (existingAttribute != null) { if (attr.getValue() == null) { instance.removeAttribute(existingAttribute); } else { existingAttribute.setValue(attr.getValue()); } } else { instance.addAttribute(attr); } } }
@Test public void shouldCreateAPersonWithBooleanAttributeWithoutQuotes() throws Exception { executeDataSet("personAttributeTypeWithConcept.xml"); long originalCount = service.getPeople("", false).size(); String givenName = "TestName1"; String attributeUuid = "55e6ce9e-25bf-11e3-a013-3c0754156a5f"; int attributeId = 10; String json = "{\"gender\": \"M\", \"attributes\":[{\"value\":true,\"attributeType\":" + "\"" + attributeUuid + "\"}]," + "\"names\": [{\"givenName\":\"" + givenName + "\", \"familyName\":\"TestFamily\"}]}"; SimpleObject newPerson = deserialize(handle(newPostRequest(getURI(), json))); String uuid = PropertyUtils.getProperty(newPerson, "uuid").toString(); Person person = Context.getPersonService().getPersonByUuid(uuid); assertEquals(++originalCount, service.getPeople("", false).size()); assertEquals(givenName, person.getGivenName()); assertEquals("true", person.getAttribute(attributeId).getValue()); }
@Test public void shouldCreateAPersonWithBooleanAttributeWithQuotes() throws Exception { executeDataSet("personAttributeTypeWithConcept.xml"); long originalCount = service.getPeople("", false).size(); String givenName = "TestName2"; int attributeId = 10; String attributeUuid = "55e6ce9e-25bf-11e3-a013-3c0754156a5f"; String json = "{\"gender\": \"M\", \"attributes\":[{\"value\":\"true\",\"attributeType\":" + "\"" + attributeUuid + "\"}]," + "\"names\": [{\"givenName\":\"" + givenName + "\", \"familyName\":\"TestFamily\"}]}"; SimpleObject newPerson = deserialize(handle(newPostRequest(getURI(), json))); String uuid = PropertyUtils.getProperty(newPerson, "uuid").toString(); Person person = Context.getPersonService().getPersonByUuid(uuid); assertEquals(++originalCount, service.getPeople("", false).size()); assertEquals(givenName, person.getGivenName()); assertEquals("true", person.getAttribute(attributeId).getValue()); } }
PersonAttribute personAttribute = personToUpdate.getAttribute(attribute.getName()); if (personAttribute != null) { personToUpdate.removeAttribute(personAttribute);