From 2b8c631a8ef6d6970a482914e41c59f37e3a6d08 Mon Sep 17 00:00:00 2001 From: Florian Reimair Date: Mon, 10 Aug 2015 16:52:00 +0200 Subject: approved tests --- .../peps/tests/PersonalAttributeTestCase.java | 291 +++++++++++---------- 1 file changed, 159 insertions(+), 132 deletions(-) (limited to 'id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PersonalAttributeTestCase.java') 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 0f014d896..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,138 +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 + * + * @author ricardo.ferreira@multicert.com, renato.portela@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() { - { - add("15"); - } - }, STORKStatusCode.STATUS_AVAILABLE.toString()); - - /** - * Init PersonalAttributeTestCase class. - */ - @SuppressWarnings("serial") - @BeforeClass - public static void runsBeforeTheTestSuite() { - final Map values = new HashMap() { - { - 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() { - 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()); - } + /** + * 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() { + { + add("15"); + } + }, STORKStatusCode.STATUS_AVAILABLE.toString()); + + /** + * Init PersonalAttributeTestCase class. + */ + @SuppressWarnings("serial") + @BeforeClass + public static void runsBeforeTheTestSuite() { + final Map values = new HashMap() { + { + 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 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; + } + + private boolean containsKeyAndValue(final Map 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()); + } } -- cgit v1.2.3