All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.aoreshin.junit5.allure.steps.StepWrapper Maven / Gradle / Ivy

There is a newer version: 83
Show newest version
package com.github.aoreshin.junit5.allure.steps;

import io.qameta.allure.Allure;
import io.qameta.allure.AllureLifecycle;
import io.qameta.allure.model.Status;
import io.qameta.allure.model.StepResult;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Stack;
import java.util.UUID;

final class StepWrapper {
    private static final Logger LOGGER = LogManager.getLogger();
    private static final ThreadLocal LIFECYCLE = ThreadLocal.withInitial(Allure::getLifecycle);
    private static final ThreadLocal STEP_WRAPPER_THREAD_LOCAL = ThreadLocal.withInitial(StepWrapper::new);

    private final Stack uuidStack = new Stack<>();

    private StepWrapper() {
    }

    static StepWrapper getInstance() {
        return STEP_WRAPPER_THREAD_LOCAL.get();
    }

    void startStep(String stepName) {
        String uuid = UUID.randomUUID().toString();
        LIFECYCLE.get().startStep(uuid, new StepResult().setName(stepName));
        uuidStack.push(uuid);
    }

    void stopStep() {
        if (uuidStack.size() != 0) {
            String uuid = uuidStack.pop();
            LIFECYCLE.get().updateStep(uuid, update -> {
                update.setStatus(Status.PASSED);
            });
            LIFECYCLE.get().stopStep(uuid);
        } else {
            LOGGER.warn("Стек шагов пуст");
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy