Commit d73c11af65ecb55cc7bdb96f0725b1198242e3a7

Authored by Paulo Meireles
1 parent 3be6de1e

[Mezuro] Refactoring and creating acceptance tests

features/step_definitions/mezuro_steps.rb 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +Then /^I directly delete content with name "([^\"]*)" for testing purposes$/ do |content_name|
  2 + Article.find_by_name(content_name).destroy
  3 +end
  4 +
  5 +Then /^I should be at the url "([^\"]*)"$/ do |url|
  6 + if response.class.to_s == 'Webrat::SeleniumResponse'
  7 + URI.parse(response.selenium.get_location).path.should == url
  8 + else
  9 + URI.parse(current_url).path.should == url
  10 + end
  11 +end
  12 +
  13 +Then /^I don't fill anything$/ do
  14 +end
... ...
plugins/mezuro/test/features/adding_metric_configuration.feature 0 → 100644
... ... @@ -0,0 +1,67 @@
  1 +Feature: Add metric configuration to a configuration
  2 + As a mezuro user
  3 + I want to add metric configurations to a Kalibro configuration
  4 +
  5 + Background:
  6 + Given the following users
  7 + | login | name |
  8 + | joaosilva | Joao Silva |
  9 + And I am logged in as "joaosilva"
  10 + And "Mezuro" plugin is enabled
  11 + And the following community
  12 + | identifier | name |
  13 + | mycommunity | My Community |
  14 + And "Joao Silva" is admin of "My Community"
  15 + And I am on My Community's cms
  16 + And I create a content of type "Kalibro configuration" with the following data
  17 + | Title | My Configuration |
  18 + | Description | A sample description |
  19 +
  20 + Scenario: adding a native metric configuration
  21 + When I follow "Add metric"
  22 + And I follow "Analizo"
  23 + And I follow "Lines of Code"
  24 + And I fill in the following:
  25 + | Code: | Sample Code |
  26 + | Weight: | 10.0 |
  27 + And I select "Average" from "Aggregation Form:"
  28 + And I press "Add"
  29 + Then I should see "Lines of Code"
  30 + And I should see "Analizo"
  31 + And I should see "Sample Code"
  32 +
  33 + Scenario: adding a native metric configuration without code
  34 + When I follow "Add metric"
  35 + And I follow "Analizo"
  36 + And I follow "Number of Children"
  37 + And I don't fill anything
  38 + And I press "Add"
  39 + Then I should be at the url "/myprofile/my-community/plugin/mezuro/new_metric_configuration"
  40 +
  41 + Scenario: adding a compound metric configuration
  42 + When I follow "Add metric"
  43 + And I follow "New Compound Metric"
  44 + And I fill in the following:
  45 + | Name: | Compound sample |
  46 + | Description: | 10.0 |
  47 + | Script: | return 42; |
  48 + | Code: | anyCode |
  49 + | Weight: | 10.0 |
  50 + And I select "Class" from "Scope:"
  51 + And I select "Average" from "Aggregation Form:"
  52 + And I press "Add"
  53 + Then I should see "Compound sample"
  54 +
  55 + Scenario: adding a compound metric configuration with invalid script
  56 + When I follow "Add metric"
  57 + And I follow "New Compound Metric"
  58 + And I fill in the following:
  59 + | Name: | Compound sample |
  60 + | Description: | 10.0 |
  61 + | Script: | invalid script |
  62 + | Code: | anyCode |
  63 + | Weight: | 10.0 |
  64 + And I select "Class" from "Scope:"
  65 + And I select "Average" from "Aggregation Form:"
  66 + And I press "Add"
  67 + Then I should see "Compound sample"
