Skip to content

CodelessPluginManager Class Skeleton

mikepoz59 edited this page Jun 5, 2019 · 1 revision
package com.tmobile.ct.codeless.plugin.reporting;

import com.tmobile.ct.codeless.core.Execution;
import com.tmobile.ct.codeless.core.Step;
import com.tmobile.ct.codeless.core.Suite;
import com.tmobile.ct.codeless.core.Test;
import com.tmobile.ct.codeless.core.lifecycle.ExecutionHook;
import com.tmobile.ct.codeless.core.lifecycle.StepHook;
import com.tmobile.ct.codeless.core.lifecycle.SuiteHook;
import com.tmobile.ct.codeless.core.lifecycle.TestHook;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

public class CodelessPluginManager implements SuiteHook, TestHook, StepHook, ExecutionHook {

public static final Logger log = LoggerFactory.getLogger(CodelessPluginManager.class);

    private List<TestReporter> reporters;

    private ReportingPluginHandlerService  reportingPluginHandlerService ;

    public CodelessPluginManager(){
        log.info("Instantiating codeless plugin manager;");

        log.debug("Loading qtest reporter.");
        this.reportingPluginHandlerService = new ReportingPluginHandlerService();

        log.debug("initializing reporters array");
        reporters = new ArrayList<>();
        reporters.add(this.reportingPluginHandlerService);

        log.debug("Completed instantiating codeless plugin manager;");
    }

    public void beforeExecution(Execution execution) {
        log.debug("Execution start: " + execution);
        reporters.forEach( reporter -> { reporter.beforeExecution(execution); });
    }

    public void beforeSuite(Suite suite) {
        log.debug("Suite start: " + suite);
        reporters.forEach( reporter -> { reporter.beforeSuite(suite); });
    }

    public void beforeTest(Test test){
        log.debug("Test start: " + test);
        reporters.forEach( reporter -> { reporter.beforeTest(test); });
    }

    public void beforeStep(Step step) {
        log.debug("Step start: " + step);
        reporters.forEach( reporter -> { reporter.beforeStep(step); });
    }

    public void afterStep(Step step) {
        log.debug("Step end: " + step);
        reporters.forEach( reporter -> { reporter.afterStep(step); });
    }

    public void afterTest(Test test){
        log.debug("Test end: " + test);
        reporters.forEach( reporter -> { reporter.afterTest(test); });
    }

    public void afterSuite(Suite suite) {
        log.debug("Suite end: " + suite);
        reporters.forEach( reporter -> { reporter.afterSuite(suite); });
    }

    public void afterExecution(Execution execution) {
        log.debug("Execution end: " + execution);
        reporters.forEach( reporter -> { reporter.afterExecution(execution); });
    }


    public Class getType() {
        return CodelessPluginManager.class;
    }
}