From 0725cce166b91725624e4cde694e9fde4e931bc9 Mon Sep 17 00:00:00 2001 From: Christian Kollmann Date: Mon, 22 Feb 2021 14:31:47 +0100 Subject: Refactor exception throwing and some names --- .../eidas/v2/test/tasks/InitialSearchTaskTest.java | 60 ++++++++-------------- 1 file changed, 22 insertions(+), 38 deletions(-) (limited to 'eidas_modules/authmodule-eIDAS-v2/src/test') diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java index 4dd6b92e..c9f123dc 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java @@ -131,9 +131,7 @@ public class InitialSearchTaskTest { Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList()); task.execute(pendingReq, executionContext); - String bPk = (String) - pendingReq.getSessionData(AuthProcessDataWrapper.class) - .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); + String bPk = readBpkFromSessionData(pendingReq); Assert.assertEquals("Wrong bpk", bPk, randomBpk); } @@ -150,9 +148,7 @@ public class InitialSearchTaskTest { new RegisterResult(randomBpk, randomIdentifier, newRandomGivenName, randomFamilyName, randomBirthDate))); task.execute(pendingReq, executionContext); - String bPk = (String) - pendingReq.getSessionData(AuthProcessDataWrapper.class) - .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); + String bPk = readBpkFromSessionData(pendingReq); Assert.assertEquals("Wrong bpk", bPk, randomBpk); } @@ -174,7 +170,7 @@ public class InitialSearchTaskTest { () -> task.execute(pendingReq, executionContext)); Throwable origE = exception.getOriginalException(); - Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException)); + Assert.assertTrue("Wrong exception", (origE instanceof ManualFixNecessaryException)); } @@ -196,7 +192,7 @@ public class InitialSearchTaskTest { () -> task.execute(pendingReq, executionContext)); Throwable origE = exception.getOriginalException(); - Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException)); + Assert.assertTrue("Wrong exception", (origE instanceof ManualFixNecessaryException)); } /** @@ -210,9 +206,7 @@ public class InitialSearchTaskTest { new RegisterResult(randomBpk, randomIdentifier, randomGivenName, randomFamilyName, randomBirthDate))); task.execute(pendingReq, executionContext); - String bPk = (String) - pendingReq.getSessionData(AuthProcessDataWrapper.class) - .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); + String bPk = readBpkFromSessionData(pendingReq); Assert.assertEquals("Wrong bpk", bPk, randomBpk); } @@ -228,9 +222,7 @@ public class InitialSearchTaskTest { task.execute(pendingReq, executionContext); - String bPk = (String) - pendingReq.getSessionData(AuthProcessDataWrapper.class) - .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); + String bPk = readBpkFromSessionData(pendingReq); Assert.assertEquals("Wrong bpk", bPk, randomBpk); } @@ -257,9 +249,7 @@ public class InitialSearchTaskTest { task.execute(pendingReq1, executionContext); - String bPk = (String) - pendingReq1.getSessionData(AuthProcessDataWrapper.class) - .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); + String bPk = readBpkFromSessionData(pendingReq1); Assert.assertEquals("Wrong bpk", bPk, randomBpk); } @@ -287,9 +277,7 @@ public class InitialSearchTaskTest { task.execute(pendingReq1, executionContext); - String resultBpk = (String) - pendingReq1.getSessionData(AuthProcessDataWrapper.class) - .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); + String resultBpk = readBpkFromSessionData(pendingReq1); Assert.assertEquals("Wrong bpk", resultBpk, randomBpk); } @@ -325,7 +313,7 @@ public class InitialSearchTaskTest { () -> task.execute(pendingReq1, executionContext)); Throwable origE = exception.getOriginalException(); - Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException)); + Assert.assertTrue("Wrong exception", (origE instanceof ManualFixNecessaryException)); } /** @@ -358,7 +346,7 @@ public class InitialSearchTaskTest { () -> task.execute(pendingReq1, executionContext)); Throwable origE = exception.getOriginalException(); - Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException)); + Assert.assertTrue("Wrong exception", (origE instanceof ManualFixNecessaryException)); } /** @@ -372,14 +360,12 @@ public class InitialSearchTaskTest { task.execute(pendingReq, executionContext); - String bPk = (String) - pendingReq.getSessionData(AuthProcessDataWrapper.class) - .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); + String bPk = readBpkFromSessionData(pendingReq); Assert.assertNull("Wrong bpk", bPk); Boolean transitionGUI = (Boolean) executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK); Assert.assertNull("Wrong transition", transitionGUI); - Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNB_ENTRY_TASK); + Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK); Assert.assertTrue("Wrong transition", transitionErnb); } @@ -398,13 +384,11 @@ public class InitialSearchTaskTest { task.execute(pendingReq, executionContext); - String bPk = (String) - pendingReq.getSessionData(AuthProcessDataWrapper.class) - .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); + String bPk = readBpkFromSessionData(pendingReq); Assert.assertNull("Wrong bpk", bPk); Boolean transitionGUI = (Boolean) executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK); Assert.assertTrue("Wrong transition", transitionGUI); - Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNB_ENTRY_TASK); + Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK); Assert.assertNull("Wrong transition", transitionErnb); } @@ -423,13 +407,11 @@ public class InitialSearchTaskTest { task.execute(pendingReq, executionContext); - String bPk = (String) - pendingReq.getSessionData(AuthProcessDataWrapper.class) - .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); + String bPk = readBpkFromSessionData(pendingReq); Assert.assertNull("Wrong bpk", bPk); Boolean transitionGUI = (Boolean) executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK); Assert.assertTrue("Wrong transition", transitionGUI); - Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNB_ENTRY_TASK); + Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK); Assert.assertNull("Wrong transition", transitionErnb); } @@ -450,13 +432,11 @@ public class InitialSearchTaskTest { task.execute(pendingReq, executionContext); - String bPk = (String) - pendingReq.getSessionData(AuthProcessDataWrapper.class) - .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); + String bPk = readBpkFromSessionData(pendingReq); Assert.assertNull("Wrong bpk", bPk); Boolean transitionGUI = (Boolean) executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK); Assert.assertTrue("Wrong transition", transitionGUI); - Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNB_ENTRY_TASK); + Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK); Assert.assertNull("Wrong transition", transitionErnb); } @@ -538,4 +518,8 @@ public class InitialSearchTaskTest { .attributeValueMarshaller(marshaller).build(); } + private String readBpkFromSessionData(TestRequestImpl pendingReq) { + return (String) pendingReq.getSessionData(AuthProcessDataWrapper.class) + .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); + } } -- cgit v1.2.3