From 3cd52ab38e4d57b6f056dbf47897d80f419522df Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Mon, 19 Apr 2021 18:58:31 +0200 Subject: refactor DateOfBirth in IAuthData and all implementations because DateOfBirth from SZR has not be a valid Date object --- .../impl/idp/auth/data/AuthenticationDataTest.java | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/data/AuthenticationDataTest.java (limited to 'eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/data/AuthenticationDataTest.java') diff --git a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/data/AuthenticationDataTest.java b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/data/AuthenticationDataTest.java new file mode 100644 index 00000000..9d99b158 --- /dev/null +++ b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/data/AuthenticationDataTest.java @@ -0,0 +1,85 @@ +package at.gv.egiz.eaaf.core.impl.idp.auth.data; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.BlockJUnit4ClassRunner; + +import at.gv.egiz.eaaf.core.impl.idp.AuthenticationData; + +@RunWith(BlockJUnit4ClassRunner.class) +public class AuthenticationDataTest { + + @Test + public void formatedDateButNotSet() { + AuthenticationData authData = new AuthenticationData(); + assertNull("formatedDateOfBirth", authData.getDateOfBirthFormated("dd/MM/yyy")); + + } + + @Test + public void formatedDateButInvalidPattern() { + AuthenticationData authData = new AuthenticationData(); + authData.setDateOfBirth("1940-01-01"); + assertNull("formatedDateOfBirth", authData.getDateOfBirthFormated("aa-bb-cccc")); + + } + + @Test + public void validDateStatic() { + AuthenticationData authData = new AuthenticationData(); + + String date = "1940-01-01"; + authData.setDateOfBirth(date); + + assertNotNull("birthday", authData.getDateOfBirth()); + assertEquals("birthday attribute", date, + authData.getDateOfBirth()); + assertEquals("birthday attribute", "01/01/1940", + authData.getDateOfBirthFormated("dd/MM/yyy")); + + } + + + @Test + public void validButNotUsal() { + AuthenticationData authData = new AuthenticationData(); + authData.setDateOfBirth("1970-00-00"); + + assertNotNull("birthday", authData.getDateOfBirth()); + assertEquals("birthday attribute", "1970-00-00", + authData.getDateOfBirth()); + assertNull("formatedDateOfBirth", authData.getDateOfBirthFormated("dd/MM/yyy")); + + } + + @Test + public void invalidDate() { + AuthenticationData authData = new AuthenticationData(); + authData.setDateOfBirth("1970/00/00"); + + assertNull("birthday", authData.getDateOfBirth()); + assertNull("formatedDateOfBirth", authData.getDateOfBirthFormated("dd/MM/yyy")); + + } + + + @Test + public void validDateRandom() { + AuthenticationData authData = new AuthenticationData(); + + String date = RandomStringUtils.randomNumeric(4) + "-" + RandomStringUtils.randomNumeric(2) + + "-" + RandomStringUtils.randomNumeric(2); + authData.setDateOfBirth(date); + + assertNotNull("birthday", authData.getDateOfBirth()); + assertEquals("birthday attribute", date, + authData.getDateOfBirth()); + + } + +} -- cgit v1.2.3