aboutsummaryrefslogtreecommitdiff
path: root/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PersonalAttributeTestCase.java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PersonalAttributeTestCase.java')
-rw-r--r--id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PersonalAttributeTestCase.java307
1 files changed, 158 insertions, 149 deletions
diff --git a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PersonalAttributeTestCase.java b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PersonalAttributeTestCase.java
index 458d510e0..82676ccf0 100644
--- a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PersonalAttributeTestCase.java
+++ b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PersonalAttributeTestCase.java
@@ -17,8 +17,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
-import junit.framework.Assert;
-
import org.junit.BeforeClass;
import org.junit.Test;
@@ -27,156 +25,167 @@ import eu.stork.peps.auth.commons.STORKStatusCode;
/**
* The PersonalAttribute's Test Case.
- *
+ *
* @author ricardo.ferreira@multicert.com, renato.portela@multicert.com,
- * luis.felix@multicert.com, hugo.magalhaes@multicert.com,
- * paulo.ribeiro@multicert.com
+ * luis.felix@multicert.com, hugo.magalhaes@multicert.com,
+ * paulo.ribeiro@multicert.com
* @version $Revision: 1.4 $, $Date: 2010-11-17 05:17:03 $
*/
public final class PersonalAttributeTestCase {
-
- /**
- * An empty attribute.
- */
- private static final PersonalAttribute EMPTYATTR = new PersonalAttribute();
-
- /**
- * An attribute with a complex value (canonicalResidenceAddress).
- */
- private static PersonalAttribute complexAttrValue = null;
-
- /**
- * An attribute with a simple value (age).
- */
- @SuppressWarnings("serial")
- private static final PersonalAttribute ATTR_VALUE = new PersonalAttribute(
- "age", true, new ArrayList<String>() {
- {
- add("15");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
-
- /**
- * Init PersonalAttributeTestCase class.
- */
- @SuppressWarnings("serial")
- @BeforeClass
- public static void runsBeforeTheTestSuite() {
- final Map<String, String> values = new HashMap<String, String>() {
- {
- put("countryCodeAddress", "PT");
- put("state", "Porto");
- put("town", "Porto");
- put("postalCode", "4100");
- put("streetName", "Avenida Sidonio Pais");
- put("streetNumber", "379");
- put("apartmentNumber", "B");
- }
- };
-
- complexAttrValue =
- new PersonalAttribute("canonicalResidenceAddress", true, values,
- STORKStatusCode.STATUS_AVAILABLE.toString());
+
+ /**
+ * An empty attribute.
+ */
+ private static final PersonalAttribute EMPTYATTR = new PersonalAttribute();
+
+ /**
+ * An attribute with a complex value (canonicalResidenceAddress).
+ */
+ private static PersonalAttribute complexAttrValue = null;
+
+ /**
+ * An attribute with a simple value (age).
+ */
+ @SuppressWarnings("serial")
+ private static final PersonalAttribute ATTR_VALUE = new PersonalAttribute(
+ "age", true, new ArrayList<String>() {
+ {
+ add("15");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+
+ /**
+ * Init PersonalAttributeTestCase class.
+ */
+ @SuppressWarnings("serial")
+ @BeforeClass
+ public static void runsBeforeTheTestSuite() {
+ final Map<String, String> values = new HashMap<String, String>() {
+ {
+ put("countryCodeAddress", "PT");
+ put("state", "Porto");
+ put("town", "Porto");
+ put("postalCode", "4100");
+ put("streetName", "Avenida Sidonio Pais");
+ put("streetNumber", "379");
+ put("apartmentNumber", "B");
+ }
+ };
+
+ complexAttrValue
+ = new PersonalAttribute("canonicalResidenceAddress", true, values,
+ STORKStatusCode.STATUS_AVAILABLE.toString());
+
+ }
+
+ /**
+ * Tests the {@link PersonalAttribute#toString()} method for the given
+ * simple attribute value. Values must match.
+ */
+ @Test
+ public void testToStringValues() {
+ final String attrVal = ATTR_VALUE.toString();
+ assert "age:true:[15]:Available;".equals(attrVal);
+ }
+
+ /**
+ * Tests the {@link PersonalAttribute#toString()} method for the given
+ * complex attribute value. Values must match.
+ */
+ @Test
+ public void testToStringComplexValues() {
+ //We are testing normal attribute Canonical address, only one value!
+ final Map<String,String> complexAttrVal = complexAttrValue.getComplexValue();
+ final boolean testResult = containsKeyAndValue(complexAttrVal, "postalCode", "4100") &&
+ containsKeyAndValue(complexAttrVal, "apartmentNumber", "B") &&
+ containsKeyAndValue(complexAttrVal, "state", "Porto") &&
+ containsKeyAndValue(complexAttrVal, "countryCodeAddress", "PT") &&
+ containsKeyAndValue(complexAttrVal, "streetNumber", "379") &&
+ containsKeyAndValue(complexAttrVal, "streetName", "Avenida Sidonio Pais") &&
+ containsKeyAndValue(complexAttrVal, "town", "Porto");
+ assert testResult;
+ }
- }
-
- /**
- * Tests the {@link PersonalAttribute#toString()} method for the given simple
- * attribute value. Values must match.
- */
- @Test
- public void testToStringValues() {
- Assert.assertEquals("age:true:[15,]:Available;", ATTR_VALUE.toString());
- }
-
- /**
- * Tests the {@link PersonalAttribute#toString()} method for the given complex
- * attribute value. Values must match.
- */
- @Test
- public void testToStringComplexValues() {
- Assert.assertEquals(
- "canonicalResidenceAddress:true:[postalCode=4100,apartmentNumber=B,"
- + "state=Porto,countryCodeAddress=PT,streetNumber=379,"
- + "streetName=Avenida Sidonio Pais,town=Porto,]:Available;",
- complexAttrValue.toString());
- }
-
- /**
- * Tests the {@link PersonalAttribute#isEmptyStatus()} method for the given
- * empty attribute. Must return true.
- */
- @Test
- public void testToIsEmptyStatusWithNull() {
- Assert.assertTrue(EMPTYATTR.isEmptyStatus());
- }
-
- /**
- * Tests the {@link PersonalAttribute#isEmptyStatus()} method for the given
- * new attribute. Must return true.
- */
- @Test
- public void testToIsEmptyStatusWithEmptyString() {
- final PersonalAttribute attr = (PersonalAttribute) EMPTYATTR.clone();
- attr.setStatus("");
- Assert.assertTrue(attr.isEmptyStatus());
- }
-
- /**
- * Tests the {@link PersonalAttribute#isEmptyValue()} method for the given
- * empty attribute. Must return true.
- */
- @Test
- public void testToIsEmptyValueWithNull() {
- final PersonalAttribute attr = (PersonalAttribute) EMPTYATTR.clone();
- attr.setValue(null);
- Assert.assertTrue(attr.isEmptyValue());
- }
-
- /**
- * Tests the {@link PersonalAttribute#isEmptyValue()} method for the given
- * empty attribute. Must return true.
- */
- @Test
- public void testToIsEmptyValue() {
- Assert.assertTrue(EMPTYATTR.isEmptyValue());
- }
-
- /**
- * Tests the {@link PersonalAttribute#isEmptyComplexValue()} method for the
- * given empty attribute. Must return true.
- */
- @Test
- public void testToIsEmptyComplexValueWithNull() {
- final PersonalAttribute attr = (PersonalAttribute) EMPTYATTR.clone();
- attr.setComplexValue(null);
- Assert.assertTrue(attr.isEmptyComplexValue());
- }
-
- /**
- * Tests the {@link PersonalAttribute#isEmptyComplexValue()} method for the
- * given empty attribute. Must return true.
- */
- @Test
- public void testToIsEmptyComplexValueWithEmptyComplexValue() {
- Assert.assertTrue(EMPTYATTR.isEmptyComplexValue());
- }
-
- /**
- * Tests the {@link PersonalAttribute#clone()} method for the given attribute.
- * Must return true.
- */
- @Test
- public void testCloneToComplexValue() {
- Assert.assertNotSame(complexAttrValue, complexAttrValue.clone());
- }
-
- /**
- * Tests the {@link PersonalAttribute#clone()} method for the given attribute.
- * Must return true.
- */
- @Test
- public void testCloneToValue() {
- Assert.assertNotSame(ATTR_VALUE, ATTR_VALUE.clone());
- }
+ private boolean containsKeyAndValue(final Map<String,String> complexAttrVal, final String key, final String expectedValue) {
+ final boolean res = complexAttrVal.containsKey(key) && complexAttrVal.get(key).equals(expectedValue);
+ return res;
+ }
+
+ /**
+ * Tests the {@link PersonalAttribute#isEmptyStatus()} method for the given
+ * empty attribute. Must return true.
+ */
+ @Test
+ public void testToIsEmptyStatusWithNull() {
+ assert EMPTYATTR.isEmptyStatus();
+ }
+
+ /**
+ * Tests the {@link PersonalAttribute#isEmptyStatus()} method for the given
+ * new attribute. Must return true.
+ */
+ @Test
+ public void testToIsEmptyStatusWithEmptyString() {
+ final PersonalAttribute attr = (PersonalAttribute) EMPTYATTR.clone();
+ attr.setStatus("");
+ assert attr.isEmptyStatus();
+ }
+
+ /**
+ * Tests the {@link PersonalAttribute#isEmptyValue()} method for the given
+ * empty attribute. Must return true.
+ */
+ @Test
+ public void testToIsEmptyValueWithNull() {
+ final PersonalAttribute attr = (PersonalAttribute) EMPTYATTR.clone();
+ attr.setValue(null);
+ assert attr.isEmptyValue();
+ }
+
+ /**
+ * Tests the {@link PersonalAttribute#isEmptyValue()} method for the given
+ * empty attribute. Must return true.
+ */
+ @Test
+ public void testToIsEmptyValue() {
+ assert EMPTYATTR.isEmptyValue();
+ }
+
+ /**
+ * Tests the {@link PersonalAttribute#isEmptyComplexValue()} method for the
+ * given empty attribute. Must return true.
+ */
+ @Test
+ public void testToIsEmptyComplexValueWithNull() {
+ final PersonalAttribute attr = (PersonalAttribute) EMPTYATTR.clone();
+ attr.setComplexValue(null);
+ assert attr.isEmptyComplexValue();
+ }
+
+ /**
+ * Tests the {@link PersonalAttribute#isEmptyComplexValue()} method for the
+ * given empty attribute. Must return true.
+ */
+ @Test
+ public void testToIsEmptyComplexValueWithEmptyComplexValue() {
+ assert EMPTYATTR.isEmptyComplexValue();
+ }
+
+ /**
+ * Tests the {@link PersonalAttribute#clone()} method for the given
+ * attribute. Must return true.
+ */
+ @Test
+ public void testCloneToComplexValue() {
+ assert (complexAttrValue.getComplexValue().toString().equals(complexAttrValue.getComplexValue().toString()) && !complexAttrValue.equals(complexAttrValue.clone()));
+ }
+
+ /**
+ * Tests the {@link PersonalAttribute#clone()} method for the given
+ * attribute. Must return true.
+ */
+ @Test
+ public void testCloneToValue() {
+ assert !ATTR_VALUE.equals(ATTR_VALUE.clone());
+ }
}