Mauro Talevi | 17 Jun 2013 10:02

[scm-core][1/1] Added story.filter property.

dt:after { content: ':' !important; } >Commit 3710a6f6b29f5ca14e1dbe057192e7bd9ba09859 Branch master Author Mauro Talevi <mauro.talevi-hQ+s5KbX5YmGglJvpFV4uA@public.gmane.org> Date Mon, 17 Jun 2013 09:02:17 +0100 Message Added story.filter property.

Changed file examples/core/src/main/java/org/jbehave/examples/core/CoreStories.java

48 48   * Example of how multiple stories can be run via JUnit.
49 49   * </p>
50 50   * <p>
51   * Stories are specified in classpath and correspondingly the { <at> link LoadFromClasspath} story loader is configured.
51   * Stories are specified in classpath and correspondingly the
52   * { <at> link LoadFromClasspath} story loader is configured.
52 53   * </p>
53 54   */
54 55  public class CoreStories extends JUnitStories {
58 59      public CoreStories() {
59 60          configuredEmbedder().embedderControls().doGenerateViewAfterStories(true).doIgnoreFailureInStories(false)
60 61                  .doIgnoreFailureInView(true).doVerboseFailures(true).useThreads(2).useStoryTimeoutInSecs(60);
61          //configuredEmbedder().useEmbedderControls(new PropertyBasedEmbedderControls());
62          // configuredEmbedder().useEmbedderControls(new
63          // PropertyBasedEmbedderControls());
62 64      }
63 65  
64 66       <at> Override
69 71          viewResources.put("reports", "ftl/jbehave-reports-with-totals.ftl");
70 72          // Start from default ParameterConverters instance
71 73          ParameterConverters parameterConverters = new ParameterConverters();
72          // factory to allow parameter conversion and loading from external resources (used by StoryParser too)
73          ExamplesTableFactory examplesTableFactory = new ExamplesTableFactory(new LocalizedKeywords(), new LoadFromClasspath(embeddableClass), parameterConverters, new TableTransformers());
74          // factory to allow parameter conversion and loading from external
75          // resources (used by StoryParser too)
76          ExamplesTableFactory examplesTableFactory = new ExamplesTableFactory(new LocalizedKeywords(),
77                  new LoadFromClasspath(embeddableClass), parameterConverters, new TableTransformers());
74 78          // add custom converters
75 79          parameterConverters.addConverters(new DateConverter(new SimpleDateFormat("yyyy-MM-dd")),
76 80                  new ExamplesTableConverter(examplesTableFactory));
77 81          return new MostUsefulConfiguration()
78 82                  .useStoryLoader(new LoadFromClasspath(embeddableClass))
79 83                  .useStoryParser(new RegexStoryParser(examplesTableFactory))
80              .useStoryReporterBuilder(new StoryReporterBuilder()
84                  .useStoryReporterBuilder(
85                          new StoryReporterBuilder()
81 86                                  .withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass))
82                  .withDefaultFormats()
83                  .withViewResources(viewResources)
84                  .withFormats(CONSOLE, TXT, HTML_TEMPLATE, XML_TEMPLATE)
85                  .withFailureTrace(true)
86                  .withFailureTraceCompression(true)                
87                  .withCrossReference(xref)) 
87                                  .withDefaultFormats().withViewResources(viewResources)
88                                  .withFormats(CONSOLE, TXT, HTML_TEMPLATE, XML_TEMPLATE).withFailureTrace(true)
89                                  .withFailureTraceCompression(true).withCrossReference(xref))
88 90                  .useParameterConverters(parameterConverters)
89 91                  // use '%' instead of '$' to identify parameters
90              .useStepPatternParser(new RegexPrefixCapturingPatternParser(
91                              "%")) 
92              .useStepMonitor(xref.getStepMonitor());                               
92                  .useStepPatternParser(new RegexPrefixCapturingPatternParser("%")).useStepMonitor(xref.getStepMonitor());
93 93      }
94 94  
95 95       <at> Override
96 96      public InjectableStepsFactory stepsFactory() {
97          return new InstanceStepsFactory(configuration(), new TraderSteps(new TradingService()), new AndSteps(), new MetaParametrisationSteps(),
98                  new CalendarSteps(), new PriorityMatchingSteps(), new PendingSteps(), new SandpitSteps(),
99                  new SearchSteps(), new BeforeAfterSteps(), new CompositeSteps(), new NamedParametersSteps(), new ExamplesTableParametersSteps());
97          return new InstanceStepsFactory(configuration(), new TraderSteps(new TradingService()), new AndSteps(),
98                  new MetaParametrisationSteps(), new CalendarSteps(), new PriorityMatchingSteps(), new PendingSteps(),
99                  new SandpitSteps(), new SearchSteps(), new BeforeAfterSteps(), new CompositeSteps(),
100                  new NamedParametersSteps(), new ExamplesTableParametersSteps());
100 101      }
101 102  
102 103       <at> Override
103 104      protected List<String> storyPaths() {
104          return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), "**/stories/*parameters.story", "**/failing_before*.story");
105                  
105          String filter = System.getProperty("story.filter", "**/*.story");
106          return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), filter, "**/failing_before*.story");
106 107      }
107 108  
108 109  }
109 110 \ No newline at end of file


Mauro Talevi | 17 Jun 2013 09:53

[scm-core][1/1] JBEHAVE-922: Renamed example custom type, used both for annotated and non-annotated parameter mapping.

dt:after { content: ':' !important; } >Commit 295174411643f838588b2aa79d63bea20213ec56 Branch master Author Mauro Talevi <mauro.talevi-hQ+s5KbX5YmGglJvpFV4uA@public.gmane.org> Date Mon, 17 Jun 2013 08:53:07 +0100 Message JBEHAVE-922: Renamed example custom type, used both for annotated and non-annotated parameter mapping.

Changed file examples/core/src/main/java/org/jbehave/examples/core/steps/ExamplesTableParametersSteps.java

