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

com.emc.mongoose.scenario.step.ConfigurableStepBase Maven / Gradle / Ivy

The newest version!
package com.emc.mongoose.scenario.step;

import com.emc.mongoose.scenario.ScenarioParseException;
import com.emc.mongoose.ui.config.Config;
import com.emc.mongoose.ui.log.LogUtil;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public abstract class ConfigurableStepBase
extends StepBase
implements ConfigurableStep {

	protected final List> stepConfigs;

	protected ConfigurableStepBase(
		final Config baseConfig, final List> stepConfigs
	) {
		super(baseConfig);
		this.stepConfigs = stepConfigs;
	}

	@Override
	public StepBase config(final Map stepConfig)
	throws ScenarioParseException {
		final List> stepConfigsCopy = new ArrayList<>();
		if(stepConfigs != null) {
			stepConfigsCopy.addAll(stepConfigs);
		}
		if(stepConfig != null) {
			stepConfigsCopy.add(stepConfig);
		}
		return copyInstance(stepConfigsCopy);
	}

	@Override
	public void close()
	throws IOException {
		if(stepConfigs != null) {
			stepConfigs.clear();
		}
	}

	protected abstract StepBase copyInstance(final List> stepConfigs);

	protected Config init() {
		final String autoStepId = getTypeName() + "_" + LogUtil.getDateTimeStamp() + "_"
			+ hashCode();
		final Config config = new Config(baseConfig);
		if(stepConfigs != null && stepConfigs.size() > 0) {
			for(final Map nextStepConfig : stepConfigs) {
				config.apply(nextStepConfig, autoStepId);
			}
		}
		id = config.getTestConfig().getStepConfig().getId();
		return config;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy