diff --git a/gradle.properties b/gradle.properties index cc49a59..9f53a6f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=1.1.5 +version=1.1.6 org.gradle.daemon=true org.gradle.parallel=true diff --git a/testit-adapter-cucumber4/Readme.md b/testit-adapter-cucumber4/Readme.md index 50f3d8c..c75b802 100644 --- a/testit-adapter-cucumber4/Readme.md +++ b/testit-adapter-cucumber4/Readme.md @@ -300,6 +300,8 @@ maven test -DtmsUrl=http://localhost:8080 -DtmsPrivateToken=Token -DtmsProjectId If you want to enable debug mode then see [How to enable debug logging?](https://github.com/testit-tms/adapters-java/tree/main/testit-java-commons) +If you want to add attachment for a failed test then see [How to add an attachment for a failed test?](https://github.com/testit-tms/adapters-java/tree/main/testit-java-commons) + ### Tags Use tags to specify information about autotest. diff --git a/testit-adapter-cucumber5/Readme.md b/testit-adapter-cucumber5/Readme.md index fc154b0..3f6c54c 100644 --- a/testit-adapter-cucumber5/Readme.md +++ b/testit-adapter-cucumber5/Readme.md @@ -415,6 +415,8 @@ maven test -DtmsUrl=http://localhost:8080 -DtmsPrivateToken=Token -DtmsProjectId If you want to enable debug mode then see [How to enable debug logging?](https://github.com/testit-tms/adapters-java/tree/main/testit-java-commons) +If you want to add attachment for a failed test then see [How to add an attachment for a failed test?](https://github.com/testit-tms/adapters-java/tree/main/testit-java-commons) + ### Tags Use tags to specify information about autotest. diff --git a/testit-adapter-cucumber6/Readme.md b/testit-adapter-cucumber6/Readme.md index eef9579..303a857 100644 --- a/testit-adapter-cucumber6/Readme.md +++ b/testit-adapter-cucumber6/Readme.md @@ -409,6 +409,8 @@ maven test -DtmsUrl=http://localhost:8080 -DtmsPrivateToken=Token -DtmsProjectId If you want to enable debug mode then see [How to enable debug logging?](https://github.com/testit-tms/adapters-java/tree/main/testit-java-commons) +If you want to add attachment for a failed test then see [How to add an attachment for a failed test?](https://github.com/testit-tms/adapters-java/tree/main/testit-java-commons) + ### Tags Use tags to specify information about autotest. diff --git a/testit-adapter-cucumber7/Readme.md b/testit-adapter-cucumber7/Readme.md index dd86eb2..5c7e7f8 100644 --- a/testit-adapter-cucumber7/Readme.md +++ b/testit-adapter-cucumber7/Readme.md @@ -420,6 +420,8 @@ maven test -DtmsUrl=http://localhost:8080 -DtmsPrivateToken=Token -DtmsProjectId If you want to enable debug mode then see [How to enable debug logging?](https://github.com/testit-tms/adapters-java/tree/main/testit-java-commons) +If you want to add attachment for a failed test then see [How to add an attachment for a failed test?](https://github.com/testit-tms/adapters-java/tree/main/testit-java-commons) + ### Tags Use tags to specify information about autotest. diff --git a/testit-adapter-jbehave/Readme.md b/testit-adapter-jbehave/Readme.md index 7ef26ef..53f6eeb 100644 --- a/testit-adapter-jbehave/Readme.md +++ b/testit-adapter-jbehave/Readme.md @@ -348,6 +348,8 @@ maven test -DtmsUrl=http://localhost:8080 -DtmsPrivateToken=Token -DtmsProjectId If you want to enable debug mode then see [How to enable debug logging?](https://github.com/testit-tms/adapters-java/tree/main/testit-java-commons) +If you want to add attachment for a failed test then see [How to add an attachment for a failed test?](https://github.com/testit-tms/adapters-java/tree/main/testit-java-commons) + ### Meta Use tags to specify information about autotest. diff --git a/testit-adapter-jbehave/src/main/java/ru/testit/listener/BaseJbehaveListener.java b/testit-adapter-jbehave/src/main/java/ru/testit/listener/BaseJbehaveListener.java index cd22627..3dc13e2 100644 --- a/testit-adapter-jbehave/src/main/java/ru/testit/listener/BaseJbehaveListener.java +++ b/testit-adapter-jbehave/src/main/java/ru/testit/listener/BaseJbehaveListener.java @@ -127,7 +127,7 @@ public void afterScenario() { final ExecutableTest test = executableTest.get(); final String uuid = test.getUuid(); - if (exampleUuids.isEmpty()) { + if (exampleUuids.isEmpty() && !test.isAfter()) { adapterManager.stopTestCase(uuid); } else { for (String exampleUuid : exampleUuids) { @@ -136,6 +136,7 @@ public void afterScenario() { exampleUuids.clear(); } + adapterManager.stopClassContainer(classUUID.get()); adapterManager.stopMainContainer(launcherUUID.get()); executableTest.remove(); @@ -185,5 +186,12 @@ public void failed(final String step, final Throwable cause) { } } ); + + adapterManager.stopTestCase(uuid); + executableTest.get().setAfterStatus(); + + if (exampleUuids.contains(uuid)) { + exampleUuids.remove(uuid); + } } } diff --git a/testit-adapter-junit4/Readme.md b/testit-adapter-junit4/Readme.md index dd7c152..143fbac 100644 --- a/testit-adapter-junit4/Readme.md +++ b/testit-adapter-junit4/Readme.md @@ -263,6 +263,8 @@ maven test -DtmsUrl=http://localhost:8080 -DtmsPrivateToken=Token -DtmsProjectId If you want to enable debug mode then see [How to enable debug logging?](https://github.com/testit-tms/adapters-java/tree/main/testit-java-commons) +If you want to add attachment for a failed test then see [How to add an attachment for a failed test?](https://github.com/testit-tms/adapters-java/tree/main/testit-java-commons) + ### Annotations Use annotations to specify information about autotest. diff --git a/testit-adapter-junit5/Readme.md b/testit-adapter-junit5/Readme.md index f916cc0..01610a6 100644 --- a/testit-adapter-junit5/Readme.md +++ b/testit-adapter-junit5/Readme.md @@ -282,6 +282,8 @@ maven test -DtmsUrl=http://localhost:8080 -DtmsPrivateToken=Token -DtmsProjectId If you want to enable debug mode then see [How to enable debug logging?](https://github.com/testit-tms/adapters-java/tree/main/testit-java-commons) +If you want to add attachment for a failed test then see [How to add an attachment for a failed test?](https://github.com/testit-tms/adapters-java/tree/main/testit-java-commons) + ### Annotations Use annotations to specify information about autotest. diff --git a/testit-adapter-testng/Readme.md b/testit-adapter-testng/Readme.md index 4047b54..83bb5b5 100644 --- a/testit-adapter-testng/Readme.md +++ b/testit-adapter-testng/Readme.md @@ -256,6 +256,8 @@ maven test -DtmsUrl=http://localhost:8080 -DtmsPrivateToken=Token -DtmsProjectId If you want to enable debug mode then see [How to enable debug logging?](https://github.com/testit-tms/adapters-java/tree/main/testit-java-commons) +If you want to add attachment for a failed test then see [How to add an attachment for a failed test?](https://github.com/testit-tms/adapters-java/tree/main/testit-java-commons) + ### Annotations Use annotations to specify information about autotest. diff --git a/testit-java-commons/Readme.md b/testit-java-commons/Readme.md index 91633e0..bd00a85 100644 --- a/testit-java-commons/Readme.md +++ b/testit-java-commons/Readme.md @@ -1,7 +1,41 @@ # How to enable debug logging? Create **simplelogger.properties** file in the resource directory of the project: -``` +```text org.slf4j.simpleLogger.defaultLogLevel=debug org.slf4j.simpleLogger.showDateTime=true org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd'T'HH:mm:ss.SSSZ +``` + +# How to add an attachment for a failed test? +You need to implement the AdapterListener interface and override the beforeTestStop method. +For example: + +```java +import ru.testit.services.Adapter; +import ru.testit.listener.AdapterListener; +import ru.testit.models.ItemStatus; +import ru.testit.models.TestResult; +import ru.testit.services.Adapter; + +public class AttachmentManager implements AdapterListener { + + @Override + public void beforeTestStop(final TestResult result) { + if (result.getItemStatus().equals(ItemStatus.FAILED)) { + // Add a screenshot + Adapter.addAttachments("Screenshot.jpg", new ByteArrayInputStream(((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES))); + + // Add log file + Adapter.addAttachments("/logs/failed.log"); + + // Add any text + Adapter.addAttachments("any text", "file.txt"); + } + } +} +``` + +After that, you need to add file **ru.testit.listener.AdapterListener** to **resources/META-INT/services** folder: +```text +.AttachmentManager ``` \ No newline at end of file diff --git a/testit-java-commons/src/main/java/ru/testit/listener/AdapterListener.java b/testit-java-commons/src/main/java/ru/testit/listener/AdapterListener.java new file mode 100644 index 0000000..269d79a --- /dev/null +++ b/testit-java-commons/src/main/java/ru/testit/listener/AdapterListener.java @@ -0,0 +1,9 @@ +package ru.testit.listener; + +import ru.testit.models.TestResult; + +public interface AdapterListener extends DefaultListener { + default void beforeTestStop(final TestResult result) { + //do nothing + } +} diff --git a/testit-java-commons/src/main/java/ru/testit/listener/DefaultListener.java b/testit-java-commons/src/main/java/ru/testit/listener/DefaultListener.java new file mode 100644 index 0000000..e070499 --- /dev/null +++ b/testit-java-commons/src/main/java/ru/testit/listener/DefaultListener.java @@ -0,0 +1,4 @@ +package ru.testit.listener; + +public interface DefaultListener { +} diff --git a/testit-java-commons/src/main/java/ru/testit/listener/ListenerManager.java b/testit-java-commons/src/main/java/ru/testit/listener/ListenerManager.java new file mode 100644 index 0000000..18e4489 --- /dev/null +++ b/testit-java-commons/src/main/java/ru/testit/listener/ListenerManager.java @@ -0,0 +1,34 @@ +package ru.testit.listener; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import ru.testit.models.TestResult; + +import java.util.List; +import java.util.function.BiConsumer; + +public class ListenerManager { + private static final Logger LOGGER = LoggerFactory.getLogger(ListenerManager.class); + private List listeners; + + public ListenerManager(final List listeners) { + + this.listeners = listeners; + } + + public void beforeTestStop(final TestResult result) { + runSafelyMethod(listeners, AdapterListener::beforeTestStop, result); + } + + protected void runSafelyMethod(final List listeners, + final BiConsumer method, + final S object) { + listeners.forEach(listener -> { + try { + method.accept(listener, object); + } catch (Exception e) { + LOGGER.error("Could not invoke listener method", e); + } + }); + } +} diff --git a/testit-java-commons/src/main/java/ru/testit/listener/ServiceLoaderListener.java b/testit-java-commons/src/main/java/ru/testit/listener/ServiceLoaderListener.java new file mode 100644 index 0000000..dc98b53 --- /dev/null +++ b/testit-java-commons/src/main/java/ru/testit/listener/ServiceLoaderListener.java @@ -0,0 +1,41 @@ +package ru.testit.listener; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.ServiceLoader; + +public final class ServiceLoaderListener { + private static final Logger LOGGER = LoggerFactory.getLogger(ServiceLoaderListener.class); + + private ServiceLoaderListener() { + throw new IllegalStateException("Do not have instance"); + } + + public static List load(final Class type, final ClassLoader classLoader) { + final List loaded = new ArrayList<>(); + final Iterator iterator = ServiceLoader.load(type, classLoader).iterator(); + while (nextSafely(iterator)) { + try { + final T next = iterator.next(); + loaded.add(next); + LOGGER.debug("Found type {}", type); + } catch (Exception e) { + LOGGER.error("Could not load listener {}: {}", type, e); + } + } + return loaded; + } + + private static boolean nextSafely(final Iterator iterator) { + try { + return iterator.hasNext(); + } catch (Exception e) { + LOGGER.error("nextSafely failed", e); + return false; + } + } +} diff --git a/testit-java-commons/src/main/java/ru/testit/services/Adapter.java b/testit-java-commons/src/main/java/ru/testit/services/Adapter.java index 1480781..2afe1e4 100644 --- a/testit-java-commons/src/main/java/ru/testit/services/Adapter.java +++ b/testit-java-commons/src/main/java/ru/testit/services/Adapter.java @@ -8,10 +8,12 @@ import java.io.BufferedWriter; import java.io.IOException; +import java.io.InputStream; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.util.*; public final class Adapter { @@ -112,6 +114,28 @@ public static void addAttachments(String content, String fileName) { } } + public static void addAttachments(String fileName, InputStream inputStream) { + if (fileName == null) { + LOGGER.error("Attachment name is empty"); + return; + } + + Path path = Paths.get(fileName); + try { + Files.copy(inputStream, path, StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + LOGGER.error(String.format("Can not write file '%s':", fileName), e); + } + + addAttachments(fileName); + + try { + Files.deleteIfExists(path); + } catch (IOException e) { + LOGGER.error(String.format("Can not delete file '%s':", fileName), e); + } + } + /** * @deprecated This method is no longer acceptable to compute time between versions. *

