diff options
author | Thomas <> | 2023-04-26 19:04:57 +0200 |
---|---|---|
committer | Thomas <> | 2023-04-26 19:04:57 +0200 |
commit | 88f52463fd0d3d8bf467b75798b525ce86886acc (patch) | |
tree | 5c0c2eba19651444f757a76d11ecb51953cd4599 /eaaf_core/src/test | |
parent | 23a754ddce6a407315b8ebb2494b4f0f21bdccbf (diff) | |
download | EAAF-Components-88f52463fd0d3d8bf467b75798b525ce86886acc.tar.gz EAAF-Components-88f52463fd0d3d8bf467b75798b525ce86886acc.tar.bz2 EAAF-Components-88f52463fd0d3d8bf467b75798b525ce86886acc.zip |
feat(core): add extension-point to central errorHandler service to set application specific information into error-GUI model
Diffstat (limited to 'eaaf_core/src/test')
4 files changed, 69 insertions, 17 deletions
diff --git a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/dummy/DummyDefaultErrorService.java b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/dummy/DummyDefaultErrorService.java index 347f9b5c..ad7e9bdc 100644 --- a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/dummy/DummyDefaultErrorService.java +++ b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/dummy/DummyDefaultErrorService.java @@ -1,11 +1,13 @@ package at.gv.egiz.eaaf.core.impl.idp.auth.dummy; import java.text.MessageFormat; +import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; +import at.gv.egiz.eaaf.core.api.IRequest; import at.gv.egiz.eaaf.core.api.IStatusMessenger; import at.gv.egiz.eaaf.core.api.gui.ModifyableGuiBuilderConfiguration; import at.gv.egiz.eaaf.core.api.idp.IConfiguration; @@ -40,7 +42,7 @@ public class DummyDefaultErrorService implements IErrorService { } @Override - public IHandleData createHandleData(Throwable throwable, boolean supportRedirctToSp) throws EaafException { + public IHandleData createHandleData(Throwable throwable, IRequest pendingReq) throws EaafException { String internalErrorId = extractInternalErrorCode(throwable); return HandleData.builder() @@ -49,7 +51,7 @@ public class DummyDefaultErrorService implements IErrorService { .actionType(ticketType) .logLevel(logLevel) .errorIdTokenForRedirect(errorIdTokenForRedirect) - .allowSpRedirct(supportRedirctToSp) + .allowSpRedirct(pendingReq != null) .build(); } @@ -106,10 +108,12 @@ public class DummyDefaultErrorService implements IErrorService { @Getter private LogLevel logLevel; + @Getter + private Map<String, String> additionalGuiModelElements; + public String getPreFormatedErrorMessage() { return MessageFormat.format(TECH_LOG_MSG, internalErrorCode, throwable.getMessage()); } - } } diff --git a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/service/DummyErrorGuiModelHandler.java b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/service/DummyErrorGuiModelHandler.java new file mode 100644 index 00000000..2c1da193 --- /dev/null +++ b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/service/DummyErrorGuiModelHandler.java @@ -0,0 +1,24 @@ +package at.gv.egiz.eaaf.core.impl.idp.auth.service; + +import java.util.Collections; +import java.util.Map; + +import org.apache.commons.lang3.RandomStringUtils; + +import at.gv.egiz.eaaf.core.api.IRequest; +import at.gv.egiz.eaaf.core.impl.idp.auth.services.IErrorServiceModelHandler; + +public class DummyErrorGuiModelHandler implements IErrorServiceModelHandler { + + @Override + public Map<String, String> elementsForErrorModel(IRequest pendingReq) { + if (pendingReq.getSpEntityId() != null) { + return Collections.singletonMap("test", RandomStringUtils.randomAlphanumeric(10)); + + } else { + return Collections.emptyMap(); + + } + } + +} diff --git a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/service/TicketErrorServiceTest.java b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/service/TicketErrorServiceTest.java index 2c89e49f..d30f5a95 100644 --- a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/service/TicketErrorServiceTest.java +++ b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/service/TicketErrorServiceTest.java @@ -11,6 +11,7 @@ import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest; +import org.apache.commons.lang3.RandomStringUtils; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -69,17 +70,20 @@ public class TicketErrorServiceTest { @Test public void coverDifferentExceptions() throws EaafException { - val pendingReq = new DummyPendingRequest(); + DummyPendingRequest pendingReq = new DummyPendingRequest(); pendingReq.setPendingRequestId("324"); + pendingReq.setSpEntityId(RandomStringUtils.randomAlphabetic(5)); - val errorData = ticketErrorService.createHandleData(new Exception("sl20.07.02"), true); + val errorData = ticketErrorService.createHandleData(new Exception("sl20.07.02"), pendingReq); val errorData1 = ticketErrorService.createHandleData( - new EaafException("sl20.07.02", new Object[]{"dummy"}), false); + new EaafException("sl20.07.02", new Object[] { "dummy" }), null); val errorData2 = ticketErrorService.createHandleData( - new TaskExecutionException(pendingReq, "dummy", new EaafException("auth.00", new Object[]{"dummy"})), false); - val errorData3 = ticketErrorService.createHandleData(new EaafException("auth.21", null), false); - val errorData4 = ticketErrorService.createHandleData(new EaafException("internal.pendingreqid.01", null), false); - val errorData5 = ticketErrorService.createHandleData(new EaafException("junit.01", null), false); + new TaskExecutionException(pendingReq, "dummy", new EaafException("auth.00", new Object[] { + "dummy" })), null); + val errorData3 = ticketErrorService.createHandleData(new EaafException("auth.21", null), null); + val errorData4 = ticketErrorService.createHandleData(new EaafException("internal.pendingreqid.01", null), + null); + val errorData5 = ticketErrorService.createHandleData(new EaafException("junit.01", null), null); Assert.assertNotNull(errorData); Assert.assertEquals(errorData.getActionType(), IErrorService.ActionType.TICKET); @@ -87,13 +91,17 @@ public class TicketErrorServiceTest { Assert.assertEquals(errorData.getLogLevel(), IErrorService.LogLevel.ERROR); Assert.assertEquals(ticketErrorService.getExternalCodeFromInternal(errorData.getInternalErrorCode()), "9199"); Assert.assertNotNull(errorData.getErrorIdTokenForRedirect()); - + Assert.assertNotNull(errorData.getAdditionalGuiModelElements()); + Assert.assertFalse(errorData.getAdditionalGuiModelElements().isEmpty()); + Assert.assertNotNull(errorData1); Assert.assertEquals(errorData1.getActionType(), IErrorService.ActionType.NO_TICKET); Assert.assertEquals(errorData1.getInternalErrorCode(), "sl20.07.02"); Assert.assertEquals(errorData1.getLogLevel(), IErrorService.LogLevel.WARN); Assert.assertEquals(ticketErrorService.getExternalCodeFromInternal(errorData1.getInternalErrorCode()), "1003"); Assert.assertNull(errorData1.getErrorIdTokenForRedirect()); + Assert.assertNotNull(errorData1.getAdditionalGuiModelElements()); + Assert.assertTrue(errorData1.getAdditionalGuiModelElements().isEmpty()); Assert.assertNotNull(errorData2); Assert.assertEquals(errorData2.getActionType(), IErrorService.ActionType.TICKET); @@ -130,7 +138,8 @@ public class TicketErrorServiceTest { IErrorService.IHandleData errorData = null; try { - errorData = ticketErrorService.createHandleData(new EaafException("auth.00", new Object[]{"dummy"}), false); + errorData = ticketErrorService.createHandleData(new EaafException("auth.00", new Object[] { "dummy" }), + null); } catch (EaafException e) { e.printStackTrace(); } @@ -155,7 +164,7 @@ public class TicketErrorServiceTest { IErrorService.IHandleData errorData = null; try { errorData = ticketErrorService.createHandleData( - new EaafException("internal.pendingreqid.00", new Object[]{"dummy"}), false); + new EaafException("internal.pendingreqid.00", new Object[] { "dummy" }), null); } catch (EaafException e) { e.printStackTrace(); } @@ -175,9 +184,13 @@ public class TicketErrorServiceTest { val logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("at.gv.egiz.eaaf.core"); logger.addAppender(appender); + val pendingReq = new DummyPendingRequest(); + pendingReq.setPendingRequestId("324"); + IErrorService.IHandleData errorData = null; try { - errorData = ticketErrorService.createHandleData(new EaafException("auth.01", new Object[]{"dummy"}), true); + errorData = ticketErrorService.createHandleData(new EaafException("auth.01", new Object[] { "dummy" }), + pendingReq); } catch (EaafException e) { e.printStackTrace(); } @@ -200,7 +213,7 @@ public class TicketErrorServiceTest { IErrorService.IHandleData errorData = null; try { errorData = ticketErrorService - .createHandleData(new EaafException("module.binding.14", new Object[]{"dummy"}), false); + .createHandleData(new EaafException("module.binding.14", new Object[] { "dummy" }), null); } catch (EaafException e) { e.printStackTrace(); } @@ -220,9 +233,13 @@ public class TicketErrorServiceTest { val logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("at.gv.egiz.eaaf.core"); logger.addAppender(appender); + val pendingReq = new DummyPendingRequest(); + pendingReq.setPendingRequestId("324"); + IErrorService.IHandleData errorData = null; try { - errorData = ticketErrorService.createHandleData(new EaafException("auth.21", new Object[]{"dummy"}), true); + errorData = ticketErrorService.createHandleData(new EaafException("auth.21", new Object[] { "dummy" }), + pendingReq); } catch (EaafException e) { e.printStackTrace(); } @@ -232,6 +249,7 @@ public class TicketErrorServiceTest { // Assert.assertEquals(errorData.getThrowable(), new EaafException("auth.00", new Object[] {"dummy"})); //TODO // wrong excepiton Assert.assertEquals(errorData.getInternalErrorCode(), "auth.21"); + Assert.assertTrue(errorData.getAdditionalGuiModelElements().isEmpty()); assertEquals("wrong errorLevel", LogLevel.INFO, errorData.getLogLevel()); assertFalse("ticket", errorData.getPreFormatedErrorMessage().contains("Ticket=")); @@ -239,9 +257,12 @@ public class TicketErrorServiceTest { @Test public void testErrorDataDisplay() throws EaafException { + val pendingReq = new DummyPendingRequest(); + pendingReq.setPendingRequestId("324"); IErrorService.IHandleData errorData = null; - errorData = ticketErrorService.createHandleData(new EaafException("auth.01", new Object[]{"dummy"}), true); + errorData = ticketErrorService.createHandleData(new EaafException("auth.01", new Object[] { "dummy" }), + pendingReq); Assert.assertNotNull(errorData); val guiBuilder = Mockito.mock(ModifyableGuiBuilderConfiguration.class); diff --git a/eaaf_core/src/test/resources/SpringTest-authcommon-errorService.xml b/eaaf_core/src/test/resources/SpringTest-authcommon-errorService.xml index 35bd9d6f..6264fac5 100644 --- a/eaaf_core/src/test/resources/SpringTest-authcommon-errorService.xml +++ b/eaaf_core/src/test/resources/SpringTest-authcommon-errorService.xml @@ -22,4 +22,7 @@ <bean id="simplePendingReqStrategy" class="at.gv.egiz.eaaf.core.impl.utils.SimplePendingRequestIdGenerationStrategy"/> + <bean id="dummyExtensionErrorModel" + class="at.gv.egiz.eaaf.core.impl.idp.auth.service.DummyErrorGuiModelHandler" /> + </beans> |