parse_decision 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +6 -0
  5. data/LICENSE +22 -0
  6. data/README.md +71 -0
  7. data/bin/parse_decision +126 -0
  8. data/lib/parse_decision/config.rb +90 -0
  9. data/lib/parse_decision/controller.rb +142 -0
  10. data/lib/parse_decision/parsedecisiontask.rb +31 -0
  11. data/lib/parse_decision/parser.rb +194 -0
  12. data/lib/parse_decision/pd_context.rb +148 -0
  13. data/lib/parse_decision/plugin/application.rb +48 -0
  14. data/lib/parse_decision/plugin/plugin.rb +56 -0
  15. data/lib/parse_decision/plugin/ppm_xpath.rb +70 -0
  16. data/lib/parse_decision/plugin/pre_decision_guideline.rb +177 -0
  17. data/lib/parse_decision/plugin/product.rb +176 -0
  18. data/lib/parse_decision/plugin/product_xpath.rb +52 -0
  19. data/lib/parse_decision/plugin/web_product.rb +179 -0
  20. data/lib/parse_decision/plugin.rb +50 -0
  21. data/lib/parse_decision/version.rb +5 -0
  22. data/lib/parse_decision.rb +59 -0
  23. data/parse_decision.gemspec +27 -0
  24. data/rakefile.rb +58 -0
  25. data/spec/context_spec.rb +21 -0
  26. data/spec/data/multiproduct.decision.txt +1481 -0
  27. data/spec/data/prod.decision.txt +3957 -0
  28. data/spec/data/reference/multiproduct/001-APP.xml +1 -0
  29. data/spec/data/reference/multiproduct/001-Mod-Forbear-PRODUCT.xml +357 -0
  30. data/spec/data/reference/multiproduct/001-Mod-Forgive-PRODUCT.xml +361 -0
  31. data/spec/data/reference/multiproduct/001-Mod-RateTerm-PRODUCT.xml +353 -0
  32. data/spec/data/reference/multiproduct/001-Mod-SAM-PRODUCT.xml +365 -0
  33. data/spec/data/reference/product/001-APP.xml +1 -0
  34. data/spec/data/reference/product/001-Validation-Rules.xml +536 -0
  35. data/spec/data/reference/product/002-APP.xml +1 -0
  36. data/spec/data/reference/product/002-FAPIILoanModification-PRODUCT.xml +1770 -0
  37. data/spec/data/reference/web/001-APP.xml +1 -0
  38. data/spec/data/reference/web/001-Product01-PRODUCT.xml +1088 -0
  39. data/spec/data/reference/web/002-APP.xml +1 -0
  40. data/spec/data/reference/web/002-Product01-PRODUCT.xml +15 -0
  41. data/spec/data/reference/workflow/001-APP.xml +1 -0
  42. data/spec/data/reference/workflow/001-WF-DataClearing-Pre-Rules.xml +37 -0
  43. data/spec/data/reference/workflow-2/001-APP.xml +1 -0
  44. data/spec/data/reference/workflow-2/001-WF-ProdSel-Post-Rules.xml +699 -0
  45. data/spec/data/test.rb +13 -0
  46. data/spec/data/validation.decision.txt +1199 -0
  47. data/spec/data/web.decision.txt +1128 -0
  48. data/spec/data/wf.decision.txt +43 -0
  49. data/spec/data/wf2.decision.txt +705 -0
  50. data/spec/parser_spec.rb +308 -0
  51. data/spec/plugin_app_spec.rb +40 -0
  52. data/spec/plugin_ppmxpath_spec.rb +74 -0
  53. data/spec/plugin_predecision_spec.rb +81 -0
  54. data/spec/plugin_product_spec.rb +117 -0
  55. data/spec/plugin_productxpath_spec.rb +76 -0
  56. data/spec/plugin_spec.rb +54 -0
  57. data/spec/spec_helper.rb +81 -0
  58. data/test/data/2.2.decision-multiple.txt +1391 -0
  59. data/test/data/2.2.decision.txt +1128 -0
  60. data/test/data/2.decision.txt +1481 -0
  61. data/test/plugins/test_plugin_predecisionguideline.rb +120 -0
  62. data/test/plugins/test_plugin_product.rb +120 -0
  63. data/test/test_config.rb +90 -0
  64. data/test/test_context.rb +103 -0
  65. data/test/test_parse_webdecision.rb +121 -0
  66. data/test/test_parser.rb +69 -0
  67. data/test/test_parser_parse.rb +110 -0
  68. metadata +225 -0