Use {@link Adapter#addAttachments(String attachment)} instead. diff --git a/testit-java-commons/src/main/java/ru/testit/services/AdapterManager.java b/testit-java-commons/src/main/java/ru/testit/services/AdapterManager.java index f54c799..ae2390e 100644 --- a/testit-java-commons/src/main/java/ru/testit/services/AdapterManager.java +++ b/testit-java-commons/src/main/java/ru/testit/services/AdapterManager.java @@ -8,6 +8,9 @@ import ru.testit.clients.ApiClient; import ru.testit.clients.ClientConfiguration; import ru.testit.clients.TmsApiClient; +import ru.testit.listener.AdapterListener; +import ru.testit.listener.ListenerManager; +import ru.testit.listener.ServiceLoaderListener; import ru.testit.models.*; import ru.testit.properties.AdapterConfig; import ru.testit.properties.AdapterMode; @@ -32,7 +35,13 @@ public class AdapterManager { private final ClientConfiguration clientConfiguration; private final AdapterConfig adapterConfig; + private final ListenerManager listenerManager; + public AdapterManager(ClientConfiguration clientConfiguration, AdapterConfig adapterConfig) { + this(clientConfiguration, adapterConfig, getDefaultListenerManager()); + } + + public AdapterManager(ClientConfiguration clientConfiguration, AdapterConfig adapterConfig, ListenerManager listenerManager) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Client configurations: {}", clientConfiguration); LOGGER.debug("Adapter configurations: {}", adapterConfig); @@ -45,6 +54,7 @@ public AdapterManager(ClientConfiguration clientConfiguration, AdapterConfig ada this.threadContext = new ThreadContext(); this.client = new TmsApiClient(this.clientConfiguration); this.writer = new HttpWriter(this.clientConfiguration, this.client, this.storage); + this.listenerManager = listenerManager; } public AdapterManager( @@ -53,7 +63,8 @@ public AdapterManager( ThreadContext threadContext, ResultStorage storage, Writer writer, - ApiClient client + ApiClient client, + ListenerManager listenerManager ) { this.adapterConfig = adapterConfig; this.clientConfiguration = clientConfiguration; @@ -61,6 +72,7 @@ public AdapterManager( this.storage = storage; this.writer = writer; this.client = client; + this.listenerManager = listenerManager; } public void startTests() { @@ -285,6 +297,8 @@ public void stopTestCase(final String uuid) { } final TestResult testResult = found.get(); + listenerManager.beforeTestStop(testResult); + testResult.setItemStage(ItemStage.FINISHED) .setStop(System.currentTimeMillis()); @@ -666,4 +680,9 @@ private void validateAdapterConfig() { throw new RuntimeException(error); } } + + private static ListenerManager getDefaultListenerManager() { + final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + return new ListenerManager(ServiceLoaderListener.load(AdapterListener.class, classLoader)); + } } diff --git a/testit-java-commons/src/test/java/ru/testit/services/AdapterManagerTest.java b/testit-java-commons/src/test/java/ru/testit/services/AdapterManagerTest.java index 177d6bd..4035edf 100644 --- a/testit-java-commons/src/test/java/ru/testit/services/AdapterManagerTest.java +++ b/testit-java-commons/src/test/java/ru/testit/services/AdapterManagerTest.java @@ -7,9 +7,9 @@ import ru.testit.client.invoker.ApiException; import ru.testit.client.model.TestRunStateTypeModel; import ru.testit.client.model.TestRunV2GetModel; -import ru.testit.client.model.TestRunV2PostShortModel; import ru.testit.clients.ApiClient; import ru.testit.clients.ClientConfiguration; +import ru.testit.listener.ListenerManager; import ru.testit.models.*; import ru.testit.properties.AdapterConfig; import ru.testit.properties.AdapterMode; @@ -33,6 +33,8 @@ public class AdapterManagerTest { private AdapterConfig adapterConfig; private ClientConfiguration clientConfiguration; + private ListenerManager listenerManager; + private final static String TEST_RUN_ID = "5819479d-e38b-40d0-9e35-c5b2dab50158"; @BeforeEach @@ -44,6 +46,7 @@ void init() { this.client = mock(ApiClient.class); this.adapterConfig = mock(AdapterConfig.class); this.clientConfiguration = mock(ClientConfiguration.class); + this.listenerManager = mock(ListenerManager.class); when(clientConfiguration.getUrl()).thenReturn("https://example.test/"); when(clientConfiguration.getProjectId()).thenReturn("d7defd1e-c1ed-400d-8be8-091ebfdda744"); @@ -55,7 +58,7 @@ void init() { @Test void startTests_WithTestRunId_NoInvokeCreateHandler() throws ApiException { // arrange - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.startTests(); @@ -75,7 +78,7 @@ void startTests_WithoutTestRunIdAndWithoutTestRunName_InvokeCreateHandler() thro when(client.createTestRun()).thenReturn(response); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.startTests(); @@ -97,7 +100,7 @@ void startTests_WithoutTestRunIdAndWithTestRunName_InvokeCreateHandler() throws when(client.createTestRun()).thenReturn(response); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.startTests(); @@ -115,7 +118,7 @@ void stopTests_WithCompletedTestRun_NoInvokeCompleteHandler() throws ApiExceptio when(client.getTestRun(TEST_RUN_ID)).thenReturn(response); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.stopTests(); @@ -132,7 +135,7 @@ void stopTests_WithInProgressTestRun_InvokeCompleteHandler() throws ApiException when(client.getTestRun(TEST_RUN_ID)).thenReturn(response); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.stopTests(); @@ -147,7 +150,7 @@ void startMainContainer_InvokePutHandler() { MainContainer container = Helper.generateMainContainer(); container.setStart(null); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.startMainContainer(container); @@ -166,7 +169,7 @@ void stopMainContainer_WithContainer_InvokeWriteTestsHandler() { when(storage.getTestsContainer(uuid)).thenReturn(Optional.of(container)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.stopMainContainer(uuid); @@ -185,7 +188,7 @@ void stopMainContainer_WithoutContainer_NoInvokeWriteTestsHandler() { when(storage.getTestsContainer(uuid)).thenReturn(Optional.empty()); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.stopMainContainer(container.getUuid()); @@ -206,7 +209,7 @@ void startClassContainer_WithTestContainer_InvokeGetTestsContainerHandler() { when(storage.getTestsContainer(parentUuid)).thenReturn(Optional.of(testContainer)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.startClassContainer(parentUuid, classContainer); @@ -228,7 +231,7 @@ void startClassContainer_WithoutTestContainer_InvokeGetTestsContainerHandler() { when(storage.getTestsContainer(parentUuid)).thenReturn(Optional.empty()); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.startClassContainer(parentUuid, classContainer); @@ -248,7 +251,7 @@ void stopClassContainer_WithContainer_InvokeWriteTestsHandler() { when(storage.getClassContainer(uuid)).thenReturn(Optional.of(container)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.stopClassContainer(uuid); @@ -267,7 +270,7 @@ void stopClassContainer_WithoutContainer_NoInvokeWriteTestsHandler() { when(storage.getClassContainer(uuid)).thenReturn(Optional.empty()); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.stopClassContainer(uuid); @@ -285,7 +288,7 @@ void updateClassContainer_WithContainer_InvokeUpdateHandler() { when(storage.getClassContainer(uuid)).thenReturn(Optional.of(container)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.updateClassContainer(uuid, update); @@ -302,7 +305,7 @@ void updateClassContainer_WithoutContainer_NoInvokeUpdateHandler() { when(storage.getClassContainer(uuid)).thenReturn(Optional.empty()); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.updateClassContainer(uuid, update); @@ -320,7 +323,7 @@ void startTestCase_WithTestResult_InvokeStartHandler() { when(storage.getTestResult(uuid)).thenReturn(Optional.of(result)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.startTestCase(uuid); @@ -341,7 +344,7 @@ void startTestCase_WithoutTestResult_NoInvokeStartHandler() { when(storage.getTestResult(uuid)).thenReturn(Optional.empty()); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.startTestCase(uuid); @@ -358,7 +361,7 @@ void scheduleTestCase_InvokePutHandler() { // arrange TestResult result = Helper.generateTestResult(); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.scheduleTestCase(result); @@ -377,7 +380,7 @@ void updateTestCase_WithRootWithTestResult_InvokeUpdateHandler() { when(threadContext.getRoot()).thenReturn(Optional.of(uuid)); when(storage.getTestResult(uuid)).thenReturn(Optional.of(result)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.updateTestCase(update); @@ -393,7 +396,7 @@ void updateTestCase_WithoutRoot_InvokeUpdateHandler() { when(threadContext.getRoot()).thenReturn(Optional.empty()); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.updateTestCase(update); @@ -411,7 +414,7 @@ void updateTestCase_WithRootWithoutTestResult_InvokeUpdateHandler() { when(threadContext.getRoot()).thenReturn(Optional.of(uuid)); when(storage.getTestResult(uuid)).thenReturn(Optional.empty()); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.updateTestCase(update); @@ -429,7 +432,7 @@ void stopTestCase_WithTestResult_InvokeWriteTestHandler() { when(storage.getTestResult(uuid)).thenReturn(Optional.of(result)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.stopTestCase(uuid); @@ -450,7 +453,7 @@ void stopTestCase_WithoutTestResult_NoInvokeWriteTestHandler() { when(storage.getTestResult(uuid)).thenReturn(Optional.empty()); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.stopTestCase(uuid); @@ -475,7 +478,7 @@ void startPrepareFixtureAll_InvokeStartHandler() { when(storage.getTestsContainer(parentUuid)) .thenReturn(Optional.of(container)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.startPrepareFixtureAll(parentUuid, uuid, result); @@ -502,7 +505,7 @@ void startTearDownFixtureAll_InvokeStartHandler() { when(storage.getTestsContainer(parentUuid)) .thenReturn(Optional.of(container)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.startTearDownFixtureAll(parentUuid, uuid, result); @@ -529,7 +532,7 @@ void startPrepareFixture_InvokeStartHandler() { when(storage.getClassContainer(parentUuid)) .thenReturn(Optional.of(container)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.startPrepareFixture(parentUuid, uuid, result); @@ -556,7 +559,7 @@ void startTearDownFixture_InvokeStartHandler() { when(storage.getClassContainer(parentUuid)) .thenReturn(Optional.of(container)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.startTearDownFixture(parentUuid, uuid, result); @@ -583,7 +586,7 @@ void startPrepareFixtureEachTest_InvokeStartHandler() { when(storage.getClassContainer(parentUuid)) .thenReturn(Optional.of(container)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.startPrepareFixtureEachTest(parentUuid, uuid, result); @@ -610,7 +613,7 @@ void startTearDownFixtureEachTest_InvokeStartHandler() { when(storage.getClassContainer(parentUuid)) .thenReturn(Optional.of(container)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.startTearDownFixtureEachTest(parentUuid, uuid, result); @@ -632,7 +635,7 @@ void updateFixture_WithFixture_InvokeUpdateHandler() { when(storage.getFixture(uuid)).thenReturn(Optional.of(result)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.updateFixture(uuid, update); @@ -649,7 +652,7 @@ void updateFixture_WithoutFixture_NoInvokeUpdateHandler() { when(storage.getFixture(uuid)).thenReturn(Optional.empty()); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.updateFixture(uuid, update); @@ -667,7 +670,7 @@ void stopFixture_WithFixture_InvokeClearHandler() { when(storage.getFixture(uuid)).thenReturn(Optional.of(result)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.stopFixture(uuid); @@ -687,7 +690,7 @@ void stopFixture_WithoutFixture_NoInvokeClearHandler() { when(storage.getFixture(uuid)).thenReturn(Optional.empty()); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.stopFixture(uuid); @@ -709,7 +712,7 @@ void startStep_WithCurrent_InvokeStartHandler() { when(threadContext.getCurrent()).thenReturn(Optional.of(parentUuid)); when(storage.get(parentUuid, ResultWithSteps.class)).thenReturn(Optional.of(result)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.startStep(uuid, result); @@ -731,7 +734,7 @@ void startStep_WithoutCurrent_NoInvokeStartHandler() { when(threadContext.getCurrent()).thenReturn(Optional.empty()); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.startStep(uuid, result); @@ -753,7 +756,7 @@ void updateStep_WithCurrentWithStep_InvokeUpdateHandler() { when(threadContext.getCurrent()).thenReturn(Optional.of(uuid)); when(storage.getStep(uuid)).thenReturn(Optional.of(result)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.updateStep(update); @@ -769,7 +772,7 @@ void updateStep_WithoutCurrent_NoInvokeUpdateHandler() { when(threadContext.getCurrent()).thenReturn(Optional.empty()); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.updateStep(update); @@ -787,7 +790,7 @@ void updateStep_WithCurrentWithoutStep_InvokeUpdateHandler() { when(threadContext.getCurrent()).thenReturn(Optional.of(uuid)); when(storage.getStep(uuid)).thenReturn(Optional.empty()); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.updateStep(update); @@ -808,7 +811,7 @@ void stopStep_WithRoot_InvokeStopHandler() { when(threadContext.getCurrent()).thenReturn(Optional.of(current)); when(storage.getStep(current)).thenReturn(Optional.of(result)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.stopStep(); @@ -829,7 +832,7 @@ void stopStep_WithRootEqualsCurrent_NoInvokeStopHandler() { when(threadContext.getRoot()).thenReturn(Optional.of(root)); when(threadContext.getCurrent()).thenReturn(Optional.of(root)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.stopStep(); @@ -850,7 +853,7 @@ void stopStep_WithoutRootWithCurrent_NoInvokeStopHandler() { when(threadContext.getRoot()).thenReturn(Optional.empty()); when(threadContext.getCurrent()).thenReturn(Optional.of(current)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.stopStep(); @@ -871,7 +874,7 @@ void stopStep_WithRootWithoutCurrent_NoInvokeStopHandler() { when(threadContext.getRoot()).thenReturn(Optional.of(root)); when(threadContext.getCurrent()).thenReturn(Optional.empty()); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.stopStep(); @@ -893,7 +896,7 @@ void stopStep_WithoutStepResult_NoInvokeStopHandler() { when(threadContext.getCurrent()).thenReturn(Optional.of(root)); when(storage.getStep(root)).thenReturn(Optional.empty()); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.stopStep(); @@ -914,7 +917,7 @@ void addAttachments() { when(threadContext.getCurrent()).thenReturn(Optional.of(result.getUuid())); when(storage.get(result.getUuid(), ResultWithAttachments.class)).thenReturn(Optional.of(result)); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act manager.addAttachments(new ArrayList() {{ @@ -931,7 +934,7 @@ void isFilteredMode_FilteredMode_ReturnsTrue() { // arrange when(adapterConfig.getMode()).thenReturn(AdapterMode.USE_FILTER); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act Boolean result = manager.isFilteredMode(); @@ -945,7 +948,7 @@ void isFilteredMode_NoFilteredMode_ReturnsFalse() { // arrange when(adapterConfig.getMode()).thenReturn(AdapterMode.RUN_ALL_TESTS); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act Boolean result = manager.isFilteredMode(); @@ -963,7 +966,7 @@ void getTestFromTestRun_SuccessInvoke_ReturnsListOfTests() throws ApiException { when(clientConfiguration.getConfigurationId()).thenReturn("4321"); when(client.getTestFromTestRun("1234", "4321")).thenReturn(testForRuns); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act List result = manager.getTestFromTestRun(); @@ -980,7 +983,7 @@ void getTestFromTestRun_ThrowInvoke_ReturnsListOfTests() throws ApiException { when(clientConfiguration.getConfigurationId()).thenReturn("4321"); when(client.getTestFromTestRun("1234", "4321")).thenThrow(new ApiException()); - AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client); + AdapterManager manager = new AdapterManager(clientConfiguration, adapterConfig, threadContext, storage, writer, client, listenerManager); // act List result = manager.getTestFromTestRun();