| 1 | |
package org.jbehave.core.embedder; |
| 2 | |
|
| 3 | |
import java.util.HashMap; |
| 4 | |
import java.util.Map; |
| 5 | |
|
| 6 | |
import org.jbehave.core.model.Meta; |
| 7 | |
import org.jbehave.core.model.Scenario; |
| 8 | |
import org.jbehave.core.model.Story; |
| 9 | |
|
| 10 | |
public class FilteredStory { |
| 11 | |
|
| 12 | |
private boolean storyAllowed; |
| 13 | |
private Map<Scenario, Boolean> scenariosAllowed; |
| 14 | |
|
| 15 | 47 | public FilteredStory(MetaFilter filter, Story story, StoryControls storyControls) { |
| 16 | 47 | String storyMetaPrefix = storyControls.storyMetaPrefix(); |
| 17 | 47 | String scenarioMetaPrefix = storyControls.scenarioMetaPrefix(); |
| 18 | 47 | Meta storyMeta = story.getMeta().inheritFrom(story.asMeta(storyMetaPrefix)); |
| 19 | 46 | storyAllowed = filter.allow(storyMeta); |
| 20 | 46 | scenariosAllowed = new HashMap<Scenario, Boolean>(); |
| 21 | 46 | for (Scenario scenario : story.getScenarios()) { |
| 22 | 34 | Meta scenarioMeta = scenario.getMeta().inheritFrom( |
| 23 | |
scenario.asMeta(scenarioMetaPrefix).inheritFrom(storyMeta)); |
| 24 | 34 | boolean scenarioAllowed = filter.allow(scenarioMeta); |
| 25 | 34 | scenariosAllowed.put(scenario, scenarioAllowed); |
| 26 | 34 | } |
| 27 | 46 | } |
| 28 | |
|
| 29 | |
public boolean allowed() { |
| 30 | 46 | return storyAllowed || scenariosAllowed.values().contains(true); |
| 31 | |
} |
| 32 | |
|
| 33 | |
public boolean allowed(Scenario scenario) { |
| 34 | 28 | return scenariosAllowed.get(scenario); |
| 35 | |
} |
| 36 | |
} |