... ...
plugins/mezuro/test/features/adding_ranges.feature 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +Feature: Add range to a metric configuration
  2 + As a mezuro user
  3 + I want to add ranges to a Kalibro metric configuration
  4 +
  5 + Background:
  6 + Given the following users
  7 + | login | name |
  8 + | joaosilva | Joao Silva |
  9 + And I am logged in as "joaosilva"
  10 + And "Mezuro" plugin is enabled
  11 + And the following community
  12 + | identifier | name |
  13 + | mycommunity | My Community |
  14 + And "Joao Silva" is admin of "My Community"
  15 + And I am on My Community's cms
  16 + And I create a content of type "Kalibro configuration" with the following data
  17 + | Title | My Configuration |
  18 + | Description | A sample description |
  19 + And I follow "Add metric"
  20 + And I follow "Analizo"
  21 + And I follow "Lines of Code"
  22 + And I fill in the following:
  23 + | Code: | Sample Code |
  24 + | Weight: | 10.0 |
  25 + And I select "Average" from "Aggregation Form:"
  26 + And I press "Add"
  27 + Then I should see "Lines of Code"
  28 + And I should see "Analizo"
  29 + And I should see "Sample Code"
  30 +
  31 + Scenario: adding a range to a metric configuration
  32 + When I follow "New Range" and wait
  33 + And I fill in the following:
  34 + | (*) Label: | label |
  35 + | (*) Beginning: | 1 |
  36 + | (*) End: | 10 |
  37 + | (*) Grade: | 100 |
  38 + | (*) Color: | FFFF00FF |
  39 + | Comments: | Comentário |
  40 + And I press "Save Range" and wait
  41 + And I should see "label" within "#ranges"
  42 +
... ...
plugins/mezuro/test/features/creating_configuration.feature
1   -Feature: create configuration
  1 +Feature: Create configuration
2 2 As a mezuro user
3 3 I want to create a Kalibro configuration
4 4  
... ... @@ -23,17 +23,18 @@ Feature: create configuration
23 23 And I should see "Description"
24 24 And I should see "A sample description"
25 25  
26   - Scenario: creating without title
27   - Given I am on My Community's cms
28   - When I create a content of type "Kalibro configuration" with the following data
29   - | Title | |
30   - Then I should see "1 error prohibited this {{model}} from being saved"
31   -
32   - Scenario: creating with duplicated title
  26 + Scenario: creating with duplicated name
33 27 Given I am on My Community's cms
34 28 And I create a content of type "Kalibro configuration" with the following data
35 29 | Title | Original Title |
36 30 And I am on My Community's cms
37 31 When I create a content of type "Kalibro configuration" with the following data
38 32 | Title | Original Title |
39   - Then I should see "1 error prohibited this {{model}} from being saved"
  33 + Then I should see "1 error prohibited this article from being saved"
  34 +
  35 + Scenario: creating without title
  36 + Given I am on My Community's cms
  37 + When I create a content of type "Kalibro configuration" with the following data
  38 + | Title | |
  39 + Then I should see "1 error prohibited this article from being saved"
  40 +
... ...
plugins/mezuro/test/features/creating_project.feature 0 → 100644
... ... @@ -0,0 +1,55 @@
  1 +Feature: Create project
  2 + As a mezuro user
  3 + I want to create a Kalibro project
  4 +
  5 + Background:
  6 + Given the following users
  7 + | login | name |
  8 + | joaosilva | Joao Silva |
  9 + And I am logged in as "joaosilva"
  10 + And "Mezuro" plugin is enabled
  11 + And the following community
  12 + | identifier | name |
  13 + | mycommunity | My Community |
  14 + And "Joao Silva" is admin of "My Community"
  15 +
  16 + Scenario: I see Kalibro project's input form
  17 + Given I am on My Community's cms
  18 + When I follow "New content"
  19 + And I follow "Kalibro project"
  20 + Then I should see "Title"
  21 + And I should see "License"
  22 + And I should see "Repository type"
  23 + And I should see "GIT"
  24 + And I should see "REMOTE_ZIP"
  25 + And I should see "REMOTE_TARBALL"
  26 + And I should see "SUBVERSION"
  27 + And I should see "Repository url"
  28 + And I should see "Configuration"
  29 + And I should see "Kalibro for Java"
  30 +
  31 + Scenario: I create a Kalibro project with valid attributes
  32 + Given I am on My Community's cms
  33 + When I create a content of type "Kalibro project" with the following data
  34 + | Title | Sample Project |
  35 + | License | GPL |
  36 + | Repository type | SUBVERSION |
  37 + | Repository url | https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator |
  38 + | Configuration | Kalibro for Java |
  39 + Then I should see "Sample Project"
  40 + And I should see "GPL"
  41 + And I should see "SUBVERSION"
  42 + And I should see "https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator"
  43 + And I should see "Kalibro for Java"
  44 + And I directly delete content with name "Sample Project" for testing purposes
  45 +
  46 + Scenario: I can't create a Kalibro project with invalid attributes
  47 + Given I am on My Community's cms
  48 + When I create a content of type "Kalibro project" with the following data
  49 + | Title | |
  50 + | License | GPL |
  51 + | Repository type | SUBVERSION |
  52 + | Repository url | |
  53 + | Configuration | Kalibro for Java |
  54 + Then I should see "Title can't be blank"
  55 + And I should see "Missing repository url"
