
com.automationrockstars.bmo.GunterStoryReporter Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2015, 2016 Automation RockStars Ltd.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License v2.0
* which accompanies this distribution, and is available at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Contributors:
* Automation RockStars - initial API and implementation
*******************************************************************************/
package com.automationrockstars.bmo;
import static com.automationrockstars.base.ConfigLoader.config;
import static com.automationrockstars.gunter.events.EventBus.fireEvent;
import static com.automationrockstars.gunter.events.EventFactory.createAttachment;
import static com.automationrockstars.gunter.events.EventFactory.createExecutionFinish;
import static com.automationrockstars.gunter.events.EventFactory.createExecutionStart;
import static com.automationrockstars.gunter.events.EventFactory.createSuiteFinish;
import static com.automationrockstars.gunter.events.EventFactory.createSuiteStart;
import static com.automationrockstars.gunter.events.EventFactory.createTestCaseFinish;
import static com.automationrockstars.gunter.events.EventFactory.createTestCaseStart;
import static com.automationrockstars.gunter.events.EventFactory.createTestStepFinish;
import static com.automationrockstars.gunter.events.EventFactory.createTestStepStart;
import static com.automationrockstars.gunter.events.EventFactory.toJson;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import com.automationrockstars.gunter.events.TestCaseStart;
import com.automationrockstars.gunter.events.TestExecutionStart;
import com.automationrockstars.gunter.events.TestStepFinish;
import com.automationrockstars.gunter.events.TestStepStart;
import com.automationrockstars.gunter.events.TestSuiteStart;
import com.automationrockstars.gunter.events.impl.TestStepFinishImpl;
import com.automationrockstars.gunter.rabbit.RabbitEventBroker;
public class GunterStoryReporter implements StoryReporter{
private static final AtomicBoolean isConnected = new AtomicBoolean(false);
@Override
public String name() {
return "Guner Story Reporter";
}
private static final ThreadLocal start = new InheritableThreadLocal<>();
@Override
public void start() {
try {
RabbitEventBroker.init();
isConnected.set(true);
} catch (IllegalStateException e){
isConnected.set(false);
}
if (isConnected.get()){
start.set(createExecutionStart(config().getString("execution.name",config().getString("bdd.story.filter"))));
fireEvent(toJson(start.get()));
}
}
@Override
public void finish() {
if (isConnected.get()){
fireEvent(toJson(createExecutionFinish(start.get(), "FINISHED")));
}
}
private static final ThreadLocal story = new InheritableThreadLocal<>();
@Override
public void beforeStory(String name, String description, String path) {
if (isConnected.get()){
story.set(createSuiteStart(start.get(), name));
fireEvent(toJson(story.get()));
}
}
@Override
public void afterStory() {
if (isConnected.get()){
fireEvent(toJson(createSuiteFinish(story.get(), "FINISHED")));
}
}
private static final ThreadLocal scenario = new InheritableThreadLocal<>();
@Override
public void beforeScenario(String scenarioTitle) {
if (isConnected.get()){
scenario.set(createTestCaseStart(story.get(), scenarioTitle));
fireEvent(toJson(scenario.get()));
}
}
@Override
public void afterScenario() {
if (isConnected.get()){
fireEvent(toJson(createTestCaseFinish(scenario.get(), "FINISHED")));
}
}
private static final ThreadLocal
© 2015 - 2025 Weber Informatics LLC | Privacy Policy