12 12  public class ExamplesTableParametersSteps {
13 13  
14 14       <at> Given("the parameters mapped via annotations to custom types: %table")
15      public void givenTheAnnotatedParametersList(List<AnnotatedParameters> list) {
15      public void givenTheMyParametersList(List<MyParameters> list) {
16 16          System.out.println("List annotated: "+list);
17 17      }
18 18  
19 19       <at> Given("the parameters mapped via annotations to custom type: %table")
20      public void givenTheAnnotatedParametersType(AnnotatedParameters type) {
21          System.out.println("Single annotated: "+type);
20      public void givenTheMyParametersType(MyParameters single) {
21          System.out.println("Single annotated: "+single);
22 22      }
23 23  
24 24       <at> Given("the parameters mapped via names to custom types: %table")
25      public void givenTheNamedParametersList(List<AnnotatedParameters> list) {
25      public void givenTheNamedParametersList(List<MyParameters> list) {
26 26          System.out.println("List named: "+list);
27 27      }
28 28  
29 29       <at> Given("the parameters mapped via names to custom type: %table")
30      public void givenTheNamedParametersType(AnnotatedParameters type) {
31          System.out.println("Single named: "+type);
30      public void givenTheNamedParametersType(MyParameters single) {
31          System.out.println("Single named: "+single);
32 32      }
33 33  
34 34       <at> AsParameters
35      public static class AnnotatedParameters {
35      public static class MyParameters {
36 36           <at> Parameter(name = "aString")
37 37          private String string;
38 38           <at> Parameter(name = "anInteger")


Mauro Talevi | 16 Jun 2013 19:46

[scm-core][3/3] JBEHAVE-922: Added examples_table_parameters.story to verify behaviour.

dt:after { content: ':' !important; } >Commit 6171df6b75eeb738308e060aa9668c7421ea07ce Branch master Author Mauro Talevi <mauro.talevi-hQ+s5KbX5YmGglJvpFV4uA@public.gmane.org> Date Sun, 16 Jun 2013 18:46:26 +0100 Message JBEHAVE-922: Added examples_table_parameters.story to verify behaviour.

Changed file examples/core/src/main/java/org/jbehave/examples/core/CoreStories.java

28 28  import org.jbehave.examples.core.steps.BeforeAfterSteps;
29 29  import org.jbehave.examples.core.steps.CalendarSteps;
30 30  import org.jbehave.examples.core.steps.CompositeSteps;
31  import org.jbehave.examples.core.steps.ExamplesTableParametersSteps;
31 32  import org.jbehave.examples.core.steps.MetaParametrisationSteps;
32 33  import org.jbehave.examples.core.steps.NamedParametersSteps;
33 34  import org.jbehave.examples.core.steps.PendingSteps;
95 96      public InjectableStepsFactory stepsFactory() {
96 97          return new InstanceStepsFactory(configuration(), new TraderSteps(new TradingService()), new AndSteps(), new MetaParametrisationSteps(),
97 98                  new CalendarSteps(), new PriorityMatchingSteps(), new PendingSteps(), new SandpitSteps(),
98                  new SearchSteps(), new BeforeAfterSteps(), new CompositeSteps(), new NamedParametersSteps());
99                  new SearchSteps(), new BeforeAfterSteps(), new CompositeSteps(), new NamedParametersSteps(), new ExamplesTableParametersSteps());
99 100      }
100 101  
101 102       <at> Override
102 103      protected List<String> storyPaths() {
103          return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), "**/stories/*.story", "**/failing_before*.story");
104          return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), "**/stories/*parameters.story", "**/failing_before*.story");
104 105                  
105 106      }
106 107          

Changed file examples/core/src/main/java/org/jbehave/examples/core/CoreStory.java

31 31  import org.jbehave.examples.core.steps.CalendarSteps;
32 32  import org.jbehave.examples.core.steps.CompositeNestedSteps;
33 33  import org.jbehave.examples.core.steps.CompositeSteps;
34  import org.jbehave.examples.core.steps.ExamplesTableParametersSteps;
34 35  import org.jbehave.examples.core.steps.MetaParametrisationSteps;
35 36  import org.jbehave.examples.core.steps.NamedParametersSteps;
36 37  import org.jbehave.examples.core.steps.ParameterDelimitersSteps;
108 109                  new MetaParametrisationSteps(), new CalendarSteps(), new PriorityMatchingSteps(), new PendingSteps(),
109 110                  new ParametrisedSteps(), new SandpitSteps(), new SearchSteps(), new BeforeAfterSteps(),
110 111                  new CompositeSteps(), new CompositeNestedSteps(), new NamedParametersSteps(),
111                  new ParameterDelimitersSteps());
112                  new ParameterDelimitersSteps(), new ExamplesTableParametersSteps());
112 113      }
113 114  
114 115  }

Added file examples/core/src/main/java/org/jbehave/examples/core/steps/ExamplesTableParametersSteps.java

1  package org.jbehave.examples.core.steps;
2  
3  import java.math.BigDecimal;
4  import java.util.List;
5  
6  import org.apache.commons.lang.builder.ToStringBuilder;
7  import org.apache.commons.lang.builder.ToStringStyle;
8  import org.jbehave.core.annotations.AsParameters;
9  import org.jbehave.core.annotations.Given;
10  import org.jbehave.core.annotations.Parameter;
11  
12  public class ExamplesTableParametersSteps {
13  
14       <at> Given("the parameters mapped via annotations to custom types: %table")
15      public void givenTheAnnotatedParametersList(List<AnnotatedParameters> list) {
16          System.out.println("List annotated: "+list);
17      }
18  
19       <at> Given("the parameters mapped via annotations to custom type: %table")
20      public void givenTheAnnotatedParametersType(AnnotatedParameters type) {
21          System.out.println("Single annotated: "+type);
22      }
23  
24       <at> Given("the parameters mapped via names to custom types: %table")
25      public void givenTheNamedParametersList(List<AnnotatedParameters> list) {
26          System.out.println("List named: "+list);
27      }
28  
29       <at> Given("the parameters mapped via names to custom type: %table")
30      public void givenTheNamedParametersType(AnnotatedParameters type) {
31          System.out.println("Single named: "+type);
32      }
33  
34       <at> AsParameters
35      public static class AnnotatedParameters {
36           <at> Parameter(name = "aString")
37          private String string;
38           <at> Parameter(name = "anInteger")
39          private Integer integer;
40           <at> Parameter(name = "aBigDecimal")
41          private BigDecimal bigDecimal;
42          
43           <at> Override
44          public String toString() {
45              return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
46          }
47      }
48  
49  }

Added file examples/core/src/main/java/org/jbehave/examples/core/stories/ExamplesTableParameters.java

1  package org.jbehave.examples.core.stories;
2  
3  import org.jbehave.examples.core.CoreStory;
4  
5  public class ExamplesTableParameters extends CoreStory {
6  
7  }

Added file examples/core/src/main/java/org/jbehave/examples/core/stories/examples_table_parameters.story