... ...
plugins/mezuro/test/features/echo_port_test.rb 0 → 100644
... ... @@ -0,0 +1,90 @@
  1 +require "test_helper"
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures"
  4 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures"
  5 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures"
  6 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures"
  7 +
  8 +class EchoPortTest < ActiveSupport::TestCase
  9 +
  10 + def setup
  11 + @port = Kalibro::Client::Port.new('Echo')
  12 + address = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/service.yaml")
  13 + address['KalibroService'] = 'KalibroFake'
  14 + @port.service_address=(address);
  15 + end
  16 +
  17 + should 'echo base tool' do
  18 + test BaseToolFixtures.analizo, 'BaseTool' do |base_tool|
  19 + base_tool.name = "echo " + base_tool.name
  20 + end
  21 + end
  22 +
  23 + should 'echo configuration' do
  24 + test ConfigurationFixtures.kalibro_configuration, 'Configuration' do |configuration|
  25 + configuration.name = "echo " + configuration.name
  26 + end
  27 + end
  28 +
  29 + should 'echo metric configuration' do
  30 + test_metric_configuration(MetricConfigurationFixtures.amloc_configuration)
  31 + test_metric_configuration(MetricConfigurationFixtures.sc_configuration)
  32 + end
  33 +
  34 + should 'echo module result' do
  35 + test ModuleResultFixtures.create, 'ModuleResult' do |module_result|
  36 + module_result.module.name = "echo." + module_result.module.name
  37 + end
  38 + end
  39 +
  40 + should 'echo project' do
  41 + test(ProjectFixtures.qt_calculator, 'Project') do |project|
  42 + project.name = "echo " + project.name
  43 + end
  44 + end
  45 +
  46 + should 'echo project result' do
  47 + test(ProjectResultFixtures.qt_calculator, 'ProjectResult') do |project_result|
  48 + project_result.project.name = "echo " + project_result.project.name
  49 + end
  50 + end
  51 +
  52 + should 'echo raw project' do
  53 + project = ProjectFixtures.qt_calculator
  54 + echoed = @port.request(:echo_raw_project, {:project => project.to_hash})[:project]
  55 + project.name = "echo " + project.name
  56 + project.state = nil
  57 + project.error = nil
  58 + assert_equal project, Kalibro::Entities::Project.from_hash(echoed)
  59 + end
  60 +
  61 + should 'work with enums' do
  62 + test_granularity("METHOD", "CLASS")
  63 + test_granularity("CLASS", "PACKAGE")
  64 + test_granularity("PACKAGE", "PACKAGE")
  65 + test_granularity("APPLICATION", "APPLICATION")
  66 + end
  67 +
  68 + private
  69 +
  70 + def test_metric_configuration(fixture)
  71 + test fixture, 'MetricConfiguration' do |metric_configuration|
  72 + metric_configuration.code = "echo_" + metric_configuration.code
  73 + end
  74 + end
  75 +
  76 + def test(fixture, entity_name)
  77 + entity_symbol = entity_name.underscore.to_sym
  78 + request_body = {entity_symbol => fixture.to_hash}
  79 + echoed = @port.request("echo_#{entity_symbol}".to_sym, request_body)[entity_symbol]
  80 + yield fixture
  81 + entity_class = "Kalibro::Entities::#{entity_name}".constantize
  82 + assert_equal fixture, entity_class.from_hash(echoed)
  83 + end
  84 +
  85 + def test_granularity(granularity, parent)
  86 + body = {:granularity => granularity}
  87 + assert_equal parent, @port.request(:infer_parent_granularity, body)[:parent_granularity]
  88 + end
  89 +
  90 +end
... ...
plugins/mezuro/test/features/editing_configuration.feature
... ... @@ -16,16 +16,34 @@ Feature: editing a configuration
16 16 And I create a content of type "Kalibro configuration" with the following data
17 17 | Title | My Configuration |
18 18 | Description | A sample description |
19   -
20   - Scenario: adding a metric configuration
21   - When I follow "Add metric"
  19 + And I follow "Add metric"
