From 6c7a6f8e222e4fb39a11c220b63e785f2037d428 Mon Sep 17 00:00:00 2001 From: Florian Reimair Date: Thu, 16 Jan 2014 08:55:06 +0100 Subject: fix added real source of stork modules --- .../peps/tests/PersonalAttributeTestCase.java | 182 +++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PersonalAttributeTestCase.java (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 new file mode 100644 index 000000000..458d510e0 --- /dev/null +++ b/id/server/stork2-commons/src/test/java/eu/stork/peps/tests/PersonalAttributeTestCase.java @@ -0,0 +1,182 @@ +/* + * This work is Open Source and licensed by the European Commission under the + * conditions of the European Public License v1.1 + * + * (http://www.osor.eu/eupl/european-union-public-licence-eupl-v.1.1); + * + * any use of this file implies acceptance of the conditions of this license. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +package eu.stork.peps.tests; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import junit.framework.Assert; + +import org.junit.BeforeClass; +import org.junit.Test; + +import eu.stork.peps.auth.commons.PersonalAttribute; +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 + * @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()); + } +} -- cgit v1.2.3