identityType.setAttribute(new Attribute<Serializable>(mappedName, (Serializable) value)); identityType.setAttribute(identityTypeAttribute); } else { identityType.setAttribute(identityTypeAttribute);
T storedIdentityTypeInstance = getIdentityType(true); storedIdentityTypeInstance.setAttribute(new Attribute<String>("QuestionTotal", "2")); storedIdentityTypeInstance.setAttribute(new Attribute<String>("Question1", "What is favorite toy?")); storedIdentityTypeInstance.setAttribute(new Attribute<String>("Question1Answer", "Gum")); storedIdentityTypeInstance.setAttribute(new Attribute<String>("Question2", "What is favorite word?")); storedIdentityTypeInstance.setAttribute(new Attribute<String>("Question2Answer", "Hi"));
/** * <p> * Updated the common properties for a specific {@link IdentityType} instance from another instance. * </p> * * @param fromIdentityType * @param toIdentityType */ private void updateCommonProperties(IdentityType fromIdentityType, IdentityType toIdentityType) { toIdentityType.setEnabled(fromIdentityType.isEnabled()); toIdentityType.setCreatedDate(fromIdentityType.getCreatedDate()); toIdentityType.setExpirationDate(fromIdentityType.getExpirationDate()); for (Object object : toIdentityType.getAttributes().toArray()) { Attribute<? extends Serializable> attribute = (Attribute<? extends Serializable>) object; toIdentityType.removeAttribute(attribute.getName()); } for (Attribute<? extends Serializable> attrib : fromIdentityType.getAttributes()) { toIdentityType.setAttribute(attrib); } }
/** * <p> * Sets multiple attributes and check if they are properly stored. * </p> * * @throws Exception */ @Test public void testSetMultipleAttributes() throws Exception { T storedIdentityTypeInstance = getIdentityType(true); storedIdentityTypeInstance.setAttribute(new Attribute<String>("QuestionTotal", "2")); storedIdentityTypeInstance.setAttribute(new Attribute<String>("Question1", "What is favorite toy?")); storedIdentityTypeInstance.setAttribute(new Attribute<String>("Question1Answer", "Gum")); storedIdentityTypeInstance.setAttribute(new Attribute<String>("Question2", "What is favorite word?")); storedIdentityTypeInstance.setAttribute(new Attribute<String>("Question2Answer", "Hi")); updateIdentityType(storedIdentityTypeInstance); T updatedIdentityTypeInstance = getIdentityType(false); assertEquals("2", updatedIdentityTypeInstance.<String> getAttribute("QuestionTotal").getValue()); assertEquals("What is favorite toy?", updatedIdentityTypeInstance.<String> getAttribute("Question1").getValue()); assertEquals("Gum", updatedIdentityTypeInstance.<String> getAttribute("Question1Answer").getValue()); assertEquals("What is favorite word?", updatedIdentityTypeInstance.<String[]> getAttribute("Question2").getValue()); assertEquals("Hi", updatedIdentityTypeInstance.<String> getAttribute("Question2Answer").getValue()); }
/** * <p> * Updates an attribute. * </p> * * @throws Exception */ @Test public void testUpdateAttribute() throws Exception { T storedIdentityTypeInstance = getIdentityType(true); storedIdentityTypeInstance.setAttribute(new Attribute<String[]>("multi-valued", new String[] { "1", "2", "3" })); updateIdentityType(storedIdentityTypeInstance); T updatedIdentityTypeInstance = getIdentityType(false); Attribute<String[]> multiValuedAttribute = updatedIdentityTypeInstance.getAttribute("multi-valued"); assertNotNull(multiValuedAttribute); multiValuedAttribute.setValue(new String[] { "3", "4", "5" }); updatedIdentityTypeInstance.setAttribute(multiValuedAttribute); updateIdentityType(updatedIdentityTypeInstance); updatedIdentityTypeInstance = getIdentityType(false); multiValuedAttribute = updatedIdentityTypeInstance.getAttribute("multi-valued"); assertNotNull(multiValuedAttribute); assertEquals(3, multiValuedAttribute.getValue().length); String[] values = multiValuedAttribute.getValue(); Arrays.sort(values); assertTrue(Arrays.equals(values, new String[] { "3", "4", "5" })); }
/** * <p> * Sets an one-valued attribute. * </p> * * @throws Exception */ @Test public void testSetOneValuedAttribute() throws Exception { T storedIdentityTypeInstance = getIdentityType(true); storedIdentityTypeInstance.setAttribute(new Attribute<String>("one-valued", "1")); updateIdentityType(storedIdentityTypeInstance); T updatedIdentityTypeInstance = getIdentityType(false); Attribute<String> oneValuedAttribute = updatedIdentityTypeInstance.getAttribute("one-valued"); assertNotNull(oneValuedAttribute); assertEquals("1", oneValuedAttribute.getValue()); }
/** * <p> * Sets a multi-valued attribute. * </p> * * @throws Exception */ @Test public void testSetMultiValuedAttribute() throws Exception { T storedIdentityTypeInstance = getIdentityType(true); storedIdentityTypeInstance.setAttribute(new Attribute<String[]>("multi-valued", new String[] { "1", "2", "3" })); updateIdentityType(storedIdentityTypeInstance); T updatedIdentityTypeInstance = getIdentityType(false); Attribute<String[]> multiValuedAttribute = updatedIdentityTypeInstance.getAttribute("multi-valued"); assertNotNull(multiValuedAttribute); assertNotNull(multiValuedAttribute.getValue()); assertEquals(3, multiValuedAttribute.getValue().length); }
/** * <p> * Removes an attribute. * </p> * * @throws Exception */ @Test public void testRemoveAttribute() throws Exception { T storedIdentityTypeInstance = getIdentityType(true); storedIdentityTypeInstance.setAttribute(new Attribute<String[]>("multi-valued", new String[] { "1", "2", "3" })); updateIdentityType(storedIdentityTypeInstance); T updatedIdentityTypeInstance = getIdentityType(false); Attribute<String[]> multiValuedAttribute = updatedIdentityTypeInstance.getAttribute("multi-valued"); assertNotNull(multiValuedAttribute); updatedIdentityTypeInstance.removeAttribute("multi-valued"); updateIdentityType(updatedIdentityTypeInstance); updatedIdentityTypeInstance = getIdentityType(false); multiValuedAttribute = updatedIdentityTypeInstance.getAttribute("multi-valued"); assertNull(multiValuedAttribute); }