22 20 And I follow "Analizo"
23 21 And I follow "Lines of Code"
24 22 And I fill in the following:
25   - | Code: | Sample Code |
  23 + | Code: | SampleCode |
26 24 | Weight: | 10.0 |
27   - And I select "Average" from "Aggregation:"
  25 + And I select "Average" from "Aggregation Form:"
28 26 And I press "Add"
  27 + And I press "Save" and wait
  28 +
  29 + Scenario: Keep metrics after editing configuration
  30 + When I follow "Edit" within "article-actions" and wait
  31 + And I press "Save"
29 32 Then I should see "Lines of Code"
30   - And I should see "Analizo"
31   - And I should see "Sample Code"
  33 +
  34 + #FIXME: Create new step for this scenario
  35 + Scenario: Check if title is edit-disabled
  36 + When I follow "Edit" within "article-actions" and wait
  37 + And I fill in the following:
  38 + | Title | Some Title |
  39 + And I press "Save" and wait
  40 + Then I should not see "Some Title"
  41 +
  42 +
  43 + Scenario: Check if description is edit-enabled
  44 + When I follow "Edit" within "article-actions" and wait
  45 + And I fill in the following:
  46 + | Description | Some Description |
  47 + And I press "Save" and wait
  48 + Then I should see "Some Description"
  49 + And I should see "Lines of Code"
... ...
plugins/mezuro/test/features/mezuro.feature
... ... @@ -1,69 +0,0 @@
1   -Feature: mezuro content
2   - As a noosfero user
3   - I want to create a Kalibro project
4   -
5   - Background:
6   - Given the following users
7   - | login | name |
8   - | joaosilva | Joao Silva |
9   - And I am logged in as "joaosilva"
10   - And "Mezuro" plugin is enabled
11   - And the following community
12   - | identifier | name |
13   - | mycommunity | My Community |
14   - And "Joao Silva" is admin of "My Community"
15   -
16   - Scenario: I see Kalibro project as an option to new content
17   - Given I am on My Community's cms
18   - When I follow "New content"
19   - Then I should see "Kalibro project"
20   -
21   - Scenario: I see Kalibro project's input form
22   - Given I am on My Community's cms
23   - When I follow "New content"
24   - And I follow "Kalibro project"
25   - Then I should see "Title"
26   - And I should see "License"
27   - And I should see "Repository type"
28   - And I should see "GIT"
29   - And I should see "REMOTE_ZIP"
30   - And I should see "REMOTE_TARBALL"
31   - And I should see "SUBVERSION"
32   - And I should see "Repository url"
33   - And I should see "Configuration"
34   - And I should see "Kalibro for Java"
35   -
36   - Scenario: I create a sample mezuro content
37   - Given I am on My Community's cms
38   - When I create a content of type "Kalibro project" with the following data
39   - | Title | Sample project |
40   - | License | BSD |
41   - | Repository type | GIT |
42   - | Repository url | git://example |
43   - Then I should see "Sample project"
44   - And I should see "Viewed one time"
45   - And I should see "BSD"
46   -
47   - Scenario: I create a real mezuro content
48   - Given I am on My Community's cms
49   - When I create a content of type "Kalibro project" with the following data
50   - | Title | Qt-Calculator |
51   - | License | GPL 2.0 |
52   - | Repository type | SUBVERSION |
53   - | Repository url | https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator |
54   - Then I should see "Qt-Calculator"
55   -
56   - Scenario: I see results from a real Kalibro project
57   - Given I am on My Community's cms
58   - When I create a content of type "Kalibro project" with the following data
59   - | Title | Qt-Calculator |
60   - | License | GPL |
61   - | Repository type | SUBVERSION |
62   - | Repository url | https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator |
63   - | Configuration | Kalibro for Java |
64   - Then I should see "Qt-Calculator"
65   - And I should see "GPL"
66   - And I should see "SUBVERSION"
67   - And I should see "https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator"
68   - And I should see "Kalibro for Java"
69   - And I should see "Kalibro Service is loading the source code"
plugins/mezuro/test/features/removing_metric_configuration.feature 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +Feature: Remove a metric configuration from a configuration
  2 + As a mezuro user
  3 + I want to remove metric configurations from a configuration
  4 +
  5 + Background:
  6 + Given the following users
  7 + | login | name |
  8 + | joaosilva | Joao Silva |
  9 + And I am logged in as "joaosilva"
  10 + And "Mezuro" plugin is enabled
  11 + And the following community
  12 + | identifier | name |
  13 + | mycommunity | My Community |
  14 + And "Joao Silva" is admin of "My Community"
  15 + And I am on My Community's cms
  16 + And I create a content of type "Kalibro configuration" with the following data
  17 + | Title | My Configuration |
  18 + | Description | A sample description |
  19 + When I follow "Add metric"
  20 + And I follow "Analizo"
  21 + And I follow "Lines of Code"
  22 + And I fill in the following:
  23 + | Code: | Sample Code |
  24 + | Weight: | 10.0 |
  25 + And I select "Average" from "Aggregation Form:"
  26 + And I press "Add"
  27 + And I press "Save"
  28 + And I should see "Lines of Code"
  29 +
  30 + Scenario: I remove a metric configuration
  31 + When I follow "Remove"
  32 + Then I should not see "Lines of Code"