1  Scenario:  Mapping parameters to custom types via annotations and field names 
2  
3  Given the parameters mapped via annotations to custom types: 
4  | aString | anInteger | aBigDecimal |
5  |  blah   |  1234     |  1.234      |
6  |  blah   |  7890     |  7.890      |
7  Given the parameters mapped via annotations to custom type: 
8  | aString | anInteger | aBigDecimal |
9  |  blah   |  1234     |  1.234      |
10  Given the parameters mapped via names to custom types: 
11  | string | integer | bigDecimal |
12  |  blah  |  1234   |  1.234     |
13  |  blah  |  7890   |  7.890     |
14  Given the parameters mapped via names to custom type: 
15  | string | integer | bigDecimal |
16  |  blah  |  1234   |  1.234     |
17  


Mauro Talevi | 16 Jun 2013 19:46

[scm-core][2/3] JBEHAVE-922: Added <at> Parameter annotation to support mapping fields with different names from parameters.

dt:after { content: ':' !important; } >Commit c9843d0fd24cf79978929ca4e41f974a7a526cef Branch master Author Mauro Talevi <mauro.talevi-hQ+s5KbX5YmGglJvpFV4uA@public.gmane.org> Date Sun, 16 Jun 2013 17:00:08 +0100 Message JBEHAVE-922: Added <at> Parameter annotation to support mapping fields with different names from parameters.

Added file jbehave-core/src/main/java/org/jbehave/core/annotations/Parameter.java

1  package org.jbehave.core.annotations;
2  
3  import java.lang.annotation.Documented;
4  import java.lang.annotation.ElementType;
5  import java.lang.annotation.Retention;
6  import java.lang.annotation.RetentionPolicy;
7  import java.lang.annotation.Target;
8  
9   <at> Retention(RetentionPolicy.RUNTIME)
10   <at> Target(ElementType.FIELD)
11   <at> Documented
12  public  <at> interface Parameter {
13  
14      String name();
15  
16  }

Changed file jbehave-core/src/main/java/org/jbehave/core/model/ExamplesTable.java

16 16  
17 17  import org.apache.commons.lang.builder.ToStringBuilder;
18 18  import org.apache.commons.lang.builder.ToStringStyle;
19  import org.jbehave.core.annotations.Parameter;
19 20  import org.jbehave.core.model.TableTransformers.TableTransformer;
20 21  import org.jbehave.core.steps.ChainedRow;
21 22  import org.jbehave.core.steps.ConvertedParameters;
168 169  
169 170      public ExamplesTable(String tableAsString, String headerSeparator, String valueSeparator,
170 171              String ignorableSeparator, ParameterConverters parameterConverters) {
171          this(tableAsString, headerSeparator, valueSeparator, ignorableSeparator, parameterConverters, new TableTransformers());
172          this(tableAsString, headerSeparator, valueSeparator, ignorableSeparator, parameterConverters,
173                  new TableTransformers());
172 174      }
173 175  
174 176      public ExamplesTable(String tableAsString, String headerSeparator, String valueSeparator,
370 372              T instance = type.newInstance();
371 373              Map<String, String> values = parameters.values();
372 374              for (String name : values.keySet()) {
373                  Field f = type.getDeclaredField(name);
374                  Class<?> fieldType = (Class<?>) f.getGenericType();
375                  Field field = findField(type, name);
376                  Class<?> fieldType = (Class<?>) field.getGenericType();
375 377                  Object value = parameters.valueAs(name, fieldType);
376                  f.setAccessible(true);
377                  f.set(instance, value);
378                  field.setAccessible(true);
379                  field.set(instance, value);
378 380              }
379 381              return instance;
380 382          } catch (Exception e) {
381              throw new RuntimeException("Failed to map parameters to type "+type, e);
383              throw new ParametersNotMappableToType(parameters, type, e);
382 384          }
383 385      }
384 386  
387      private <T> Field findField(Class<T> type, String name) throws NoSuchFieldException {
388          // First look for fields annotated by  <at> Parameter specifying the name
389          for (Field field : type.getDeclaredFields()) {
390              if (field.isAnnotationPresent(Parameter.class)) {
391                  Parameter parameter = field.getAnnotation(Parameter.class);
392                  if (name.equals(parameter.name())) {
393                      return field;
394                  }
395              }
396          }
397          // Default to field matching given name
398          return type.getDeclaredField(name);
399      }
400  
385 401      private Parameters createParameters(Map<String, String> values) {
386 402          return new ConvertedParameters(new ChainedRow(new ConvertedParameters(values, parameterConverters), defaults),
387 403                  parameterConverters);
436 452  
437 453      }
438 454  
455       <at> SuppressWarnings("serial")
456      public static class ParametersNotMappableToType extends RuntimeException {
457  
458          public ParametersNotMappableToType(Parameters parameters, Class<?> type, Exception e) {
459              super(parameters.values() + " not mappable to type " + type, e);
460          }
461  
462      }
463  
439 464  }

Changed file jbehave-core/src/test/java/org/jbehave/core/model/ExamplesTableBehaviour.java

20 20  import org.apache.commons.lang.builder.ToStringBuilder;
21 21  import org.apache.commons.lang.builder.ToStringStyle;
22 22  import org.jbehave.core.annotations.AsParameters;
23  import org.jbehave.core.annotations.Parameter;
23 24  import org.jbehave.core.model.ExamplesTable.RowNotFound;
24 25  import org.jbehave.core.model.TableTransformers.TableTransformer;
25 26  import org.jbehave.core.steps.ConvertedParameters.ValueNotFound;
301 302      }
302 303  
303 304       <at> Test
304      public void shouldMapTableRowToCustomType() throws Exception {
305      public void shouldMapParametersToAnnotatedType() throws Exception {
305 306          // Given
306 307          ExamplesTableFactory factory = new ExamplesTableFactory();
307 308  
317 318      }
318 319  
319 320       <at> Test
321      public void shouldMapParametersToAnnotatedTypeWithAnnotatedFields() throws Exception {
322          // Given
323          ExamplesTableFactory factory = new ExamplesTableFactory();
324  
325          // When
326          String tableAsString = "|aString|anInteger|\n|11|22|";
327          ExamplesTable examplesTable = factory.createExamplesTable(tableAsString);
328  
329          // Then
330          for (MyParametersWithAnnotatedFields parameters : examplesTable.getRowsAs(MyParametersWithAnnotatedFields.class)) {
331              assertThat(parameters.string, equalTo("11"));
332              assertThat(parameters.integer, equalTo(22));
333          }
334      }
335  
336       <at> Test
320 337      public void shouldThrowExceptionIfValuesOrRowsAreNotFound() throws Exception {
321 338          // Given
322 339          ParameterConverters parameterConverters = new ParameterConverters();
458 475              return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
459 476          }
460 477      }
478  
479       <at> AsParameters
480      public static class MyParametersWithAnnotatedFields {
481  
482           <at> Parameter(name = "aString")
483          private String string;
484           <at> Parameter(name = "anInteger")
485          private Integer integer;
486  
487           <at> Override
488          public String toString() {
489              return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
490          }
491      }
492  
461 493  }


