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

com.epam.reportportal.cucumber.ScenarioContext Maven / Gradle / Ivy

There is a newer version: 5.3.2
Show newest version
/*
 * Copyright 2021 EPAM Systems
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.epam.reportportal.cucumber;

import io.cucumber.plugin.event.Node;
import io.cucumber.plugin.event.TestCase;
import io.reactivex.Maybe;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.net.URI;
import java.util.Optional;

import static java.util.Optional.ofNullable;

public class ScenarioContext {

	private final int line;
	private final URI uri;
	private final RuleContext rule;
	private final Node.Scenario scenario;
	private final Node.ScenarioOutline scenarioOutline;
	private final Node.Example example;

	private TestCase testCase;
	private Maybe id = Maybe.empty();
	private Maybe hookId = Maybe.empty();
	private Maybe stepId = Maybe.empty();

	public ScenarioContext(@Nonnull URI scenarioFilePath, @Nullable RuleContext ruleNode, @Nonnull Node.Scenario scenarioNode) {
		uri = scenarioFilePath;
		rule = ruleNode;
		scenario = scenarioNode;
		scenarioOutline = null;
		example = null;
		line = scenario.getLocation().getLine();
	}

	public ScenarioContext(@Nonnull URI scenarioFilePath, @Nullable RuleContext ruleNode, @Nonnull Node.ScenarioOutline scenarioOutlineNode,
			@Nonnull Node.Example exampleNode) {
		uri = scenarioFilePath;
		rule = ruleNode;
		scenario = null;
		scenarioOutline = scenarioOutlineNode;
		example = exampleNode;
		line = scenarioOutline.getLocation().getLine();
	}

	public int getLine() {
		return line;
	}

	@Nonnull
	@SuppressWarnings("unused")
	public Optional getTestCase() {
		return ofNullable(testCase);
	}

	public void setTestCase(@Nullable TestCase testCase) {
		this.testCase = testCase;
	}

	@Nonnull
	public Optional getRule() {
		return ofNullable(rule);
	}

	@Nonnull
	public URI getUri() {
		return uri;
	}

	@Nonnull
	public Maybe getId() {
		return id;
	}

	public void setId(@Nonnull Maybe id) {
		this.id = id;
	}

	public void setHookId(@Nonnull Maybe hookStepId) {
		hookId = hookStepId;
	}

	@Nonnull
	public Maybe getHookId() {
		return hookId;
	}

	public void setStepId(@Nonnull Maybe currentStepId) {
		stepId = currentStepId;
	}

	@Nonnull
	public Maybe getStepId() {
		return stepId;
	}

	@Nonnull
	public Optional getExample() {
		return ofNullable(example);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy