Scenario.java

  1. package org.jbehave.core.model;

  2. import static org.apache.commons.lang3.StringUtils.EMPTY;

  3. import java.util.Arrays;
  4. import java.util.List;
  5. import java.util.Properties;
  6. import java.util.UUID;

  7. import org.apache.commons.lang3.builder.ToStringBuilder;
  8. import org.apache.commons.lang3.builder.ToStringStyle;

  9. public class Scenario extends StepsContainer {

  10.     private final String id = UUID.randomUUID().toString();
  11.     private final String title;
  12.     private final Meta meta;
  13.     private final GivenStories givenStories;
  14.     private final ExamplesTable examplesTable;

  15.     public Scenario() {
  16.         this(Arrays.<String>asList());
  17.     }

  18.     public Scenario(List<String> steps) {
  19.         this(null, steps);
  20.     }

  21.     public Scenario(String title, Meta meta) {
  22.         this(title, meta, null, null, Arrays.<String>asList());
  23.     }

  24.     public Scenario(String title, List<String> steps) {
  25.         this(title, null, null, null, steps);
  26.     }

  27.     public Scenario(String title, Meta meta, GivenStories givenStories, ExamplesTable examplesTable,
  28.             List<String> steps) {
  29.         super(steps);
  30.         this.title = title;
  31.         this.meta = meta;
  32.         this.givenStories = givenStories;
  33.         this.examplesTable = examplesTable;
  34.     }

  35.     public String getTitle() {
  36.         if (title == null) {
  37.             return EMPTY;
  38.         }
  39.         return title;
  40.     }

  41.     public boolean hasGivenStories() {
  42.         return givenStories != null;
  43.     }

  44.     public GivenStories getGivenStories() {
  45.         if (!hasGivenStories()) {
  46.             return GivenStories.EMPTY;
  47.         }
  48.         return givenStories;
  49.     }

  50.     public boolean hasExamplesTable() {
  51.         return examplesTable != null;
  52.     }

  53.     public ExamplesTable getExamplesTable() {
  54.         if (!hasExamplesTable()) {
  55.             return ExamplesTable.EMPTY;
  56.         }
  57.         return examplesTable;
  58.     }

  59.     public String getId() {
  60.         return id;
  61.     }

  62.     public boolean hasMeta() {
  63.         return meta != null;
  64.     }

  65.     public Meta getMeta() {
  66.         if (!hasMeta()) {
  67.             return Meta.EMPTY;
  68.         }
  69.         return meta;
  70.     }

  71.     public Meta asMeta(String prefix) {
  72.         Properties p = new Properties();
  73.         p.setProperty(prefix + "title", getTitle());
  74.         p.setProperty(prefix + "givenStories", getGivenStories().asString());
  75.         p.setProperty(prefix + "examplesTable", getExamplesTable().asString());
  76.         return new Meta(p);
  77.     }

  78.     @Override
  79.     public String toString() {
  80.         return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
  81.     }

  82. }