... ...
plugins/mezuro/test/functional/echo_port_test.rb
... ... @@ -1,88 +0,0 @@
1   -require "test_helper"
2   -
3   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures"
4   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures"
5   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures"
6   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures"
7   -
8   -class EchoPortTest < ActiveSupport::TestCase
9   -
10   - def setup
11   - @port = Kalibro::Client::Port.new('Echo')
12   - @port.service_address=('http://valinhos.ime.usp.br:50688/KalibroFake/');
13   - end
14   -
15   - should 'echo base tool' do
16   - test BaseToolFixtures.analizo, 'BaseTool' do |base_tool|
17   - base_tool.name = "echo " + base_tool.name
18   - end
19   - end
20   -
21   - should 'echo configuration' do
22   - test ConfigurationFixtures.kalibro_configuration, 'Configuration' do |configuration|
23   - configuration.name = "echo " + configuration.name
24   - end
25   - end
26   -
27   - should 'echo metric configuration' do
28   - test_metric_configuration(MetricConfigurationFixtures.amloc_configuration)
29   - test_metric_configuration(MetricConfigurationFixtures.sc_configuration)
30   - end
31   -
32   - should 'echo module result' do
33   - test ModuleResultFixtures.create, 'ModuleResult' do |module_result|
34   - module_result.module.name = "echo." + module_result.module.name
35   - end
36   - end
37   -
38   - should 'echo project' do
39   - test(ProjectFixtures.qt_calculator, 'Project') do |project|
40   - project.name = "echo " + project.name
41   - end
42   - end
43   -
44   - should 'echo project result' do
45   - test(ProjectResultFixtures.qt_calculator, 'ProjectResult') do |project_result|
46   - project_result.project.name = "echo " + project_result.project.name
47   - end
48   - end
49   -
50   - should 'echo raw project' do
51   - project = ProjectFixtures.qt_calculator
52   - echoed = @port.request(:echo_raw_project, {:project => project.to_hash})[:project]
53   - project.name = "echo " + project.name
54   - project.state = nil
55   - project.error = nil
56   - assert_equal project, Kalibro::Entities::Project.from_hash(echoed)
57   - end
58   -
59   - should 'work with enums' do
60   - test_granularity("METHOD", "CLASS")
61   - test_granularity("CLASS", "PACKAGE")
62   - test_granularity("PACKAGE", "PACKAGE")
63   - test_granularity("APPLICATION", "APPLICATION")
64   - end
65   -
66   - private
67   -
68   - def test_metric_configuration(fixture)
69   - test fixture, 'MetricConfiguration' do |metric_configuration|
70   - metric_configuration.code = "echo_" + metric_configuration.code
71   - end
72   - end
73   -
74   - def test(fixture, entity_name)
75   - entity_symbol = entity_name.underscore.to_sym
76   - request_body = {entity_symbol => fixture.to_hash}
77   - echoed = @port.request("echo_#{entity_symbol}".to_sym, request_body)[entity_symbol]
78   - yield fixture
79   - entity_class = "Kalibro::Entities::#{entity_name}".constantize
80   - assert_equal fixture, entity_class.from_hash(echoed)
81   - end
82   -
83   - def test_granularity(granularity, parent)
84   - body = {:granularity => granularity}
85   - assert_equal parent, @port.request(:infer_parent_granularity, body)[:parent_granularity]
86   - end
87   -
88   -end