Commit d4f2df646bd0ab1fe7b42780692429c44428e0ca
Committed by
João M. M. da Silva
1 parent
d8b981b8
Exists in
master
and in
29 other branches
[Mezuro] Completed project model, fixtures and tests refactoring.
Showing
3 changed files
with
58 additions
and
56 deletions
Show diff stats
plugins/mezuro/lib/kalibro/project.rb
1 | class Kalibro::Project < Kalibro::Model | 1 | class Kalibro::Project < Kalibro::Model |
2 | 2 | ||
3 | - attr_accessor :name, :license, :description, :repository, :configuration_name, :state, :kalibro_error | 3 | + attr_accessor :id, :name, :description |
4 | 4 | ||
5 | - def self.all_names | ||
6 | - response = request("Project", :get_project_names)[:project_name] | 5 | + def self.all |
6 | + response = request("Project", :all_projects)[:project].to_a | ||
7 | response = [] if response.nil? | 7 | response = [] if response.nil? |
8 | - response | 8 | + response.map {|project| new project} |
9 | end | 9 | end |
10 | 10 | ||
11 | - def self.find_by_name(project_name) | ||
12 | - new request("Project", :get_project, :project_name => project_name)[:project] | 11 | + def self.find(project_id) |
12 | + new request("Project", :get_project, :project_id => project_id)[:project] | ||
13 | end | 13 | end |
14 | 14 | ||
15 | - def repository=(value) | ||
16 | - @repository = Kalibro::Repository.to_object value | 15 | + def self.project_of(repository_id) |
16 | + new request("Project", :project_of, :repository_id => repository_id)[:project] | ||
17 | end | 17 | end |
18 | - | 18 | +=begin |
19 | def error=(value) | 19 | def error=(value) |
20 | @kalibro_error = Kalibro::Error.to_object value | 20 | @kalibro_error = Kalibro::Error.to_object value |
21 | end | 21 | end |
@@ -47,5 +47,6 @@ class Kalibro::Project < Kalibro::Model | @@ -47,5 +47,6 @@ class Kalibro::Project < Kalibro::Model | ||
47 | add_error exception | 47 | add_error exception |
48 | end | 48 | end |
49 | end | 49 | end |
50 | +=end | ||
50 | 51 | ||
51 | end | 52 | end |
plugins/mezuro/test/fixtures/project_fixtures.rb
@@ -6,22 +6,15 @@ class ProjectFixtures | @@ -6,22 +6,15 @@ class ProjectFixtures | ||
6 | Kalibro::Project.new project_hash | 6 | Kalibro::Project.new project_hash |
7 | end | 7 | end |
8 | 8 | ||
9 | + def self.created_project | ||
10 | + Kalibro::Project.new :name => 'Qt-Calculator', :description => 'Calculator for Qt' | ||
11 | + end | ||
12 | + | ||
9 | def self.project_hash | 13 | def self.project_hash |
10 | { | 14 | { |
15 | + :id => 42, | ||
11 | :name => 'Qt-Calculator', | 16 | :name => 'Qt-Calculator', |
12 | - :license => 'GPL', | ||
13 | - :description => 'Calculator for Qt', | ||
14 | - :repository => RepositoryFixtures.repository_hash, | ||
15 | - :configuration_name => 'Kalibro for Java', | ||
16 | - :state => 'READY', | ||
17 | - :attributes! => | ||
18 | - { | ||
19 | - :repository=> | ||
20 | - { | ||
21 | - "xsi:type"=>"kalibro:repositoryXml", | ||
22 | - "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance" | ||
23 | - } | ||
24 | - } | 17 | + :description => 'Calculator for Qt' |
25 | } | 18 | } |
26 | end | 19 | end |
27 | 20 |
plugins/mezuro/test/unit/kalibro/project_test.rb
@@ -7,64 +7,71 @@ class ProjectTest < ActiveSupport::TestCase | @@ -7,64 +7,71 @@ class ProjectTest < ActiveSupport::TestCase | ||
7 | def setup | 7 | def setup |
8 | @hash = ProjectFixtures.project_hash | 8 | @hash = ProjectFixtures.project_hash |
9 | @project = ProjectFixtures.project | 9 | @project = ProjectFixtures.project |
10 | + @created_project = ProjectFixtures.created_project | ||
10 | @project_content = ProjectFixtures.project_content | 11 | @project_content = ProjectFixtures.project_content |
11 | end | 12 | end |
13 | + | ||
14 | + should 'initialize new project from hash' do | ||
15 | + project = Kalibro::Project.new @hash | ||
16 | + assert_equal @hash[:name], project.name | ||
17 | + end | ||
12 | 18 | ||
13 | - should 'get all project names' do | ||
14 | - response_hash = {:project_name => [@project.name]} | ||
15 | - Kalibro::Project.expects(:request).with("Project", :get_project_names).returns(response_hash) | ||
16 | - assert_equal response_hash[:project_name], Kalibro::Project.all_names | 19 | + should 'convert project to hash' do |
20 | + hash = @project.to_hash | ||
21 | + assert_equal @project.name, hash[:name] | ||
17 | end | 22 | end |
18 | 23 | ||
19 | - should 'return empty when there are no projects' do | ||
20 | - response_hash = {:project_name => nil} | ||
21 | - Kalibro::Project.expects(:request).with("Project", :get_project_names).returns(response_hash) | ||
22 | - assert_equal [], Kalibro::Project.all_names | 24 | + should 'answer if project exists in kalibro' do |
25 | + Kalibro::Project.expects(:request).with("Project", :project_exists, {:project_id => @project.id}).returns({:exists => true}) | ||
26 | + assert Kalibro::Project.exists?(@project.id) | ||
23 | end | 27 | end |
24 | 28 | ||
25 | - should 'find project by name' do | ||
26 | - request_body = {:project_name => @project.name} | ||
27 | - response_hash = {:project => @hash} | ||
28 | - Kalibro::Project.expects(:new).with(@hash).returns(@project) | ||
29 | - Kalibro::Project.expects(:request).with("Project", :get_project, request_body).returns(response_hash) | ||
30 | - assert_equal @project, Kalibro::Project.find_by_name(@project.name) | 29 | + should 'find project' do |
30 | + Kalibro::Project.expects(:request).with("Project", :get_project, {:project_id => @project.id}).returns(:project => @hash) | ||
31 | + assert_equal @hash[:name], Kalibro::Project.find(@project.id).name | ||
31 | end | 32 | end |
32 | 33 | ||
33 | should 'raise error when project doesnt exist' do | 34 | should 'raise error when project doesnt exist' do |
34 | - request_body = {:project_name => @project.name} | ||
35 | - Kalibro::Project.expects(:request).with("Project", :get_project, request_body).raises(Exception.new("(S:Server) There is no project named " + @project.name)) | ||
36 | - assert_raise Exception do Kalibro::Project.find_by_name(@project.name) end | 35 | + request_body = {:project_id => @project.id} |
36 | + Kalibro::Project.expects(:request).with("Project", :get_project, request_body).raises(Exception.new("(S:Server) There is no project with id #{@project.id}")) | ||
37 | + assert_raise Exception do Kalibro::Project.find(@project.id) end | ||
38 | + end | ||
39 | + | ||
40 | + should 'get project of a repository' do | ||
41 | + repository_id = 31 | ||
42 | + Kalibro::Project.expects(:request).with("Project", :project_of, {:repository_id => repository_id}).returns({:project => @hash}) | ||
43 | + assert_equal @hash[:name], Kalibro::Project.project_of(repository_id).name | ||
44 | + end | ||
45 | + | ||
46 | + should 'get all project' do | ||
47 | + Kalibro::Project.expects(:request).with("Project", :all_projects).returns({:project => [@hash]}) | ||
48 | + assert_equal @hash[:name], Kalibro::Project.all.first.name | ||
49 | + end | ||
50 | + | ||
51 | + should 'return empty when there are no projects' do | ||
52 | + Kalibro::Project.expects(:request).with("Project", :all_projects).returns({:project => nil}) | ||
53 | + assert_equal [], Kalibro::Project.all | ||
37 | end | 54 | end |
38 | 55 | ||
39 | should 'return true when project is saved successfully' do | 56 | should 'return true when project is saved successfully' do |
40 | - Kalibro::Project.expects(:request).with("Project", :save_project, {:project => @project.to_hash}) | ||
41 | - assert @project.save | 57 | + id_from_kalibro = 1 |
58 | + Kalibro::Project.expects(:request).with("Project", :save_project, {:project => @created_project.to_hash}).returns(id_from_kalibro) | ||
59 | + assert @created_project.save | ||
60 | + assert_equal id_from_kalibro, @created_project.id | ||
42 | end | 61 | end |
43 | 62 | ||
44 | should 'return false when project is not saved successfully' do | 63 | should 'return false when project is not saved successfully' do |
45 | Kalibro::Project.expects(:request).with("Project", :save_project, {:project => @project.to_hash}).raises(Exception.new) | 64 | Kalibro::Project.expects(:request).with("Project", :save_project, {:project => @project.to_hash}).raises(Exception.new) |
46 | assert !(@project.save) | 65 | assert !(@project.save) |
66 | + assert_nil @created_project.id | ||
47 | end | 67 | end |
48 | 68 | ||
49 | should 'remove existent project from service' do | 69 | should 'remove existent project from service' do |
50 | - Kalibro::Project.expects(:request).with("Project", :remove_project, {:project_name => @project.name}) | 70 | + Kalibro::Project.expects(:request).with("Project", :delete_project, {:project_id => @project.id}) |
51 | @project.destroy | 71 | @project.destroy |
52 | end | 72 | end |
53 | - | ||
54 | - should 'initialize new project from hash' do | ||
55 | - project = Kalibro::Project.new @hash | ||
56 | - assert_equal @project.name, project.name | ||
57 | - assert_equal @project.repository.type, project.repository.type | ||
58 | - end | ||
59 | 73 | ||
60 | - should 'convert project to hash' do | ||
61 | - hash = @project.to_hash | ||
62 | - assert_equal @hash[:name], hash[:name] | ||
63 | - assert_equal @hash[:configuration_name], hash[:configuration_name] | ||
64 | - assert_equal @hash[:repository], hash[:repository] | ||
65 | - assert_equal @hash[:state], hash[:state] | ||
66 | - end | ||
67 | - | 74 | +=begin |
68 | should 'process project without days' do | 75 | should 'process project without days' do |
69 | Kalibro::Project.expects(:request).with('Kalibro', :process_project, {:project_name => @project.name}) | 76 | Kalibro::Project.expects(:request).with('Kalibro', :process_project, {:project_name => @project.name}) |
70 | @project.process_project | 77 | @project.process_project |
@@ -84,5 +91,6 @@ class ProjectTest < ActiveSupport::TestCase | @@ -84,5 +91,6 @@ class ProjectTest < ActiveSupport::TestCase | ||
84 | Kalibro::Project.expects(:request).with("Kalibro", :cancel_periodic_process, {:project_name => @project.name}) | 91 | Kalibro::Project.expects(:request).with("Kalibro", :cancel_periodic_process, {:project_name => @project.name}) |
85 | @project.cancel_periodic_process | 92 | @project.cancel_periodic_process |
86 | end | 93 | end |
94 | +=end | ||
87 | 95 | ||
88 | end | 96 | end |