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(); + } +}