From c259c0219160253795b51838aa6bf5cf63bc8617 Mon Sep 17 00:00:00 2001 From: David Kornel Date: Thu, 29 Feb 2024 10:08:05 +0100 Subject: [PATCH] Add RM annotations for better UX (#19) * Add RM annotations for better UX Signed-off-by: David Kornel --- .../annotations/ResourceManager.java | 22 ++++++++++++++ .../annotations/ResourceManagerDebug.java | 20 +++++++++++++ .../annotations/TestVisualSeparator.java | 20 +++++++++++++ .../ResourceManagerCleanerExtension.java | 29 +++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 test-frame-common/src/main/java/io/skodjob/testframe/annotations/ResourceManager.java create mode 100644 test-frame-common/src/main/java/io/skodjob/testframe/annotations/ResourceManagerDebug.java create mode 100644 test-frame-common/src/main/java/io/skodjob/testframe/annotations/TestVisualSeparator.java create mode 100644 test-frame-common/src/main/java/io/skodjob/testframe/listeners/ResourceManagerCleanerExtension.java diff --git a/test-frame-common/src/main/java/io/skodjob/testframe/annotations/ResourceManager.java b/test-frame-common/src/main/java/io/skodjob/testframe/annotations/ResourceManager.java new file mode 100644 index 0000000..4798465 --- /dev/null +++ b/test-frame-common/src/main/java/io/skodjob/testframe/annotations/ResourceManager.java @@ -0,0 +1,22 @@ +/* + * Copyright Skodjob authors. + * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). + */ +package io.skodjob.testframe.annotations; + +import io.skodjob.testframe.listeners.ResourceManagerCleanerExtension; +import io.skodjob.testframe.listeners.ResourceManagerExtension; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target(ElementType.TYPE) +@Retention(RUNTIME) +@ExtendWith(ResourceManagerExtension.class) +@ExtendWith(ResourceManagerCleanerExtension.class) +public @interface ResourceManager { +} diff --git a/test-frame-common/src/main/java/io/skodjob/testframe/annotations/ResourceManagerDebug.java b/test-frame-common/src/main/java/io/skodjob/testframe/annotations/ResourceManagerDebug.java new file mode 100644 index 0000000..e0eab50 --- /dev/null +++ b/test-frame-common/src/main/java/io/skodjob/testframe/annotations/ResourceManagerDebug.java @@ -0,0 +1,20 @@ +/* + * Copyright Skodjob authors. + * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). + */ +package io.skodjob.testframe.annotations; + +import io.skodjob.testframe.listeners.ResourceManagerExtension; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target(ElementType.TYPE) +@Retention(RUNTIME) +@ExtendWith(ResourceManagerExtension.class) +public @interface ResourceManagerDebug { +} diff --git a/test-frame-common/src/main/java/io/skodjob/testframe/annotations/TestVisualSeparator.java b/test-frame-common/src/main/java/io/skodjob/testframe/annotations/TestVisualSeparator.java new file mode 100644 index 0000000..b17df52 --- /dev/null +++ b/test-frame-common/src/main/java/io/skodjob/testframe/annotations/TestVisualSeparator.java @@ -0,0 +1,20 @@ +/* + * Copyright Skodjob authors. + * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). + */ +package io.skodjob.testframe.annotations; + +import io.skodjob.testframe.listeners.TestVisualSeparatorExtension; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target(ElementType.TYPE) +@Retention(RUNTIME) +@ExtendWith(TestVisualSeparatorExtension.class) +public @interface TestVisualSeparator { +} diff --git a/test-frame-common/src/main/java/io/skodjob/testframe/listeners/ResourceManagerCleanerExtension.java b/test-frame-common/src/main/java/io/skodjob/testframe/listeners/ResourceManagerCleanerExtension.java new file mode 100644 index 0000000..1000112 --- /dev/null +++ b/test-frame-common/src/main/java/io/skodjob/testframe/listeners/ResourceManagerCleanerExtension.java @@ -0,0 +1,29 @@ +/* + * Copyright Skodjob authors. + * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). + */ +package io.skodjob.testframe.listeners; + +import io.skodjob.testframe.resources.ResourceManager; +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; + +/** + * jUnit5 specific class which listening on test callbacks + */ +public class ResourceManagerCleanerExtension + implements AfterAllCallback, AfterEachCallback { + + @Override + public void afterAll(ExtensionContext extensionContext) { + ResourceManager.setTestContext(extensionContext); + ResourceManager.getInstance().deleteResources(); + } + + @Override + public void afterEach(ExtensionContext extensionContext) { + ResourceManager.setTestContext(extensionContext); + ResourceManager.getInstance().deleteResources(); + } +}