From e44b699607bb6c5563673bd257fa24b108d6096a Mon Sep 17 00:00:00 2001 From: Franzi321 <71708325+Franzi321@users.noreply.github.com> Date: Fri, 30 Oct 2020 15:29:17 +0100 Subject: [PATCH] TSK-1444: enable disabled tests --- .../test/security/JaasExtensionTest.java | 26 ++++++------- .../security/JaasExtensionTestExtensions.java | 37 +++++++++++++++++++ 2 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 common/taskana-common-test/src/test/java/pro/taskana/common/test/security/JaasExtensionTestExtensions.java diff --git a/common/taskana-common-test/src/test/java/pro/taskana/common/test/security/JaasExtensionTest.java b/common/taskana-common-test/src/test/java/pro/taskana/common/test/security/JaasExtensionTest.java index bd21f7631..58f095c92 100644 --- a/common/taskana-common-test/src/test/java/pro/taskana/common/test/security/JaasExtensionTest.java +++ b/common/taskana-common-test/src/test/java/pro/taskana/common/test/security/JaasExtensionTest.java @@ -14,7 +14,6 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DynamicContainer; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.Nested; @@ -25,11 +24,13 @@ import org.junit.jupiter.api.extension.ExtendWith; import pro.taskana.common.api.security.CurrentUserContext; import pro.taskana.common.internal.security.CurrentUserContextImpl; +import pro.taskana.common.test.security.JaasExtensionTestExtensions.ShouldThrowJunitException; +import pro.taskana.common.test.security.JaasExtensionTestExtensions.ShouldThrowParameterResolutionException; @ExtendWith(JaasExtension.class) class JaasExtensionTest { - private static final String INSIDE_DYNAMIC_TEST_USER = "insidedynamictest"; + private static final String INSIDE_DYNAMIC_TEST_USER = "inside_dynamic_test"; private static final CurrentUserContext CURRENT_USER_CONTEXT = new CurrentUserContextImpl(true); private static final DynamicTest NOT_NULL_DYNAMIC_TEST = dynamicTest("dynamic test", () -> assertThat(CURRENT_USER_CONTEXT.getUserid()).isNotNull()); @@ -153,17 +154,20 @@ class JaasExtensionTest { @WithAccessId(user = "user") @Test - @Disabled("this can be tested with a org.junit.platform.launcher.TestExecutionListener") - void should_NotInjectParameter_When_ParameterIsPresent_On_Test(WithAccessId accessId) { - assertThat(CURRENT_USER_CONTEXT.getUserid()).isEqualTo("user"); + @ExtendWith(ShouldThrowParameterResolutionException.class) + void should_NotInjectParameter_When_TestTemplateIsNotUsed( + @SuppressWarnings("unused") WithAccessId accessId) { + // THIS IS NOT RELEVANT + assertThat(true).isTrue(); } @WithAccessId(user = "user") @WithAccessId(user = "user2") @Test - @Disabled("this can be tested with a org.junit.platform.launcher.TestExecutionListener") - void should_ThrowException_When_MultipleAnnotationsExist_On_Test() { - assertThat(CURRENT_USER_CONTEXT.getUserid()).isNull(); + @ExtendWith(ShouldThrowJunitException.class) + void should_ThrowJunitException_When_MultipleAnnotationsExist_On_Test() { + // THIS IS NOT RELEVANT + assertThat(true).isTrue(); } // endregion @@ -196,12 +200,6 @@ class JaasExtensionTest { // region JaasExtension#interceptTestTemplateMethod - @TestTemplate - @Disabled("this can be tested with a org.junit.platform.launcher.TestExecutionListener") - void should_NotFindContextProvider_When_AnnotationIsMissing_On_TestTemplate() { - assertThat(CURRENT_USER_CONTEXT.getUserid()).isNotNull(); - } - @WithAccessId(user = "testtemplate") @TestTemplate void should_SetJaasSubject_When_AnnotationExists_On_TestTemplate() { diff --git a/common/taskana-common-test/src/test/java/pro/taskana/common/test/security/JaasExtensionTestExtensions.java b/common/taskana-common-test/src/test/java/pro/taskana/common/test/security/JaasExtensionTestExtensions.java new file mode 100644 index 000000000..c64ad0abc --- /dev/null +++ b/common/taskana-common-test/src/test/java/pro/taskana/common/test/security/JaasExtensionTestExtensions.java @@ -0,0 +1,37 @@ +package pro.taskana.common.test.security; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.ParameterResolutionException; +import org.junit.jupiter.api.extension.TestExecutionExceptionHandler; +import org.junit.platform.commons.JUnitException; + +public class JaasExtensionTestExtensions { + static class ShouldThrowParameterResolutionException implements TestExecutionExceptionHandler { + + @Override + public void handleTestExecutionException(ExtensionContext context, Throwable throwable) + throws Throwable { + if (throwable instanceof ParameterResolutionException) { + return; + } + throw throwable; + } + } + + static class ShouldThrowJunitException implements TestExecutionExceptionHandler { + + @Override + public void handleTestExecutionException(ExtensionContext context, Throwable throwable) + throws Throwable { + if (throwable instanceof JUnitException) { + JUnitException exception = (JUnitException) throwable; + assertThat(exception.getMessage()) + .isEqualTo("Please use @TestTemplate instead of @Test for multiple accessIds"); + return; + } + throw throwable; + } + } +}