Mauro Talevi | 16 Jun 2013 19:46

[scm-core][1/3] JBEHAVE-922: Added ExamplesTableParametersConverter.

dt:after { content: ':' !important; } >Commit bae96e32c1833ec2aee54fec1db5be17955176a1 Branch master Author Mauro Talevi <mauro.talevi-hQ+s5KbX5YmGglJvpFV4uA@public.gmane.org> Date Sun, 16 Jun 2013 16:21:06 +0100 Message JBEHAVE-922: Added ExamplesTableParametersConverter.

Added file jbehave-core/src/main/java/org/jbehave/core/annotations/AsParameters.java

1  package org.jbehave.core.annotations;
2  
3  import java.lang.annotation.Documented;
4  import java.lang.annotation.ElementType;
5  import java.lang.annotation.Retention;
6  import java.lang.annotation.RetentionPolicy;
7  import java.lang.annotation.Target;
8  
9   <at> Retention(RetentionPolicy.RUNTIME)
10   <at> Target(ElementType.TYPE)
11   <at> Documented
12  public  <at> interface AsParameters {
13  
14  }

Changed file jbehave-core/src/main/java/org/jbehave/core/model/ExamplesTable.java

3 3  import java.io.ByteArrayInputStream;
4 4  import java.io.IOException;
5 5  import java.io.PrintStream;
6  import java.lang.reflect.Field;
6 7  import java.util.ArrayList;
7 8  import java.util.Collections;
8 9  import java.util.HashMap;
354 355          return rows;
355 356      }
356 357  
358      public <T> List<T> getRowsAs(Class<T> type) {
359          List<T> rows = new ArrayList<T>();
360  
361          for (Parameters parameters : getRowsAsParameters()) {
362              rows.add(mapToType(parameters, type));
363          }
364  
365          return rows;
366      }
367  
368      private <T> T mapToType(Parameters parameters, Class<T> type){
369          try {
370              T instance = type.newInstance();
371              Map<String, String> values = parameters.values();
372              for ( String name : values.keySet() ){
373                  Field f = type.getDeclaredField(name);
374                  Class<?> fieldType = (Class<?>) f.getGenericType();
375                  Object value = parameters.valueAs(name, fieldType);    
376                  f.setAccessible(true);
377                  f.set(instance, value);
378              }
379              return instance;
380          } catch (Exception e) {
381              throw new RuntimeException("Failed to map parameters to type "+type, e);
382          }
383      }
384         
357 385      private Parameters createParameters(Map<String, String> values) {
358 386          return new ConvertedParameters(new ChainedRow(new ConvertedParameters(values, parameterConverters), defaults),
359 387                  parameterConverters);
407 435          }
408 436  
409 437      }
438  
410 439  }

Changed file jbehave-core/src/main/java/org/jbehave/core/steps/ParameterConverters.java

20 20  import java.util.concurrent.atomic.AtomicLong;
21 21  
22 22  import org.apache.commons.lang.BooleanUtils;
23  import org.jbehave.core.annotations.AsParameters;
23 24  import org.jbehave.core.configuration.MostUsefulConfiguration;
24 25  import org.jbehave.core.model.ExamplesTable;
25 26  import org.jbehave.core.model.ExamplesTableFactory;
41 42   * <li>{ <at> link ParameterConverters.DateConverter DateConverter}</li>
42 43   * <li>{ <at> link ParameterConverters.ExamplesTableConverter ExamplesTableConverter}
43 44   * </li>
45   * <li>{ <at> link ParameterConverters.ExamplesTableParametersConverter
46   * ExamplesTableParametersConverter}</li>
44 47   * <li>{ <at> link ParameterConverters.MethodReturningConverter
45 48   * MethodReturningConverter}</li>
46 49   * </ul>
116 119  
117 120      protected ParameterConverter[] defaultConverters(Locale locale, String listSeparator) {
118 121          String escapedListSeparator = escapeRegexPunctuation(listSeparator);
122          ExamplesTableFactory tableFactory = new ExamplesTableFactory(this);
119 123          ParameterConverter[] defaultConverters = { new BooleanConverter(),
120 124                  new NumberConverter(NumberFormat.getInstance(locale)),
121 125                  new NumberListConverter(NumberFormat.getInstance(locale), escapedListSeparator),
122 126                  new StringListConverter(escapedListSeparator), new DateConverter(),
123                  new ExamplesTableConverter(new ExamplesTableFactory(this)) };
127                  new ExamplesTableConverter(tableFactory), new ExamplesTableParametersConverter(tableFactory) };
124 128          return defaultConverters;
125 129      }
126 130  
640 644      }
641 645  
642 646      /**
647       * Converts ExamplesTable to list of parameters, mapped to annotated custom
648       * types.
649       */
650      public static class ExamplesTableParametersConverter implements ParameterConverter {
651  
652          private final ExamplesTableFactory factory;
653  
654          public ExamplesTableParametersConverter() {
655              this(new ExamplesTableFactory());
656          }
657  
658          public ExamplesTableParametersConverter(ExamplesTableFactory factory) {
659              this.factory = factory;
660          }
661  
662          public boolean accept(Type type) {
663              if (type instanceof ParameterizedType) {
664                  Class<?> rawClass = rawClass(type);
665                  Class<?> argumentClass = argumentClass(type);
666                  if (rawClass.isAnnotationPresent(AsParameters.class)
667                          || argumentClass.isAnnotationPresent(AsParameters.class)) {
668                      return true;
669                  }
670              } else if (type instanceof Class) {
671                  return ((Class<?>) type).isAnnotationPresent(AsParameters.class);
672              }
673              return false;
674          }
675  
676          private Class<?> rawClass(Type type) {
677              return (Class<?>) ((ParameterizedType) type).getRawType();
678          }
679  
680          private Class<?> argumentClass(Type type) {
681              if (type instanceof ParameterizedType) {
682                  return (Class<?>) ((ParameterizedType) type).getActualTypeArguments()[0];
683              } else {
684                  return (Class<?>) type;
685              }
686          }
687  
688          public Object convertValue(String value, Type type) {
689              List<?> rows = factory.createExamplesTable(value).getRowsAs(argumentClass(type));
690              if (type instanceof ParameterizedType) {
691                  return rows;
692              }
693              return rows.iterator().next();
694          }
695  
696      }
697  
698      /**
643 699       * Invokes method on instance to return value.
644 700       */
645 701      public static class MethodReturningConverter implements ParameterConverter {

Changed file jbehave-core/src/test/java/org/jbehave/core/model/ExamplesTableBehaviour.java

17 17  import java.util.Properties;
18 18  
19 19  import org.apache.commons.io.output.ByteArrayOutputStream;
20  import org.apache.commons.lang.builder.ToStringBuilder;
21  import org.apache.commons.lang.builder.ToStringStyle;
22  import org.jbehave.core.annotations.AsParameters;
20 23  import org.jbehave.core.model.ExamplesTable.RowNotFound;
21 24  import org.jbehave.core.model.TableTransformers.TableTransformer;
22 25  import org.jbehave.core.steps.ConvertedParameters.ValueNotFound;
298 301      }
299 302  
300 303       <at> Test
304      public void shouldMapTableRowToCustomType() throws Exception {
305          // Given
306          ExamplesTableFactory factory = new ExamplesTableFactory();
307  
308          // When
309          String tableAsString = "|string|integer|\n|11|22|";
310          ExamplesTable examplesTable = factory.createExamplesTable(tableAsString);
311  
312          // Then
313          for (MyParameters parameters : examplesTable.getRowsAs(MyParameters.class)) {
314              assertThat(parameters.string, equalTo("11"));
315              assertThat(parameters.integer, equalTo(22));
316          }
317      }
318  
319       <at> Test
301 320      public void shouldThrowExceptionIfValuesOrRowsAreNotFound() throws Exception {
302 321          // Given
303 322          ParameterConverters parameterConverters = new ParameterConverters();
428 447          return null;
429 448      }
430 449  
450       <at> AsParameters
451      public static class MyParameters {
452  
453          private String string;
454          private Integer integer;
455  
456           <at> Override
457          public String toString() {
458              return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
459          }
460      }
431 461  }