@@ -0,0 +1,308 @@
1
+ require 'spec_helper'
2
+
3
+ describe ParseDecision::Parser do
4
+
5
+ let(:parser) { ParseDecision::Parser.new }
6
+ let(:outdir) { 'tmp/spec/parser' }
7
+ let(:wfsrc_log) { 'spec/data/wf.decision.txt' }
8
+
9
+ before :each do
10
+ out = Pathname.new outdir
11
+ out.rmtree if out.exist? && out.directory?
12
+ end
13
+
14
+ it "raises an error if an output dir is not set" do
15
+ expect { parser.parseFile(wfsrc_log) }.to raise_error("outdir missing")
16
+ end
17
+
18
+ let(:wfrules_output) { outdir+'/001-WF-DataClearing-Pre-Rules.xml' }
19
+ let(:wfapp_output) { outdir+'/001-APP.xml' }
20
+ let(:wflog_output) { outdir+'/wf.decision.txt' }
21
+
22
+ let(:wfrules_file) { Pathname.new wfrules_output }
23
+ let(:wfapp_file) { Pathname.new wfapp_output }
24
+ let(:wfsource_file) { Pathname.new wflog_output }
25
+
26
+ it "parses a file" do
27
+ parser.parse wfsrc_log, outdir
28
+
29
+ wfrules_file.exist?.should be_truthy
30
+ wfapp_file.exist?.should be_truthy
31
+ wfsource_file.exist?.should be_truthy
32
+ end
33
+
34
+ describe "parsed workflow decisions" do
35
+
36
+ # Reference files
37
+ let(:wfapp_reference) { 'spec/data/reference/workflow/001-APP.xml' }
38
+ let(:wfrules_reference) { 'spec/data/reference/workflow/001-WF-DataClearing-Pre-Rules.xml' }
39
+
40
+ let(:wfrules_result) { file_to_array( wfrules_output ) }
41
+ let(:wfapp_result) { file_to_array( wfapp_output ) }
42
+ let(:wf_ref_file) { file_to_array( wfrules_reference ) }
43
+ let(:wfapp_ref_file) { file_to_array( wfapp_reference ) }
44
+
45
+ it "contain rules" do
46
+ parser.parse wfsrc_log, outdir
47
+
48
+ wfrules_result.should include 'CURRENT LOAN STAGE'
49
+ wfrules_result.should include '<Rule Name='
50
+ end
51
+
52
+ it "match reference output files" do
53
+ parser.parse wfsrc_log, outdir
54
+
55
+ wfrules_result.should eq wf_ref_file
56
+ wfapp_result.should eq wfapp_ref_file
57
+ end
58
+ end
59
+
60
+ describe "parsed product decisions" do
61
+
62
+ let(:src_log) { 'spec/data/prod.decision.txt' }
63
+
64
+ let(:log_output) { outdir+'/prod.decision.txt' }
65
+ let(:app_output) { outdir+'/002-APP.xml' }
66
+ let(:rules_output) { outdir+'/002-FAPIILoanModification-PRODUCT.xml' }
67
+
68
+ # Reference files
69
+ let(:app_reference) { 'spec/data/reference/product/002-APP.xml' }
70
+ let(:rules_reference) { 'spec/data/reference/product/002-FAPIILoanModification-PRODUCT.xml' }
71
+
72
+ let(:app_result) { file_to_array( app_output ) }
73
+ let(:rules_result) { file_to_array( rules_output ) }
74
+ let(:app_ref_file) { file_to_array( app_reference ) }
75
+ let(:rules_ref_file) { file_to_array( rules_reference ) }
76
+
77
+ it "contain rules" do
78
+ parser.parse src_log, outdir
79
+
80
+ app_result.should include '<DECISION_REQUEST>'
81
+ rules_result.should include '<Rule Name='
82
+ end
83
+
84
+ it "match reference output files" do
85
+ parser.parse src_log, outdir
86
+
87
+ app_result.should eq app_ref_file
88
+ rules_result.should eq rules_ref_file
89
+ end
90
+
91
+ end
92
+
93
+ describe "parsed validation decisions" do
94
+
95
+ let(:src_log) { 'spec/data/prod.decision.txt' }
96
+
97
+ let(:log_output) { outdir+'/prod.decision.txt' }
98
+ let(:app_output) { outdir+'/001-APP.xml' }
99
+ let(:rules_output) { outdir+'/001-Validation-Rules.xml' }
100
+
101
+ # Reference files
102
+ let(:app_reference) { 'spec/data/reference/product/001-APP.xml' }
103
+ let(:rules_reference) { 'spec/data/reference/product/001-Validation-Rules.xml' }
104
+
105
+ let(:app_result) { file_to_array( app_output ) }
106
+ let(:rules_result) { file_to_array( rules_output ) }
107
+ let(:app_ref_file) { file_to_array( app_reference ) }
108
+ let(:rules_ref_file) { file_to_array( rules_reference ) }
109
+
110
+ it "contain rules" do
111
+ parser.parse src_log, outdir
112
+
113
+ app_result.should include '<DECISION_REQUEST>'
114
+ rules_result.should include '<Rule Name='
115
+ end
116
+
117
+ it "match reference output files" do
118
+ parser.parse src_log, outdir
119
+
120
+ app_result.should eq app_ref_file
121
+ rules_result.should eq rules_ref_file
122
+ end
123
+
124
+ end
125
+
126
+ describe "parsed validation decisions with discard data" do
127
+
128
+ let(:src_log) { 'spec/data/validation.decision.txt' }
129
+
130
+ let(:log_output) { outdir+'/validation.decision.txt' }
131
+ let(:app_output) { outdir+'/001-APP.xml' }
132
+ let(:rules_output) { outdir+'/001-Validation-Rules.xml' }
133
+
134
+ # Reference files
135
+ let(:app_reference) { 'spec/data/reference/validation/001-APP.xml' }
136
+ let(:rules_reference) { 'spec/data/reference/validation/001-Validation-Rules.xml' }
137
+
138
+ let(:app_result) { file_to_array( app_output ) }
139
+ let(:rules_result) { file_to_array( rules_output ) }
140
+ let(:app_ref_file) { file_to_array( app_reference ) }
141
+ let(:rules_ref_file) { file_to_array( rules_reference ) }
142
+
143
+ it "contain request XML" do
144
+ parser.parse src_log, outdir
145
+
146
+ app_result.should include '<DECISION_REQUEST>'
147
+ end
148
+
149
+ it "contain Decision open tag element" do
150
+ parser.parse src_log, outdir
151
+
152
+ rules_result.should include '<Decision GuidelineId="39"'
153
+ end
154
+
155
+ it "contain Rules open tag" do
156
+ parser.parse src_log, outdir
157
+
158
+ rules_result.should include '<Rules>'
159
+ end
160
+
161
+ it "contain at least one rule tag" do
162
+ parser.parse src_log, outdir
163
+
164
+ app_result.should include '<DECISION_REQUEST>'
165
+ rules_result.should include '<Decision GuidelineId="39"'
166
+ rules_result.should include '<Rules>'
167
+ rules_result.should include '<Rule Name='
168
+ end
169
+
170
+ it "match reference output files" do
171
+ parser.parse src_log, outdir
172
+
173
+ app_result.should eq app_ref_file
174
+ rules_result.should eq rules_ref_file
175
+ end
176
+
177
+ end
178
+
179
+ describe "parsed workflow2 decisions" do
180
+
181
+ let(:src_log) { 'spec/data/wf2.decision.txt' }
182
+
183
+ let(:log_output) { outdir+'/wf2.decision.txt' }
184
+ let(:app_output) { outdir+'/001-APP.xml' }
185
+ let(:rules_output) { outdir+'/001-WF-ProdSel-Post-Rules.xml' }
186
+
187
+ # Reference files
188
+ let(:app_reference) { 'spec/data/reference/workflow-2/001-APP.xml' }
189
+ let(:rules_reference) { 'spec/data/reference/workflow-2/001-WF-ProdSel-Post-Rules.xml' }
190
+
191
+ let(:app_result) { file_to_array( app_output ) }
192
+ let(:rules_result) { file_to_array( rules_output ) }
193
+ let(:app_ref_file) { file_to_array( app_reference ) }
194
+ let(:rules_ref_file) { file_to_array( rules_reference ) }
195
+
196
+ it "contain rules" do
197
+ parser.parse src_log, outdir
198
+
199
+ app_result.should include '<DECISION_REQUEST>'
200
+ rules_result.should include '<Rule Name='
201
+ end
202
+
203
+ it "match reference output files" do
204
+ parser.parse src_log, outdir
205
+
206
+ app_result.should eq app_ref_file
207
+ rules_result.should eq rules_ref_file
208
+ end
209
+
210
+ end
211
+
212
+ describe "parsed multi-product decisions" do
213
+
214
+ let(:src_log) { 'spec/data/multiproduct.decision.txt' }
215
+
216
+ let(:app_output) { outdir+'/001-APP.xml' }
217
+ let(:rules_output1) { outdir+'/001-Mod-Forbear-PRODUCT.xml' }
218
+ let(:rules_output2) { outdir+'/001-Mod-Forgive-PRODUCT.xml' }
219
+ let(:rules_output3) { outdir+'/001-Mod-RateTerm-PRODUCT.xml' }
220
+ let(:rules_output4) { outdir+'/001-Mod-SAM-PRODUCT.xml' }
221
+ let(:log_output) { outdir+'/multiproduct.decision.txt' }
222
+
223
+ # Reference files
224
+ let(:app_reference) { 'spec/data/reference/multiproduct/001-APP.xml' }
225
+ let(:rules_reference1) { 'spec/data/reference/multiproduct/001-Mod-Forbear-PRODUCT.xml' }
226
+ let(:rules_reference2) { 'spec/data/reference/multiproduct/001-Mod-Forgive-PRODUCT.xml' }
227
+ let(:rules_reference3) { 'spec/data/reference/multiproduct/001-Mod-RateTerm-PRODUCT.xml' }
228
+ let(:rules_reference4) { 'spec/data/reference/multiproduct/001-Mod-SAM-PRODUCT.xml' }
229
+
230
+ let(:app_result) { file_to_array( app_output ) }
231
+ let(:rules_result1) { file_to_array( rules_output1 ) }
232
+ let(:rules_result2) { file_to_array( rules_output2 ) }
233
+ let(:rules_result3) { file_to_array( rules_output3 ) }
234
+ let(:rules_result4) { file_to_array( rules_output4 ) }
235
+ let(:app_ref_file) { file_to_array( app_reference ) }
236
+ let(:rules_ref_file1) { file_to_array( rules_reference1 ) }
237
+ let(:rules_ref_file2) { file_to_array( rules_reference2 ) }
238
+ let(:rules_ref_file3) { file_to_array( rules_reference3 ) }
239
+ let(:rules_ref_file4) { file_to_array( rules_reference4 ) }
240
+
241
+ it "contain rules" do
242
+ parser.parse src_log, outdir
243
+
244
+ app_result.should include '<DECISION_REQUEST>'
245
+ rules_result1.should include '<Rule Name='
246
+ rules_result2.should include '<Rule Name='
247
+ rules_result3.should include '<Rule Name='
248
+ rules_result4.should include '<Rule Name='
249
+ end
250
+
251
+ it "match reference output files" do
252
+ parser.parse src_log, outdir
253
+
254
+ app_result.should eq app_ref_file
255
+ rules_result1.should eq rules_ref_file1
256
+ rules_result2.should eq rules_ref_file2
257
+ rules_result3.should eq rules_ref_file3
258
+ rules_result4.should eq rules_ref_file4
259
+ end
260
+
261
+ end
262
+
263
+ describe "parsed web decisions" do
264
+
265
+ let(:src_log) { 'spec/data/web.decision.txt' }
266
+
267
+ let(:app_output1) { outdir+'/001-APP.xml' }
268
+ let(:app_output2) { outdir+'/002-APP.xml' }
269
+ let(:rules_output1) { outdir+'/001-Product01-PRODUCT.xml' }
270
+ let(:rules_output2) { outdir+'/002-Product01-PRODUCT.xml' }
271
+ let(:log_output) { outdir+'/web.decision.txt' }
272
+
273
+ # Reference files
274
+ let(:app_reference1) { 'spec/data/reference/web/001-APP.xml' }
275
+ let(:app_reference2) { 'spec/data/reference/web/002-APP.xml' }
276
+ let(:rules_reference1) { 'spec/data/reference/web/001-Product01-PRODUCT.xml' }
277
+ let(:rules_reference2) { 'spec/data/reference/web/002-Product01-PRODUCT.xml' }
278
+
279
+ let(:app_result1) { file_to_array( app_output1 ) }
280
+ let(:app_result2) { file_to_array( app_output2 ) }
281
+ let(:rules_result1) { file_to_array( rules_output1 ) }
282
+ let(:rules_result2) { file_to_array( rules_output2 ) }
283
+ let(:app_ref_file1) { file_to_array( app_reference1 ) }
284
+ let(:app_ref_file2) { file_to_array( app_reference2 ) }
285
+ let(:rules_ref_file1) { file_to_array( rules_reference1 ) }
286
+ let(:rules_ref_file2) { file_to_array( rules_reference2 ) }
287
+
288
+ it "contain rules" do
289
+ parser.parse src_log, outdir
290
+
291
+ app_result1.should include '<DECISION_REQUEST>'
292
+ app_result2.should include '<DECISION_REQUEST>'
293
+ rules_result1.should include '<Rule Name='
294
+ rules_result2.should include '<Rule Name='
295
+ end
296
+
297
+ it "match reference output files" do
298
+ parser.parse src_log, outdir
299
+
300
+ app_result1.should eq app_ref_file1
301
+ app_result2.should eq app_ref_file2
302
+ rules_result1.should eq rules_ref_file1
303
+ rules_result2.should eq rules_ref_file2
304
+ end
305
+
306
+ end
307
+
308
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+
3
+ describe "Plugin::Application" do
4
+
5
+ def a_context
6
+ ctx = ParseDecision::PDContext.new
7
+ ctx.outdir = 'tmp/spec'
8
+ ctx
9
+ end
10
+
11
+ context "when #execute is called" do
12
+
13
+ Given (:context) { a_context }
14
+ Given (:plug) { ParseDecision::Plugin::Application.new }
15
+ Given (:line) { '<DECISION_REQUEST><APPLICATION Blah="bleh"/></DECISION_REQUEST>' }
16
+
17
+ context "with line containing '<APPLICATION '" do
18
+ When (:result) { plug.execute( context, line ) }
19
+
20
+ Then { result.should eq true }
21
+
22
+ context "and context state will change" do
23
+ Then { context.state.should eq :app }
24
+ end
25
+ end
26
+
27
+ Given(:another_line) { '<Guideline Name="Blargh" />' }
28
+
29
+ context "with line that does not contain '<APPLICATION '" do
30
+ When(:result) { plug.execute( context, another_line ) }
31
+
32
+ Then { result.should eq false }
33
+
34
+ context "and context state will not change" do
35
+ Then { context.state.should eq nil }
36
+ end
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,74 @@
1
+ require "spec_helper"
2
+
3
+ describe "Plugin::PpmXpath" do
4
+
5
+ def a_context( _state=nil )
6
+ ctx = ParseDecision::PDContext.new
7
+ ctx.outdir = 'tmp/spec'
8
+ ctx.state = _state
9
+ ctx
10
+ end
11
+
12
+ start_string = '*APP XPATH xml*'
13
+ end_string = '<PPXPATH>'
14
+
15
+ context "when #execute is called" do
16
+
17
+ Given (:context) { a_context }
18
+ Given (:plug) { ParseDecision::Plugin::PpmXpath.new }
19
+
20
+ context "with a current state of :app" do
21
+ Given (:context) { a_context( :app ) }
22
+
23
+ context "with line containing '#{start_string}'" do
24
+ Given (:line) { start_string }
25
+
26
+ When (:result) { plug.execute( context, line ) }
27
+
28
+ Then { result.should eq true }
29
+
30
+ context "and context state will change" do
31
+ Then { context.state.should eq :appPpmXpath }
32
+ end
33
+ end
34
+
35
+ context "any other lines are refused" do
36
+ Given (:line) { "anything other than start_string" }
37
+ Given! (:start_state) { context.state }
38
+
39
+ When (:result) { plug.execute( context, line ) }
40
+
41
+ Then { result.should eq false }
42
+
43
+ context "and context state will not change" do
44
+ Then { context.state.should eq start_state }
45
+ end
46
+ end
47
+ end
48
+
49
+ context "with a current state of :appPpmXpath" do
50
+ Given (:context) { a_context( :appPpmXpath ) }
51
+
52
+ context "accept any line without #{end_string}" do
53
+ Given (:line) { "anything" }
54
+
55
+ When (:result) { plug.execute( context, line ) }
56
+
57
+ Then { result.should eq true }
58
+ end
59
+
60
+ context "stop accepting lines after #{end_string} received" do
61
+ Given (:line) { end_string }
62
+
63
+ When (:result) { plug.execute( context, line ) }
64
+
65
+ Then { result.should eq true }
66
+
67
+ context "and context state will change to :app" do
68
+ Then { context.state.should eq :app }
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+
@@ -0,0 +1,81 @@
1
+ require "spec_helper"
2
+
3
+ def start_decision_element(name)
4
+ '<Decision GuidelineId="123" GuidelineName="'+name+'"'
5
+ end
6
+
7
+ describe "Plugin::PreDecisionGuideline" do
8
+
9
+ ppms_string = '<PARAMS><_DATA_SET'
10
+ gdl_string = '<Guideline '
11
+ end_string = '</Decision>'
12
+
13
+ context "when #execute is called" do
14
+
15
+ Given (:context) { create_context }
16
+ Given (:plug) { ParseDecision::Plugin::PreDecisionGuideline.new }
17
+
18
+ context "with a current state of :app" do
19
+ Given (:context) { create_context( :app ) }
20
+ Given! (:start_state) { context.state }
21
+
22
+ context "with line containing '#{ppms_string}'" do
23
+ Given (:line) { ppms_string }
24
+
25
+ When (:result) { plug.execute( context, line ) }
26
+
27
+ Then { result.should eq true }
28
+
29
+ context "and context state will not change" do
30
+ Then { context.state.should eq start_state }
31
+ end
32
+ end
33
+
34
+ context "with line containing '#{gdl_string}'" do
35
+ Given (:line) { "#{gdl_string}blahblahblah" }
36
+
37
+ When (:result) { plug.execute( context, line ) }
38
+
39
+ Then { result.should eq true }
40
+
41
+ context "and context state will change to :preDecisionGdl" do
42
+ Then { context.state.should eq :preDecisionGdl }
43
+ end
44
+ end
45
+ end
46
+
47
+ context "with a current state of :preDecisionGdl" do
48
+ Given (:context) { create_context( :preDecisionGdl ) }
49
+
50
+ context "accept any line" do
51
+ Given (:line) { "anything" }
52
+
53
+ When (:result) { plug.execute( context, line ) }
54
+
55
+ Then { result.should eq true }
56
+ end
57
+
58
+ context "creates filename from Decision element's GuidelineName attribute" do
59
+ Given (:line) { "#{start_decision_element('TestGdl')} blahblahblah" }
60
+
61
+ When (:result) { plug.execute( context, line ) }
62
+
63
+ Then { result.should eq true }
64
+ Then { plug.outfile.should eq "000-TestGdl-Rules.xml" }
65
+ end
66
+
67
+ context "stop accepting lines after #{end_string} received" do
68
+ Given (:line) { end_string }
69
+
70
+ When (:result) { plug.execute( context, line ) }
71
+
72
+ Then { result.should eq true }
73
+
74
+ context "and context state will change to :app" do
75
+ Then { context.state.should eq :app }
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+
@@ -0,0 +1,117 @@
1
+ require "spec_helper"
2
+
3
+ def start_product_element(name)
4
+ '<PRODUCTS><PRODUCT Name="'+name+'"'
5
+ end
6
+
7
+ describe "Plugin::Product" do
8
+
9
+ ppm_start_string = "<PARAMS><_DATA_SET"
10
+ rule_start_string = "<Rules>"
11
+ rule_end_string = "</Decision>"
12
+ end_string = '</Decision>'
13
+
14
+ context "when #execute is called" do
15
+
16
+ # Can't use #let here. We want the same plugin to be used so it's
17
+ # updated as we move through the flow.
18
+ plug = ParseDecision::Plugin::Product.new
19
+
20
+ context "with a current state of :app" do
21
+ # Can't use #let here. We want the same context to be used so it's
22
+ # updated as we move through the flow.
23
+ ctx = create_context( :app )
24
+
25
+ context "with line containing '#{start_product_element('Test')}'" do
26
+ let (:line) { start_product_element('Test') }
27
+
28
+ it "returns true and state should change to :productXml" do
29
+
30
+ result = plug.execute( ctx, line )
31
+
32
+ result.should eq true
33
+ ctx.state.should eq :productXml
34
+ end
35
+
36
+ context "with a current state of :productXml" do
37
+
38
+ context "with line containing '#{ppm_start_string}'" do
39
+ let (:line) { ppm_start_string }
40
+
41
+ it "returns true and state should change to :productPpms" do
42
+ result = plug.execute( ctx, line )
43
+
44
+ result.should eq true
45
+ ctx.state.should eq :productPpms
46
+ end
47
+
48
+ context "with a current state of :productPpms" do
49
+
50
+ context "with line containing '#{rule_start_string}'" do
51
+ let (:line) { rule_start_string }
52
+
53
+ it "returns true and state should change to :productRules" do
54
+ result = plug.execute( ctx, line )
55
+
56
+ result.should eq true
57
+ ctx.state.should eq :productRules
58
+ end
59
+
60
+ context "then plugin will accept all lines" do
61
+ let (:line) { "any old line" }
62
+
63
+ it "returns true and state should not change" do
64
+ result = plug.execute( ctx, line )
65
+
66
+ result.should eq true
67
+ ctx.state.should eq :productRules
68
+ end # it "returns true and state should not change"
69
+
70
+ context "until it receives '#{rule_end_string}'" do
71
+ let (:line) { rule_end_string }
72
+
73
+ it "returns true and state should change to :app" do
74
+ result = plug.execute( ctx, line )
75
+
76
+ result.should eq true
77
+ ctx.state.should eq :app
78
+ end # it "returns true and state should change to :app"
79
+ end # context "until it receives '#{rule_end_string}'"
80
+ end # context "then plugin will accept all lines"
81
+ end # context "with line containing '#{rule_start_string}'"
82
+ end # context "with a current state of :productPpms"
83
+ end # context "with line containing '#{ppm_start_string}'"
84
+ end # context "with a current state of :productXml"
85
+ end # context "with line containing '#{start_product_element('Test')}'"
86
+
87
+ context "with line containing anything else" do
88
+ ctx = create_context( :app )
89
+ let (:line) { "blahblahblah" }
90
+
91
+ it "should return false and not change state" do
92
+ result = plug.execute( ctx, line )
93
+
94
+ result.should eq false
95
+ ctx.state.should eq :app
96
+ end
97
+ end # context "with line containing anything else"
98
+ end # context "with a current state of :app"
99
+ end # context "when #execute is called"
100
+
101
+ =begin
102
+ context "with line containing '#{end_string}'" do
103
+ Given (:line) { "#{end_string}blahblahblah" }
104
+
105
+ When (:result) { plug.execute( ctx, line ) }
106
+
107
+ Then { result.should eq true }
108
+
109
+ context "and context state will change to :app" do
110
+ Then { ctx.state.should eq :app }
111
+ end
112
+ end
113
+ end
114
+ end
115
+ =end
116
+ end # describe "Plugin::Product"
117
+
@@ -0,0 +1,76 @@
1
+ require "spec_helper"
2
+
3
+ def start_decision_element(name)
4
+ '<Decision GuidelineId="123" GuidelineName="'+name+'"'
5
+ end
6
+
7
+ describe "Plugin::ProductXpath" do
8
+
9
+ start_string = '*PRODUCT XPATH xml*'
10
+ end_string = '<PPXPATH>'
11
+
12
+ context "when #execute is called" do
13
+
14
+ Given (:context) { create_context }
15
+ Given (:plug) { ParseDecision::Plugin::ProductXpath.new }
16
+
17
+ context "with a current state of :app" do
18
+ Given (:context) { create_context( :app ) }
19
+ Given! (:start_state) { context.state }
20
+
21
+ context "with line containing '#{start_string}'" do
22
+ Given (:line) { start_string }
23
+
24
+ When (:result) { plug.execute( context, line ) }
25
+
26
+ Then { result.should eq true }
27
+
28
+ context "and context state will change to :productXpath" do
29
+ Then { context.state.should eq :productXpath }
30
+ end
31
+ end
32
+
33
+ context "with line containing anything else" do
34
+ Given (:line) { "blahblahblah" }
35
+
36
+ When (:result) { plug.execute( context, line ) }
37
+
38
+ Then { result.should eq false }
39
+
40
+ context "and context state will not change" do
41
+ Then { context.state.should eq start_state }
42
+ end
43
+ end
44
+ end
45
+
46
+ context "with a current state of :productXpath" do
47
+ Given (:context) { create_context( :productXpath ) }
48
+ Given! (:start_state) { context.state }
49
+
50
+ context "accept any line" do
51
+ Given (:line) { "anything" }
52
+
53
+ When (:result) { plug.execute( context, line ) }
54
+
55
+ Then { result.should eq true }
56
+
57
+ context "and context state will not change" do
58
+ Then { context.state.should eq start_state }
59
+ end
60
+ end
61
+
62
+ context "with line containing '#{end_string}'" do
63
+ Given (:line) { "#{end_string}blahblahblah" }
64
+
65
+ When (:result) { plug.execute( context, line ) }
66
+
67
+ Then { result.should eq true }
68
+
69
+ context "and context state will change to :app" do
70
+ Then { context.state.should eq :app }
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+