diff --git a/lib/trailblazer/workflow.rb b/lib/trailblazer/workflow.rb index fb20da1..8fb3ee6 100644 --- a/lib/trailblazer/workflow.rb +++ b/lib/trailblazer/workflow.rb @@ -6,7 +6,7 @@ module Workflow end end -require "trailblazer/workflow/generate" +require "trailblazer/workflow/parse" require "trailblazer/workflow/collaboration" require "trailblazer/workflow/collaboration/lane" require "trailblazer/workflow/collaboration/messages" diff --git a/lib/trailblazer/workflow/generate.rb b/lib/trailblazer/workflow/parse.rb similarity index 88% rename from lib/trailblazer/workflow/generate.rb rename to lib/trailblazer/workflow/parse.rb index f6801ce..df38ee6 100644 --- a/lib/trailblazer/workflow/generate.rb +++ b/lib/trailblazer/workflow/parse.rb @@ -5,7 +5,7 @@ module Trailblazer module Workflow # Computes a {Intermediate} data structures for every lane from a TRB PRO/editor .json file. - class Generate < Trailblazer::Activity::Railway + class Parse < Trailblazer::Activity::Railway Element = Struct.new(:id, :type, :data, :links, :label) Link = Struct.new(:target_id, :semantic) @@ -89,13 +89,13 @@ def self.compile_intermediate(ctx, lane:, start_event:, termini_map:, **) ctx[:value] = [lane.id, intermediate] end - step Generate.method(:transform_from_json), id: :transform_from_json + step Parse.method(:transform_from_json), id: :transform_from_json step Each(dataset_from: :lanes, item_key: :lane, collect: true) { - step Generate.method(:find_start_event), id: :find_start_event - fail Generate.method(:default_start_event), id: :default_start_event, + step Parse.method(:find_start_event), id: :find_start_event + fail Parse.method(:default_start_event), id: :default_start_event, Output(:success) => Track(:success) - step Generate.method(:compute_termini_map), id: :compute_termini_map - step Generate.method(:compile_intermediate), id: :compute_intermediate + step Parse.method(:compute_termini_map), id: :compute_termini_map + step Parse.method(:compile_intermediate), id: :compute_intermediate }, Out() => ->(ctx, collected_from_each:, **) { {intermediates: collected_from_each.to_h} } #{:collected_from_each => :intermediates} end end diff --git a/test/generate_test.rb b/test/generate_test.rb index b2bd514..97c89d7 100644 --- a/test/generate_test.rb +++ b/test/generate_test.rb @@ -60,674 +60,3 @@ module StateGuards ) end end - -class GenerateTest < Minitest::Spec - # UNIT TEST {Generate::Representer} - it "works with PRO's JSON format" do - # from ../pro-rails/test/fixtures/bpmn2/moderation.xml-exported.json - moderation_json = File.read("test/fixtures/v1/posting-v11.json") - - collaboration = Trailblazer::Workflow::Generate::Representer::Collaboration.new(OpenStruct.new).from_json(moderation_json) - - assert_equal collaboration.id, 18 - - lifecycle_lane = collaboration.lanes.find { |lane| lane.id == "⛾.lifecycle.posting" } - - assert_equal lifecycle_lane.id, "⛾.lifecycle.posting" - - # assert_equal lifecycle_lane.type "lane" - assert_equal lifecycle_lane.elements.size, 39 - - create = lifecycle_lane.elements[12] - assert_equal create.id, "Activity_0wwfenp" - assert_equal create.label, "Create" - assert_equal create.type, :task - assert_equal create.links.size, 2 - assert_equal create.links[0].target_id, "throw-after-Activity_0wwfenp" - assert_equal create.links[0].semantic, :success - assert_equal create.links[1].target_id, "Event_0odjl3c" - assert_equal create.links[1].semantic, :failure - assert_equal create.data, {} - - suspend = lifecycle_lane.elements[32] - assert_equal suspend.id, "suspend-Gateway_1wzosup" - assert_equal suspend.type, :suspend - assert_equal suspend.links.size, 0 - assert_equal suspend.data["resumes"], ["catch-before-Activity_0wr78cv", "catch-before-Activity_0q9p56e"] - end - - it do - moderation_json = File.read("test/fixtures/v1/posting-v11.json") - - signal, (ctx, _) = Trailblazer::Workflow::Generate.invoke([{json_document: moderation_json}, {}]) - - #@ test {:structure}, which is the directly parsed graph - assert_equal ctx[:structure].messages.size, 21 - - lanes = ctx[:intermediates] - - # TODO: test ui lane - # puts lanes["⛾.lifecycle.posting"].pretty_inspect - assert_equal lanes["⛾.lifecycle.posting"].pretty_inspect, %(#:throw_event, :label=>"invalid!"}>=> - [#], - #:throw_event, :label=>"invalid!"}>=> - [#], - #:terminus, :label=>"success"}>=>[], - #:throw_event, :label=>"invalid!"}>=> - [#], - #:task, :label=>"Update"}>=> - [#, - #], - #:task, :label=>"Notify approver"}>=> - [#], - #:task, :label=>"Approve"}>=> - [#], - #:task, :label=>"Publish"}>=> - [#], - #:task, :label=>"Archive"}>=> - [#], - #:task, :label=>"Delete"}>=> - [#], - #:task, :label=>"Revise"}>=> - [#, - #], - #:task, :label=>"Reject"}>=> - [#], - #:task, :label=>"Create"}>=> - [#, - #], - #true, :type=>:catch_event}>=> - [#], - #:throw_event}>=> - [#], - #:catch_event}>=> - [#], - #:throw_event}>=> - [#], - #:catch_event}>=> - [#], - #:throw_event}>=> - [#], - #:catch_event}>=> - [#], - #:throw_event}>=> - [#], - #:catch_event}>=> - [#], - #:throw_event}>=> - [#], - #:catch_event}>=> - [#], - #:throw_event}>=> - [#], - #:catch_event}>=> - [#], - #:throw_event}>=> - [#], - #:catch_event}>=> - [#], - #:throw_event}>=> - [#], - #:catch_event}>=> - [#], - #:throw_event}>=> - [#], - # - ["catch-before-Activity_0q9p56e", "catch-before-Activity_0wr78cv"], - :type=>:suspend}>=>[], - # - ["catch-before-Activity_0wr78cv", "catch-before-Activity_0q9p56e"], - :type=>:suspend}>=>[], - # - ["catch-before-Activity_0d9yewp", "catch-before-Activity_1qrkaz0"], - :type=>:suspend}>=>[], - # - ["catch-before-Activity_1bjelgv", - "catch-before-Activity_0cc4us9", - "catch-before-Activity_0q9p56e"], - :type=>:suspend}>=>[], - #["catch-before-Activity_18qv6ob"], :type=>:suspend}>=>[], - # - ["catch-before-Activity_18qv6ob", "catch-before-Activity_0wr78cv"], - :type=>:suspend}>=>[], - #["catch-before-Activity_0wwfenp"], :type=>:suspend}>=>[], - #["catch-before-Activity_1hgscu3"], :type=>:suspend}>=>[]}, - stop_task_ids= - {"Event_1p8873y"=>:Event_1p8873y, - "suspend-Gateway_0fnbg3r"=>:suspend, - "suspend-Gateway_1wzosup"=>:suspend, - "suspend-Gateway_0y3f8tz"=>:suspend, - "suspend-Gateway_1hp2ssj"=>:suspend, - "suspend-Gateway_01p7uj7"=>:suspend, - "suspend-Gateway_1kl7pnm"=>:suspend, - "suspend-gw-to-catch-before-Activity_0wwfenp"=>:suspend, - "suspend-gw-to-catch-before-Activity_1hgscu3"=>:suspend}, - start_task_id="catch-before-Activity_0wwfenp"> -) - - - assert_equal lanes["☝.UI.blogger"].pretty_inspect, %(#:catch_event, :label=>"accepted?"}>=> - [#], - #:catch_event, :label=>"valid?"}>=> - [#], - #:catch_event, :label=>"invalid?"}>=> - [#], - #:catch_event, :label=>"rejected?"}>=> - [#], - #:task, :label=>"Update form"}>=> - [#], - #:task, :label=>"Notify approver"}>=> - [#], - #:task, :label=>"Publish"}>=> - [#], - #:task, :label=>"Delete"}>=> - [#], - #:task, :label=>"Delete? form"}>=> - [#], - #:task, :label=>"Cancel"}>=> - [#], - #:task, :label=>"Revise"}>=> - [#], - #:task, :label=>"Revise form"}>=> - [#], - #:task, :label=>"Update"}>=> - [#], - #:catch_event, :label=>"valid?"}>=> - [#], - #:catch_event, :label=>"invalid?"}>=> - [#], - #:task, :label=>"Update form with errors"}>=> - [#], - #:task, :label=>"Revise form with errors"}>=> - [#], - #:task, :label=>"Archive"}>=> - [#], - #:catch_event}>=> - [#], - #:catch_event}>=> - [#], - #:catch_event}>=> - [#], - #:terminus, :label=>"success"}>=>[], - #:catch_event, :label=>"invalid?"}>=> - [#], - #:catch_event, :label=>"valid?"}>=> - [#], - #:task, :label=>"Create"}>=> - [#], - #:task, :label=>"Create form with errors"}>=> - [#], - #:catch_event}>=> - [#], - #:throw_event}>=> - [#], - #:catch_event}>=> - [#], - #:throw_event}>=> - [#], - #:catch_event}>=> - [#], - #:throw_event}>=> - [#], - #:catch_event}>=> - [#], - #:throw_event}>=> - [#], - #:catch_event}>=> - [#], - #:throw_event}>=> - [#], - #:catch_event}>=> - [#], - #:throw_event}>=> - [#], - #:catch_event}>=> - [#], - #:throw_event}>=> - [#], - #:catch_event}>=> - [#], - #:catch_event}>=> - [#], - #:catch_event}>=> - [#], - #:catch_event}>=> - [#], - #:task, :label=>"Create form"}>=> - [#], - #true, :type=>:catch_event}>=> - [#], - #["catch-before-Activity_1165bw9"], :type=>:suspend}>=>[], - #["catch-before-Activity_0j78uzd"], :type=>:suspend}>=>[], - #["Event_1npw1tg", "Event_1vb197y"], :type=>:suspend}>=>[], - # - ["catch-before-Activity_1165bw9", - "catch-before-Activity_0ha7224", - "catch-before-Activity_0bsjggk"], - :type=>:suspend}>=>[], - #["Event_1bz3ivj", "Event_1wly6jj"], :type=>:suspend}>=>[], - #["catch-before-Activity_1wiumzv"], :type=>:suspend}>=>[], - # - ["catch-before-Activity_15nnysv", "catch-before-Activity_1uhozy1"], - :type=>:suspend}>=>[], - #["Event_1vf88fn", "Event_1nt0djb"], :type=>:suspend}>=>[], - # - ["catch-before-Activity_1165bw9", "catch-before-Activity_1dt5di5"], - :type=>:suspend}>=>[], - #["catch-before-Activity_1psp91r"], :type=>:suspend}>=>[], - #["Event_0km79t5", "Event_0co8ygx"], :type=>:suspend}>=>[], - # - ["catch-before-Activity_1165bw9", "catch-before-Activity_1dt5di5"], - :type=>:suspend}>=>[], - # - ["catch-before-Activity_0zsock2", "catch-before-Activity_1dt5di5"], - :type=>:suspend}>=>[], - #["Event_1vrfxsv"], :type=>:suspend}>=>[], - #["Event_0j1jua6"], :type=>:suspend}>=>[], - #["Event_19ha0ea"], :type=>:suspend}>=>[], - #["catch-before-Activity_0fy41qq"], :type=>:suspend}>=>[], - #["catch-before-Activity_0zsock2"], :type=>:suspend}>=>[], - #["catch-before-Activity_0wc2mcq"], :type=>:suspend}>=>[]}, - stop_task_ids= - {"Event_0h6yhq6"=>:Event_0h6yhq6, - "suspend-Gateway_01cn7zv"=>:suspend, - "suspend-Gateway_0nxerxv"=>:suspend, - "suspend-Gateway_063k28q"=>:suspend, - "suspend-Gateway_1sq41iq"=>:suspend, - "suspend-Gateway_1sch8el"=>:suspend, - "suspend-Gateway_1xs96ik"=>:suspend, - "suspend-Gateway_100g9dn"=>:suspend, - "suspend-Gateway_1runwh1"=>:suspend, - "suspend-Gateway_1g3fhu2"=>:suspend, - "suspend-Gateway_14h0q7a"=>:suspend, - "suspend-Gateway_1d05yki"=>:suspend, - "suspend-Gateway_0kknfje"=>:suspend, - "suspend-Gateway_1xnsssa"=>:suspend, - "suspend-gw-to-Event_1vrfxsv"=>:suspend, - "suspend-gw-to-Event_0j1jua6"=>:suspend, - "suspend-gw-to-Event_19ha0ea"=>:suspend, - "suspend-gw-to-catch-before-Activity_0fy41qq"=>:suspend, - "suspend-gw-to-catch-before-Activity_0zsock2"=>:suspend, - "suspend-gw-to-catch-before-Activity_0wc2mcq"=>:suspend}, - start_task_id="catch-before-Activity_0wc2mcq"> -) - end -end diff --git a/test/parse_test.rb b/test/parse_test.rb new file mode 100644 index 0000000..737ecae --- /dev/null +++ b/test/parse_test.rb @@ -0,0 +1,672 @@ +require "test_helper" + +class ParseTest < Minitest::Spec + # UNIT TEST {Parse::Representer} + it "works with PRO's JSON format" do + # from ../pro-rails/test/fixtures/bpmn2/moderation.xml-exported.json + moderation_json = File.read("test/fixtures/v1/posting-v11.json") + + collaboration = Trailblazer::Workflow::Parse::Representer::Collaboration.new(OpenStruct.new).from_json(moderation_json) + + assert_equal collaboration.id, 18 + + lifecycle_lane = collaboration.lanes.find { |lane| lane.id == "⛾.lifecycle.posting" } + + assert_equal lifecycle_lane.id, "⛾.lifecycle.posting" + + # assert_equal lifecycle_lane.type "lane" + assert_equal lifecycle_lane.elements.size, 39 + + create = lifecycle_lane.elements[12] + assert_equal create.id, "Activity_0wwfenp" + assert_equal create.label, "Create" + assert_equal create.type, :task + assert_equal create.links.size, 2 + assert_equal create.links[0].target_id, "throw-after-Activity_0wwfenp" + assert_equal create.links[0].semantic, :success + assert_equal create.links[1].target_id, "Event_0odjl3c" + assert_equal create.links[1].semantic, :failure + assert_equal create.data, {} + + suspend = lifecycle_lane.elements[32] + assert_equal suspend.id, "suspend-Gateway_1wzosup" + assert_equal suspend.type, :suspend + assert_equal suspend.links.size, 0 + assert_equal suspend.data["resumes"], ["catch-before-Activity_0wr78cv", "catch-before-Activity_0q9p56e"] + end + + it do + moderation_json = File.read("test/fixtures/v1/posting-v11.json") + + signal, (ctx, _) = Trailblazer::Workflow::Parse.invoke([{json_document: moderation_json}, {}]) + + #@ test {:structure}, which is the directly parsed graph + assert_equal ctx[:structure].messages.size, 21 + + lanes = ctx[:intermediates] + + # TODO: test ui lane + # puts lanes["⛾.lifecycle.posting"].pretty_inspect + assert_equal lanes["⛾.lifecycle.posting"].pretty_inspect, %(#:throw_event, :label=>"invalid!"}>=> + [#], + #:throw_event, :label=>"invalid!"}>=> + [#], + #:terminus, :label=>"success"}>=>[], + #:throw_event, :label=>"invalid!"}>=> + [#], + #:task, :label=>"Update"}>=> + [#, + #], + #:task, :label=>"Notify approver"}>=> + [#], + #:task, :label=>"Approve"}>=> + [#], + #:task, :label=>"Publish"}>=> + [#], + #:task, :label=>"Archive"}>=> + [#], + #:task, :label=>"Delete"}>=> + [#], + #:task, :label=>"Revise"}>=> + [#, + #], + #:task, :label=>"Reject"}>=> + [#], + #:task, :label=>"Create"}>=> + [#, + #], + #true, :type=>:catch_event}>=> + [#], + #:throw_event}>=> + [#], + #:catch_event}>=> + [#], + #:throw_event}>=> + [#], + #:catch_event}>=> + [#], + #:throw_event}>=> + [#], + #:catch_event}>=> + [#], + #:throw_event}>=> + [#], + #:catch_event}>=> + [#], + #:throw_event}>=> + [#], + #:catch_event}>=> + [#], + #:throw_event}>=> + [#], + #:catch_event}>=> + [#], + #:throw_event}>=> + [#], + #:catch_event}>=> + [#], + #:throw_event}>=> + [#], + #:catch_event}>=> + [#], + #:throw_event}>=> + [#], + # + ["catch-before-Activity_0q9p56e", "catch-before-Activity_0wr78cv"], + :type=>:suspend}>=>[], + # + ["catch-before-Activity_0wr78cv", "catch-before-Activity_0q9p56e"], + :type=>:suspend}>=>[], + # + ["catch-before-Activity_0d9yewp", "catch-before-Activity_1qrkaz0"], + :type=>:suspend}>=>[], + # + ["catch-before-Activity_1bjelgv", + "catch-before-Activity_0cc4us9", + "catch-before-Activity_0q9p56e"], + :type=>:suspend}>=>[], + #["catch-before-Activity_18qv6ob"], :type=>:suspend}>=>[], + # + ["catch-before-Activity_18qv6ob", "catch-before-Activity_0wr78cv"], + :type=>:suspend}>=>[], + #["catch-before-Activity_0wwfenp"], :type=>:suspend}>=>[], + #["catch-before-Activity_1hgscu3"], :type=>:suspend}>=>[]}, + stop_task_ids= + {"Event_1p8873y"=>:Event_1p8873y, + "suspend-Gateway_0fnbg3r"=>:suspend, + "suspend-Gateway_1wzosup"=>:suspend, + "suspend-Gateway_0y3f8tz"=>:suspend, + "suspend-Gateway_1hp2ssj"=>:suspend, + "suspend-Gateway_01p7uj7"=>:suspend, + "suspend-Gateway_1kl7pnm"=>:suspend, + "suspend-gw-to-catch-before-Activity_0wwfenp"=>:suspend, + "suspend-gw-to-catch-before-Activity_1hgscu3"=>:suspend}, + start_task_id="catch-before-Activity_0wwfenp"> +) + + + assert_equal lanes["☝.UI.blogger"].pretty_inspect, %(#:catch_event, :label=>"accepted?"}>=> + [#], + #:catch_event, :label=>"valid?"}>=> + [#], + #:catch_event, :label=>"invalid?"}>=> + [#], + #:catch_event, :label=>"rejected?"}>=> + [#], + #:task, :label=>"Update form"}>=> + [#], + #:task, :label=>"Notify approver"}>=> + [#], + #:task, :label=>"Publish"}>=> + [#], + #:task, :label=>"Delete"}>=> + [#], + #:task, :label=>"Delete? form"}>=> + [#], + #:task, :label=>"Cancel"}>=> + [#], + #:task, :label=>"Revise"}>=> + [#], + #:task, :label=>"Revise form"}>=> + [#], + #:task, :label=>"Update"}>=> + [#], + #:catch_event, :label=>"valid?"}>=> + [#], + #:catch_event, :label=>"invalid?"}>=> + [#], + #:task, :label=>"Update form with errors"}>=> + [#], + #:task, :label=>"Revise form with errors"}>=> + [#], + #:task, :label=>"Archive"}>=> + [#], + #:catch_event}>=> + [#], + #:catch_event}>=> + [#], + #:catch_event}>=> + [#], + #:terminus, :label=>"success"}>=>[], + #:catch_event, :label=>"invalid?"}>=> + [#], + #:catch_event, :label=>"valid?"}>=> + [#], + #:task, :label=>"Create"}>=> + [#], + #:task, :label=>"Create form with errors"}>=> + [#], + #:catch_event}>=> + [#], + #:throw_event}>=> + [#], + #:catch_event}>=> + [#], + #:throw_event}>=> + [#], + #:catch_event}>=> + [#], + #:throw_event}>=> + [#], + #:catch_event}>=> + [#], + #:throw_event}>=> + [#], + #:catch_event}>=> + [#], + #:throw_event}>=> + [#], + #:catch_event}>=> + [#], + #:throw_event}>=> + [#], + #:catch_event}>=> + [#], + #:throw_event}>=> + [#], + #:catch_event}>=> + [#], + #:catch_event}>=> + [#], + #:catch_event}>=> + [#], + #:catch_event}>=> + [#], + #:task, :label=>"Create form"}>=> + [#], + #true, :type=>:catch_event}>=> + [#], + #["catch-before-Activity_1165bw9"], :type=>:suspend}>=>[], + #["catch-before-Activity_0j78uzd"], :type=>:suspend}>=>[], + #["Event_1npw1tg", "Event_1vb197y"], :type=>:suspend}>=>[], + # + ["catch-before-Activity_1165bw9", + "catch-before-Activity_0ha7224", + "catch-before-Activity_0bsjggk"], + :type=>:suspend}>=>[], + #["Event_1bz3ivj", "Event_1wly6jj"], :type=>:suspend}>=>[], + #["catch-before-Activity_1wiumzv"], :type=>:suspend}>=>[], + # + ["catch-before-Activity_15nnysv", "catch-before-Activity_1uhozy1"], + :type=>:suspend}>=>[], + #["Event_1vf88fn", "Event_1nt0djb"], :type=>:suspend}>=>[], + # + ["catch-before-Activity_1165bw9", "catch-before-Activity_1dt5di5"], + :type=>:suspend}>=>[], + #["catch-before-Activity_1psp91r"], :type=>:suspend}>=>[], + #["Event_0km79t5", "Event_0co8ygx"], :type=>:suspend}>=>[], + # + ["catch-before-Activity_1165bw9", "catch-before-Activity_1dt5di5"], + :type=>:suspend}>=>[], + # + ["catch-before-Activity_0zsock2", "catch-before-Activity_1dt5di5"], + :type=>:suspend}>=>[], + #["Event_1vrfxsv"], :type=>:suspend}>=>[], + #["Event_0j1jua6"], :type=>:suspend}>=>[], + #["Event_19ha0ea"], :type=>:suspend}>=>[], + #["catch-before-Activity_0fy41qq"], :type=>:suspend}>=>[], + #["catch-before-Activity_0zsock2"], :type=>:suspend}>=>[], + #["catch-before-Activity_0wc2mcq"], :type=>:suspend}>=>[]}, + stop_task_ids= + {"Event_0h6yhq6"=>:Event_0h6yhq6, + "suspend-Gateway_01cn7zv"=>:suspend, + "suspend-Gateway_0nxerxv"=>:suspend, + "suspend-Gateway_063k28q"=>:suspend, + "suspend-Gateway_1sq41iq"=>:suspend, + "suspend-Gateway_1sch8el"=>:suspend, + "suspend-Gateway_1xs96ik"=>:suspend, + "suspend-Gateway_100g9dn"=>:suspend, + "suspend-Gateway_1runwh1"=>:suspend, + "suspend-Gateway_1g3fhu2"=>:suspend, + "suspend-Gateway_14h0q7a"=>:suspend, + "suspend-Gateway_1d05yki"=>:suspend, + "suspend-Gateway_0kknfje"=>:suspend, + "suspend-Gateway_1xnsssa"=>:suspend, + "suspend-gw-to-Event_1vrfxsv"=>:suspend, + "suspend-gw-to-Event_0j1jua6"=>:suspend, + "suspend-gw-to-Event_19ha0ea"=>:suspend, + "suspend-gw-to-catch-before-Activity_0fy41qq"=>:suspend, + "suspend-gw-to-catch-before-Activity_0zsock2"=>:suspend, + "suspend-gw-to-catch-before-Activity_0wc2mcq"=>:suspend}, + start_task_id="catch-before-Activity_0wc2mcq"> +) + end +end