aboutsummaryrefslogtreecommitdiff
path: root/id/server/stork2-commons/src/test
diff options
context:
space:
mode:
authorThomas Lenz <tlenz@iaik.tugraz.at>2015-08-27 12:07:52 +0200
committerThomas Lenz <tlenz@iaik.tugraz.at>2015-08-27 12:07:52 +0200
commit1051a42329a603821f415383343d253724d4cd65 (patch)
treef8a0b6e8445b7034dfe38d6ba3a61f1429a75a6e /id/server/stork2-commons/src/test
parentbb1b12ac5b240629e16ea1c7a50891e99f4adc14 (diff)
parenteb0cf88708f3d689c2cb6bb0dbf83dd290bee887 (diff)
downloadmoa-id-spss-1051a42329a603821f415383343d253724d4cd65.tar.gz
moa-id-spss-1051a42329a603821f415383343d253724d4cd65.tar.bz2
moa-id-spss-1051a42329a603821f415383343d253724d4cd65.zip
Merge STORK-SAML-Engine 1.5.1 and STORK-Commons 1.5.1
Conflicts: id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeProviderFactory.java id/server/stork2-saml-engine/src/main/java/eu/stork/peps/auth/engine/core/validator/CustomAttributeQueryValidator.java id/server/stork2-saml-engine/src/main/java/eu/stork/peps/auth/engine/core/validator/MultipleAssertionResponseValidator.java
Diffstat (limited to 'id/server/stork2-commons/src/test')
-rw-r--r--id/server/stork2-commons/src/test/java/eu/stork/peps/tests/AttributeProvidersMapTestCase.java225
-rw-r--r--id/server/stork2-commons/src/test/java/eu/stork/peps/tests/AttributeSourceTestCase.java144
-rw-r--r--id/server/stork2-commons/src/test/java/eu/stork/peps/tests/AttributeUtilTestCase.java998
-rw-r--r--id/server/stork2-commons/src/test/java/eu/stork/peps/tests/ComplexAttributesMarshalling.java238
-rw-r--r--id/server/stork2-commons/src/test/java/eu/stork/peps/tests/DateUtilTestCase.java522
-rw-r--r--id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PEPSUtilTestCase.java1020
-rw-r--r--id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PersonalAttributeListTestCase.java1448
-rw-r--r--id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PersonalAttributeTestCase.java307
-rw-r--r--id/server/stork2-commons/src/test/java/eu/stork/peps/tests/package-info.java1
-rw-r--r--id/server/stork2-commons/src/test/resources/log4j.xml24
10 files changed, 2456 insertions, 2471 deletions
diff --git a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/AttributeProvidersMapTestCase.java b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/AttributeProvidersMapTestCase.java
index 89f5adbed..3d0aa4d45 100644
--- a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/AttributeProvidersMapTestCase.java
+++ b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/AttributeProvidersMapTestCase.java
@@ -15,120 +15,121 @@ import eu.stork.peps.auth.commons.PersonalAttributeList;
/**
* The AttributeSource's Test Case.
- *
- * @author Stelios Lelis (stelios.lelis@aegean.gr), Elias Pastos (ilias@aegean.gr)
- *
+ *
+ * @author Stelios Lelis (stelios.lelis@aegean.gr), Elias Pastos
+ * (ilias@aegean.gr)
+ *
* @version $Revision: $, $Date: $
*/
public class AttributeProvidersMapTestCase {
- @Test
- public void testObjectOK1() {
- final IAttributeProvidersMap map = new AttributeProvidersMap();
- final AttributeSource source = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL");
- final IPersonalAttributeList pal = new PersonalAttributeList();
- boolean outcome = false;
-
- //Add a single item
- map.put(source, pal);
-
- if ( map.containsKey(source) ) {
- outcome = true;
- }
-
- assertTrue(outcome);
- }
-
- @Test
- public void testObjectOK2() {
- final IAttributeProvidersMap map = new AttributeProvidersMap();
- final AttributeSource source = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL");
- final IPersonalAttributeList pal = new PersonalAttributeList();
- boolean outcome = false;
-
- //Add a single item
- map.put(source, pal);
-
- if ( map.containsKey(source) ) {
- if ( map.get(source)!=null ) {
- outcome = true;
- }
- }
-
- assertTrue(outcome);
- }
-
- @Test
- public void testObjectOK3() {
- final IAttributeProvidersMap map = new AttributeProvidersMap();
- final AttributeSource source = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL");
- final AttributeSource target = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL");
- final IPersonalAttributeList pal = new PersonalAttributeList();
- boolean outcome = false;
-
- //Add a single item
- map.put(source, pal);
-
- if ( map.containsKey(target) ) {
- outcome = true;
- }
-
- assertTrue(outcome);
- }
-
- @Test
- public void testObjectOK4() {
- final IAttributeProvidersMap map = new AttributeProvidersMap();
- final AttributeSource source = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL");
- final AttributeSource target = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL");
- final IPersonalAttributeList pal = new PersonalAttributeList();
- boolean outcome = false;
-
- //Add a single item
- map.put(source, pal);
-
- if ( map.containsKey(target) ) {
- if ( map.get(target)!=null ) {
- outcome = true;
- }
- }
-
- assertTrue(outcome);
- }
-
- @Test
- public void testObjectNOK1() {
- final IAttributeProvidersMap map = new AttributeProvidersMap();
- final AttributeSource source = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL");
- final AttributeSource target = new AttributeSource(new Country("ID1", "Name 1"), "URL");
- final IPersonalAttributeList pal = new PersonalAttributeList();
- boolean outcome = false;
-
- //Add a single item
- map.put(source, pal);
-
- if ( map.containsKey(target) ) {
- outcome = true;
- }
-
- assertFalse(outcome);
- }
-
- @Test
- public void testObjectNOK2() {
- final IAttributeProvidersMap map = new AttributeProvidersMap();
- final AttributeSource source = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL");
- final AttributeSource target = new AttributeSource(new AttributeProvider("ID2", "Name 1", null), "URL");
- final IPersonalAttributeList pal = new PersonalAttributeList();
- boolean outcome = false;
-
- //Add a single item
- map.put(source, pal);
-
- if ( map.containsKey(target) ) {
- outcome = true;
- }
-
- assertFalse(outcome);
- }
+ @Test
+ public void testObjectOK1() {
+ final IAttributeProvidersMap map = new AttributeProvidersMap();
+ final AttributeSource source = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL");
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ boolean outcome = false;
+
+ //Add a single item
+ map.put(source, pal);
+
+ if (map.containsKey(source)) {
+ outcome = true;
+ }
+
+ assertTrue(outcome);
+ }
+
+ @Test
+ public void testObjectOK2() {
+ final IAttributeProvidersMap map = new AttributeProvidersMap();
+ final AttributeSource source = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL");
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ boolean outcome = false;
+
+ //Add a single item
+ map.put(source, pal);
+
+ if (map.containsKey(source)) {
+ if (map.get(source) != null) {
+ outcome = true;
+ }
+ }
+
+ assertTrue(outcome);
+ }
+
+ @Test
+ public void testObjectOK3() {
+ final IAttributeProvidersMap map = new AttributeProvidersMap();
+ final AttributeSource source = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL");
+ final AttributeSource target = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL");
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ boolean outcome = false;
+
+ //Add a single item
+ map.put(source, pal);
+
+ if (map.containsKey(target)) {
+ outcome = true;
+ }
+
+ assertTrue(outcome);
+ }
+
+ @Test
+ public void testObjectOK4() {
+ final IAttributeProvidersMap map = new AttributeProvidersMap();
+ final AttributeSource source = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL");
+ final AttributeSource target = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL");
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ boolean outcome = false;
+
+ //Add a single item
+ map.put(source, pal);
+
+ if (map.containsKey(target)) {
+ if (map.get(target) != null) {
+ outcome = true;
+ }
+ }
+
+ assertTrue(outcome);
+ }
+
+ @Test
+ public void testObjectNOK1() {
+ final IAttributeProvidersMap map = new AttributeProvidersMap();
+ final AttributeSource source = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL");
+ final AttributeSource target = new AttributeSource(new Country("ID1", "Name 1"), "URL");
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ boolean outcome = false;
+
+ //Add a single item
+ map.put(source, pal);
+
+ if (map.containsKey(target)) {
+ outcome = true;
+ }
+
+ assertFalse(outcome);
+ }
+
+ @Test
+ public void testObjectNOK2() {
+ final IAttributeProvidersMap map = new AttributeProvidersMap();
+ final AttributeSource source = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL");
+ final AttributeSource target = new AttributeSource(new AttributeProvider("ID2", "Name 1", null), "URL");
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ boolean outcome = false;
+
+ //Add a single item
+ map.put(source, pal);
+
+ if (map.containsKey(target)) {
+ outcome = true;
+ }
+
+ assertFalse(outcome);
+ }
}
diff --git a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/AttributeSourceTestCase.java b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/AttributeSourceTestCase.java
index e0f685ade..a3fb6468f 100644
--- a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/AttributeSourceTestCase.java
+++ b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/AttributeSourceTestCase.java
@@ -11,78 +11,80 @@ import eu.stork.peps.auth.commons.Country;
/**
* The AttributeSource's Test Case.
- *
- * @author Stelios Lelis (stelios.lelis@aegean.gr), Elias Pastos (ilias@aegean.gr)
- *
+ *
+ * @author Stelios Lelis (stelios.lelis@aegean.gr), Elias Pastos
+ * (ilias@aegean.gr)
+ *
* @version $Revision: $, $Date: $
*/
public final class AttributeSourceTestCase {
- private final AttributeSource ap1 = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL1");
- private final AttributeSource ap2 = new AttributeSource(new AttributeProvider("ID2", "Name 2", null), "URL2");
- private final AttributeSource ap3 = new AttributeSource(new AttributeProvider("ID1", "Name 2", null), "URL2");
- private final AttributeSource ap4 = new AttributeSource(new AttributeProvider("ID1", "Name 2", null), "URL1");
- private final AttributeSource ap5 = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL1");
-
- private final AttributeSource c1 = new AttributeSource(new Country("ID1", "Name 1"), "URL1");
- private final AttributeSource c2 = new AttributeSource(new Country("ID2", "Name 2"), "URL2");
- private final AttributeSource c3 = new AttributeSource(new Country("ID1", "Name 2"), "URL2");
- private final AttributeSource c4 = new AttributeSource(new Country("ID1", "Name 2"), "URL1");
- private final AttributeSource c5 = new AttributeSource(new Country("ID1", "Name 1"), "URL1");
-
- @Test
- public void testNotEquals1() {
- assertFalse(ap1.equals(ap2));
- }
-
- @Test
- public void testNotEquals2() {
- assertFalse(ap1.equals(c1));
- }
-
- @Test
- public void testNotEquals3() {
- assertFalse(c1.equals(c2));
- }
-
- @Test
- public void testEquals1() {
- assertTrue(ap1.equals(ap3));
- }
-
- @Test
- public void testEquals2() {
- assertTrue(ap1.equals(ap4));
- }
-
- @Test
- public void testEquals3() {
- assertTrue(ap1.equals(ap5));
- }
-
- @Test
- public void testEquals4() {
- assertTrue(c1.equals(c3));
- }
-
- @Test
- public void testEquals5() {
- assertTrue(c1.equals(c4));
- }
-
- @Test
- public void testEquals6() {
- assertTrue(c1.equals(c5));
- }
-
- @Test
- public void testEquals7() {
- final Object obj = ap5;
- assertTrue(ap1.equals(obj));
- }
-
- @Test
- public void testEquals8() {
- final Object obj = c5;
- assertTrue(c1.equals(obj));
- }
+
+ private final AttributeSource ap1 = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL1");
+ private final AttributeSource ap2 = new AttributeSource(new AttributeProvider("ID2", "Name 2", null), "URL2");
+ private final AttributeSource ap3 = new AttributeSource(new AttributeProvider("ID1", "Name 2", null), "URL2");
+ private final AttributeSource ap4 = new AttributeSource(new AttributeProvider("ID1", "Name 2", null), "URL1");
+ private final AttributeSource ap5 = new AttributeSource(new AttributeProvider("ID1", "Name 1", null), "URL1");
+
+ private final AttributeSource c1 = new AttributeSource(new Country("ID1", "Name 1"), "URL1");
+ private final AttributeSource c2 = new AttributeSource(new Country("ID2", "Name 2"), "URL2");
+ private final AttributeSource c3 = new AttributeSource(new Country("ID1", "Name 2"), "URL2");
+ private final AttributeSource c4 = new AttributeSource(new Country("ID1", "Name 2"), "URL1");
+ private final AttributeSource c5 = new AttributeSource(new Country("ID1", "Name 1"), "URL1");
+
+ @Test
+ public void testNotEquals1() {
+ assertFalse(ap1.innerEquals(ap2));
+ }
+
+ @Test
+ public void testNotEquals2() {
+ assertFalse(ap1.innerEquals(c1));
+ }
+
+ @Test
+ public void testNotEquals3() {
+ assertFalse(c1.innerEquals(c2));
+ }
+
+ @Test
+ public void testEquals1() {
+ assertTrue(ap1.innerEquals(ap3));
+ }
+
+ @Test
+ public void testEquals2() {
+ assertTrue(ap1.innerEquals(ap4));
+ }
+
+ @Test
+ public void testEquals3() {
+ assertTrue(ap1.innerEquals(ap5));
+ }
+
+ @Test
+ public void testEquals4() {
+ assertTrue(c1.innerEquals(c3));
+ }
+
+ @Test
+ public void testEquals5() {
+ assertTrue(c1.innerEquals(c4));
+ }
+
+ @Test
+ public void testEquals6() {
+ assertTrue(c1.innerEquals(c5));
+ }
+
+ @Test
+ public void testEquals7() {
+ final Object obj = ap5;
+ assertTrue(ap1.equals(obj));
+ }
+
+ @Test
+ public void testEquals8() {
+ final Object obj = c5;
+ assertTrue(c1.equals(obj));
+ }
}
diff --git a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/AttributeUtilTestCase.java b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/AttributeUtilTestCase.java
index 77fc4b9c2..524a7446c 100644
--- a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/AttributeUtilTestCase.java
+++ b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/AttributeUtilTestCase.java
@@ -31,507 +31,507 @@ import eu.stork.peps.auth.commons.PersonalAttributeList;
/**
* The AttributeUtil's Test Case.
- *
+ *
* @author ricardo.ferreira@multicert.com, renato.portela@multicert.com,
- * luis.felix@multicert.com
- *
+ * luis.felix@multicert.com
+ *
* @version $Revision: $, $Date: $
*/
public final class AttributeUtilTestCase {
-
- /**
- * Empty String to be used on the tests.
- */
- private static final String EMPTY_STRING = "";
-
- /**
- * Tuple value sample to be used on the tests.
- */
- private static final String[] TUPLE_STRING = new String[] { "age", "true",
- "[18]", "Available" };
-
- /**
- * Complex value to be used on escape/unescape tests.
- */
- private static final String COMPLEX_VAL = "postalCode=4100,"
- + "apartmentNumber=A,state=Porto,countryCodeAddress=PT,streetNumber=379,"
- + "streetName=Avenida Sidonio Pais,town=Porto,";
-
- /**
- * Escaped Complex value to be used on escape/unescape tests.
- */
- private static final String ESC_COMPLEX_VAL = "postalCode=4100%44"
- + "apartmentNumber=A%44state=Porto%44countryCodeAddress=PT%44"
- + "streetNumber=379%44streetName=Avenida Sidonio Pais%44town=Porto%44";
-
- /**
- * Simple value to be used on escape/unescape tests.
- */
- private static final String SIMPLE_VAL = "Avenida da Boavista, Porto";
-
- /**
- * Escaped simple value to be used on escape/unescape tests.
- */
- private static final String ESC_SIMPLE_VAL = "Avenida da Boavista%44 Porto";
-
- /**
- * Simple text to be used on escape/unescape tests. Must match the escaped
- * text.
- */
- private static final String SIMPLE_TEXT = "John Doe";
-
- /**
- * Tests the {@link AttributeUtil#escape(String)} method for the given complex
- * attribute value (canonical address' example attribute value).
- */
- @Test
- public void testEscapeSpecialCharsComplexVal() {
- assertEquals(AttributeUtil.escape(COMPLEX_VAL), ESC_COMPLEX_VAL);
- }
-
- /**
- * Tests the {@link AttributeUtil#escape(String)} method for the given
- * attribute value.
- */
- @Test
- public void testEscapeSpecialCharsVal() {
- assertEquals(AttributeUtil.escape(SIMPLE_VAL), ESC_SIMPLE_VAL);
- }
-
- /**
- * Tests the {@link AttributeUtil#escape(String)} method for the given simple
- * text: no special characters to escape.
- */
- @Test
- public void testEscapeNormalChars() {
- assertEquals(AttributeUtil.escape(SIMPLE_TEXT), SIMPLE_TEXT);
- }
-
- /**
- * Tests the {@link AttributeUtil#unescape(String)} method for the given
- * escape complex attribute value (canonical address' example attribute
- * value).
- */
- @Test
- public void testUnescapeSpecialCharsComplexVal() {
- assertEquals(AttributeUtil.unescape(ESC_COMPLEX_VAL), COMPLEX_VAL);
- }
-
- /**
- * Tests the {@link AttributeUtil#escape(String)} method for the given escape
- * attribute value.
- */
- @Test
- public void testUnescapeSpecialCharsVal() {
- assertEquals(AttributeUtil.unescape(ESC_SIMPLE_VAL), SIMPLE_VAL);
- }
-
- /**
- * Tests the {@link AttributeUtil#escape(String)} method for the given simple
- * text: no special characters to unescape.
- */
- @Test
- public void testUnescapeNormalChars() {
- assertEquals(AttributeUtil.unescape(SIMPLE_TEXT), SIMPLE_TEXT);
- }
-
- /**
- * Tests the {@link AttributeUtil#appendIfNotNull(StringBuilder, Object)}
- * method for the given empty string.
- */
- @Test
- public void testAppendIfNotNullEmptyStr() {
- final StringBuilder strBuilder = new StringBuilder(SIMPLE_TEXT);
- AttributeUtil.appendIfNotNull(strBuilder, EMPTY_STRING);
- assertEquals(strBuilder.toString(), SIMPLE_TEXT);
- }
-
- /**
- * Tests the {@link AttributeUtil#appendIfNotNull(StringBuilder, Object)}
- * method for the given string.
- */
- @Test
- public void testAppendIfNotNullStr() {
- final StringBuilder strBuilder = new StringBuilder();
- AttributeUtil.appendIfNotNull(strBuilder, SIMPLE_TEXT);
- assertEquals(strBuilder.toString(), SIMPLE_TEXT);
- }
-
- /**
- * Tests the {@link AttributeUtil#appendIfNotNull(StringBuilder, Object)}
- * method for the given null value.
- */
- @Test
- public void testAppendIfNotNull() {
- final StringBuilder strBuilder = new StringBuilder();
- AttributeUtil.appendIfNotNull(strBuilder, null);
- assertEquals(strBuilder.toString(), EMPTY_STRING);
- }
-
- /**
- * Tests the {@link AttributeUtil#listToString(List, String)} method for the
- * given List with two values.
- */
- @Test
- public void testListToStringTwoVals() {
- final List<String> vals = new ArrayList<String>();
- vals.add(SIMPLE_VAL);
- vals.add(SIMPLE_TEXT);
-
- final StringBuilder strBuilder = new StringBuilder();
- strBuilder.append(ESC_SIMPLE_VAL);
- strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
- strBuilder.append(SIMPLE_TEXT);
- strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
-
- assertEquals(
- AttributeUtil.listToString(vals,
- PEPSValues.ATTRIBUTE_VALUE_SEP.toString()), strBuilder.toString());
- }
-
- /**
- * Tests the {@link AttributeUtil#listToString(List, String)} method for the
- * given List with one values.
- */
- @Test
- public void testListToStringOneVal() {
- final List<String> vals = new ArrayList<String>();
- vals.add(SIMPLE_VAL);
-
- final StringBuilder strBuilder = new StringBuilder();
- strBuilder.append(ESC_SIMPLE_VAL);
- strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
-
- assertEquals(
- AttributeUtil.listToString(vals,
- PEPSValues.ATTRIBUTE_VALUE_SEP.toString()), strBuilder.toString());
- }
-
- /**
- * Tests the {@link AttributeUtil#listToString(List, String)} method for the
- * given List with one value.
- */
- @Test
- public void testListToStringEmptyVal() {
- final List<String> vals = new ArrayList<String>();
-
- final StringBuilder strBuilder = new StringBuilder();
-
- assertEquals(
- AttributeUtil.listToString(vals,
- PEPSValues.ATTRIBUTE_VALUE_SEP.toString()), strBuilder.toString());
- }
-
- /**
- * Tests the {@link AttributeUtil#mapToString(java.util.Map, String)} method
- * for the given Map with one value.
- */
- @Test
- public void testMapToStringOneVal() {
- final Map<String, String> vals = new HashMap<String, String>();
- vals.put("CanonicalAddress", COMPLEX_VAL);
-
- final StringBuilder strBuilder = new StringBuilder();
- strBuilder.append("CanonicalAddress=");
- strBuilder.append(ESC_COMPLEX_VAL);
- strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
-
- assertEquals(AttributeUtil.mapToString(vals,
- PEPSValues.ATTRIBUTE_VALUE_SEP.toString()), strBuilder.toString());
- }
-
- /**
- * Tests the {@link AttributeUtil#mapToString(java.util.Map, String)} method
- * for the given empty Map.
- */
- @Test
- public void testMapToStringEmptyVal() {
- final Map<String, String> vals = new HashMap<String, String>();
-
- final StringBuilder strBuilder = new StringBuilder();
-
- assertEquals(AttributeUtil.mapToString(vals,
- PEPSValues.ATTRIBUTE_VALUE_SEP.toString()), strBuilder.toString());
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
- * invalid List.
- */
- @Test
- public void testIsValidValueInvalidList() {
- final StringBuilder strBuilder = new StringBuilder();
- strBuilder.append(ESC_SIMPLE_VAL);
- strBuilder.append("]");
- assertFalse(AttributeUtil.isValidValue(strBuilder.toString()));
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
- * null value.
- */
- @Test
- public void testIsValidValueNullList() {
- assertFalse(AttributeUtil.isValidValue(null));
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
- * empty List.
- */
- @Test
- public void testIsValidValueEmptyList() {
- assertTrue(AttributeUtil.isValidValue("[]"));
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
- * empty List.
- */
- @Test
- public void testIsValidValueEmptyCommaList() {
- assertTrue(AttributeUtil.isValidValue("[,]"));
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
- * one simple value List.
- */
- @Test
- public void testIsValidValueOneValueList() {
- final StringBuilder strBuilder = new StringBuilder();
- strBuilder.append("[");
- strBuilder.append(ESC_SIMPLE_VAL);
- strBuilder.append("]");
- assertTrue(AttributeUtil.isValidValue(strBuilder.toString()));
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
- * one simple value List.
- */
- @Test
- public void testIsValidValueOneValueCommaList() {
- final StringBuilder strBuilder = new StringBuilder();
- strBuilder.append("[");
- strBuilder.append(ESC_SIMPLE_VAL);
- strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
- strBuilder.append("]");
- assertTrue(AttributeUtil.isValidValue(strBuilder.toString()));
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
- * one complex value List.
- */
- @Test
- public void testIsValidValueOneComplexValueList() {
- final StringBuilder strBuilder = new StringBuilder();
- strBuilder.append("[");
- strBuilder.append(ESC_COMPLEX_VAL);
- strBuilder.append("]");
- assertTrue(AttributeUtil.isValidValue(strBuilder.toString()));
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
- * one complex value List.
- */
- @Test
- public void testIsValidValueOneComplexValueCommaList() {
- final StringBuilder strBuilder = new StringBuilder();
- strBuilder.append("[");
- strBuilder.append(ESC_COMPLEX_VAL);
- strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
- strBuilder.append("]");
- assertTrue(AttributeUtil.isValidValue(strBuilder.toString()));
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
- * multi value List.
- */
- @Test
- public void testIsValidValueMultiValueList() {
- final StringBuilder strBuilder = new StringBuilder();
- strBuilder.append("[");
- strBuilder.append(ESC_SIMPLE_VAL);
- strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
- strBuilder.append(SIMPLE_TEXT);
- strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
- strBuilder.append("]");
- assertTrue(AttributeUtil.isValidValue(strBuilder.toString()));
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
- * invalid multi value List.
- */
- @Test
- public void testIsValidValueInvalidMultiValueList() {
- final StringBuilder strBuilder = new StringBuilder();
- strBuilder.append(ESC_SIMPLE_VAL);
- strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
- strBuilder.append(SIMPLE_TEXT);
- strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
- strBuilder.append("]");
- assertFalse(AttributeUtil.isValidValue(strBuilder.toString()));
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidType(String)} method for the given
- * true type.
- */
- @Test
- public void testIsValidTypetrue() {
- assertTrue(AttributeUtil.isValidType("true"));
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidType(String)} method for the given
- * True type.
- */
- @Test
- public void testIsValidTypeTrue() {
- assertTrue(AttributeUtil.isValidType("True"));
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidType(String)} method for the given
- * TRUE type.
- */
- @Test
- public void testIsValidTypeTRUE() {
- assertTrue(AttributeUtil.isValidType("TRUE"));
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidType(String)} method for the given
- * invalid type.
- */
- @Test
- public void testIsValidTypeInvalidType() {
- assertFalse(AttributeUtil.isValidType("str"));
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidType(String)} method for the given
- * false type.
- */
- @Test
- public void testIsValidTypefalse() {
- assertTrue(AttributeUtil.isValidType("false"));
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidType(String)} method for the given
- * False type.
- */
- @Test
- public void testIsValidTypeFalse() {
- assertTrue(AttributeUtil.isValidType("False"));
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidType(String)} method for the given
- * FALSE type.
- */
- @Test
- public void testIsValidTypeFALSEVal() {
- assertTrue(AttributeUtil.isValidType("False"));
- }
-
- /**
- * Tests the {@link AttributeUtil#isValidType(String)} method for the given
- * null.
- */
- @Test
- public void testIsValidTypeNullVal() {
- assertFalse(AttributeUtil.isValidType(null));
- }
-
- /**
- * Tests the {@link AttributeUtil#hasValidTuples(String[])} method for the
- * given valid tuple.
- */
- @Test
- public void testHasValidTuples() {
- assertTrue(AttributeUtil.hasValidTuples(TUPLE_STRING));
- }
-
- /**
- * Tests the {@link AttributeUtil#hasValidTuples(String[])} method for the
- * given invalid tuple.
- */
- @Test
- public void testHasValidTuplesInvalid() {
- final String[] tuple = new String[]{"name", "type"};
- assertFalse(AttributeUtil.hasValidTuples(tuple));
- }
-
- /**
- * Tests the {@link AttributeUtil#hasValidTuples(String[])} method for the
- * given invalid tuple with valid size.
- */
- @Test
- public void testHasValidTuplesSameSizeInvalidValues() {
- final String[] tuple = new String[] { "age", "type", "[18]", "Available"};
- assertFalse(AttributeUtil.hasValidTuples(tuple));
- }
-
- /**
- * Tests the {@link AttributeUtil#hasValidTuples(String[])} method for the
- * given null value.
- */
- @Test
- public void testHasValidTuplesNull() {
- assertFalse(AttributeUtil.hasValidTuples(null));
- }
-
- /**
- * Tests the
- * {@link AttributeUtil#checkMandatoryAttributes(IPersonalAttributeList)}
- * method for the given attribute list..
- */
- @Test
- public void testCheckMandatoryAttributes() {
- final IPersonalAttributeList attrList = new PersonalAttributeList();
- attrList.populate("isAgeOver:true:[18,]:Available;");
- assertTrue(AttributeUtil.checkMandatoryAttributes(attrList));
-
- }
-
- /**
- * Tests the
- * {@link AttributeUtil#checkMandatoryAttributes(IPersonalAttributeList)}
- * method for the given null value.
- */
- @Test(expected = NullPointerException.class)
- public void testCheckMandatoryAttributesNullAttrList() {
- assertTrue(AttributeUtil.checkMandatoryAttributes(null));
- }
-
- /**
- * Tests the
- * {@link AttributeUtil#checkMandatoryAttributes(IPersonalAttributeList)}
- * method for the given empty attribute list.
- */
- @Test
- public void testCheckMandatoryAttributesEmptyAttrList() {
- final IPersonalAttributeList attrList = new PersonalAttributeList();
- assertTrue(AttributeUtil.checkMandatoryAttributes(attrList));
- }
-
- /**
- * Tests the
- * {@link AttributeUtil#checkMandatoryAttributes(IPersonalAttributeList)}
- * method for the given attribute list (missing mandatory attribute).
- */
- @Test
- public void testCheckMandatoryAttributesMissingAttr() {
- final IPersonalAttributeList attrList = new PersonalAttributeList();
- attrList.populate("isAgeOver:true:[]:NotAvailable;");
- assertFalse(AttributeUtil.checkMandatoryAttributes(attrList));
- }
-
+
+ /**
+ * Empty String to be used on the tests.
+ */
+ private static final String EMPTY_STRING = "";
+
+ /**
+ * Tuple value sample to be used on the tests.
+ */
+ private static final String[] TUPLE_STRING = new String[]{"age", "true",
+ "[18]", "Available"};
+
+ /**
+ * Complex value to be used on escape/unescape tests.
+ */
+ private static final String COMPLEX_VAL = "postalCode=4100,"
+ + "apartmentNumber=A,state=Porto,countryCodeAddress=PT,streetNumber=379,"
+ + "streetName=Avenida Sidonio Pais,town=Porto,";
+
+ /**
+ * Escaped Complex value to be used on escape/unescape tests.
+ */
+ private static final String ESC_COMPLEX_VAL = "postalCode=4100%44"
+ + "apartmentNumber=A%44state=Porto%44countryCodeAddress=PT%44"
+ + "streetNumber=379%44streetName=Avenida Sidonio Pais%44town=Porto%44";
+
+ /**
+ * Simple value to be used on escape/unescape tests.
+ */
+ private static final String SIMPLE_VAL = "Avenida da Boavista, Porto";
+
+ /**
+ * Escaped simple value to be used on escape/unescape tests.
+ */
+ private static final String ESC_SIMPLE_VAL = "Avenida da Boavista%44 Porto";
+
+ /**
+ * Simple text to be used on escape/unescape tests. Must match the escaped
+ * text.
+ */
+ private static final String SIMPLE_TEXT = "John Doe";
+
+ /**
+ * Tests the {@link AttributeUtil#escape(String)} method for the given
+ * complex attribute value (canonical address' example attribute value).
+ */
+ @Test
+ public void testEscapeSpecialCharsComplexVal() {
+ assertEquals(AttributeUtil.escape(COMPLEX_VAL), ESC_COMPLEX_VAL);
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#escape(String)} method for the given
+ * attribute value.
+ */
+ @Test
+ public void testEscapeSpecialCharsVal() {
+ assertEquals(AttributeUtil.escape(SIMPLE_VAL), ESC_SIMPLE_VAL);
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#escape(String)} method for the given
+ * simple text: no special characters to escape.
+ */
+ @Test
+ public void testEscapeNormalChars() {
+ assertEquals(AttributeUtil.escape(SIMPLE_TEXT), SIMPLE_TEXT);
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#unescape(String)} method for the given
+ * escape complex attribute value (canonical address' example attribute
+ * value).
+ */
+ @Test
+ public void testUnescapeSpecialCharsComplexVal() {
+ assertEquals(AttributeUtil.unescape(ESC_COMPLEX_VAL), COMPLEX_VAL);
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#escape(String)} method for the given
+ * escape attribute value.
+ */
+ @Test
+ public void testUnescapeSpecialCharsVal() {
+ assertEquals(AttributeUtil.unescape(ESC_SIMPLE_VAL), SIMPLE_VAL);
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#escape(String)} method for the given
+ * simple text: no special characters to unescape.
+ */
+ @Test
+ public void testUnescapeNormalChars() {
+ assertEquals(AttributeUtil.unescape(SIMPLE_TEXT), SIMPLE_TEXT);
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#appendIfNotNull(StringBuilder, Object)}
+ * method for the given empty string.
+ */
+ @Test
+ public void testAppendIfNotNullEmptyStr() {
+ final StringBuilder strBuilder = new StringBuilder(SIMPLE_TEXT);
+ AttributeUtil.appendIfNotNull(strBuilder, EMPTY_STRING);
+ assertEquals(strBuilder.toString(), SIMPLE_TEXT);
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#appendIfNotNull(StringBuilder, Object)}
+ * method for the given string.
+ */
+ @Test
+ public void testAppendIfNotNullStr() {
+ final StringBuilder strBuilder = new StringBuilder();
+ AttributeUtil.appendIfNotNull(strBuilder, SIMPLE_TEXT);
+ assertEquals(strBuilder.toString(), SIMPLE_TEXT);
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#appendIfNotNull(StringBuilder, Object)}
+ * method for the given null value.
+ */
+ @Test
+ public void testAppendIfNotNull() {
+ final StringBuilder strBuilder = new StringBuilder();
+ AttributeUtil.appendIfNotNull(strBuilder, null);
+ assertEquals(strBuilder.toString(), EMPTY_STRING);
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#listToString(List, String)} method for the
+ * given List with two values.
+ */
+ @Test
+ public void testListToStringTwoVals() {
+ final List<String> vals = new ArrayList<String>();
+ vals.add(SIMPLE_VAL);
+ vals.add(SIMPLE_TEXT);
+
+ final StringBuilder strBuilder = new StringBuilder();
+ strBuilder.append(ESC_SIMPLE_VAL);
+ strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
+ strBuilder.append(SIMPLE_TEXT);
+ strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
+
+ assertEquals(
+ AttributeUtil.listToString(vals,
+ PEPSValues.ATTRIBUTE_VALUE_SEP.toString()), strBuilder.toString());
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#listToString(List, String)} method for the
+ * given List with one values.
+ */
+ @Test
+ public void testListToStringOneVal() {
+ final List<String> vals = new ArrayList<String>();
+ vals.add(SIMPLE_VAL);
+
+ final StringBuilder strBuilder = new StringBuilder();
+ strBuilder.append(ESC_SIMPLE_VAL);
+ strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
+
+ assertEquals(
+ AttributeUtil.listToString(vals,
+ PEPSValues.ATTRIBUTE_VALUE_SEP.toString()), strBuilder.toString());
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#listToString(List, String)} method for the
+ * given List with one value.
+ */
+ @Test
+ public void testListToStringEmptyVal() {
+ final List<String> vals = new ArrayList<String>();
+
+ final StringBuilder strBuilder = new StringBuilder();
+
+ assertEquals(
+ AttributeUtil.listToString(vals,
+ PEPSValues.ATTRIBUTE_VALUE_SEP.toString()), strBuilder.toString());
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#mapToString(java.util.Map, String)} method
+ * for the given Map with one value.
+ */
+ @Test
+ public void testMapToStringOneVal() {
+ final Map<String, String> vals = new HashMap<String, String>();
+ vals.put("CanonicalAddress", COMPLEX_VAL);
+
+ final StringBuilder strBuilder = new StringBuilder();
+ strBuilder.append("CanonicalAddress=");
+ strBuilder.append(ESC_COMPLEX_VAL);
+ strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
+
+ assertEquals(AttributeUtil.mapToString(vals,
+ PEPSValues.ATTRIBUTE_VALUE_SEP.toString()), strBuilder.toString());
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#mapToString(java.util.Map, String)} method
+ * for the given empty Map.
+ */
+ @Test
+ public void testMapToStringEmptyVal() {
+ final Map<String, String> vals = new HashMap<String, String>();
+
+ final StringBuilder strBuilder = new StringBuilder();
+
+ assertEquals(AttributeUtil.mapToString(vals,
+ PEPSValues.ATTRIBUTE_VALUE_SEP.toString()), strBuilder.toString());
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
+ * invalid List.
+ */
+ @Test
+ public void testIsValidValueInvalidList() {
+ final StringBuilder strBuilder = new StringBuilder();
+ strBuilder.append(ESC_SIMPLE_VAL);
+ strBuilder.append("]");
+ assertFalse(AttributeUtil.isValidValue(strBuilder.toString()));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
+ * null value.
+ */
+ @Test
+ public void testIsValidValueNullList() {
+ assertFalse(AttributeUtil.isValidValue(null));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
+ * empty List.
+ */
+ @Test
+ public void testIsValidValueEmptyList() {
+ assertTrue(AttributeUtil.isValidValue("[]"));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
+ * empty List.
+ */
+ @Test
+ public void testIsValidValueEmptyCommaList() {
+ assertTrue(AttributeUtil.isValidValue("[,]"));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
+ * one simple value List.
+ */
+ @Test
+ public void testIsValidValueOneValueList() {
+ final StringBuilder strBuilder = new StringBuilder();
+ strBuilder.append("[");
+ strBuilder.append(ESC_SIMPLE_VAL);
+ strBuilder.append("]");
+ assertTrue(AttributeUtil.isValidValue(strBuilder.toString()));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
+ * one simple value List.
+ */
+ @Test
+ public void testIsValidValueOneValueCommaList() {
+ final StringBuilder strBuilder = new StringBuilder();
+ strBuilder.append("[");
+ strBuilder.append(ESC_SIMPLE_VAL);
+ strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
+ strBuilder.append("]");
+ assertTrue(AttributeUtil.isValidValue(strBuilder.toString()));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
+ * one complex value List.
+ */
+ @Test
+ public void testIsValidValueOneComplexValueList() {
+ final StringBuilder strBuilder = new StringBuilder();
+ strBuilder.append("[");
+ strBuilder.append(ESC_COMPLEX_VAL);
+ strBuilder.append("]");
+ assertTrue(AttributeUtil.isValidValue(strBuilder.toString()));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
+ * one complex value List.
+ */
+ @Test
+ public void testIsValidValueOneComplexValueCommaList() {
+ final StringBuilder strBuilder = new StringBuilder();
+ strBuilder.append("[");
+ strBuilder.append(ESC_COMPLEX_VAL);
+ strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
+ strBuilder.append("]");
+ assertTrue(AttributeUtil.isValidValue(strBuilder.toString()));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
+ * multi value List.
+ */
+ @Test
+ public void testIsValidValueMultiValueList() {
+ final StringBuilder strBuilder = new StringBuilder();
+ strBuilder.append("[");
+ strBuilder.append(ESC_SIMPLE_VAL);
+ strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
+ strBuilder.append(SIMPLE_TEXT);
+ strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
+ strBuilder.append("]");
+ assertTrue(AttributeUtil.isValidValue(strBuilder.toString()));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidValue(String)} method for the given
+ * invalid multi value List.
+ */
+ @Test
+ public void testIsValidValueInvalidMultiValueList() {
+ final StringBuilder strBuilder = new StringBuilder();
+ strBuilder.append(ESC_SIMPLE_VAL);
+ strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
+ strBuilder.append(SIMPLE_TEXT);
+ strBuilder.append(PEPSValues.ATTRIBUTE_VALUE_SEP.toString());
+ strBuilder.append("]");
+ assertFalse(AttributeUtil.isValidValue(strBuilder.toString()));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidType(String)} method for the given
+ * true type.
+ */
+ @Test
+ public void testIsValidTypetrue() {
+ assertTrue(AttributeUtil.isValidType("true"));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidType(String)} method for the given
+ * True type.
+ */
+ @Test
+ public void testIsValidTypeTrue() {
+ assertTrue(AttributeUtil.isValidType("True"));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidType(String)} method for the given
+ * TRUE type.
+ */
+ @Test
+ public void testIsValidTypeTRUE() {
+ assertTrue(AttributeUtil.isValidType("TRUE"));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidType(String)} method for the given
+ * invalid type.
+ */
+ @Test
+ public void testIsValidTypeInvalidType() {
+ assertFalse(AttributeUtil.isValidType("str"));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidType(String)} method for the given
+ * false type.
+ */
+ @Test
+ public void testIsValidTypefalse() {
+ assertTrue(AttributeUtil.isValidType("false"));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidType(String)} method for the given
+ * False type.
+ */
+ @Test
+ public void testIsValidTypeFalse() {
+ assertTrue(AttributeUtil.isValidType("False"));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidType(String)} method for the given
+ * FALSE type.
+ */
+ @Test
+ public void testIsValidTypeFALSEVal() {
+ assertTrue(AttributeUtil.isValidType("False"));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#isValidType(String)} method for the given
+ * null.
+ */
+ @Test
+ public void testIsValidTypeNullVal() {
+ assertFalse(AttributeUtil.isValidType(null));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#hasValidTuples(String[])} method for the
+ * given valid tuple.
+ */
+ @Test
+ public void testHasValidTuples() {
+ assertTrue(AttributeUtil.hasValidTuples(TUPLE_STRING));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#hasValidTuples(String[])} method for the
+ * given invalid tuple.
+ */
+ @Test
+ public void testHasValidTuplesInvalid() {
+ final String[] tuple = new String[]{"name", "type"};
+ assertFalse(AttributeUtil.hasValidTuples(tuple));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#hasValidTuples(String[])} method for the
+ * given invalid tuple with valid size.
+ */
+ @Test
+ public void testHasValidTuplesSameSizeInvalidValues() {
+ final String[] tuple = new String[]{"age", "type", "[18]", "Available"};
+ assertFalse(AttributeUtil.hasValidTuples(tuple));
+ }
+
+ /**
+ * Tests the {@link AttributeUtil#hasValidTuples(String[])} method for the
+ * given null value.
+ */
+ @Test
+ public void testHasValidTuplesNull() {
+ assertFalse(AttributeUtil.hasValidTuples(null));
+ }
+
+ /**
+ * Tests the
+ * {@link AttributeUtil#checkMandatoryAttributes(IPersonalAttributeList)}
+ * method for the given attribute list..
+ */
+ @Test
+ public void testCheckMandatoryAttributes() {
+ final IPersonalAttributeList attrList = new PersonalAttributeList();
+ attrList.populate("isAgeOver:true:[18,]:Available;");
+ assertTrue(AttributeUtil.checkMandatoryAttributes(attrList));
+
+ }
+
+ /**
+ * Tests the
+ * {@link AttributeUtil#checkMandatoryAttributes(IPersonalAttributeList)}
+ * method for the given null value.
+ */
+ @Test(expected = NullPointerException.class)
+ public void testCheckMandatoryAttributesNullAttrList() {
+ assertTrue(AttributeUtil.checkMandatoryAttributes(null));
+ }
+
+ /**
+ * Tests the
+ * {@link AttributeUtil#checkMandatoryAttributes(IPersonalAttributeList)}
+ * method for the given empty attribute list.
+ */
+ @Test
+ public void testCheckMandatoryAttributesEmptyAttrList() {
+ final IPersonalAttributeList attrList = new PersonalAttributeList();
+ assertTrue(AttributeUtil.checkMandatoryAttributes(attrList));
+ }
+
+ /**
+ * Tests the
+ * {@link AttributeUtil#checkMandatoryAttributes(IPersonalAttributeList)}
+ * method for the given attribute list (missing mandatory attribute).
+ */
+ @Test
+ public void testCheckMandatoryAttributesMissingAttr() {
+ final IPersonalAttributeList attrList = new PersonalAttributeList();
+ attrList.populate("isAgeOver:true:[]:NotAvailable;");
+ assertFalse(AttributeUtil.checkMandatoryAttributes(attrList));
+ }
+
}
diff --git a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/ComplexAttributesMarshalling.java b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/ComplexAttributesMarshalling.java
index fc6e65f70..f2383c07a 100644
--- a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/ComplexAttributesMarshalling.java
+++ b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/ComplexAttributesMarshalling.java
@@ -11,7 +11,6 @@
package eu.stork.peps.tests;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.StringWriter;
@@ -35,8 +34,7 @@ import eu.stork.peps.complex.attributes.eu.stork.names.tc.stork._1_0.assertion.R
/**
* @author Advania Examples on how to use the jaxb marshaller. The classes are created from the
* StorkcomplexAttributes.xsd schema located in resources.
- * @version $Revision: 1.00 $, $Date: 2014-17-02 11:15:00 $
- *
+ * @version $Revision: 1.00 $, $Date: 2014-17-02 11:15:00 $
*/
public class ComplexAttributesMarshalling {
@@ -65,59 +63,48 @@ public class ComplexAttributesMarshalling {
rptObject.setLegalForm("Yet another type of person");
}
- /**
+ /**
* Test marshalling canonical address <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- * <canonicalResidenceAddress xmlns="urn:eu:stork:names:tc:STORK:1.0:assertion">
+ * <canonicalResidenceAddress xmlns="urn:eu:stork:names:tc:STORK:1.0:assertion">
* <countryCodeAddress>IS</countryCodeAddress> <state>Reykjavik</state> <municipalityCode>RVK</municipalityCode>
* <town>Reykjavik</town> <postalCode>101</postalCode> <streetName>Laugavegur</streetName>
* <streetNumber>1</streetNumber> <apartmentNumber>10</apartmentNumber> </canonicalResidenceAddress>
- */
- @Test
- public void testMarshallCanonicalResidencAddress()
- {
- try
- {
- final CanonicalAddressType object = new CanonicalAddressType();
- object.setApartmentNumber("10");
- object.setCountryCodeAddress("IS");
- object.setMunicipalityCode("RVK");
- object.setPostalCode("101");
- object.setState("Reykjavik");
- object.setStreetName("Laugavegur");
- object.setStreetNumber("1");
- object.setTown("Reykjavik");
-
- final JAXBContext context = JAXBContext.newInstance(CanonicalAddressType.class);
- final Marshaller m = context.createMarshaller();
- m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- final ObjectFactory objf = new ObjectFactory();
-
- m.marshal(objf.createCanonicalResidenceAddress(object), new FileOutputStream("CanonicalAddressType.xml"));
- m.marshal(objf.createCanonicalResidenceAddress(object), System.out);
- }
+ */
+ @Test
+ public void testMarshallCanonicalResidencAddress() {
+ try {
+ final CanonicalAddressType object = new CanonicalAddressType();
+ object.setApartmentNumber("10");
+ object.setCountryCodeAddress("IS");
+ object.setMunicipalityCode("RVK");
+ object.setPostalCode("101");
+ object.setState("Reykjavik");
+ object.setStreetName("Laugavegur");
+ object.setStreetNumber("1");
+ object.setTown("Reykjavik");
+
+ final JAXBContext context = JAXBContext.newInstance(CanonicalAddressType.class);
+ final Marshaller m = context.createMarshaller();
+ m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ final ObjectFactory objf = new ObjectFactory();
+
+ m.marshal(objf.createCanonicalResidenceAddress(object), new FileOutputStream("CanonicalAddressType.xml"));
+ m.marshal(objf.createCanonicalResidenceAddress(object), System.out);
+ }
catch ( Exception e ) {
- e.printStackTrace();
+ e.printStackTrace();
}
}
@Test
public void testForDiana() {
initMandateValues();
-
+
try {
// Create the marshallers'
final JAXBContext mandateTypeContext = JAXBContext.newInstance(MandateType.class);
final Marshaller mandateMarshaller = mandateTypeContext.createMarshaller();
- final Unmarshaller mandateUnmarshaller = mandateTypeContext.createUnmarshaller();
-
- // final JAXBContext MandateContentTypecontext = JAXBContext.newInstance(MandateContentType.class);
- // final Marshaller mandM = MandateContentTypecontext.createMarshaller();
- //
- // final JAXBContext RepresentationPersonTypecontext =
- // JAXBContext.newInstance(RepresentationPersonType.class);
- // final Marshaller repM = RepresentationPersonTypecontext.createMarshaller();
- //
final ObjectFactory objf = new ObjectFactory();
MandateType mandate = new MandateType();
@@ -135,54 +122,21 @@ public class ComplexAttributesMarshalling {
mandate.setRepresented(represented);
MandateContentType mandateContent1 = new MandateContentType();
- // OriginalMandateType omt1 = new OriginalMandateType();
- // omt1.setMimeType("text/plain");
- // omt1.setValue("Chief executive officer".getBytes());
mandateContent1.setOriginalMandate("Chief executive officer".getBytes());
mandateContent1.setOriginalMandateType("text/plain");
MandateContentType mandateContent2 = new MandateContentType();
- // mandateContent2.setOriginalMandate(omt1);
mandateContent2.setOriginalMandate("Chief executive officer2".getBytes());
mandateContent2.setOriginalMandateType("text/plain");
mandate.getMandateContent().add(mandateContent1);
mandate.getMandateContent().add(mandateContent2);
- // create a hashmap
- // HashMap<String, String> complexMandate = new HashMap<String, String>();
-
// marshall the mandatecontent
StringWriter sw = new StringWriter();
mandateMarshaller.marshal(objf.createMandate(mandate), sw);
System.out.print(sw.toString());
- // add it to the hashmap
- // complexMandate.put("representative", sw.toString());
- // sw.flush();
- //
- // // continue with the rest of the objects.
- // repM.marshal(objf.createRepresentationPerson(rpObject), sw);
- // System.out.print(sw.toString());
- // complexMandate.put("representative", sw.toString());
- // sw.flush();
- //
- // MandateType mandateType = new MandateType();
- //
- // repM.marshal(objf.createRepresentationPerson(rptObject), sw);
- // System.out.print(sw.toString());
- // complexMandate.put("represented", sw.toString());
- // sw.flush();
- //
- // // add the complex values to the attr.list.
- // PersonalAttribute pal = new PersonalAttribute();
- //
- // pal.setName("mandateContent");
- // pal.setIsRequired(pal.isRequired());
- // pal.setStatus(STORKStatusCode.STATUS_AVAILABLE.toString());
- // pal.setComplexValue(complexMandate);
- //
- // System.out.println(pal.toString());
- }
+ }
catch ( JAXBException e ) {
e.printStackTrace();
}
@@ -210,91 +164,83 @@ public class ComplexAttributesMarshalling {
StringWriter sw = new StringWriter();
m.marshal(objf.createMandate(object), sw);
- }
+ }
catch ( Exception e ) {
e.printStackTrace();
}
}
- /**
+ /**
* Test unmarshalling canonical address <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- * <canonicalResidenceAddress xmlns="urn:eu:stork:names:tc:STORK:1.0:assertion">
+ * <canonicalResidenceAddress xmlns="urn:eu:stork:names:tc:STORK:1.0:assertion">
* <countryCodeAddress>IS</countryCodeAddress> <state>Reykjavik</state> <municipalityCode>RVK</municipalityCode>
* <town>Reykjavik</town> <postalCode>101</postalCode> <streetName>Laugavegur</streetName>
* <streetNumber>1</streetNumber> <apartmentNumber>10</apartmentNumber> </canonicalResidenceAddress>
- */
- @Test
- public void testUnmarshallCanonicalAddress()
- {
- JAXBContext uContext;
- try
- {
- uContext = JAXBContext.newInstance(CanonicalAddressType.class);
- final Unmarshaller u = uContext.createUnmarshaller();
- final File file = new File("CanonicalAddressType.xml");
-
- final JAXBElement<CanonicalAddressType> root = u.unmarshal(new StreamSource(file), CanonicalAddressType.class);
- final CanonicalAddressType foo = root.getValue();
-
- final String A = foo.getStreetName();
- final String B = foo.getStreetNumber();
-
- System.out.println("Streetname: " + A);
- System.out.println("Streetnumber: " + B);
-
- }
- catch (final JAXBException e)
- {
- e.printStackTrace();
- }
- }
-
- /**
+ */
+ @Test
+ public void testUnmarshallCanonicalAddress() {
+ JAXBContext uContext;
+ try {
+ uContext = JAXBContext.newInstance(CanonicalAddressType.class);
+ final Unmarshaller u = uContext.createUnmarshaller();
+ final File file = new File("CanonicalAddressType.xml");
+
+ final JAXBElement<CanonicalAddressType> root = u.unmarshal(new StreamSource(file),
+ CanonicalAddressType.class);
+ final CanonicalAddressType foo = root.getValue();
+
+ final String A = foo.getStreetName();
+ final String B = foo.getStreetNumber();
+
+ System.out.println("Streetname: " + A);
+ System.out.println("Streetnumber: " + B);
+
+ }
+ catch ( final JAXBException e ) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
* Test marshalling has bank account <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <hasAccountInBank
* xmlns="urn:eu:stork:names:tc:STORK:1.0:assertion"> <bankName>Arion</bankName> <AQAA>3</AQAA> </hasAccountInBank>
- */
- @Test
- public void testMarshallHasBankAccount()
- {
- try
- {
- final HasAccountInBankType object = new HasAccountInBankType();
- object.setAQAA(3);
- object.setBankName("Arion Bank");
- final JAXBContext context = JAXBContext.newInstance(HasAccountInBankType.class);
- final Marshaller m = context.createMarshaller();
- final ObjectFactory o = new ObjectFactory();
- m.marshal(o.createHasAccountInBank(object), new FileOutputStream ("hasbankaccount.xml"));
- m.marshal(o.createHasAccountInBank(object), System.out);
-
- }
- catch (FileNotFoundException e) {
- e.printStackTrace();
+ */
+ @Test
+ public void testMarshallHasBankAccount() {
+ try {
+ final HasAccountInBankType object = new HasAccountInBankType();
+ object.setAQAA(3);
+ object.setBankName("Arion Bank");
+ final JAXBContext context = JAXBContext.newInstance(HasAccountInBankType.class);
+ final Marshaller m = context.createMarshaller();
+ final ObjectFactory o = new ObjectFactory();
+ m.marshal(o.createHasAccountInBank(object), new FileOutputStream("hasbankaccount.xml"));
+ m.marshal(o.createHasAccountInBank(object), System.out);
- }catch ( Exception e ) {
- e.printStackTrace();
-
- }
- }
+ }
+ catch ( Exception e ) {
+ e.printStackTrace();
+ }
+ }
- /**
+ /**
* Test unmarshalling has bank account <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <hasAccountInBank
* xmlns="urn:eu:stork:names:tc:STORK:1.0:assertion"> <bankName>Arion</bankName> <AQAA>3</AQAA> </hasAccountInBank>
- */
- @Test
- public void testUnmarshallHasBankAccount()
- {
- try
- {
- final JAXBContext context = JAXBContext.newInstance(HasAccountInBankType.class);
- final Unmarshaller um = context.createUnmarshaller();
- final File file = new File("hasbankaccount.xml");
- final JAXBElement<HasAccountInBankType> root = um.unmarshal(new StreamSource(file), HasAccountInBankType.class);
- final HasAccountInBankType foo = root.getValue();
- System.out.println(foo.getBankName());
- } catch (final JAXBException e) {
- e.printStackTrace();
- }
- }
-
+ */
+ @Test
+ public void testUnmarshallHasBankAccount() {
+ try {
+ final JAXBContext context = JAXBContext.newInstance(HasAccountInBankType.class);
+ final Unmarshaller um = context.createUnmarshaller();
+ final File file = new File("hasbankaccount.xml");
+ final JAXBElement<HasAccountInBankType> root = um.unmarshal(new StreamSource(file),
+ HasAccountInBankType.class);
+ final HasAccountInBankType foo = root.getValue();
+ System.out.println(foo.getBankName());
+ }
+ catch ( final JAXBException e ) {
+ e.printStackTrace();
+ }
+ }
+
}
diff --git a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/DateUtilTestCase.java b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/DateUtilTestCase.java
index f6cacd67b..6c9a17ddc 100644
--- a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/DateUtilTestCase.java
+++ b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/DateUtilTestCase.java
@@ -19,7 +19,6 @@ import java.util.Properties;
import org.joda.time.DateTime;
import org.junit.Assert;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import eu.stork.peps.auth.commons.DateUtil;
@@ -28,269 +27,268 @@ import eu.stork.peps.auth.commons.exceptions.SecurityPEPSException;
/**
* 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.2 $, $Date: 2010-11-17 05:17:03 $
*/
public final class DateUtilTestCase {
-
- /**
- * Stork Format date.
- */
- private static final String FORMAT = "yyyyMMdd";
-
- /**
- * Expected 10 value.
- */
- private static final int TEN = 10;
-
- /**
- * Expected 11 value.
- */
- private static final int ELEVEN = 11;
-
- /**
- * The testing Date ("current" date).
- */
- private static final DateTime TESTDATE = new DateTime(2011, 10, 10, 15, 20,
- 0, 0);
-
- /**
- * Init DateUtilTestCase class.
- */
- @BeforeClass
- public static void runsBeforeTheTestSuite() {
- final Properties configs = new Properties();
- configs.setProperty("invalidAgeDateValue.code", "35");
- configs.setProperty("invalidAttributeValue.code", "34");
- configs
- .setProperty(
- "invalidAttributeValue.message",
- "Unexpected or invalid content was encountered within a "
- + "<saml:Attribute> or <saml:AttributeValue> element.");
- PEPSUtil.createInstance(configs);
- }
-
- /**
- * Tests the {@link DateUtil#calculateAge} method for the given year against
- * the testDate: 2011-10-10 15:20:00.0. Must return 10.
- */
- @Test
- public void calculateAgeFromYear() {
- Assert.assertTrue(TEN == DateUtil.calculateAge("2000", TESTDATE, FORMAT));
- }
-
- /**
- * Tests the {@link DateUtil#calculateAge} method for the given year and month
- * against the testDate: 2011-10-10 15:20:00.0. Must return 11.
- */
- @Test
- public void calculateAgeFromEarlyMonth() {
- Assert.assertTrue(ELEVEN == DateUtil.calculateAge("200001", TESTDATE,
- FORMAT));
- }
-
- /**
- * Tests the {@link DateUtil#calculateAge} method for the given year and month
- * against the testDate: 2011-10-10 15:20:00.0. Must return 10.
- */
- @Test
- public void calculateAgeFromSameMonth() {
- Assert.assertTrue(TEN == DateUtil.calculateAge("200010", TESTDATE, FORMAT));
- }
-
- /**
- * Tests the {@link DateUtil#calculateAge} method for the given year and month
- * against the testDate: 2011-10-10 15:20:00.0. Must return 10.
- */
- @Test
- public void calculateAgeFromLaterMonth() {
- Assert.assertTrue(TEN == DateUtil.calculateAge("200011", TESTDATE, FORMAT));
- }
-
- /**
- * Tests the {@link DateUtil#calculateAge} method for the given full date
- * against the testDate: 2011-10-10 15:20:00.0. Must return 11.
- */
- @Test
- public void calculateAgeFromEarlyFullDate() {
- Assert.assertTrue(ELEVEN == DateUtil.calculateAge("20000101", TESTDATE,
- FORMAT));
- }
-
- /**
- * Tests the {@link DateUtil#calculateAge} method for the given full date
- * against the testDate: 2011-10-10 15:20:00.0. Must return 11.
- */
- @Test
- public void calculateAgeFromSameDay() {
- Assert.assertTrue(ELEVEN == DateUtil.calculateAge("20001010", TESTDATE,
- FORMAT));
- }
-
- /**
- * Tests the {@link DateUtil#calculateAge} method for the given full date
- * against the testDate: 2011-10-10 15:20:00.0. Must return 10.
- */
- @Test
- public void calculateAgeFromLaterFullDate() {
- Assert.assertTrue(TEN == DateUtil
- .calculateAge("20001011", TESTDATE, FORMAT));
- }
-
- /**
- * Tests the {@link DateUtil#calculateAge} method for the given full date
- * against the testDate: 2011-10-10 15:20:00.0. Must return a
- * SecurityPEPSException exception.
- */
- @Test(expected = SecurityPEPSException.class)
- public void calculateAgeFromInvalidDate() {
- DateUtil.calculateAge("200", TESTDATE, FORMAT);
- }
-
- /**
- * Tests the {@link DateUtil#calculateAge} method for the given full date
- * against the testDate: 2011-10-10 15:20:00.0. Must return a
- * SecurityPEPSException exception.
- */
- @Test(expected = SecurityPEPSException.class)
- public void calculateAgeFromInvalidMonth() {
- DateUtil.calculateAge("200013", TESTDATE, FORMAT);
- }
-
- /**
- * Tests the {@link DateUtil#calculateAge} method for the given full date
- * against the testDate: 2011-10-10 15:20:00.0. Must return a
- * SecurityPEPSException exception.
- */
- @Test(expected = SecurityPEPSException.class)
- public void calculateAgeFromInvalidDay() {
- DateUtil.calculateAge("20000230", TESTDATE, FORMAT);
- }
-
- /**
- * Tests the {@link DateUtil#calculateAge} method for the given full date
- * against the testDate: 2011-10-10 15:20:00.0. Must return a
- * SecurityPEPSException exception.
- */
- @Test(expected = SecurityPEPSException.class)
- public void calculateAgeFromNullDate() {
- DateUtil.calculateAge(null, TESTDATE, FORMAT);
- }
-
- /**
- * Tests the {@link DateUtil#calculateAge} method for the given full date
- * against the testDate: 2011-10-10 15:20:00.0. Must return a
- * SecurityPEPSException exception.
- */
- @Test(expected = SecurityPEPSException.class)
- public void calculateAgeFromNullCurDate() {
- DateUtil.calculateAge("2000", null, FORMAT);
- }
-
- /**
- * Tests the {@link DateUtil#calculateAge} method for the given full date
- * against the testDate: 2011-10-10 15:20:00.0. Must return a
- * SecurityPEPSException exception.
- */
- @Test(expected = SecurityPEPSException.class)
- public void calculateAgeFromNullFormat() {
- DateUtil.calculateAge("2000", TESTDATE, null);
- }
-
- /**
- * Tests the {@link DateUtil#isValidFormatDate} method for the given year.
- * Must return true
- */
- @Test
- public void isValidFormatDateFromYear() {
- Assert.assertTrue(DateUtil.isValidFormatDate("2000", FORMAT));
- }
-
- /**
- * Tests the {@link DateUtil#isValidFormatDate} method for the given year and
- * month. Must return true.
- */
- @Test
- public void isValidFormatDateFromMonth() {
- Assert.assertTrue(DateUtil.isValidFormatDate("200001", FORMAT));
- }
-
- /**
- * Tests the {@link DateUtil#isValidFormatDate} method for the given year.
- * Must return false.
- */
- @Test
- public void isValidFormatDate() {
- Assert.assertTrue(DateUtil.isValidFormatDate("20000101", FORMAT));
- }
-
- /**
- * Tests the {@link DateUtil#isValidFormatDate} method for the given year.
- * Must return false.
- */
- @Test
- public void isValidFormatDateInvalidYear() {
- Assert.assertFalse(DateUtil.isValidFormatDate("200", FORMAT));
- }
-
- /**
- * Tests the {@link DateUtil#isValidFormatDate} method for the given year.
- * Must return false.
- */
- @Test
- public void isValidFormatDateInvalidMonth() {
- Assert.assertFalse(DateUtil.isValidFormatDate("200013", FORMAT));
- }
-
- /**
- * Tests the {@link DateUtil#isValidFormatDate} method for the given year.
- * Must return false.
- */
- @Test
- public void isValidFormatDateInvalidDate() {
- Assert.assertFalse(DateUtil.isValidFormatDate("20010229", FORMAT));
- }
-
- /**
- * Tests the {@link DateUtil#isValidFormatDate} method for the given year.
- * Must return false.
- */
- @Test
- public void isValidFormatDateNullDate() {
- Assert.assertFalse(DateUtil.isValidFormatDate(null, FORMAT));
- }
-
- /**
- * Tests the {@link DateUtil#isValidFormatDate} method for the given year.
- * Must return false.
- */
- @Test
- public void isValidFormatDateNullFormat() {
- Assert.assertFalse(DateUtil.isValidFormatDate("2000", null));
- }
-
- /**
- * Tests the {@link DateUtil#currentTimeStamp()} method for the current
- * TimeStamp (TS). Must return true.
- */
- @Test
- public void testCurrentTimeStampBefore() {
- Timestamp ts = DateUtil.currentTimeStamp();
- Assert.assertNotSame(ts, DateUtil.currentTimeStamp());
- }
-
- /**
- * Tests the {@link DateUtil#currentTimeStamp()} method for the current
- * TimeStamp (TS). Must return true.
- */
- @Test
- @Ignore
- public void testCurrentTimeStampAfter() {
- Timestamp ts = DateUtil.currentTimeStamp();
- Assert.assertEquals(DateUtil.currentTimeStamp(), ts);
- }
-
+
+ /**
+ * Stork Format date.
+ */
+ private static final String FORMAT = "yyyyMMdd";
+
+ /**
+ * Expected 10 value.
+ */
+ private static final int TEN = 10;
+
+ /**
+ * Expected 11 value.
+ */
+ private static final int ELEVEN = 11;
+
+ /**
+ * The testing Date ("current" date).
+ */
+ private static final DateTime TESTDATE = new DateTime(2011, 10, 10, 15, 20,
+ 0, 0);
+
+ /**
+ * Init DateUtilTestCase class.
+ */
+ @BeforeClass
+ public static void runsBeforeTheTestSuite() {
+ final Properties configs = new Properties();
+ configs.setProperty("invalidAgeDateValue.code", "35");
+ configs.setProperty("invalidAttributeValue.code", "34");
+ configs
+ .setProperty(
+ "invalidAttributeValue.message",
+ "Unexpected or invalid content was encountered within a "
+ + "<saml:Attribute> or <saml:AttributeValue> element.");
+ PEPSUtil.createInstance(configs);
+ }
+
+ /**
+ * Tests the {@link DateUtil#calculateAge} method for the given year against
+ * the testDate: 2011-10-10 15:20:00.0. Must return 10.
+ */
+ @Test
+ public void calculateAgeFromYear() {
+ Assert.assertTrue(TEN == DateUtil.calculateAge("2000", TESTDATE, FORMAT));
+ }
+
+ /**
+ * Tests the {@link DateUtil#calculateAge} method for the given year and
+ * month against the testDate: 2011-10-10 15:20:00.0. Must return 11.
+ */
+ @Test
+ public void calculateAgeFromEarlyMonth() {
+ Assert.assertTrue(ELEVEN == DateUtil.calculateAge("200001", TESTDATE,
+ FORMAT));
+ }
+
+ /**
+ * Tests the {@link DateUtil#calculateAge} method for the given year and
+ * month against the testDate: 2011-10-10 15:20:00.0. Must return 10.
+ */
+ @Test
+ public void calculateAgeFromSameMonth() {
+ Assert.assertTrue(TEN == DateUtil.calculateAge("200010", TESTDATE, FORMAT));
+ }
+
+ /**
+ * Tests the {@link DateUtil#calculateAge} method for the given year and
+ * month against the testDate: 2011-10-10 15:20:00.0. Must return 10.
+ */
+ @Test
+ public void calculateAgeFromLaterMonth() {
+ Assert.assertTrue(TEN == DateUtil.calculateAge("200011", TESTDATE, FORMAT));
+ }
+
+ /**
+ * Tests the {@link DateUtil#calculateAge} method for the given full date
+ * against the testDate: 2011-10-10 15:20:00.0. Must return 11.
+ */
+ @Test
+ public void calculateAgeFromEarlyFullDate() {
+ Assert.assertTrue(ELEVEN == DateUtil.calculateAge("20000101", TESTDATE,
+ FORMAT));
+ }
+
+ /**
+ * Tests the {@link DateUtil#calculateAge} method for the given full date
+ * against the testDate: 2011-10-10 15:20:00.0. Must return 11.
+ */
+ @Test
+ public void calculateAgeFromSameDay() {
+ Assert.assertTrue(ELEVEN == DateUtil.calculateAge("20001010", TESTDATE,
+ FORMAT));
+ }
+
+ /**
+ * Tests the {@link DateUtil#calculateAge} method for the given full date
+ * against the testDate: 2011-10-10 15:20:00.0. Must return 10.
+ */
+ @Test
+ public void calculateAgeFromLaterFullDate() {
+ Assert.assertTrue(TEN == DateUtil
+ .calculateAge("20001011", TESTDATE, FORMAT));
+ }
+
+ /**
+ * Tests the {@link DateUtil#calculateAge} method for the given full date
+ * against the testDate: 2011-10-10 15:20:00.0. Must return a
+ * SecurityPEPSException exception.
+ */
+ @Test(expected = SecurityPEPSException.class)
+ public void calculateAgeFromInvalidDate() {
+ DateUtil.calculateAge("200", TESTDATE, FORMAT);
+ }
+
+ /**
+ * Tests the {@link DateUtil#calculateAge} method for the given full date
+ * against the testDate: 2011-10-10 15:20:00.0. Must return a
+ * SecurityPEPSException exception.
+ */
+ @Test(expected = SecurityPEPSException.class)
+ public void calculateAgeFromInvalidMonth() {
+ DateUtil.calculateAge("200013", TESTDATE, FORMAT);
+ }
+
+ /**
+ * Tests the {@link DateUtil#calculateAge} method for the given full date
+ * against the testDate: 2011-10-10 15:20:00.0. Must return a
+ * SecurityPEPSException exception.
+ */
+ @Test(expected = SecurityPEPSException.class)
+ public void calculateAgeFromInvalidDay() {
+ DateUtil.calculateAge("20000230", TESTDATE, FORMAT);
+ }
+
+ /**
+ * Tests the {@link DateUtil#calculateAge} method for the given full date
+ * against the testDate: 2011-10-10 15:20:00.0. Must return a
+ * SecurityPEPSException exception.
+ */
+ @Test(expected = SecurityPEPSException.class)
+ public void calculateAgeFromNullDate() {
+ DateUtil.calculateAge(null, TESTDATE, FORMAT);
+ }
+
+ /**
+ * Tests the {@link DateUtil#calculateAge} method for the given full date
+ * against the testDate: 2011-10-10 15:20:00.0. Must return a
+ * SecurityPEPSException exception.
+ */
+ @Test(expected = SecurityPEPSException.class)
+ public void calculateAgeFromNullCurDate() {
+ DateUtil.calculateAge("2000", null, FORMAT);
+ }
+
+ /**
+ * Tests the {@link DateUtil#calculateAge} method for the given full date
+ * against the testDate: 2011-10-10 15:20:00.0. Must return a
+ * SecurityPEPSException exception.
+ */
+ @Test(expected = SecurityPEPSException.class)
+ public void calculateAgeFromNullFormat() {
+ DateUtil.calculateAge("2000", TESTDATE, null);
+ }
+
+ /**
+ * Tests the {@link DateUtil#isValidFormatDate} method for the given year.
+ * Must return true
+ */
+ @Test
+ public void isValidFormatDateFromYear() {
+ Assert.assertTrue(DateUtil.isValidFormatDate("2000", FORMAT));
+ }
+
+ /**
+ * Tests the {@link DateUtil#isValidFormatDate} method for the given year
+ * and month. Must return true.
+ */
+ @Test
+ public void isValidFormatDateFromMonth() {
+ Assert.assertTrue(DateUtil.isValidFormatDate("200001", FORMAT));
+ }
+
+ /**
+ * Tests the {@link DateUtil#isValidFormatDate} method for the given year.
+ * Must return false.
+ */
+ @Test
+ public void isValidFormatDate() {
+ Assert.assertTrue(DateUtil.isValidFormatDate("20000101", FORMAT));
+ }
+
+ /**
+ * Tests the {@link DateUtil#isValidFormatDate} method for the given year.
+ * Must return false.
+ */
+ @Test
+ public void isValidFormatDateInvalidYear() {
+ Assert.assertFalse(DateUtil.isValidFormatDate("200", FORMAT));
+ }
+
+ /**
+ * Tests the {@link DateUtil#isValidFormatDate} method for the given year.
+ * Must return false.
+ */
+ @Test
+ public void isValidFormatDateInvalidMonth() {
+ Assert.assertFalse(DateUtil.isValidFormatDate("200013", FORMAT));
+ }
+
+ /**
+ * Tests the {@link DateUtil#isValidFormatDate} method for the given year.
+ * Must return false.
+ */
+ @Test
+ public void isValidFormatDateInvalidDate() {
+ Assert.assertFalse(DateUtil.isValidFormatDate("20010229", FORMAT));
+ }
+
+ /**
+ * Tests the {@link DateUtil#isValidFormatDate} method for the given year.
+ * Must return false.
+ */
+ @Test
+ public void isValidFormatDateNullDate() {
+ Assert.assertFalse(DateUtil.isValidFormatDate(null, FORMAT));
+ }
+
+ /**
+ * Tests the {@link DateUtil#isValidFormatDate} method for the given year.
+ * Must return false.
+ */
+ @Test
+ public void isValidFormatDateNullFormat() {
+ Assert.assertFalse(DateUtil.isValidFormatDate("2000", null));
+ }
+
+ /**
+ * Tests the {@link DateUtil#currentTimeStamp()} method for the current
+ * TimeStamp (TS). Must return true.
+ */
+ @Test
+ public void testCurrentTimeStampBefore() {
+ Timestamp ts = DateUtil.currentTimeStamp();
+ Assert.assertNotSame(ts, DateUtil.currentTimeStamp());
+ }
+
+ /**
+ * Tests the {@link DateUtil#currentTimeStamp()} method for the current
+ * TimeStamp (TS). Must return true.
+ */
+ @Test
+ public void testCurrentTimeStampAfter() {
+ Timestamp ts = DateUtil.currentTimeStamp();
+ Assert.assertEquals(DateUtil.currentTimeStamp(), ts);
+ }
+
}
diff --git a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PEPSUtilTestCase.java b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PEPSUtilTestCase.java
index d4841ed43..95c1f4594 100644
--- a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PEPSUtilTestCase.java
+++ b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PEPSUtilTestCase.java
@@ -36,518 +36,518 @@ import eu.stork.peps.auth.commons.exceptions.InvalidParameterPEPSException;
/**
* The PEPSUtil's Test Case.
- *
+ *
* @author ricardo.ferreira@multicert.com, renato.portela@multicert.com,
- * luis.felix@multicert.com
- *
+ * luis.felix@multicert.com
+ *
* @version $Revision: $, $Date: $
*/
public final class PEPSUtilTestCase {
-
- /**
- * Message example.
- */
- private static final String MESSAGE_SAMPLE = "003002 - Authentication Failed";
-
- /**
- * Error message example.
- */
- private static final String ERROR_MESSAGE_SAMPLE = "Authentication Failed";
-
- /**
- * Error code example.
- */
- private static final String ERROR_CODE_SAMPLE = "003002";
-
- /**
- * Properties values for testing proposes.
- */
- private static final Properties CONFIGS1 = new Properties();
-
- /**
- * Properties values for testing proposes.
- */
- private static final Properties CONFIGS2 = new Properties();
-
- /**
- * The empty string value: "".
- */
- private static final String EMPTY_STRING = "";
-
- /**
- * The empty byte value: [].
- */
- private static final byte[] EMPTY_BYTE = new byte[] {};
-
- /**
- * The empty byte hash value.
- */
- private static final byte[] EMPTY_HASH_BYTE = new byte[] { -49, -125, -31,
- 53, 126, -17, -72, -67, -15, 84, 40, 80, -42, 109, -128, 7, -42, 32, -28,
- 5, 11, 87, 21, -36, -125, -12, -87, 33, -45, 108, -23, -50, 71, -48, -47,
- 60, 93, -123, -14, -80, -1, -125, 24, -46, -121, 126, -20, 47, 99, -71, 49,
- -67, 71, 65, 122, -127, -91, 56, 50, 122, -7, 39, -38, 62 };
-
- /**
- * The SAML example byte[] value.
- */
- private static final byte[] SAML_BYTE_SAMPLE = new byte[] { 60, 115, 97, 109,
- 108, 62, 46, 46, 46, 60, 47, 115, 97, 109, 108 };
-
- /**
- * The SAML's Base64 example value.
- */
- private static final String SAML_BASE64_SAMPLE = "PHNhbWw+Li4uPC9zYW1s";
-
- /**
- * The SAML's Base64 byte[] example value.
- */
- private static byte[] SAML_BASE64_BYTE_SAMPLE = new byte[] { 80, 72, 78, 104,
- 98, 87, 119, 43, 76, 105, 52, 117, 80, 67, 57, 122, 89, 87, 49, 115 };
-
- /**
- * The SAML's Base64 Hash byte[] example value.
- */
- private static byte[] HASH_BYTE_SAMPLE = new byte[] { 67, 38, 11, 115, 49,
- -5, 54, -85, 38, 43, -99, 96, 71, -41, 50, -96, 71, -86, 90, -97, 66, -67,
- 90, 101, 30, 82, -13, 60, -106, -72, -103, -75, 19, 2, -107, 107, -6, -56,
- 34, -111, -44, -57, -26, -5, 33, 78, -1, 30, 21, 74, -26, 118, -46, -12,
- -102, 12, -56, 30, -59, -104, -21, -42, -103, 82 };
-
- /**
- * Init PEPSUtilTestCase class.
- */
- @BeforeClass
- public static void runsBeforeTheTestSuite() {
-
- CONFIGS1.setProperty("max.attrList.size", "20000");
- CONFIGS1.setProperty("attrList.code", "202005");
- CONFIGS1.setProperty("attrList.message", "invalid.attrList.parameter");
-
- CONFIGS1.setProperty("max.qaaLevel.size", "1");
- CONFIGS1.setProperty("max.spUrl.size", "inv");
- CONFIGS1.setProperty("validation.active", "true");
- CONFIGS1.setProperty("hashDigest.className",
- "org.bouncycastle.crypto.digests.SHA512Digest");
- CONFIGS1.setProperty("invalidAgeDateValue.code", "35");
- CONFIGS1.setProperty("invalidAttributeValue.code", "34");
- CONFIGS1.setProperty("invalidAttributeValue.message",
- "Unexpected or invalid content was encountered within a "
- + "<saml:Attribute> or <saml:AttributeValue> element.");
- }
-
- /**
- * Tests the {@link PEPSUtil#createInstance(Properties)} method for the given
- * properties object.
- */
- @Test
- public void testCreateInstance() {
- Assert.assertNotNull(PEPSUtil.createInstance(CONFIGS2));
- }
-
- /**
- * Tests the {@link PEPSUtil#getConfigs()}.
- */
- @Test
- public void testGetConfigs() {
- final PEPSUtil pepsUtils = PEPSUtil.createInstance(CONFIGS1);
- assertEquals(pepsUtils.getConfigs(), CONFIGS1);
- }
-
- /**
- * Tests the {@link PEPSUtil#getConfigs()}.
- */
- @Test
- public void testGetConfigsDifferent() {
- final PEPSUtil pepsUtils = PEPSUtil.createInstance(CONFIGS1);
- assertNotSame(pepsUtils.getConfigs(), CONFIGS2);
- }
-
- /**
- * Tests the {@link PEPSUtil#getConfig(String)} method for the given existing
- * config.
- */
- @Test
- public void testGetConfigExists() {
- assertEquals(PEPSUtil.getConfig("hashDigest.className"),
- "org.bouncycastle.crypto.digests.SHA512Digest");
- }
-
- /**
- * Tests the {@link PEPSUtil#getConfig(String)} method for the given not
- * existing config.
- */
- @Test
- public void testGetConfigNoExists() {
- assertNull(PEPSUtil.getConfig("doesnt.exists"));
- }
-
- /**
- * Tests the {@link PEPSUtil#getConfig(String)} method for the given null
- * value.
- */
- @Test(expected = NullPointerException.class)
- public void testGetConfigNull() {
- assertNull(PEPSUtil.getConfig(null));
- }
-
- /**
- * Tests the {@link PEPSUtil#isValidParameter(String, String)} method for the
- * given param values.
- */
- @Test
- public void testIsValidParameterExists() {
- assertTrue(PEPSUtil.isValidParameter("qaaLevel", "1"));
- }
-
- /**
- * Tests the {@link PEPSUtil#isValidParameter(String, String)} method for the
- * given param values.
- */
- @Test
- public void testIsValidParameterExistsGreat() {
- assertFalse(PEPSUtil.isValidParameter("qaaLevel", "12"));
- }
-
- /**
- * Tests the {@link PEPSUtil#isValidParameter(String, String)} method for the
- * given param values.
- */
- @Test
- public void testIsValidParameterExistsIvalidConf() {
- assertFalse(PEPSUtil
- .isValidParameter("spUrl", "http://localhost:8080/SP/"));
- }
-
- /**
- * Tests the {@link PEPSUtil#isValidParameter(String, String)} method for the
- * given param values.
- */
- @Test
- public void testIsValidParameterNotExists() {
- assertFalse(PEPSUtil.isValidParameter("doesntexists",
- "http://localhost:8080/SP/"));
- }
-
- /**
- * Tests the {@link PEPSUtil#isValidParameter(String, String)} method for the
- * given param values.
- */
- @Test
- public void testIsValidParameterNullParamName() {
- assertFalse(PEPSUtil.isValidParameter(null, "http://localhost:8080/SP/"));
- }
-
- /**
- * Tests the {@link PEPSUtil#isValidParameter(String, String)} method for the
- * given param values.
- */
- @Test
- public void testIsValidParameterNullParamValue() {
- assertFalse(PEPSUtil.isValidParameter("spUrl", null));
- }
-
- /**
- * Tests the {@link PEPSUtil#validateParameter(String, String, Object)} method
- * for the given object values.
- */
- @Test
- public void testValidateParameterValid() {
- final IPersonalAttributeList persAttrList = new PersonalAttributeList();
- persAttrList.populate("isAgeOver:true:[15,]:Available;");
- PEPSUtil.validateParameter("ServiceProviderAction",
- PEPSParameters.ATTRIBUTE_LIST.toString(), persAttrList);
- }
-
- /**
- * Tests the {@link PEPSUtil#validateParameter(String, String, Object)} method
- * for the given string values.
- */
- @Test(expected = InvalidParameterPEPSException.class)
- public void testValidateParameterNull() {
- PEPSUtil.validateParameter("ServiceProviderAction",
- PEPSParameters.ATTRIBUTE_LIST.toString(), null);
- }
-
- /**
- * Tests the {@link PEPSUtil#validateParameter(String, String, String)} method
- * for the given string values.
- *
- * The tested class just invokes
- * {@link PEPSUtil#validateParameter(String, String, String, String, String)}
- * so further tests will be later.
- */
- @Test
- public void testValidateParameter() {
- PEPSUtil.validateParameter("ServiceProviderAction",
- PEPSParameters.ATTRIBUTE_LIST.toString(),
- "isAgeOver:true:[15,]:Available;");
- }
-
- /**
- * Tests the
- * {@link PEPSUtil#validateParameter(String, String, String, PEPSErrors)}
- * method for the given string value and {@link PEPSErrors} enum.
- *
- * The tested class just invokes
- * {@link PEPSUtil#validateParameter(String, String, String, String, String)}
- * so further tests will be later.
- */
- @Test
- public void testValidateParameterPEPSErrors() {
- PEPSUtil.validateParameter("CountrySelectorAction",
- PEPSParameters.ATTRIBUTE_LIST.toString(),
- "isAgeOver:true:[15,]:Available;",
- PEPSErrors.SP_COUNTRY_SELECTOR_INVALID_ATTR);
- }
-
- /**
- * Tests the
- * {@link PEPSUtil#validateParameter(String, String, String, String, String)}
- * method for the given string values.
- */
- @Test
- public void testValidateParameterValidParams() {
- PEPSUtil.validateParameter("ServiceProviderAction", "qaaLevel", "1",
- "qaaLevel.code", "qaaLevel.message");
- }
-
- /**
- * Tests the
- * {@link PEPSUtil#validateParameter(String, String, String, String, String)}
- * method for the given string values.
- */
- @Test(expected = InvalidParameterPEPSException.class)
- public void testValidateParameterInvalidParamValue() {
- PEPSUtil.validateParameter("ServiceProviderAction", "qaaLevel", "10",
- "qaaLevel.code", "qaaLevel.message");
- }
-
- /**
- * Tests the
- * {@link PEPSUtil#validateParameter(String, String, String, String, String)}
- * method for the given string values.
- */
- @Test(expected = InvalidParameterPEPSException.class)
- public void testValidateParameterInvalidParamName() {
- PEPSUtil.validateParameter("ServiceProviderAction", "doesnt.exists", "1",
- "qaaLevel.code", "qaaLevel.message");
- }
-
- /**
- * Tests the
- * {@link PEPSUtil#validateParameter(String, String, String, String, String)}
- * method for the given string values.
- */
- @Test(expected = InvalidParameterPEPSException.class)
- public void testValidateParameterNullParamName() {
- PEPSUtil.validateParameter("ServiceProviderAction", null, "1",
- "qaaLevel.code", "qaaLevel.message");
- }
-
- /**
- * Tests the
- * {@link PEPSUtil#validateParameter(String, String, String, String, String)}
- * method for the given string values.
- */
- @Test(expected = InvalidParameterPEPSException.class)
- public void testValidateParameterNullParamValue() {
- PEPSUtil.validateParameter("ServiceProviderAction", "qaaLevel", null,
- "qaaLevel.code", "qaaLevel.message");
- }
-
- /**
- * Tests the {@link PEPSUtil#encodeSAMLToken(byte[])} method for the given
- * string value.
- */
- @Test
- public void testEncodeSAMLToken() {
- assertEquals(PEPSUtil.encodeSAMLToken(SAML_BYTE_SAMPLE), SAML_BASE64_SAMPLE);
- }
-
- /**
- * Tests the {@link PEPSUtil#encodeSAMLToken(byte[])} method for the given
- * null.
- */
- @Test(expected = NullPointerException.class)
- public void testEncodeSAMLTokenNull() {
- assertNotSame(PEPSUtil.encodeSAMLToken(null), SAML_BASE64_SAMPLE);
- }
-
- /**
- * Tests the {@link PEPSUtil#encodeSAMLToken(byte[])} method for the given
- * empty byte[] value.
- */
- @Test
- public void testEncodeSAMLTokenEmpty() {
- assertEquals(PEPSUtil.encodeSAMLToken(EMPTY_BYTE), EMPTY_STRING);
- }
-
- /**
- * Tests the {@link PEPSUtil#decodeSAMLToken(byte[])} method for the given
- * byte[] value.
- */
- @Test
- public void testDecodeSAMLToken() {
- assertArrayEquals(PEPSUtil.decodeSAMLToken(SAML_BASE64_SAMPLE),
- SAML_BYTE_SAMPLE);
- }
-
- /**
- * Tests the {@link PEPSUtil#decodeSAMLToken(byte[])} method for the given
- * null value.
- */
- @Test(expected = NullPointerException.class)
- public void testDecodeSAMLTokenNull() {
- assertNotSame(PEPSUtil.decodeSAMLToken(null), SAML_BYTE_SAMPLE);
- }
-
- /**
- * Tests the {@link PEPSUtil#decodeSAMLToken(byte[])} method for the given
- * empty string value.
- */
- @Test(expected = StringIndexOutOfBoundsException.class)
- public void testDecodeSAMLTokenEmpty() {
- assertTrue(PEPSUtil.decodeSAMLToken(EMPTY_STRING) == EMPTY_BYTE);
- }
-
- /**
- * Tests the {@link PEPSUtil#hashPersonalToken(byte[])} method for the given
- * byte[] value.
- */
- @Test
- public void testHashPersonalToken() {
- assertArrayEquals(PEPSUtil.hashPersonalToken(SAML_BASE64_BYTE_SAMPLE),
- HASH_BYTE_SAMPLE);
- }
-
- /**
- * Tests the {@link PEPSUtil#hashPersonalToken(byte[])} method for the given
- * null value.
- */
- @Test(expected = InternalErrorPEPSException.class)
- public void testHashPersonalTokenNull() {
- assertNull(PEPSUtil.hashPersonalToken(null));
- }
-
- /**
- * Tests the {@link PEPSUtil#hashPersonalToken(byte[])} method for the given
- * empty value.
- */
- @Test
- public void testHashPersonalTokenEmpty() {
- assertArrayEquals(PEPSUtil.hashPersonalToken(EMPTY_BYTE), EMPTY_HASH_BYTE);
- }
-
- /**
- * Tests the {@link PEPSUtil#getStorkErrorCode(String)} method for the given
- * correct message.
- */
- @Test
- public void testGetStorkErrorCodeExists() {
- assertEquals(PEPSUtil.getStorkErrorCode(MESSAGE_SAMPLE), ERROR_CODE_SAMPLE);
- }
-
- /**
- * Tests the {@link PEPSUtil#getStorkErrorCode(String)} method for the given
- * invalid message.
- */
- @Test
- public void testGetStorkErrorCodeNoExists() {
- assertNull(PEPSUtil.getStorkErrorCode(ERROR_MESSAGE_SAMPLE));
- }
-
- /**
- * Tests the {@link PEPSUtil#getStorkErrorCode(String)} method for the given
- * empty message.
- */
- @Test
- public void testGetStorkErrorCodeEmpty() {
- assertNull(PEPSUtil.getStorkErrorCode(EMPTY_STRING));
- }
-
- /**
- * Tests the {@link PEPSUtil#getStorkErrorCode(String)} method for the given
- * null message.
- */
- @Test
- public void testGetStorkErrorCodeNull() {
- assertNull(PEPSUtil.getStorkErrorCode(null));
- }
-
- /**
- * Tests the {@link PEPSUtil#getStorkErrorCode(String)} method for the given
- * invalid message.
- */
- @Test
- public void testGetStorkErrorCodeWithSepFake() {
- assertNull(PEPSUtil.getStorkErrorCode("-"));
- }
-
- /**
- * Tests the {@link PEPSUtil#getStorkErrorCode(String)} method for the given
- * invalid message.
- */
- @Test
- public void testGetStorkErrorCodeWithSepAndCodeFake() {
- assertNull(PEPSUtil.getStorkErrorCode("000001 -"));
- }
-
- /**
- * Tests the {@link PEPSUtil#getStorkErrorMessage(String)} method for the
- * given correct message.
- */
- @Test
- public void testGetStorkErrorMessageExists() {
- assertEquals(PEPSUtil.getStorkErrorMessage(MESSAGE_SAMPLE),
- ERROR_MESSAGE_SAMPLE);
- }
-
- /**
- * Tests the {@link PEPSUtil#getStorkErrorMessage(String)} method for the
- * given invalid message.
- */
- @Test
- public void testGetStorkErrorMessageNoExists() {
- assertEquals(PEPSUtil.getStorkErrorMessage(ERROR_MESSAGE_SAMPLE),
- ERROR_MESSAGE_SAMPLE);
- }
-
- /**
- * Tests the {@link PEPSUtil#getStorkErrorMessage(String)} method for the
- * given empty message.
- */
- @Test
- public void testGetStorkErrorMessageEmpty() {
- assertEquals(PEPSUtil.getStorkErrorMessage(EMPTY_STRING),
- EMPTY_STRING);
- }
-
- /**
- * Tests the {@link PEPSUtil#getStorkErrorMessage(String)} method for the
- * given null message.
- */
- @Test
- public void testGetStorkErrorMessageNull() {
- assertNull(PEPSUtil.getStorkErrorMessage(null));
- }
-
- /**
- * Tests the {@link PEPSUtil#getStorkErrorMessage(String)} method for the
- * given invalid message.
- */
- @Test
- public void testGetStorkErrorMessageWithSepFake() {
- assertEquals(PEPSUtil.getStorkErrorMessage("-"),"-");
- }
-
- /**
- * Tests the {@link PEPSUtil#getStorkErrorMessage(String)} method for the
- * given invalid message.
- */
- @Test
- public void testGetStorkErrorMessageWithSepAndCodeFake() {
- assertEquals(PEPSUtil.getStorkErrorMessage("000001 -"),"000001 -");
- }
-
+
+ /**
+ * Message example.
+ */
+ private static final String MESSAGE_SAMPLE = "003002 - Authentication Failed";
+
+ /**
+ * Error message example.
+ */
+ private static final String ERROR_MESSAGE_SAMPLE = "Authentication Failed";
+
+ /**
+ * Error code example.
+ */
+ private static final String ERROR_CODE_SAMPLE = "003002";
+
+ /**
+ * Properties values for testing proposes.
+ */
+ private static final Properties CONFIGS1 = new Properties();
+
+ /**
+ * Properties values for testing proposes.
+ */
+ private static final Properties CONFIGS2 = new Properties();
+
+ /**
+ * The empty string value: "".
+ */
+ private static final String EMPTY_STRING = "";
+
+ /**
+ * The empty byte value: [].
+ */
+ private static final byte[] EMPTY_BYTE = new byte[]{};
+
+ /**
+ * The empty byte hash value.
+ */
+ private static final byte[] EMPTY_HASH_BYTE = new byte[]{-49, -125, -31,
+ 53, 126, -17, -72, -67, -15, 84, 40, 80, -42, 109, -128, 7, -42, 32, -28,
+ 5, 11, 87, 21, -36, -125, -12, -87, 33, -45, 108, -23, -50, 71, -48, -47,
+ 60, 93, -123, -14, -80, -1, -125, 24, -46, -121, 126, -20, 47, 99, -71, 49,
+ -67, 71, 65, 122, -127, -91, 56, 50, 122, -7, 39, -38, 62};
+
+ /**
+ * The SAML example byte[] value.
+ */
+ private static final byte[] SAML_BYTE_SAMPLE = new byte[]{60, 115, 97, 109,
+ 108, 62, 46, 46, 46, 60, 47, 115, 97, 109, 108};
+
+ /**
+ * The SAML's Base64 example value.
+ */
+ private static final String SAML_BASE64_SAMPLE = "PHNhbWw+Li4uPC9zYW1s";
+
+ /**
+ * The SAML's Base64 byte[] example value.
+ */
+ private static byte[] SAML_BASE64_BYTE_SAMPLE = new byte[]{80, 72, 78, 104,
+ 98, 87, 119, 43, 76, 105, 52, 117, 80, 67, 57, 122, 89, 87, 49, 115};
+
+ /**
+ * The SAML's Base64 Hash byte[] example value.
+ */
+ private static byte[] HASH_BYTE_SAMPLE = new byte[]{67, 38, 11, 115, 49,
+ -5, 54, -85, 38, 43, -99, 96, 71, -41, 50, -96, 71, -86, 90, -97, 66, -67,
+ 90, 101, 30, 82, -13, 60, -106, -72, -103, -75, 19, 2, -107, 107, -6, -56,
+ 34, -111, -44, -57, -26, -5, 33, 78, -1, 30, 21, 74, -26, 118, -46, -12,
+ -102, 12, -56, 30, -59, -104, -21, -42, -103, 82};
+
+ /**
+ * Init PEPSUtilTestCase class.
+ */
+ @BeforeClass
+ public static void runsBeforeTheTestSuite() {
+
+ CONFIGS1.setProperty("max.attrList.size", "20000");
+ CONFIGS1.setProperty("attrList.code", "202005");
+ CONFIGS1.setProperty("attrList.message", "invalid.attrList.parameter");
+
+ CONFIGS1.setProperty("max.qaaLevel.size", "1");
+ CONFIGS1.setProperty("max.spUrl.size", "inv");
+ CONFIGS1.setProperty("validation.active", "true");
+ CONFIGS1.setProperty("hashDigest.className",
+ "org.bouncycastle.crypto.digests.SHA512Digest");
+ CONFIGS1.setProperty("invalidAgeDateValue.code", "35");
+ CONFIGS1.setProperty("invalidAttributeValue.code", "34");
+ CONFIGS1.setProperty("invalidAttributeValue.message",
+ "Unexpected or invalid content was encountered within a "
+ + "<saml:Attribute> or <saml:AttributeValue> element.");
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#createInstance(Properties)} method for the
+ * given properties object.
+ */
+ @Test
+ public void testCreateInstance() {
+ Assert.assertNotNull(PEPSUtil.createInstance(CONFIGS2));
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#getConfigs()}.
+ */
+ @Test
+ public void testGetConfigs() {
+ final PEPSUtil pepsUtils = PEPSUtil.createInstance(CONFIGS1);
+ assertEquals(pepsUtils.getConfigs(), CONFIGS1);
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#getConfigs()}.
+ */
+ @Test
+ public void testGetConfigsDifferent() {
+ final PEPSUtil pepsUtils = PEPSUtil.createInstance(CONFIGS1);
+ assertNotSame(pepsUtils.getConfigs(), CONFIGS2);
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#getConfig(String)} method for the given
+ * existing config.
+ */
+ @Test
+ public void testGetConfigExists() {
+ assertEquals(PEPSUtil.getConfig("hashDigest.className"),
+ "org.bouncycastle.crypto.digests.SHA512Digest");
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#getConfig(String)} method for the given not
+ * existing config.
+ */
+ @Test
+ public void testGetConfigNoExists() {
+ assertNull(PEPSUtil.getConfig("doesnt.exists"));
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#getConfig(String)} method for the given null
+ * value.
+ */
+ @Test(expected = NullPointerException.class)
+ public void testGetConfigNull() {
+ assertNull(PEPSUtil.getConfig(null));
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#isValidParameter(String, String)} method for
+ * the given param values.
+ */
+ @Test
+ public void testIsValidParameterExists() {
+ assertTrue(PEPSUtil.isValidParameter("qaaLevel", "1"));
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#isValidParameter(String, String)} method for
+ * the given param values.
+ */
+ @Test
+ public void testIsValidParameterExistsGreat() {
+ assertFalse(PEPSUtil.isValidParameter("qaaLevel", "12"));
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#isValidParameter(String, String)} method for
+ * the given param values.
+ */
+ @Test
+ public void testIsValidParameterExistsIvalidConf() {
+ assertFalse(PEPSUtil
+ .isValidParameter("spUrl", "http://localhost:8080/SP/"));
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#isValidParameter(String, String)} method for
+ * the given param values.
+ */
+ @Test
+ public void testIsValidParameterNotExists() {
+ assertFalse(PEPSUtil.isValidParameter("doesntexists",
+ "http://localhost:8080/SP/"));
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#isValidParameter(String, String)} method for
+ * the given param values.
+ */
+ @Test
+ public void testIsValidParameterNullParamName() {
+ assertFalse(PEPSUtil.isValidParameter(null, "http://localhost:8080/SP/"));
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#isValidParameter(String, String)} method for
+ * the given param values.
+ */
+ @Test
+ public void testIsValidParameterNullParamValue() {
+ assertFalse(PEPSUtil.isValidParameter("spUrl", null));
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#validateParameter(String, String, Object)}
+ * method for the given object values.
+ */
+ @Test
+ public void testValidateParameterValid() {
+ final IPersonalAttributeList persAttrList = new PersonalAttributeList();
+ persAttrList.populate("isAgeOver:true:[15,]:Available;");
+ PEPSUtil.validateParameter("ServiceProviderAction",
+ PEPSParameters.ATTRIBUTE_LIST.toString(), persAttrList);
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#validateParameter(String, String, Object)}
+ * method for the given string values.
+ */
+ @Test(expected = InvalidParameterPEPSException.class)
+ public void testValidateParameterNull() {
+ PEPSUtil.validateParameter("ServiceProviderAction",
+ PEPSParameters.ATTRIBUTE_LIST.toString(), null);
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#validateParameter(String, String, String)}
+ * method for the given string values.
+ *
+ * The tested class just invokes
+ * {@link PEPSUtil#validateParameter(String, String, String, String, String)}
+ * so further tests will be later.
+ */
+ @Test
+ public void testValidateParameter() {
+ PEPSUtil.validateParameter("ServiceProviderAction",
+ PEPSParameters.ATTRIBUTE_LIST.toString(),
+ "isAgeOver:true:[15,]:Available;");
+ }
+
+ /**
+ * Tests the
+ * {@link PEPSUtil#validateParameter(String, String, String, PEPSErrors)}
+ * method for the given string value and {@link PEPSErrors} enum.
+ *
+ * The tested class just invokes
+ * {@link PEPSUtil#validateParameter(String, String, String, String, String)}
+ * so further tests will be later.
+ */
+ @Test
+ public void testValidateParameterPEPSErrors() {
+ PEPSUtil.validateParameter("CountrySelectorAction",
+ PEPSParameters.ATTRIBUTE_LIST.toString(),
+ "isAgeOver:true:[15,]:Available;",
+ PEPSErrors.SP_COUNTRY_SELECTOR_INVALID_ATTR);
+ }
+
+ /**
+ * Tests the
+ * {@link PEPSUtil#validateParameter(String, String, String, String, String)}
+ * method for the given string values.
+ */
+ @Test
+ public void testValidateParameterValidParams() {
+ PEPSUtil.validateParameter("ServiceProviderAction", "qaaLevel", "1",
+ "qaaLevel.code", "qaaLevel.message");
+ }
+
+ /**
+ * Tests the
+ * {@link PEPSUtil#validateParameter(String, String, String, String, String)}
+ * method for the given string values.
+ */
+ @Test(expected = InvalidParameterPEPSException.class)
+ public void testValidateParameterInvalidParamValue() {
+ PEPSUtil.validateParameter("ServiceProviderAction", "qaaLevel", "10",
+ "qaaLevel.code", "qaaLevel.message");
+ }
+
+ /**
+ * Tests the
+ * {@link PEPSUtil#validateParameter(String, String, String, String, String)}
+ * method for the given string values.
+ */
+ @Test(expected = InvalidParameterPEPSException.class)
+ public void testValidateParameterInvalidParamName() {
+ PEPSUtil.validateParameter("ServiceProviderAction", "doesnt.exists", "1",
+ "qaaLevel.code", "qaaLevel.message");
+ }
+
+ /**
+ * Tests the
+ * {@link PEPSUtil#validateParameter(String, String, String, String, String)}
+ * method for the given string values.
+ */
+ @Test(expected = InvalidParameterPEPSException.class)
+ public void testValidateParameterNullParamName() {
+ PEPSUtil.validateParameter("ServiceProviderAction", null, "1",
+ "qaaLevel.code", "qaaLevel.message");
+ }
+
+ /**
+ * Tests the
+ * {@link PEPSUtil#validateParameter(String, String, String, String, String)}
+ * method for the given string values.
+ */
+ @Test(expected = InvalidParameterPEPSException.class)
+ public void testValidateParameterNullParamValue() {
+ PEPSUtil.validateParameter("ServiceProviderAction", "qaaLevel", null,
+ "qaaLevel.code", "qaaLevel.message");
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#encodeSAMLToken(byte[])} method for the given
+ * string value.
+ */
+ @Test
+ public void testEncodeSAMLToken() {
+ assertEquals(PEPSUtil.encodeSAMLToken(SAML_BYTE_SAMPLE), SAML_BASE64_SAMPLE);
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#encodeSAMLToken(byte[])} method for the given
+ * null.
+ */
+ @Test(expected = NullPointerException.class)
+ public void testEncodeSAMLTokenNull() {
+ assertNotSame(PEPSUtil.encodeSAMLToken(null), SAML_BASE64_SAMPLE);
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#encodeSAMLToken(byte[])} method for the given
+ * empty byte[] value.
+ */
+ @Test
+ public void testEncodeSAMLTokenEmpty() {
+ assertEquals(PEPSUtil.encodeSAMLToken(EMPTY_BYTE), EMPTY_STRING);
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#decodeSAMLToken(byte[])} method for the given
+ * byte[] value.
+ */
+ @Test
+ public void testDecodeSAMLToken() {
+ assertArrayEquals(PEPSUtil.decodeSAMLToken(SAML_BASE64_SAMPLE),
+ SAML_BYTE_SAMPLE);
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#decodeSAMLToken(byte[])} method for the given
+ * null value.
+ */
+ @Test(expected = NullPointerException.class)
+ public void testDecodeSAMLTokenNull() {
+ assertNotSame(PEPSUtil.decodeSAMLToken(null), SAML_BYTE_SAMPLE);
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#decodeSAMLToken(byte[])} method for the given
+ * empty string value.
+ */
+ @Test(expected = StringIndexOutOfBoundsException.class)
+ public void testDecodeSAMLTokenEmpty() {
+ assertTrue(PEPSUtil.decodeSAMLToken(EMPTY_STRING) == EMPTY_BYTE);
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#hashPersonalToken(byte[])} method for the given
+ * byte[] value.
+ */
+ @Test
+ public void testHashPersonalToken() {
+ assertArrayEquals(PEPSUtil.hashPersonalToken(SAML_BASE64_BYTE_SAMPLE),
+ HASH_BYTE_SAMPLE);
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#hashPersonalToken(byte[])} method for the given
+ * null value.
+ */
+ @Test(expected = InternalErrorPEPSException.class)
+ public void testHashPersonalTokenNull() {
+ assertNull(PEPSUtil.hashPersonalToken(null));
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#hashPersonalToken(byte[])} method for the given
+ * empty value.
+ */
+ @Test
+ public void testHashPersonalTokenEmpty() {
+ assertArrayEquals(PEPSUtil.hashPersonalToken(EMPTY_BYTE), EMPTY_HASH_BYTE);
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#getStorkErrorCode(String)} method for the given
+ * correct message.
+ */
+ @Test
+ public void testGetStorkErrorCodeExists() {
+ assertEquals(PEPSUtil.getStorkErrorCode(MESSAGE_SAMPLE), ERROR_CODE_SAMPLE);
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#getStorkErrorCode(String)} method for the given
+ * invalid message.
+ */
+ @Test
+ public void testGetStorkErrorCodeNoExists() {
+ assertNull(PEPSUtil.getStorkErrorCode(ERROR_MESSAGE_SAMPLE));
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#getStorkErrorCode(String)} method for the given
+ * empty message.
+ */
+ @Test
+ public void testGetStorkErrorCodeEmpty() {
+ assertNull(PEPSUtil.getStorkErrorCode(EMPTY_STRING));
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#getStorkErrorCode(String)} method for the given
+ * null message.
+ */
+ @Test
+ public void testGetStorkErrorCodeNull() {
+ assertNull(PEPSUtil.getStorkErrorCode(null));
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#getStorkErrorCode(String)} method for the given
+ * invalid message.
+ */
+ @Test
+ public void testGetStorkErrorCodeWithSepFake() {
+ assertNull(PEPSUtil.getStorkErrorCode("-"));
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#getStorkErrorCode(String)} method for the given
+ * invalid message.
+ */
+ @Test
+ public void testGetStorkErrorCodeWithSepAndCodeFake() {
+ assertNull(PEPSUtil.getStorkErrorCode("000001 -"));
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#getStorkErrorMessage(String)} method for the
+ * given correct message.
+ */
+ @Test
+ public void testGetStorkErrorMessageExists() {
+ assertEquals(PEPSUtil.getStorkErrorMessage(MESSAGE_SAMPLE),
+ ERROR_MESSAGE_SAMPLE);
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#getStorkErrorMessage(String)} method for the
+ * given invalid message.
+ */
+ @Test
+ public void testGetStorkErrorMessageNoExists() {
+ assertEquals(PEPSUtil.getStorkErrorMessage(ERROR_MESSAGE_SAMPLE),
+ ERROR_MESSAGE_SAMPLE);
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#getStorkErrorMessage(String)} method for the
+ * given empty message.
+ */
+ @Test
+ public void testGetStorkErrorMessageEmpty() {
+ assertEquals(PEPSUtil.getStorkErrorMessage(EMPTY_STRING),
+ EMPTY_STRING);
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#getStorkErrorMessage(String)} method for the
+ * given null message.
+ */
+ @Test
+ public void testGetStorkErrorMessageNull() {
+ assertNull(PEPSUtil.getStorkErrorMessage(null));
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#getStorkErrorMessage(String)} method for the
+ * given invalid message.
+ */
+ @Test
+ public void testGetStorkErrorMessageWithSepFake() {
+ assertEquals(PEPSUtil.getStorkErrorMessage("-"), "-");
+ }
+
+ /**
+ * Tests the {@link PEPSUtil#getStorkErrorMessage(String)} method for the
+ * given invalid message.
+ */
+ @Test
+ public void testGetStorkErrorMessageWithSepAndCodeFake() {
+ assertEquals(PEPSUtil.getStorkErrorMessage("000001 -"), "000001 -");
+ }
+
}
diff --git a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PersonalAttributeListTestCase.java b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PersonalAttributeListTestCase.java
index 7052b320a..7800e78b5 100644
--- a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PersonalAttributeListTestCase.java
+++ b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PersonalAttributeListTestCase.java
@@ -22,726 +22,756 @@ import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
+import eu.stork.peps.auth.commons.IPersonalAttributeList;
import eu.stork.peps.auth.commons.PersonalAttribute;
import eu.stork.peps.auth.commons.PersonalAttributeList;
import eu.stork.peps.auth.commons.STORKStatusCode;
/**
* The PersonalAttributeList'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.5 $, $Date: 2010-11-17 05:17:02 $
*/
public final class PersonalAttributeListTestCase {
-
- /**
- * isAgeOver constant value.
- */
- private static final String ISAGEOVER_CONS = "isAgeOver";
-
- /**
- * 1 constant value.
- */
- private static final int ONE_CONS = 1;
-
- /**
- * 2 constant value.
- */
- private static final int TWO_CONS = 2;
-
- /**
- * An empty attribute.
- */
- @SuppressWarnings("unused")
- private static final PersonalAttributeList EMPTY_ATTR_LIST =
- new PersonalAttributeList(0);
-
- /**
- * An attribute with a complex value (canonicalResidenceAddress).
- */
- private static PersonalAttribute complexAttrValue = null;
-
- /**
- * Simple attribute value list string.
- */
- private static final String SIMPLE_ATTRLIST =
- "isAgeOver:true:[15,]:Available;";
-
- /**
- * Simple attribute value list string.
- */
- private static final String SIMPLE_ATTRLIST2 =
- "isAgeOver:true:[18,]:Available;";
-
- /**
- * Simple attribute value list string.
- */
- private static final String SIMPLE_ATTRLIST3 =
- "isAgeOver:true:[15,]:Available;isAgeOver:true:[18,]:Available;";
-
- /**
- * Simple attribute value list string.
- */
- private static final String SIMPLE_ATTRLIST3_REVERSE =
- "isAgeOver:true:[18,]:Available;isAgeOver:true:[15,]:Available;";
- /**
- * Simple attribute value list string.
- */
- private static final String COMPLEX_ATTRLIST =
- "canonicalResidenceAddress:true:[postalCode=4100,apartmentNumber=Ed. B,"
- + "state=Porto,countryCodeAddress=PT,streetNumber=379,"
- + "streetName=Avenida Sidonio Pais,town=Porto,]:Available;";
- /**
- * Mix attribute list string.
- */
- private static final String STR_MIX_ATTR_LIST =
- "isAgeOver:true:[15,]:Available;canonicalResidenceAddress:true:["
- + "postalCode=4100,apartmentNumber=Ed.B,state=Porto,countryCodeAddress=PT,"
- + "streetNumber=379,streetName=Avenida Sidonio Pais,town=Porto,]:"
- + "Available;";
-
- /**
- * Mix attribute list 2 string.
- */
- private static final String STR_MIX_ATTR_LIST2 =
- "isAgeOver:true:[15,]:Available;canonicalResidenceAddress:true:["
- + "postalCode=4100,apartmentNumber=Ed.B,state=Porto,countryCodeAddress=PT,"
- + "streetNumber=379,streetName=Avenida Sidonio Pais,town=Porto,]:Available;"
- + "mandateContent:true:["
- + "isJoint=\"isjoint\",typeOfPower=\"power\",ValidTo=\"validto\",validfrom=\"validfrom\",AQAA=\"3\",isChained=\"ischained\",]:"
- + "Available;";
-
- /**
- * Attribute List example.
- */
- @SuppressWarnings({ "serial" })
- private static final PersonalAttribute ATTR_VALUE = new PersonalAttribute(
- "age", true, new ArrayList<String>() {
- {
- add("15");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
-
- /**
- * Init PersonalAttributeListTestCase 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", "Ed. B");
- }
- };
-
- complexAttrValue =
- new PersonalAttribute("canonicalResidenceAddress", true, values,
- STORKStatusCode.STATUS_AVAILABLE.toString());
-
- }
-
- /**
- * Testing Personal Attribute List add method. Personal Attribute list must be
- * size 1 - Simple attribute.
- */
- @Test
- public void testAddSimpleAttr() {
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.add(ATTR_VALUE);
- Assert.assertTrue(attrList.size() == 1);
- }
-
- /**
- * Testing Personal Attribute List add method. Personal Attribute list must be
- * size 1 - Complex attribute.
- */
- @Test
- public void testAddCompleAttr() {
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.add(complexAttrValue);
- Assert.assertTrue(attrList.size() == 1);
- }
-
- /**
- * Testing Personal Attribute List add method. Personal Attribute list must be
- * size 0 - no attribute.
- */
- @Test
- public void testAddNull() {
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.add(null);
- Assert.assertTrue(attrList.size() == 0);
- }
-
- /**
- * Testing Personal Attribute List add method. Same attribute name added
- * twice. Personal Attribute list must be size 2 - IsAgeOver attribute added
- * twice.
- */
- @SuppressWarnings("serial")
- @Test
- public void testAddSameAttrName() {
- final PersonalAttribute attrValueUnder =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("15");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
-
- final PersonalAttribute attrValueOver =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("18");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.add(attrValueUnder);
- attrList.add(attrValueOver);
- Assert.assertTrue(attrList.size() == 2);
- }
-
- /**
- * Testing Personal Attribute List add method. Same attribute name added
- * twice. Personal Attribute list must be size 2 - IsAgeOver attribute added
- * twice.
- */
- @SuppressWarnings("serial")
- @Test
- public void testAddSameAttrNameEmpty() {
- final PersonalAttribute attrValueUnder =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("15");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
-
- final PersonalAttribute attrValueOver =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.add(attrValueUnder);
- attrList.add(attrValueOver);
- Assert.assertTrue(attrList.size() == 2);
- }
-
- /**
- * Testing Personal Attribute List put method. Personal Attribute list must be
- * size 1 - Simple Value.
- */
- @Test
- public void testPutSimpleAttr() {
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.put(ATTR_VALUE.getName(), ATTR_VALUE);
- Assert.assertTrue(attrList.size() == 1);
- }
-
- /**
- * Testing Personal Attribute List put method. Personal Attribute list must be
- * size 1 - Complex Value.
- */
- @Test
- public void testPutComplexAttr() {
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.put(ATTR_VALUE.getName(), complexAttrValue);
- Assert.assertTrue(attrList.size() == 1);
- }
-
- /**
- * Testing Personal Attribute List put method. Personal Attribute list must be
- * size 0 - no attribute.
- */
- @Test
- public void testPutNull() {
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.put("", null);
- Assert.assertTrue(attrList.size() == 0);
- }
-
- /**
- * Testing Personal Attribute List put method. Personal Attribute list must be
- * size 2 - IsAgeOver attribute added twice.
- */
- @SuppressWarnings("serial")
- @Test
- public void testPutSameAttrName() {
- final PersonalAttribute attrValueUnder =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("15");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
-
- final PersonalAttribute attrValueOver =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("18");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
-
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.put(attrValueUnder.getName(), attrValueUnder);
- attrList.put(attrValueOver.getName(), attrValueOver);
- Assert.assertTrue(attrList.size() == 2);
- }
-
- /**
- * Testing Personal Attribute List put method. Personal Attribute list must be
- * size 2 - IsAgeOver attribute added twice.
- */
- @SuppressWarnings("serial")
- @Test
- public void testPutSameAttrNameEmpty() {
- final PersonalAttribute attrValueUnder =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("15");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
-
- final PersonalAttribute attrValueOver =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
-
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.put(attrValueUnder.getName(), attrValueUnder);
- attrList.put(attrValueOver.getName(), attrValueOver);
- Assert.assertTrue(attrList.size() == 2);
- }
-
- /**
- * Testing Personal Attribute List get method. Personal Attribute list must be
- * size 1 - Simple attribute.
- */
- @Test
- public void testGetSimpleAttr() {
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.add(ATTR_VALUE);
- Assert.assertEquals(ATTR_VALUE, attrList.get(ATTR_VALUE.getName()));
- }
-
- /**
- * Testing Personal Attribute List add method. Personal Attribute list must be
- * size 1 - Complex attribute.
- */
- @Test
- public void testGetCompleAttr() {
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.add(complexAttrValue);
- Assert.assertEquals(complexAttrValue.toString(),
- attrList.get(complexAttrValue.getName()).toString());
- }
-
- /**
- * Testing Personal Attribute List get method. Personal Attribute list must be
- * size 2 - IsAgeOver attribute.
- */
- @SuppressWarnings("serial")
- @Test
- public void testGetIsAgeOverAttr() {
- final PersonalAttribute attrValueUnder =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("15");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
-
- final PersonalAttribute attrValueOver =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("18");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.add(attrValueUnder);
- attrList.add(attrValueOver);
- Assert.assertEquals(SIMPLE_ATTRLIST,
- attrList.get(attrValueUnder.getName()).toString());
- Assert.assertEquals(SIMPLE_ATTRLIST2,
- attrList.get(attrValueOver.getName()).toString());
- }
-
- /**
- * Testing Personal Attribute List populate method. Personal Attribute list
- * must be size 1 - Simple attribute.
- */
- @Test
- public void testPopulateSimpleAttr() {
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.populate(SIMPLE_ATTRLIST);
- Assert.assertTrue(attrList.size() == 1);
- }
-
- /**
- * Testing Personal Attribute List populate method. Personal Attribute list
- * must be size 1 - Complex attribute.
- */
- @Test
- public void testPopulateComplexAttr() {
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.populate(COMPLEX_ATTRLIST);
- Assert.assertTrue(attrList.size() == 1);
- }
-
- /**
- * Testing Personal Attribute List populate method. Personal Attribute list
- * must be size 1 - Simple and Complex attribute.
- */
- @Test
- public void testPopulateMixAttrs() {
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.populate(STR_MIX_ATTR_LIST);
- Assert.assertTrue(attrList.size() == 2);
- }
-
- /**
- * Testing Personal Attribute List toString method using add.
- */
- @SuppressWarnings("serial")
- @Test
- public void testToStringFromAdd() {
- final PersonalAttribute attrValueUnder =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("15");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
-
- final PersonalAttribute attrValueOver =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("18");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.add(attrValueUnder);
- attrList.add(attrValueOver);
- Assert.assertEquals(SIMPLE_ATTRLIST3_REVERSE, attrList.toString());
- }
-
- /**
- * Testing Personal Attribute List toString method using put.
- *
- */
- @SuppressWarnings("serial")
- @Test
- public void testToStringFromPut() {
- final PersonalAttribute attrValueUnder =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("15");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
-
- final PersonalAttribute attrValueOver =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("18");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.put(attrValueUnder.getName(), attrValueUnder);
- attrList.put(attrValueOver.getName(), attrValueOver);
- Assert.assertEquals(SIMPLE_ATTRLIST3_REVERSE, attrList.toString());
- }
-
- /**
- * Testing Personal Attribute List toString method using populate.
- */
- @Test
- public void testToStringFromSimplePopulate() {
- final String strAttrList = "isAgeOver:true";
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.populate(strAttrList);
- Assert.assertEquals("isAgeOver:true:[]:;", attrList.toString());
- }
-
- /**
- * Testing Personal Attribute List toString method using populate.
- */
- @Test
- public void testToStringFromPopulate() {
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.populate(SIMPLE_ATTRLIST3);
- Assert.assertEquals(SIMPLE_ATTRLIST3_REVERSE, attrList.toString());
- }
-
- /**
- * Testing Personal Attribute List populate method, with invalid values.
- */
- @Test
- public void testPopulateWithInvalidValuesFormat() {
- final PersonalAttributeList pal = new PersonalAttributeList();
- pal.populate("name:type:values:status;");
- Assert.assertEquals(pal, new PersonalAttributeList());
- }
-
- /**
- * Testing Personal Attribute List populate method, with invalid format.
- */
- @Test
- public void testPopulateWithInvalidFormat() {
-
- final PersonalAttributeList pal = new PersonalAttributeList();
- pal.populate("name:type::status;");
- Assert.assertEquals(pal, new PersonalAttributeList());
- }
-
- /**
- * Testing Personal Attribute List clone method using add.
- */
- @SuppressWarnings("serial")
- @Test
- public void testCloneFromAdd() {
- final PersonalAttribute attrValueUnder =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("15");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
-
- final PersonalAttribute attrValueOver =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("18");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.add(attrValueUnder);
- attrList.add(attrValueOver);
- Assert.assertNotSame(attrList, attrList.clone());
- }
-
- /**
- * Testing Personal Attribute List clone method using put.
- */
- @SuppressWarnings("serial")
- @Test
- public void testCloneFromPut() {
- final PersonalAttribute attrValueUnder =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("15");
- }
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
+
+ /**
+ * isAgeOver constant value.
+ */
+ private static final String ISAGEOVER_CONS = "isAgeOver";
+
+ /**
+ * 1 constant value.
+ */
+ private static final int ONE_CONS = 1;
+
+ /**
+ * 2 constant value.
+ */
+ private static final int TWO_CONS = 2;
+
+ /**
+ * An empty attribute.
+ */
+ @SuppressWarnings("unused")
+ private static final IPersonalAttributeList EMPTY_ATTR_LIST
+ = new PersonalAttributeList(0);
+
+ /**
+ * An attribute with a complex value (canonicalResidenceAddress).
+ */
+ private static PersonalAttribute complexAttrValue = null;
+
+ /**
+ * Simple attribute value list string.
+ */
+ private static final String SIMPLE_ATTRLIST
+ = "isAgeOver:true:[15]:Available;";
+
+ /**
+ * Simple attribute value list string.
+ */
+ private static final String SIMPLE_ATTRLIST2
+ = "isAgeOver:true:[18]:Available;";
+
+ /**
+ * Simple attribute value list string.
+ */
+ private static final String SIMPLE_ATTRLIST3
+ = "isAgeOver:true:[15]:Available;isAgeOver:true:[18]:Available;";
- final PersonalAttribute attrValueOver =
- new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
- {
- add("18");
+ /**
+ * Simple attribute value list string.
+ */
+ private static final String SIMPLE_ATTRLIST4
+ = "isAgeOver:true:[15,18]:Available;";
+
+ /**
+ * Simple attribute value list string.
+ */
+ private static final String SIMPLE_ATTRLIST3_REVERSE
+ = "isAgeOver:true:[18]:Available;isAgeOver:true:[15]:Available;";
+ /**
+ * Simple attribute value list string.
+ */
+ private static final String COMPLEX_ATTRLIST
+ = "canonicalResidenceAddress:true:[postalCode=4100,apartmentNumber=Ed. B,"
+ + "state=Porto,countryCodeAddress=PT,streetNumber=379,"
+ + "streetName=Avenida Sidonio Pais,town=Porto]:Available;";
+ /**
+ * Mix attribute list string.
+ */
+ private static final String STR_MIX_ATTR_LIST
+ = "isAgeOver:true:[15]:Available;canonicalResidenceAddress:true:["
+ + "postalCode=4100,apartmentNumber=Ed.B,state=Porto,countryCodeAddress=PT,"
+ + "streetNumber=379,streetName=Avenida Sidonio Pais,town=Porto]:"
+ + "Available;";
+
+ /**
+ * Mix attribute list 2 string.
+ */
+ private static final String STR_MIX_ATTR_LIST2
+ = "isAgeOver:true:[15]:Available;canonicalResidenceAddress:true:["
+ + "postalCode=4100,apartmentNumber=Ed.B,state=Porto,countryCodeAddress=PT,"
+ + "streetNumber=379,streetName=Avenida Sidonio Pais,town=Porto]:Available;"
+ + "mandateContent:true:["
+ + "isJoint=\"isjoint\",typeOfPower=\"power\",ValidTo=\"validto\",validfrom=\"validfrom\",AQAA=\"3\",isChained=\"ischained\",]:"
+ + "Available;";
+
+ /**
+ * Attribute List example.
+ */
+ @SuppressWarnings({"serial"})
+ private static final PersonalAttribute ATTR_VALUE = new PersonalAttribute(
+ "age", true, new ArrayList<String>() {
+ {
+ add("15");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+
+ /**
+ * Init PersonalAttributeListTestCase 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", "Ed. B");
+ }
+ };
+
+ complexAttrValue
+ = new PersonalAttribute("canonicalResidenceAddress", true, values,
+ STORKStatusCode.STATUS_AVAILABLE.toString());
+
+ }
+
+ /**
+ * Testing Personal Attribute List add method. Personal Attribute list must
+ * be size 1 - Simple attribute.
+ */
+ @Test
+ public void testAddSimpleAttr() {
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.add(ATTR_VALUE);
+ Assert.assertTrue(attrList.size() == 1);
+ }
+
+ /**
+ * Testing Personal Attribute List add method. Personal Attribute list must
+ * be size 1 - Complex attribute.
+ */
+ @Test
+ public void testAddCompleAttr() {
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.add(complexAttrValue);
+ Assert.assertTrue(attrList.size() == 1);
+ }
+
+ /**
+ * Testing Personal Attribute List add method. Personal Attribute list must
+ * be size 0 - no attribute.
+ */
+ @Test
+ public void testAddNull() {
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.add(null);
+ Assert.assertTrue(attrList.size() == 0);
+ }
+
+ /**
+ * Testing Personal Attribute List add method. Same attribute name added
+ * twice. Personal Attribute list must be size 2 - IsAgeOver attribute added
+ * twice.
+ */
+ @SuppressWarnings("serial")
+ @Test
+ public void testAddSameAttrName() {
+ final PersonalAttribute attrValueUnder
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("15");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+
+ final PersonalAttribute attrValueOver
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("18");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.add(attrValueUnder);
+ attrList.add(attrValueOver);
+ System.out.println();
+ Assert.assertTrue(attrList.get(attrValueOver.getName()).getValue().size() == 2);
+ }
+
+ /**
+ * Testing Personal Attribute List add method. Same attribute name added
+ * twice. Personal Attribute list must be size 2 - IsAgeOver attribute added
+ * twice.
+ */
+ @SuppressWarnings("serial")
+ @Test
+ public void testAddSameAttrNameEmpty() {
+ final PersonalAttribute attrValueUnder
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("15");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+
+ final PersonalAttribute attrValueOver
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.add(attrValueUnder);
+ attrList.add(attrValueOver);
+ Assert.assertTrue(attrList.size() == 1);
+ Assert.assertTrue(attrList.get(attrValueOver.getName()).getValue().size() == 2);
+ }
+
+ /**
+ * Testing Personal Attribute List put method. Personal Attribute list must
+ * be size 1 - Simple Value.
+ */
+ @Test
+ public void testPutSimpleAttr() {
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.put(ATTR_VALUE.getName(), ATTR_VALUE);
+ Assert.assertTrue(attrList.size() == 1);
+ }
+
+ /**
+ * Testing Personal Attribute List put method. Personal Attribute list must
+ * be size 1 - Complex Value.
+ */
+ @Test
+ public void testPutComplexAttr() {
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.put(ATTR_VALUE.getName(), complexAttrValue);
+ Assert.assertTrue(attrList.size() == 1);
+ }
+
+ /**
+ * Testing Personal Attribute List put method. Personal Attribute list must
+ * be size 0 - no attribute.
+ */
+ @Test(expected = NullPointerException.class)
+ public void testPutNull() {
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.put("", null);
+ Assert.assertTrue(attrList.size() == 0);
+ }
+
+ /**
+ * Testing Personal Attribute List put method. Personal Attribute list must
+ * be size 2 - IsAgeOver attribute added twice.
+ */
+ @SuppressWarnings("serial")
+ @Test
+ public void testPutSameAttrName() {
+ final PersonalAttribute attrValueUnder
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("15");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+
+ final PersonalAttribute attrValueOver
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("18");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.put(attrValueUnder.getName(), attrValueUnder);
+ attrList.put(attrValueOver.getName(), attrValueOver);
+ Assert.assertTrue(attrList.size() == 1);
+ Assert.assertTrue(attrList.get(attrValueOver.getName()).getValue().size() == 2);
+ }
+
+ /**
+ * Testing Personal Attribute List put method. Personal Attribute list must
+ * be size 2 - IsAgeOver attribute added twice.
+ */
+ @SuppressWarnings("serial")
+ @Test
+ public void testPutSameAttrNameEmpty() {
+ final PersonalAttribute attrValueUnder
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("15");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+
+ final PersonalAttribute attrValueOver
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.put(attrValueUnder.getName(), attrValueUnder);
+ attrList.put(attrValueOver.getName(), attrValueOver);
+ Assert.assertTrue(attrList.size() == 1);
+ Assert.assertTrue(attrList.get(attrValueOver.getName()).getValue().size() == 2);
+ }
+
+ /**
+ * Testing Personal Attribute List get method. Personal Attribute list must
+ * be size 1 - Simple attribute.
+ */
+ @Test
+ public void testGetSimpleAttr() {
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.add(ATTR_VALUE);
+ Assert.assertEquals(ATTR_VALUE, attrList.get(ATTR_VALUE.getName()));
+ }
+
+ /**
+ * Testing Personal Attribute List add method. Personal Attribute list must
+ * be size 1 - Complex attribute.
+ */
+ @Test
+ public void testGetCompleAttr() {
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.add(complexAttrValue);
+ Assert.assertEquals(complexAttrValue.toString(),
+ attrList.get(complexAttrValue.getName()).toString());
+ }
+
+ /**
+ * Testing Personal Attribute List get method. Personal Attribute list must
+ * be size 2 - IsAgeOver attribute.
+ */
+ @SuppressWarnings("serial")
+ @Test
+ public void testGetIsAgeOverAttr() {
+ final PersonalAttribute attrValueUnder
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("15");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+
+ final PersonalAttribute attrValueOver
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("18");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.add(attrValueUnder);
+ attrList.add(attrValueOver);
+ Assert.assertNotEquals(SIMPLE_ATTRLIST,
+ attrList.get(attrValueUnder.getName()).toString());
+ Assert.assertNotEquals(SIMPLE_ATTRLIST2,
+ attrList.get(attrValueOver.getName()).toString());
+ Assert.assertEquals(SIMPLE_ATTRLIST4,
+ attrList.get(attrValueOver.getName()).toString());
+ }
+
+ /**
+ * Testing Personal Attribute List populate method. Personal Attribute list
+ * must be size 1 - Simple attribute.
+ */
+ @Test
+ public void testPopulateSimpleAttr() {
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.populate(SIMPLE_ATTRLIST);
+ Assert.assertTrue(attrList.size() == 1);
+ }
+
+ /**
+ * Testing Personal Attribute List populate method. Personal Attribute list
+ * must be size 1 - Complex attribute.
+ */
+ @Test
+ public void testPopulateComplexAttr() {
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.populate(COMPLEX_ATTRLIST);
+ Assert.assertTrue(attrList.size() == 1);
+ }
+
+ /**
+ * Testing Personal Attribute List populate method. Personal Attribute list
+ * must be size 1 - Simple and Complex attribute.
+ */
+ @Test
+ public void testPopulateMixAttrs() {
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.populate(STR_MIX_ATTR_LIST);
+ Assert.assertTrue(attrList.size() == 2);
+ //Assert.assertTrue(attrList.get(attrValueOver.getName()).getValue().size() == 2);
+ }
+
+ /**
+ * Testing Personal Attribute List toString method using add.
+ */
+ @SuppressWarnings("serial")
+ @Test
+ public void testToStringFromAdd() {
+ final PersonalAttribute attrValueUnder
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("15");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+
+ final PersonalAttribute attrValueOver
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("18");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.add(attrValueUnder);
+ attrList.add(attrValueOver);
+ Assert.assertEquals(SIMPLE_ATTRLIST4, attrList.toString());
+ }
+
+ /**
+ * Testing Personal Attribute List toString method using put.
+ *
+ */
+ @SuppressWarnings("serial")
+ @Test
+ public void testToStringFromPut() {
+ final PersonalAttribute attrValueUnder
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("15");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+
+ final PersonalAttribute attrValueOver
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("18");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.put(attrValueUnder.getName(), attrValueUnder);
+ attrList.put(attrValueOver.getName(), attrValueOver);
+ Assert.assertEquals(SIMPLE_ATTRLIST4, attrList.toString());
+ }
+
+ /**
+ * Testing Personal Attribute List toString method using populate.
+ */
+ @Test
+ public void testToStringFromSimplePopulate() {
+ final String strAttrList = "isAgeOver:true";
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.populate(strAttrList);
+ Assert.assertEquals("isAgeOver:true:[]:;", attrList.toString());
+ }
+
+ /**
+ * Testing Personal Attribute List toString method using populate.
+ */
+ @Test
+ public void testToStringFromPopulate() {
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.populate(SIMPLE_ATTRLIST3);
+ Assert.assertEquals(SIMPLE_ATTRLIST4, attrList.toString());
+ }
+
+ /**
+ * Testing Personal Attribute List populate method, with invalid values.
+ */
+ @Test
+ public void testPopulateWithInvalidValuesFormat() {
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ pal.populate("name:type:values:status;");
+ Assert.assertEquals(pal, new PersonalAttributeList());
+ }
+
+ /**
+ * Testing Personal Attribute List populate method, with invalid format.
+ */
+ @Test
+ public void testPopulateWithInvalidFormat() {
+
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ pal.populate("name:type::status;");
+ Assert.assertEquals(pal, new PersonalAttributeList());
+ }
+
+ /**
+ * Testing Personal Attribute List clone method using add.
+ */
+ @SuppressWarnings("serial")
+ @Test
+ public void testCloneFromAdd() {
+ final PersonalAttribute attrValueUnder
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("15");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+
+ final PersonalAttribute attrValueOver
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("18");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.add(attrValueUnder);
+ attrList.add(attrValueOver);
+ Assert.assertNotSame(attrList, attrList.clone());
+ }
+
+ /**
+ * Testing Personal Attribute List clone method using put.
+ */
+ @SuppressWarnings("serial")
+ @Test
+ public void testCloneFromPut() {
+ final PersonalAttribute attrValueUnder
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("15");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+
+ final PersonalAttribute attrValueOver
+ = new PersonalAttribute(ISAGEOVER_CONS, true, new ArrayList<String>() {
+ {
+ add("18");
+ }
+ }, STORKStatusCode.STATUS_AVAILABLE.toString());
+ final IPersonalAttributeList attrList = new PersonalAttributeList(1);
+ attrList.put(attrValueUnder.getName(), attrValueUnder);
+ attrList.put(attrValueOver.getName(), attrValueOver);
+ Assert.assertNotSame(attrList, attrList.clone());
+ }
+
+ /**
+ * Testing Personal Attribute List clone method using populate.
+ */
+ @Test
+ public void testCloneFromPopulate() {
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ pal.populate(SIMPLE_ATTRLIST3);
+ Assert.assertNotSame(pal, pal.clone());
+ }
+
+ /**
+ * Testing Personal Attribute List iterator.
+ */
+ @Test
+ public void testIterator() {
+ final String strAttrList
+ = "isAgeOver:true:[15,]:Available;isAgeOver:true:[18,]:Available;";
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ pal.populate(strAttrList);
+ final Iterator<PersonalAttribute> itAttr = pal.iterator();
+ while (itAttr.hasNext()) {
+ final PersonalAttribute attr = itAttr.next();
+ Assert.assertEquals(ISAGEOVER_CONS, attr.getName());
}
- }, STORKStatusCode.STATUS_AVAILABLE.toString());
- final PersonalAttributeList attrList = new PersonalAttributeList(1);
- attrList.put(attrValueUnder.getName(), attrValueUnder);
- attrList.put(attrValueOver.getName(), attrValueOver);
- Assert.assertNotSame(attrList, attrList.clone());
- }
-
- /**
- * Testing Personal Attribute List clone method using populate.
- */
- @Test
- public void testCloneFromPopulate() {
- final PersonalAttributeList pal = new PersonalAttributeList();
- pal.populate(SIMPLE_ATTRLIST3);
- Assert.assertNotSame(pal, pal.clone());
- }
-
- /**
- * Testing Personal Attribute List iterator.
- */
- @Test
- public void testIterator() {
- final String strAttrList =
- "isAgeOver:true:[15,]:Available;isAgeOver:true:[18,]:Available;";
- final PersonalAttributeList pal = new PersonalAttributeList();
- pal.populate(strAttrList);
- final Iterator<PersonalAttribute> itAttr = pal.iterator();
- while (itAttr.hasNext()) {
- final PersonalAttribute attr = itAttr.next();
- Assert.assertEquals(ISAGEOVER_CONS, attr.getName());
- }
- }
-
- /**
- * Testing Personal Attribute List's GetOptionalAttributes method with empty attribute list.
- */
- @Test
- public void testGetOptionalAttributesWithEmptyList() {
- final PersonalAttributeList pal = new PersonalAttributeList();
- Assert.assertTrue(pal.getOptionalAttributes().isEmpty());
- }
-
- /**
- * Testing Personal Attribute List's GetOptionalAttributes method without optional attributes.
- */
- @Test
- public void testGetOptionalAttributesWithoutOptional() {
- final String strAttrList =
- "isAgeOver:true:[15,]:Available;isAgeOver:true:[18,]:Available;";
- final PersonalAttributeList pal = new PersonalAttributeList();
- pal.populate(strAttrList);
- Assert.assertTrue(pal.getOptionalAttributes().isEmpty());
- }
-
- /**
- * Testing Personal Attribute List's GetOptionalAttributes method with one optional attribute.
- */
- @Test
- public void testGetOptionalAttributesWithOneOptional() {
- final String strAttrList =
- "age:false:[]:;isAgeOver:true:[15,]:;isAgeOver:true:[18,]:;";
- final PersonalAttributeList pal = new PersonalAttributeList();
- pal.populate(strAttrList);
- Assert.assertTrue(pal.getOptionalAttributes().size() == ONE_CONS);
- }
-
- /**
- * Testing Personal Attribute List's GetOptionalAttributes method with two optional attribute.
- */
- @Test
- public void testGetOptionalAttributesWithOnlyOptional() {
- final String strAttrList =
- "age:false:[]:;isAgeOver:false:[18,]:;";
- final PersonalAttributeList pal = new PersonalAttributeList();
- pal.populate(strAttrList);
- Assert.assertTrue(pal.getOptionalAttributes().size() == TWO_CONS);
- }
-
- /**
- * Testing Personal Attribute List's getMandatoryAttributes method with empty attribute list.
- */
- @Test
- public void testGetMandatoryAttributesWithEmptyList() {
- final PersonalAttributeList pal = new PersonalAttributeList();
- Assert.assertTrue(pal.getMandatoryAttributes().isEmpty());
- }
-
- /**
- * Testing Personal Attribute List's getMandatoryAttributes method without mandatory attributes.
- */
- @Test
- public void testGetMandatoryAttributesWithoutMandatory() {
- final String strAttrList =
- "isAgeOver:false:[15,]:Available;isAgeOver:false:[18,]:Available;";
- final PersonalAttributeList pal = new PersonalAttributeList();
- pal.populate(strAttrList);
- Assert.assertTrue(pal.getMandatoryAttributes().isEmpty());
- }
-
- /**
- * Testing Personal Attribute List's GetMandatoryAttributes method with one mandatory attribute.
- */
- @Test
- public void testGetMandatoryAttributesWithOneMandatory() {
- final String strAttrList =
- "age:true:[]:;isAgeOver:false:[15,]:;isAgeOver:false:[18,]:;";
- final PersonalAttributeList pal = new PersonalAttributeList();
- pal.populate(strAttrList);
- Assert.assertTrue(pal.getMandatoryAttributes().size() == ONE_CONS);
- }
-
- /**
- * Testing Personal Attribute List's GetMandatoryAttributes method with two mandatory attribute.
- */
- @Test
- public void testGetMandatoryAttributesWithOnlyMandatory() {
- final String strAttrList =
- "age:true:[]:;isAgeOver:true:[18,]:;";
- final PersonalAttributeList pal = new PersonalAttributeList();
- pal.populate(strAttrList);
- Assert.assertTrue(pal.getMandatoryAttributes().size() == TWO_CONS);
- }
-
- /**
- * Testing Personal Attribute List's getSimpleValueAttributes method with empty attribute list.
- */
- @Test
- public void testGetSimpleValueAttributesWithEmptyList() {
- final PersonalAttributeList pal = new PersonalAttributeList();
- Assert.assertTrue(pal.getSimpleValueAttributes().isEmpty());
- }
-
- /**
- * Testing Personal Attribute List's getSimpleValueAttributes() method without simple attributes.
- */
- @Test
- public void testGetSimpleValueAttributesWithoutSimple() {
- final PersonalAttributeList pal = new PersonalAttributeList();
- pal.populate(COMPLEX_ATTRLIST);
- Assert.assertTrue(pal.getSimpleValueAttributes().isEmpty());
- }
-
- /**
- * Testing Personal Attribute List's getSimpleValueAttributes() method with one simple attribute.
- */
- @Test
- public void testGetSimpleValueAttributesWithOneSimple() {
- final PersonalAttributeList pal = new PersonalAttributeList();
- pal.populate(STR_MIX_ATTR_LIST);
- Assert.assertTrue(pal.getSimpleValueAttributes().size() == ONE_CONS);
- }
-
- /**
- * Testing Personal Attribute List's GetMandatoryAttributes method with two simple attribute.
- */
- @Test
- public void testGetSimpleValueAttributesWithOnlySimple() {
- final PersonalAttributeList pal = new PersonalAttributeList();
- pal.populate(SIMPLE_ATTRLIST3);
- Assert.assertTrue(pal.getSimpleValueAttributes().size() == TWO_CONS);
- }
-
- /**
- * Testing Personal Attribute List's getComplexValueAttributes method with empty attribute list.
- */
- @Test
- public void testGetComplexAttributesWithEmptyList() {
- final PersonalAttributeList pal = new PersonalAttributeList();
- Assert.assertTrue(pal.getComplexAttributes().isEmpty());
- }
-
- /**
- * Testing Personal Attribute List's getComplexAttributes() method without complex attributes.
- */
- @Test
- public void testGetComplexAttributesWithoutSimple() {
- final PersonalAttributeList pal = new PersonalAttributeList();
- pal.populate(SIMPLE_ATTRLIST2);
- Assert.assertTrue(pal.getComplexAttributes().isEmpty());
- }
-
- /**
- * Testing Personal Attribute List's getComplexAttributes() method with one complex attribute.
- */
- @Test
- public void testGetComplexAttributesWithOneComplex() {
- final PersonalAttributeList pal = new PersonalAttributeList();
- pal.populate(STR_MIX_ATTR_LIST);
- Assert.assertTrue(pal.getComplexAttributes().size() == ONE_CONS);
- }
-
- /**
- * Testing Personal Attribute List's GetMandatoryAttributes method with only two Complex attribute.
- */
- @Test
- public void testGetComplexAttributesWithOnlyComplex() {
- final PersonalAttributeList pal = new PersonalAttributeList();
- pal.populate(STR_MIX_ATTR_LIST2);
- Assert.assertTrue(pal.getComplexAttributes().size() == TWO_CONS);
- }
+ }
+
+ /**
+ * Testing Personal Attribute List's GetOptionalAttributes method with empty
+ * attribute list.
+ */
+ @Test
+ public void testGetOptionalAttributesWithEmptyList() {
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ Assert.assertTrue(pal.getOptionalAttributes().isEmpty());
+ }
+
+ /**
+ * Testing Personal Attribute List's GetOptionalAttributes method without
+ * optional attributes.
+ */
+ @Test
+ public void testGetOptionalAttributesWithoutOptional() {
+ final String strAttrList
+ = "isAgeOver:true:[15,]:Available;isAgeOver:true:[18,]:Available;";
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ pal.populate(strAttrList);
+ Assert.assertTrue(pal.getOptionalAttributes().isEmpty());
+ }
+
+ /**
+ * Testing Personal Attribute List's GetOptionalAttributes method with one
+ * optional attribute.
+ */
+ @Test
+ public void testGetOptionalAttributesWithOneOptional() {
+ final String strAttrList
+ = "age:false:[]:;isAgeOver:true:[15,]:;isAgeOver:true:[18,]:;";
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ pal.populate(strAttrList);
+ Assert.assertTrue(pal.getOptionalAttributes().size() == ONE_CONS);
+ }
+
+ /**
+ * Testing Personal Attribute List's GetOptionalAttributes method with two
+ * optional attribute.
+ */
+ @Test
+ public void testGetOptionalAttributesWithOnlyOptional() {
+ final String strAttrList
+ = "age:false:[]:;isAgeOver:false:[18,]:;";
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ pal.populate(strAttrList);
+ Assert.assertTrue(pal.getOptionalAttributes().size() == TWO_CONS);
+ }
+
+ /**
+ * Testing Personal Attribute List's getMandatoryAttributes method with
+ * empty attribute list.
+ */
+ @Test
+ public void testGetMandatoryAttributesWithEmptyList() {
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ Assert.assertTrue(pal.getMandatoryAttributes().isEmpty());
+ }
+
+ /**
+ * Testing Personal Attribute List's getMandatoryAttributes method without
+ * mandatory attributes.
+ */
+ @Test
+ public void testGetMandatoryAttributesWithoutMandatory() {
+ final String strAttrList
+ = "isAgeOver:false:[15,]:Available;isAgeOver:false:[18,]:Available;";
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ pal.populate(strAttrList);
+ Assert.assertTrue(pal.getMandatoryAttributes().isEmpty());
+ }
+
+ /**
+ * Testing Personal Attribute List's GetMandatoryAttributes method with one
+ * mandatory attribute.
+ */
+ @Test
+ public void testGetMandatoryAttributesWithOneMandatory() {
+ final String strAttrList
+ = "age:true:[]:;isAgeOver:false:[15,]:;isAgeOver:false:[18,]:;";
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ pal.populate(strAttrList);
+ Assert.assertTrue(pal.getMandatoryAttributes().size() == ONE_CONS);
+ }
+
+ /**
+ * Testing Personal Attribute List's GetMandatoryAttributes method with two
+ * mandatory attribute.
+ */
+ @Test
+ public void testGetMandatoryAttributesWithOnlyMandatory() {
+ final String strAttrList
+ = "age:true:[]:;isAgeOver:true:[18,]:;";
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ pal.populate(strAttrList);
+ Assert.assertTrue(pal.getMandatoryAttributes().size() == TWO_CONS);
+ }
+
+ /**
+ * Testing Personal Attribute List's getSimpleValueAttributes method with
+ * empty attribute list.
+ */
+ @Test
+ public void testGetSimpleValueAttributesWithEmptyList() {
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ Assert.assertTrue(pal.getSimpleValueAttributes().isEmpty());
+ }
+
+ /**
+ * Testing Personal Attribute List's getSimpleValueAttributes() method
+ * without simple attributes.
+ */
+ @Test
+ public void testGetSimpleValueAttributesWithoutSimple() {
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ pal.populate(COMPLEX_ATTRLIST);
+ Assert.assertTrue(pal.getSimpleValueAttributes().isEmpty());
+ }
+
+ /**
+ * Testing Personal Attribute List's getSimpleValueAttributes() method with
+ * one simple attribute.
+ */
+ @Test
+ public void testGetSimpleValueAttributesWithOneSimple() {
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ pal.populate(STR_MIX_ATTR_LIST);
+ Assert.assertTrue(pal.getSimpleValueAttributes().size() == ONE_CONS);
+ }
+
+ /**
+ * Testing Personal Attribute List's GetMandatoryAttributes method with two
+ * simple attribute.
+ */
+ @Test
+ public void testGetSimpleValueAttributesWithOnlySimple() {
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ pal.populate(SIMPLE_ATTRLIST3);
+ Assert.assertTrue(pal.getSimpleValueAttributes().size() == ONE_CONS);
+ }
+
+ /**
+ * Testing Personal Attribute List's getComplexValueAttributes method with
+ * empty attribute list.
+ */
+ @Test
+ public void testGetComplexAttributesWithEmptyList() {
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ Assert.assertTrue(pal.getComplexAttributes().isEmpty());
+ }
+
+ /**
+ * Testing Personal Attribute List's getComplexAttributes() method without
+ * complex attributes.
+ */
+ @Test
+ public void testGetComplexAttributesWithoutSimple() {
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ pal.populate(SIMPLE_ATTRLIST2);
+ Assert.assertTrue(pal.getComplexAttributes().isEmpty());
+ }
+
+ /**
+ * Testing Personal Attribute List's getComplexAttributes() method with one
+ * complex attribute.
+ */
+ @Test
+ public void testGetComplexAttributesWithOneComplex() {
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ pal.populate(STR_MIX_ATTR_LIST);
+ Assert.assertTrue(pal.getComplexAttributes().size() == ONE_CONS);
+ }
+
+ /**
+ * Testing Personal Attribute List's GetMandatoryAttributes method with only
+ * two Complex attribute.
+ */
+ @Test
+ public void testGetComplexAttributesWithOnlyComplex() {
+ final IPersonalAttributeList pal = new PersonalAttributeList();
+ pal.populate(STR_MIX_ATTR_LIST2);
+ Assert.assertTrue(pal.getComplexAttributes().size() == TWO_CONS);
+ }
}
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());
+ }
}
diff --git a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/package-info.java b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/package-info.java
index 452602210..37841dd03 100644
--- a/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/package-info.java
+++ b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/package-info.java
@@ -2,4 +2,3 @@
* This package provides all JUnit test classes.
*/
package eu.stork.peps.tests;
-
diff --git a/id/server/stork2-commons/src/test/resources/log4j.xml b/id/server/stork2-commons/src/test/resources/log4j.xml
index 0ad2ea9a4..2bba8b69f 100644
--- a/id/server/stork2-commons/src/test/resources/log4j.xml
+++ b/id/server/stork2-commons/src/test/resources/log4j.xml
@@ -2,18 +2,18 @@
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
- <appender name="MainLogger" class="org.apache.log4j.DailyRollingFileAppender">
- <param name="File" value="stork-commons.log" />
- <param name="DatePattern" value="'.'yyyy-MM-dd" />
- <param name="Append" value="true" />
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%d{HH:mm:ss:SSS} - %p - %C{1} - %m%n" />
- </layout>
- </appender>
+ <appender name="MainLogger" class="org.apache.log4j.DailyRollingFileAppender">
+ <param name="File" value="stork-commons.log" />
+ <param name="DatePattern" value="'.'yyyy-MM-dd" />
+ <param name="Append" value="true" />
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d{HH:mm:ss:SSS} - %p - %C{1} - %m%n" />
+ </layout>
+ </appender>
- <root>
- <priority value="info" />
- <appender-ref ref="MainLogger" />
- </root>
+ <root>
+ <priority value="info" />
+ <appender-ref ref="MainLogger" />
+ </root>
</log4j:configuration>