package cz.moneta.test.harness.extensions;

import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtensionContext;

import static cz.moneta.test.harness.constants.ConstantsForUnitTests.CONFIG_PROPERTY_IDENTIFIER;

//Dirty trick how to set system property for test execution
public class SystemVariableExtensionForTest implements ExecutionCondition, AfterAllCallback {

    @Override
    public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
        System.setProperty(CONFIG_PROPERTY_IDENTIFIER, "config/env_test_config");
        return ConditionEvaluationResult.enabled("Enabled");
    }

    @Override
    public void afterAll(ExtensionContext extensionContext) throws Exception {
        System.clearProperty(CONFIG_PROPERTY_IDENTIFIER);
    }
}