Changed file jbehave-core/src/test/java/org/jbehave/core/steps/ParameterConvertersBehaviour.java

28 28  import org.jbehave.core.steps.ParameterConverters.EnumConverter;
29 29  import org.jbehave.core.steps.ParameterConverters.EnumListConverter;
30 30  import org.jbehave.core.steps.ParameterConverters.ExamplesTableConverter;
31  import org.jbehave.core.steps.ParameterConverters.ExamplesTableParametersConverter;
31 32  import org.jbehave.core.steps.ParameterConverters.MethodReturningConverter;
32 33  import org.jbehave.core.steps.ParameterConverters.NumberConverter;
33 34  import org.jbehave.core.steps.ParameterConverters.NumberListConverter;
34 35  import org.jbehave.core.steps.ParameterConverters.ParameterConverter;
35 36  import org.jbehave.core.steps.ParameterConverters.ParameterConvertionFailed;
36 37  import org.jbehave.core.steps.ParameterConverters.StringListConverter;
38  import org.jbehave.core.steps.SomeSteps.MyParameters;
37 39  import org.junit.Test;
38 40  
39 41  import static org.hamcrest.MatcherAssert.assertThat;
40 42  
41 43  import static org.hamcrest.Matchers.equalTo;
42  import static org.hamcrest.Matchers.is;
43 44  import static org.hamcrest.Matchers.instanceOf;
45  import static org.hamcrest.Matchers.is;
44 46  
45 47  import static org.junit.Assert.fail;
46 48  import static org.mockito.Mockito.mock;
337 339      }
338 340  
339 341       <at> Test
340      public void shouldConvertMultilineTableParameter() throws ParseException, IntrospectionException {
342      public void shouldConvertMultilineTable() throws ParseException, IntrospectionException {
341 343          ParameterConverter converter = new ExamplesTableConverter();
342 344          assertThat(converter.accept(ExamplesTable.class), is(true));
343 345          assertThat(converter.accept(WrongType.class), is(false));
355 357      }
356 358  
357 359       <at> Test
360      public void shouldConvertMultilineTableToParameters() throws ParseException, IntrospectionException {
361          ParameterConverter converter = new ExamplesTableParametersConverter();
362          Type type = SomeSteps.methodFor("aMethodWithExamplesTableParameters").getGenericParameterTypes()[0];
363          assertThat(converter.accept(type), is(true));
364          assertThat(converter.accept(WrongType.class), is(false));
365          assertThat(converter.accept(mock(Type.class)), is(false));
366          String value = "|col1|col2|\n|row11|row12|\n|row21|row22|\n";
367           <at> SuppressWarnings("unchecked")
368          List<MyParameters> parameters = (List<MyParameters>) converter.convertValue(value, type);
369          assertThat(parameters.size(), equalTo(2));
370          MyParameters row1 = parameters.get(0);
371          assertThat(row1.col1, equalTo("row11"));
372          assertThat(row1.col2, equalTo("row12"));
373          MyParameters row2 = parameters.get(1);
374          assertThat(row2.col1, equalTo("row21"));
375          assertThat(row2.col2, equalTo("row22"));
376      }
377  
378       <at> Test
379      public void shouldConvertSinglelineTableToParameters() throws ParseException, IntrospectionException {
380          ParameterConverter converter = new ExamplesTableParametersConverter();
381          Type type = SomeSteps.methodFor("aMethodWithExamplesTableParameter").getGenericParameterTypes()[0];
382          assertThat(converter.accept(type), is(true));
383          assertThat(converter.accept(WrongType.class), is(false));
384          assertThat(converter.accept(mock(Type.class)), is(false));
385          String value = "|col1|col2|\n|row11|row12|\n";
386          MyParameters parameters = (MyParameters) converter.convertValue(value, type);
387          assertThat(parameters.col1, equalTo("row11"));
388          assertThat(parameters.col2, equalTo("row12"));
389      }
390  
391       <at> Test
358 392      public void shouldConvertParameterFromMethodReturningValue() throws ParseException, IntrospectionException {
359 393          Method method = SomeSteps.methodFor("aMethodReturningExamplesTable");
360 394          ParameterConverter converter = new MethodReturningConverter(method, new SomeSteps());

Changed file jbehave-core/src/test/java/org/jbehave/core/steps/SomeSteps.java

10 10  import java.util.List;
11 11  import java.util.Set;
12 12  
13  import org.jbehave.core.annotations.AsParameters;
13 14  import org.jbehave.core.annotations.BeforeScenario;
14 15  import org.jbehave.core.annotations.Named;
15 16  import org.jbehave.core.failures.PendingStepFound;
103 104         return new ExamplesTable(value);
104 105      }
105 106  
107      public void aMethodWithExamplesTableParameter(MyParameters args) {
108          this.args = args;
109      }
110  
111      public void aMethodWithExamplesTableParameters(List<MyParameters> args) {
112          this.args = args;
113      }
114  
115       <at> AsParameters
116      public static class MyParameters {
117          String col1;
118          String col2;
119          
120      }
121  
106 122      public ExamplesTable aFailingMethodReturningExamplesTable(String value){
107 123          throw new RuntimeException(value);
108 124      }


Mauro Talevi | 9 Jun 2013 13:28

[scm-tutorial][1/1] Updated to latest core release.

dt:after { content: ':' !important; } >Commit 805d27b250f61d42d21304b696e87ce68506ff29 Branch master Author Mauro Talevi <mauro.talevi-hQ+s5KbX5YmGglJvpFV4uA@public.gmane.org> Date Sun, 9 Jun 2013 12:28:20 +0100 Message Updated to latest core release.

Changed file etsy-web-runner/pom.xml

9 9    <name>Etsy.com Stories Web Runner</name>
10 10  
11 11    <properties>
12      <jbehave.core.version>3.8-SNAPSHOT</jbehave.core.version>
12      <jbehave.core.version>3.9-SNAPSHOT</jbehave.core.version>
13 13      <jbehave.web.version>3.6-SNAPSHOT</jbehave.web.version>
14 14      <jbehave.site.version>3.1.1</jbehave.site.version>
15 15      <jbehave.webrunner.name>etsy-stories-runner</jbehave.webrunner.name>
26 26        <artifactId>etsy-stories-java-spring</artifactId>
27 27        <version>${project.version}</version>
28 28      </dependency>
29      <dependency>
30        <groupId>org.seleniumhq.selenium.fluent</groupId>
31        <artifactId>fluent-selenium</artifactId>
32        <version>1.6.3</version>
33      </dependency>
29 34    </dependencies>
30 35  
31 36    <build>
40 45              <target>1.5</target>
41 46            </configuration>
42 47          </plugin>
43          <!--This plugin's configuration is used to store Eclipse m2e settings 
44            only. It has no influence on the Maven build itself. -->
45          <plugin>
46            <groupId>org.eclipse.m2e</groupId>
47            <artifactId>lifecycle-mapping</artifactId>
48            <version>1.0.0</version>
49            <configuration>
50              <lifecycleMappingMetadata>
51                <pluginExecutions>
52                  <pluginExecution>
53                    <pluginExecutionFilter>
54                      <groupId>org.apache.maven.plugins</groupId>
55                      <artifactId>maven-dependency-plugin</artifactId>
56                      <versionRange>[2.1,)</versionRange>
57                      <goals>
58                        <goal>copy</goal>
59                        <goal>unpack</goal>
60                      </goals>
61                    </pluginExecutionFilter>
62                    <action>
63                      <ignore></ignore>
64                    </action>
65                  </pluginExecution>
66                  <pluginExecution>
67                    <pluginExecutionFilter>
68                      <groupId>org.jbehave</groupId>
69                      <artifactId>jbehave-maven-plugin</artifactId>
70                      <versionRange>[${jbehave.core.version},)</versionRange>
71                      <goals>
72                        <goal>unpack-view-resources</goal>
73                      </goals>
74                    </pluginExecutionFilter>
75                    <action>
76                      <ignore></ignore>
77                    </action>
78                  </pluginExecution>
79                  <pluginExecution>
80                    <pluginExecutionFilter>
81                      <groupId>org.codehaus.gmaven</groupId>
82                      <artifactId>gmaven-plugin</artifactId>
83                      <versionRange>[${gmaven.version},)</versionRange>
84                      <goals>
85                        <goal>generateStubs</goal>
86                        <goal>compile</goal>
87                        <goal>generateTestStubs</goal>
88                        <goal>testCompile</goal>
89                      </goals>
90                    </pluginExecutionFilter>
91                    <action>
92                      <ignore></ignore>
93                    </action>
94                  </pluginExecution>
95                </pluginExecutions>
96              </lifecycleMappingMetadata>
97            </configuration>
98          </plugin>
99 48        </plugins>
100 49      </pluginManagement>
101 50      <plugins>
175 124      <profile>
176 125        <id>stable</id>
177 126        <properties>
178          <jbehave.core.version>3.7.0</jbehave.core.version>
127          <jbehave.core.version>3.8.0</jbehave.core.version>
179 128          <jbehave.web.version>3.5.4</jbehave.web.version>
180 129        </properties>
181 130      </profile>


Mauro Talevi | 3 Jun 2013 09:21

[scm-site][1/1] Added README.

dt:after { content: ':' !important; } >Commit 44c0311ad009e3789b94166c5081a735de05e4fb Branch master Author Mauro Talevi <mauro.talevi-hQ+s5KbX5YmGglJvpFV4uA@public.gmane.org> Date Mon, 3 Jun 2013 09:21:03 +0200 Message Added README.

Added file README.md

1  [![Build Status](https://travis-ci.org/jbehave/jbehave-site.png)](https://travis-ci.org/jbehave/jbehave-site)
2  
3  # JBehave Site
4  
5  JBehave Site contains the static web site content of [jbehave.org](http://jbehave.org) as well as resources used by other JBehave projects, notably Core and Web.
6  
7  ## Contributing and Developing
8  
9  Please report issues, feature requests on the Codehaus [issue
10  tracker](http://jira.codehaus.org/browse/JBEHAVE) or discuss them on the
11  [dev mail-list](http://xircles.codehaus.org/lists/dev-b1QraVsTlj/IJWOP8RzEEmD2FQJk+8+b@public.gmane.org).
12  
13  Keep an eye on the  [Travis Continuous Integration](http://travis-ci.org/jbehave/jbehave) server for JBehave builds.
14  
15  ## License
16  
17  See LICENSE.txt in the source root (BSD).


Mauro Talevi | 3 Jun 2013 09:11

[scm-site][1/1] Updated scripts. Added travis config.

dt:after { content: ':' !important; } >Commit 4fe13c5ff04dd32c3e133a93d9a6d3b2d9a8a3f4 Branch master Author Mauro Talevi <mauro.talevi-hQ+s5KbX5YmGglJvpFV4uA@public.gmane.org> Date Mon, 3 Jun 2013 09:11:45 +0200 Message Updated scripts. Added travis config.

Added file .travis.yml

1  language: java
2  env: MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=128m"
3  install: /bin/true
4  script: mvn clean install | grep -v -E "Download(ed|ing)"
5  jdk:
6    - openjdk6
7    - openjdk7
8    - oraclejdk7

Changed file release.sh

27 27    exit;
28 28  fi
29 29  
30  mvn --batch-mode release:prepare -Preporting,distribution -DreleaseVersion=$VERSION -Dtag=$NAME-$VERSION -DdevelopmentVersion=$NEXT 
31  mvn release:perform -Preporting,distribution
30  PROFILES=atlassian,jenkins,reporting,distribution
31  mvn --batch-mode release:prepare -P$PROFILES -DreleaseVersion=$VERSION -Dtag=$NAME-$VERSION -DdevelopmentVersion=$NEXT 
32  mvn release:perform -P$PROFILES
32 33  
33 34  CWD=`pwd`
34 35  cd $CWD/../jbehave-site/site-upload

Changed file snapshot.sh

10 10    exit;
11 11  fi
12 12  
13  mvn clean deploy -Preporting,distribution
13  mvn -U clean deploy -Preporting,distribution
14 14  
15 15  CWD=`pwd`
16 16  cd $CWD/../jbehave-site/site-upload


Mauro Talevi | 2 Jun 2013 11:32

[scm-core][15/15] JBEHAVE-899 Added needle module

dt:after { content: ':' !important; } >Commit 82d8b6b87048246ebddc9119bfcac5c048e67216 Branch master Author Mauro Talevi <mauro.talevi-hQ+s5KbX5YmGglJvpFV4uA@public.gmane.org> Date Sun, 2 Jun 2013 11:31:38 +0200 Message JBEHAVE-899 Added needle module Changed files:

M examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/AnnotatedPathRunnerUsingNeedle.java
M examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/ParentAnnotatedEmbedderUsingNeedle.java
D examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/TraderServiceInjectionProvider.java
M examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/TraderStoriesUsingNeedle.java
M examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/NeedleTraderSteps.java
M examples/trader-needle/src/test/java/org/jbehave/examples/trader/needle/NeedleTraderStepsConstructorInjectionTest.java
A examples/trader-needle/src/test/java/org/jbehave/examples/trader/needle/NeedleTraderStepsConstructorInjectionTest.java
A examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/provider/TraderServiceInjectionProvider.java
M examples/trader-needle/pom.xml
A examples/trader-needle/src/test/resources/log4j.properties
M jbehave-needle/src/test/java/org/jbehave/core/configuration/needle/NeedleAnnotationBuilderBehaviour.java
M jbehave-needle/src/main/java/org/jbehave/core/steps/needle/NeedleStepsFactory.java
M pom.xml
M examples/pom.xml
M examples/trader/src/main/java/org/jbehave/examples/trader/steps/TraderSteps.java
M jbehave-needle/src/main/java/org/jbehave/core/configuration/needle/NeedleAnnotationBuilder.java
M jbehave-needle/src/main/java/org/jbehave/core/steps/needle/configuration/CollectInjectionProvidersFromStepsInstance.java
M jbehave-needle/src/main/java/org/jbehave/core/steps/needle/configuration/CreateInstanceByDefaultConstructor.java
M jbehave-needle/src/main/java/org/jbehave/core/steps/needle/configuration/JBehaveNeedleConfiguration.java
M jbehave-needle/src/main/java/org/jbehave/core/steps/needle/configuration/LoadResourceBundle.java
A examples/trader-needle/pom.xml
A examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/AnnotatedEmbedderUsingNeedle.java
A examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/AnnotatedEmbedderUsingNeedleAndSteps.java
A examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/AnnotatedPathRunnerUsingNeedle.java
A examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/InheritingAnnotatedEmbedderUsingSteps.java
A examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/NeedleTraderSteps.java
A examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/ParentAnnotatedEmbedderUsingNeedle.java
A examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/TraderServiceInjectionProvider.java
A examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/TraderStoriesUsingNeedle.java
A examples/trader-needle/src/main/resources/needle.properties
A jbehave-needle/src/main/java/org/jbehave/core/annotations/needle/DefaultInstanceInjectionProvider.java
A jbehave-needle/src/main/java/org/jbehave/core/configuration/needle/NeedleAnnotationBuilder.java
A jbehave-needle/src/main/java/org/jbehave/core/junit/needle/NeedleAnnotatedEmbedderRunner.java
A jbehave-needle/src/main/java/org/jbehave/core/junit/needle/NeedleAnnotatedPathRunner.java
A jbehave-needle/src/test/java/org/jbehave/core/configuration/needle/NeedleAnnotationBuilderBehaviour.java
A jbehave-needle/src/test/java/org/jbehave/core/configuration/needle/ValueGetterProvider.java
A jbehave-needle/src/test/java/org/jbehave/core/junit/needle/NeedleAnnotatedEmbedderRunnerBehaviour.java
A jbehave-needle/src/test/java/org/jbehave/core/steps/needle/NeedleStepsFactoryBehaviour.java
A jbehave-needle/src/test/java/org/jbehave/core/steps/needle/ValueGetter.java
A jbehave-needle/src/test/resources/jbehave-needle.properties
M jbehave-needle/pom.xml
D jbehave-needle/src/test/java/org/jbehave/core/steps/needle/NeedleStepsFactoryBehavior.java
M jbehave-needle/src/test/resources/log4j.properties
M settings.xml
A jbehave-needle/pom.xml
A jbehave-needle/src/main/java/org/jbehave/core/annotations/needle/InjectionProviderInstancesSupplier.java
A jbehave-needle/src/main/java/org/jbehave/core/annotations/needle/NeedleInjectionProvider.java
A jbehave-needle/src/main/java/org/jbehave/core/annotations/needle/UsingNeedle.java
A jbehave-needle/src/main/java/org/jbehave/core/steps/needle/NeedleStepsFactory.java
A jbehave-needle/src/main/java/org/jbehave/core/steps/needle/configuration/CollectInjectionProvidersFromStepsInstance.java
A jbehave-needle/src/main/java/org/jbehave/core/steps/needle/configuration/CreateInstanceByDefaultConstructor.java
A jbehave-needle/src/main/java/org/jbehave/core/steps/needle/configuration/JBehaveNeedleConfiguration.java
A jbehave-needle/src/main/java/org/jbehave/core/steps/needle/configuration/LoadResourceBundle.java
A jbehave-needle/src/main/java/org/jbehave/core/steps/needle/configuration/ReadInjectionProviderClassNames.java
A jbehave-needle/src/test/java/org/jbehave/core/steps/needle/NeedleStepsFactoryBehavior.java
A jbehave-needle/src/test/resources/log4j.properties
A jbehave-needle/src/test/resources/needle.properties

Jan Galinski | 2 Jun 2013 11:32

[scm-core][14/15] moved provider to extra package and organized imports

dt:after { content: ':' !important; } >Commit c4aa030b59270f0099a652476734ea8905e3df08 Branch master Author Jan Galinski <jan.galinski-IJu/0kNRF9qOJsaolrKA/Q@public.gmane.org> Date Thu, 9 May 2013 12:05:12 +0200 Message moved provider to extra package and organized imports

Changed file examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/AnnotatedPathRunnerUsingNeedle.java

9 9  import org.junit.runner.RunWith;
10 10  
11 11  /**
12   * Run stories via annotated embedder configuration and steps using Needle. The textual trader stories are exactly the
13   same ones found in the jbehave-trader-example. Here we are only concerned with using the container to compose the
14   * configuration and the steps instances.
12   * Run stories via annotated embedder configuration and steps using Needle. The
13   textual trader stories are exactly the same ones found in the
14   jbehave-trader-example. Here we are only concerned with using the container
15   to compose the configuration and the steps instances.
15 16   */
16 17   <at> RunWith(NeedleAnnotatedPathRunner.class)
17 18   <at> Configure

Changed file examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/ParentAnnotatedEmbedderUsingNeedle.java

6 6  import org.jbehave.core.annotations.needle.UsingNeedle;
7 7  import org.jbehave.core.embedder.Embedder;
8 8  import org.jbehave.core.junit.needle.NeedleAnnotatedEmbedderRunner;
9  import org.jbehave.examples.trader.needle.provider.TraderServiceInjectionProvider;
9 10  import org.junit.runner.RunWith;
10 11  
11 12   <at> RunWith(NeedleAnnotatedEmbedderRunner.class)

Deleted file examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/TraderServiceInjectionProvider.java

1  package org.jbehave.examples.trader.needle;
2  
3  import org.jbehave.core.annotations.needle.DefaultInstanceInjectionProvider;
4  import org.jbehave.examples.trader.service.TradingService;
5  
6  /**
7   * Injection provider holding the service.
8   * 
9   *  <at> author Simon Zambrovski
10   */
11  public final class TraderServiceInjectionProvider extends DefaultInstanceInjectionProvider<TradingService> {
12  
13      public TraderServiceInjectionProvider() {
14          super(new TradingService());
15      }
16  }

Changed file examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/TraderStoriesUsingNeedle.java

10 10  import org.jbehave.core.steps.InjectableStepsFactory;
11 11  import org.jbehave.core.steps.needle.NeedleStepsFactory;
12 12  import org.jbehave.examples.trader.TraderStories;
13  import org.jbehave.examples.trader.needle.provider.TraderServiceInjectionProvider;
13 14  import org.jbehave.examples.trader.steps.AndSteps;
14 15  import org.jbehave.examples.trader.steps.BeforeAfterSteps;
15 16  import org.jbehave.examples.trader.steps.CalendarSteps;
21 22  import de.akquinet.jbosscc.needle.injection.InjectionProvider;
22 23  
23 24  /**
24   * Run trader stories using NeedleStepsFactory. The textual trader stories are exactly the same ones found in the
25   jbehave-trader-example. Here we are only concerned with using the container to compose the steps instances.
25   * Run trader stories using NeedleStepsFactory. The textual trader stories are
26   exactly the same ones found in the jbehave-trader-example. Here we are only
27   * concerned with using the container to compose the steps instances.
26 28   */
27 29  public class TraderStoriesUsingNeedle extends TraderStories {
28 30  
29 31     <at> Override
30 32    public InjectableStepsFactory stepsFactory() {
31          final Class<?>[] steps = new Class<?>[] { NeedleTraderSteps.class, BeforeAfterSteps.class, AndSteps.class,
32                  CalendarSteps.class, PendingSteps.class, PriorityMatchingSteps.class, SandpitSteps.class,
33                  SearchSteps.class };
33      final Class<?>[] steps = new Class<?>[] { NeedleTraderSteps.class, BeforeAfterSteps.class, AndSteps.class, CalendarSteps.class, PendingSteps.class,
34          PriorityMatchingSteps.class, SandpitSteps.class, SearchSteps.class };
34 35  
35 36      final Set<InjectionProvider<?>> providers = new HashSet<InjectionProvider<?>>();
36 37      providers.add(new TraderServiceInjectionProvider());


Jan Galinski | 2 Jun 2013 11:32

[scm-core][13/15] enable constructor injection

dt:after { content: ':' !important; } >Commit c8b4a7d7dfd3499b279082bbf1c8f8691f25ca10 Branch master Author Jan Galinski <jan.galinski-IJu/0kNRF9qOJsaolrKA/Q@public.gmane.org> Date Thu, 9 May 2013 12:03:31 +0200 Message enable constructor injection

Changed file examples/trader-needle/src/main/java/org/jbehave/examples/trader/needle/NeedleTraderSteps.java

11 11  public class NeedleTraderSteps extends TraderSteps {
12 12  
13 13     <at> Inject
14      private TradingService injectedService;
15  
16      public NeedleTraderSteps() {
17  
18      }
19  
20       <at> Override
21      public TradingService getService() {
22          return this.injectedService;
14    public NeedleTraderSteps(final TradingService service) {
15      super(service);
23 16    }
24 17  
25 18  }

Changed file examples/trader-needle/src/test/java/org/jbehave/examples/trader/needle/NeedleTraderStepsConstructorInjectionTest.java

5 5  import static org.junit.Assert.assertThat;
6 6  
7 7  import org.jbehave.examples.trader.model.Trader;
8  import org.jbehave.examples.trader.needle.provider.TraderServiceInjectionProvider;
8 9  import org.jbehave.examples.trader.service.TradingService;
9 10  import org.junit.Rule;
10 11  import org.junit.Test;
11 12  
12  import de.akquinet.jbosscc.needle.annotation.InjectIntoMany;
13 13  import de.akquinet.jbosscc.needle.annotation.ObjectUnderTest;
14 14  import de.akquinet.jbosscc.needle.junit.NeedleRule;
15 15  
16  /**
17   * Assure constructor injection with { <at> link TradingService} works.
18   * 
19   *  <at> author Jan Galinski, Holisticon AG
20   */
16 21  public class NeedleTraderStepsConstructorInjectionTest {
17 22  
18 23    private static final String BAR = "bar";
19 24    private static final String FOO = "foo";
20 25  
21 26     <at> Rule
22    public final NeedleRule needleRule = new NeedleRule();
23  
24    /**
25     * Constructor Injection on needleTraderSteps works. But needle creates a mock
26     * of { <at> link TradingService} by default. By using { <at> link InjectIntoMany}, a
27     * concrete instance is bound.
28     */
29     <at> InjectIntoMany
30    private final TradingService tradingService = new TradingService();
27    public final NeedleRule needleRule = new NeedleRule(new TraderServiceInjectionProvider());
31 28  
32 29     <at> ObjectUnderTest
33 30    private NeedleTraderSteps needleTraderSteps;



Gmane