spec/sync_states_spec.rb in rhoconnect-3.4.5 vs spec/sync_states_spec.rb in rhoconnect-4.0.0.beta.10
- old
+ new
@@ -2,47 +2,53 @@
describe "Sync Server States" do
it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => true do
before(:each) do
@s = Source.load(@s_fields[:name],@s_params)
- @cs = ClientSync.new(@s,@c,2)
+ @model = Rhoconnect::Model::Base.create(@s)
+ rhcud = lambda { @model.send(params[:operation].to_sym, params["#{params[:operation]}_object".to_sym]) }
+ @sscud = Rhoconnect::Handler::Changes::Runner.new(['create', 'update', 'delete'], @model, @c, rhcud, {})
+ rh = lambda { @model.query(params[:query]) }
+ @ssq = Rhoconnect::Handler::Query::Runner.new(@model, @c, rh, {})
end
describe "client creates objects" do
it "should create object and create link for client" do
@product1['link'] = 'temp1'
params = {'create'=>{'1'=>@product1}}
backend_data = {'backend_id'=>@product1}
- set_state(@cs.client.docname(:cd_size) => 0,
- @s.docname(:md_size) => 0)
+ set_doc_state(@sscud.client, :cd_size => 0)
+ set_doc_state(@s, :md_size => 0)
@s.read_state.refresh_time = Time.now.to_i + 3600
- @cs.receive_cud(params)
- verify_result(@c.docname(:create) => {},
- @c.docname(:cd_size) => "1",
- @s.docname(:md_size) => "1",
- @c.docname(:cd) => backend_data,
- @c.docname(:create_links) => {'1'=>{'l'=>'backend_id'}},
- @s.docname(:md) => backend_data)
+ @sscud.params = params
+ @sscud.run
+ verify_source_queue_data(@s, :create => [])
+ verify_doc_result(@c, {:cd_size => "1",
+ :cd => backend_data,
+ :create_links => {'1'=>{'l'=>'backend_id'}}})
+ verify_doc_result(@s, {:md_size => "1",
+ :md => backend_data})
end
it "should create object and send link to client" do
@product1['link'] = 'temp1'
params = {'create'=>{'1'=>@product1}}
backend_data = {'backend_id'=>@product1}
- set_state(@cs.client.docname(:cd_size) => 0,
- @s.docname(:md_size) => 0)
+ set_doc_state(@sscud.client, :cd_size => 0)
+ set_doc_state(@s, :md_size => 0)
@s.read_state.refresh_time = Time.now.to_i + 3600
- @cs.receive_cud(params)
- verify_result(@c.docname(:create) => {},
- @c.docname(:cd_size) => "1",
- @s.docname(:md_size) => "1",
- @c.docname(:cd) => backend_data,
- @c.docname(:create_links) => {'1'=>{'l'=>'backend_id'}},
- @s.docname(:md) => backend_data)
- res = @cs.send_cud
- res.should == [{'version'=>ClientSync::SYNC_VERSION},{"token"=>res[1]['token']},
+ @sscud.params = params
+ @sscud.run
+ verify_source_queue_data(@s, :create => [])
+ verify_doc_result(@c, {:cd_size => "1",
+ :cd => backend_data,
+ :create_links => {'1'=>{'l'=>'backend_id'}}})
+ verify_doc_result(@s, {:md_size => "1",
+ :md => backend_data})
+ res = @ssq.run
+ res.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>res[1]['token']},
{"count"=>0}, {"progress_count"=>0}, {"total_count"=>1},
{"links"=> {'1'=>{'l'=>'backend_id'}}}]
end
end
@@ -50,22 +56,23 @@
describe "client deletes objects" do
it "should delete object" do
params = {'delete'=>{'1'=>@product1}}
data = {'1'=>@product1,'2'=>@product2,'3'=>@product3}
expected = {'2'=>@product2,'3'=>@product3}
- set_state(@cs.client.docname(:cd) => data,
- @cs.client.docname(:cd_size) => data.size,
- @s.docname(:md) => data,
- @s.docname(:md_size) => data.size)
+ set_doc_state(@sscud.client, {:cd => data,
+ :cd_size => data.size})
+ set_doc_state(@s, {:md => data,
+ :md_size => data.size})
@s.read_state.refresh_time = Time.now.to_i + 3600
- @cs.receive_cud(params)
- verify_result(@cs.client.docname(:delete) => {},
- @cs.client.docname(:cd) => expected,
- @s.docname(:md) => expected,
- @cs.client.docname(:delete_page) => {},
- @cs.client.docname(:cd_size) => "2",
- @s.docname(:md_size) => "2",
- 'test_delete_storage' => {'1'=>@product1})
+ @sscud.params = params
+ @sscud.run
+ verify_source_queue_data(@s, :delete => [])
+ verify_doc_result(@sscud.client, {:cd => expected,
+ :delete_page => {},
+ :cd_size => "2"})
+ verify_doc_result(@s, {:md => expected,
+ :md_size => "2"})
+ verify_result('test_delete_storage' => {'1'=>@product1})
end
end
end
end
\ No newline at end of file