epc 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/Gemfile +22 -0
- data/Rakefile +67 -0
- data/Rakefile.gem +1 -0
- data/bin/epc +10 -0
- data/lib/epc.rb +126 -0
- data/lib/epc/client/base_client.rb +80 -0
- data/lib/epc/client/http_client.rb +19 -0
- data/lib/epc/client/json_client.rb +48 -0
- data/lib/epc/command/archive_project_command.rb +24 -0
- data/lib/epc/command/archive_solution_command.rb +21 -0
- data/lib/epc/command/attach_library_command.rb +82 -0
- data/lib/epc/command/attach_libraryset_command.rb +32 -0
- data/lib/epc/command/attach_runtime_command.rb +27 -0
- data/lib/epc/command/base_command.rb +451 -0
- data/lib/epc/command/bind_service_command.rb +35 -0
- data/lib/epc/command/build_command.rb +83 -0
- data/lib/epc/command/config/create_config_command.rb +55 -0
- data/lib/epc/command/copy_deployment_command.rb +21 -0
- data/lib/epc/command/create_command.rb +13 -0
- data/lib/epc/command/create_dependency_command.rb +43 -0
- data/lib/epc/command/define_service_command.rb +37 -0
- data/lib/epc/command/delete_config_command.rb +63 -0
- data/lib/epc/command/delete_dependency_command.rb +40 -0
- data/lib/epc/command/delete_group_command.rb +40 -0
- data/lib/epc/command/delete_library_command.rb +30 -0
- data/lib/epc/command/delete_librarylanguage_command.rb +40 -0
- data/lib/epc/command/delete_libraryset_command.rb +40 -0
- data/lib/epc/command/delete_project_command.rb +54 -0
- data/lib/epc/command/delete_role_command.rb +25 -0
- data/lib/epc/command/delete_serviceversion_command.rb +52 -0
- data/lib/epc/command/delete_solution_command.rb +39 -0
- data/lib/epc/command/delete_user_command.rb +31 -0
- data/lib/epc/command/deploy_command.rb +142 -0
- data/lib/epc/command/deployment/create_deployment_command.rb +82 -0
- data/lib/epc/command/detach_library_command.rb +35 -0
- data/lib/epc/command/detach_libraryset_command.rb +8 -0
- data/lib/epc/command/group/create_group_command.rb +21 -0
- data/lib/epc/command/info_command.rb +11 -0
- data/lib/epc/command/library/create_library_command.rb +45 -0
- data/lib/epc/command/librarylanguage/create_librarylanguage_command.rb +24 -0
- data/lib/epc/command/libraryset/create_libraryset_command.rb +54 -0
- data/lib/epc/command/list_approvals_command.rb +27 -0
- data/lib/epc/command/list_attachedlibraries_command.rb +42 -0
- data/lib/epc/command/list_boundservices_command.rb +40 -0
- data/lib/epc/command/list_config_command.rb +60 -0
- data/lib/epc/command/list_dependencies_command.rb +43 -0
- data/lib/epc/command/list_deployments_command.rb +68 -0
- data/lib/epc/command/list_groups_command.rb +19 -0
- data/lib/epc/command/list_libraries_command.rb +19 -0
- data/lib/epc/command/list_librarylanguages_command.rb +19 -0
- data/lib/epc/command/list_librarysets_command.rb +26 -0
- data/lib/epc/command/list_objectroles_command.rb +25 -0
- data/lib/epc/command/list_objecttypes_command.rb +20 -0
- data/lib/epc/command/list_permissiongroups_command.rb +20 -0
- data/lib/epc/command/list_projects_command.rb +36 -0
- data/lib/epc/command/list_projecttypes_command.rb +20 -0
- data/lib/epc/command/list_rolepermissions_command.rb +21 -0
- data/lib/epc/command/list_roles_command.rb +26 -0
- data/lib/epc/command/list_runtimes_command.rb +16 -0
- data/lib/epc/command/list_service_types_command.rb +19 -0
- data/lib/epc/command/list_servicedefinitions_command.rb +19 -0
- data/lib/epc/command/list_serviceversions_command.rb +21 -0
- data/lib/epc/command/list_solutions_command.rb +25 -0
- data/lib/epc/command/list_stages_command.rb +21 -0
- data/lib/epc/command/list_users_command.rb +26 -0
- data/lib/epc/command/list_versions_command.rb +39 -0
- data/lib/epc/command/login_command.rb +32 -0
- data/lib/epc/command/logout_command.rb +20 -0
- data/lib/epc/command/objectrole/create_objectrole_command.rb +19 -0
- data/lib/epc/command/project/create_project_command.rb +78 -0
- data/lib/epc/command/pull_command.rb +209 -0
- data/lib/epc/command/push_command.rb +194 -0
- data/lib/epc/command/refresh_solution_command.rb +71 -0
- data/lib/epc/command/renew_command.rb +19 -0
- data/lib/epc/command/request_passwordchange_command.rb +23 -0
- data/lib/epc/command/role/create_role_command.rb +17 -0
- data/lib/epc/command/serviceversion/create_serviceversion_command.rb +33 -0
- data/lib/epc/command/show_deployment_command.rb +57 -0
- data/lib/epc/command/show_group_command.rb +35 -0
- data/lib/epc/command/show_libraryset_command.rb +54 -0
- data/lib/epc/command/show_project_command.rb +74 -0
- data/lib/epc/command/show_projecttype_command.rb +18 -0
- data/lib/epc/command/show_role_command.rb +46 -0
- data/lib/epc/command/show_solution_command.rb +54 -0
- data/lib/epc/command/show_user_command.rb +42 -0
- data/lib/epc/command/solution/create_solution_command.rb +34 -0
- data/lib/epc/command/solution/list_solutions_command.rb +25 -0
- data/lib/epc/command/solution/update_solution_command.rb +43 -0
- data/lib/epc/command/submit_deployment_command.rb +19 -0
- data/lib/epc/command/target_command.rb +26 -0
- data/lib/epc/command/unarchive_project_command.rb +23 -0
- data/lib/epc/command/unarchive_solution_command.rb +21 -0
- data/lib/epc/command/unbind_service_command.rb +42 -0
- data/lib/epc/command/undefine_service_command.rb +33 -0
- data/lib/epc/command/undeploy_command.rb +106 -0
- data/lib/epc/command/update_config_command.rb +62 -0
- data/lib/epc/command/update_deploymentproject_command.rb +54 -0
- data/lib/epc/command/update_group_command.rb +43 -0
- data/lib/epc/command/update_librarylanguage_command.rb +28 -0
- data/lib/epc/command/update_libraryset_command.rb +80 -0
- data/lib/epc/command/update_project_command.rb +49 -0
- data/lib/epc/command/update_role_command.rb +47 -0
- data/lib/epc/command/update_rolepermissions_command.rb +83 -0
- data/lib/epc/command/update_solution_command.rb +45 -0
- data/lib/epc/command/update_user_command.rb +57 -0
- data/lib/epc/command/user/create_user_command.rb +27 -0
- data/lib/epc/command/vote_deployment_command.rb +29 -0
- data/lib/epc/config.rb +245 -0
- data/lib/epc/error/basic_error.rb +6 -0
- data/lib/epc/error/fatal_error.rb +6 -0
- data/lib/epc/error/input_error.rb +6 -0
- data/lib/epc/error/internal_error.rb +6 -0
- data/lib/epc/help.rb +292 -0
- data/lib/epc/persistent_attributes.rb +18 -0
- data/lib/epc/runner.rb +177 -0
- data/lib/epc/tabular_outputter.rb +161 -0
- data/lib/epc/version.rb +3 -0
- data/lib/fixnum.rb +9 -0
- data/lib/object.rb +13 -0
- data/test/command/archive_project_command_test.rb +41 -0
- data/test/command/archive_solution_command_test.rb +40 -0
- data/test/command/attach_library_command_test.rb +124 -0
- data/test/command/attach_libraryset_command_test.rb +49 -0
- data/test/command/attach_runtime_command_test.rb +44 -0
- data/test/command/base_command_test.rb +276 -0
- data/test/command/bind_service_command_test.rb +46 -0
- data/test/command/build_command_test.rb +103 -0
- data/test/command/copy_deployment_command_test.rb +38 -0
- data/test/command/create_config_command_test.rb +124 -0
- data/test/command/create_dependency_command_test.rb +55 -0
- data/test/command/create_deployment_command_test.rb +136 -0
- data/test/command/create_group_command_test.rb +34 -0
- data/test/command/create_library_command_test.rb +61 -0
- data/test/command/create_librarylanguage_command_test.rb +51 -0
- data/test/command/create_libraryset_command_test.rb +81 -0
- data/test/command/create_objectrole_command_test.rb +37 -0
- data/test/command/create_project_command_test.rb +102 -0
- data/test/command/create_role_command_test.rb +31 -0
- data/test/command/create_serviceversion_command_test.rb +60 -0
- data/test/command/create_solution_command_test.rb +70 -0
- data/test/command/create_user_command_test.rb +54 -0
- data/test/command/define_service_command_test.rb +55 -0
- data/test/command/delete_config_command_test.rb +82 -0
- data/test/command/delete_dependency_command_test.rb +50 -0
- data/test/command/delete_group_command_test.rb +56 -0
- data/test/command/delete_library_command_test.rb +43 -0
- data/test/command/delete_librarylanguage_command_test.rb +55 -0
- data/test/command/delete_libraryset_command_test.rb +55 -0
- data/test/command/delete_project_command_test.rb +76 -0
- data/test/command/delete_role_command_test.rb +41 -0
- data/test/command/delete_serviceversion_command_test.rb +53 -0
- data/test/command/delete_solution_command_test.rb +79 -0
- data/test/command/delete_user_command_test.rb +56 -0
- data/test/command/deploy_command_test.rb +185 -0
- data/test/command/detach_library_command_test.rb +53 -0
- data/test/command/info_command_test.rb +17 -0
- data/test/command/list_approvals_command_test.rb +41 -0
- data/test/command/list_boundservices_command_test.rb +46 -0
- data/test/command/list_config_command_test.rb +72 -0
- data/test/command/list_dependencies_command_test.rb +46 -0
- data/test/command/list_deployments_command_test.rb +112 -0
- data/test/command/list_deploymentstages_command_test.rb +44 -0
- data/test/command/list_libraries_command_test.rb +42 -0
- data/test/command/list_librarylanguages_command_test.rb +34 -0
- data/test/command/list_librarysets_command_test.rb +33 -0
- data/test/command/list_objectroles_command_test.rb +41 -0
- data/test/command/list_objecttypes_command_test.rb +25 -0
- data/test/command/list_permissiongroups_command_test.rb +25 -0
- data/test/command/list_projects_command_test.rb +63 -0
- data/test/command/list_projecttypes_command_test.rb +39 -0
- data/test/command/list_rolepermissions_command_test.rb +39 -0
- data/test/command/list_roles_command_test.rb +46 -0
- data/test/command/list_runtimes_command_test.rb +30 -0
- data/test/command/list_service_types_command_test.rb +44 -0
- data/test/command/list_servicedefinitions_command_test.rb +44 -0
- data/test/command/list_serviceversions_command_test.rb +47 -0
- data/test/command/list_solutions_command_test.rb +48 -0
- data/test/command/list_users_command_test.rb +33 -0
- data/test/command/login_command_test.rb +83 -0
- data/test/command/logout_command_test.rb +30 -0
- data/test/command/pull_command_test.rb +229 -0
- data/test/command/push_command_test.rb +246 -0
- data/test/command/refresh_solution_command_test.rb +35 -0
- data/test/command/renew_command_test.rb +43 -0
- data/test/command/request_passwordchange_command_test.rb +31 -0
- data/test/command/show_group_command_test.rb +50 -0
- data/test/command/show_libraryset_command_test.rb +51 -0
- data/test/command/show_project_command_test.rb +57 -0
- data/test/command/show_projecttype_command_test.rb +46 -0
- data/test/command/show_role_command_test.rb +37 -0
- data/test/command/show_solution_command_test.rb +59 -0
- data/test/command/show_user_command_test.rb +50 -0
- data/test/command/submit_deployment_command_test.rb +37 -0
- data/test/command/target_command_test.rb +58 -0
- data/test/command/unarchive_project_command_test.rb +45 -0
- data/test/command/unarchive_solution_command_test.rb +43 -0
- data/test/command/unbind_service_command_test.rb +48 -0
- data/test/command/undefine_service_command_test.rb +49 -0
- data/test/command/update_config_command_test.rb +74 -0
- data/test/command/update_deploymentproject_command_test.rb +77 -0
- data/test/command/update_group_command_test.rb +69 -0
- data/test/command/update_librarylanguage_command_test.rb +43 -0
- data/test/command/update_libraryset_command_test.rb +113 -0
- data/test/command/update_project_command_test.rb +56 -0
- data/test/command/update_role_command_test.rb +42 -0
- data/test/command/update_rolepermissions_command_test.rb +54 -0
- data/test/command/update_solution_command_test.rb +58 -0
- data/test/command/update_user_command_test.rb +76 -0
- data/test/command/vote_deployment_command_test.rb +33 -0
- data/test/config_test.rb +70 -0
- data/test/successful_test.rb +21 -0
- data/test/test_files/pom.xml +273 -0
- data/test/test_helper.rb +25 -0
- metadata +470 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.expand_path "../../../lib/epc", __FILE__
|
2
|
+
require "test/unit"
|
3
|
+
require 'shoulda'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
class UndefineServiceCommandTest < Test::Unit::TestCase
|
7
|
+
should_require_login
|
8
|
+
|
9
|
+
context "execution" do
|
10
|
+
setup do
|
11
|
+
@mock_client = mock('Client')
|
12
|
+
end
|
13
|
+
|
14
|
+
should "require the user to specify the service_name" do
|
15
|
+
@command = EPC::Command::UndefineServiceCommand.new(@mock_client)
|
16
|
+
@command.expects(:say).with("You must specify a name for the service")
|
17
|
+
@command.expects(:say).with(EPC::Help::COMMAND_USAGES[:undefine_service])
|
18
|
+
@command.execute
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "service undefinition" do
|
23
|
+
setup do
|
24
|
+
@mock_client = stub('Client')
|
25
|
+
@command = EPC::Command::UndefineServiceCommand.new(@mock_client)
|
26
|
+
end
|
27
|
+
|
28
|
+
should "query core for service_id if service name was specified" do
|
29
|
+
@command.expects(:get_resource_id).returns(0)
|
30
|
+
@command.expects(:say).with("my_mysql_instance service could not be found.")
|
31
|
+
assert_equal(@command.execute("my_mysql_instance"), 1)
|
32
|
+
end
|
33
|
+
|
34
|
+
should "fail if status is not 201" do
|
35
|
+
@command.expects(:get_resource_id).returns(1)
|
36
|
+
@mock_client.expects(:delete).with(EPC::Config::SERVICE_DEFINITIONS_PATH + "/1").returns([400, {'message' => 'Not Found'}])
|
37
|
+
@command.expects(:say).with("Service removal failed with: [Not Found]")
|
38
|
+
assert_equal(@command.execute("my_mysql_instance"), 400)
|
39
|
+
end
|
40
|
+
|
41
|
+
should "undefine a service" do
|
42
|
+
@command.expects(:get_resource_id).returns(1)
|
43
|
+
@mock_client.expects(:delete).with(EPC::Config::SERVICE_DEFINITIONS_PATH + "/1").returns([200, {'id' => 1}])
|
44
|
+
@command.expects(:say).with("my_mysql_instance has been undefined.")
|
45
|
+
assert_equal(@command.execute("my_mysql_instance"), 200)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UpdateConfigCommandTest < Test::Unit::TestCase
|
4
|
+
should_require_login
|
5
|
+
|
6
|
+
context "fail" do
|
7
|
+
setup do
|
8
|
+
@mock_client = mock("Client")
|
9
|
+
@command = EPC::Command::UpdateConfigCommand.new(@mock_client)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "fail if no key specified" do
|
13
|
+
@command.expects(:say).with("You have to specify a key and its value.")
|
14
|
+
assert_equal(@command.execute, 1)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
should "fail if status code is not 200" do
|
19
|
+
@command.expects(:extract_configuration_level).returns(["Project", 1])
|
20
|
+
|
21
|
+
@mock_client.expects(:get).with(EPC::Config::CONFIGURATIONS_PATH + "/Project/1").
|
22
|
+
returns([200,
|
23
|
+
[{:name => "key1", :value => "value2", :id => 1}],
|
24
|
+
{}])
|
25
|
+
|
26
|
+
@mock_client.expects(:put).with(EPC::Config::CONFIGURATIONS_PATH+"/1",
|
27
|
+
{:name => "key1", :value => "value1", :required => false}
|
28
|
+
).returns([400, {:message => "Not Found"}, {}])
|
29
|
+
|
30
|
+
@command.expects("say").with("Request failed with message [Not Found]")
|
31
|
+
assert_equal(@command.execute("key1=value1"), 400)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
should "fail if key doesn't exist" do
|
36
|
+
@command.expects(:extract_configuration_level).returns(["Project", 1])
|
37
|
+
|
38
|
+
@mock_client.expects(:get).with(EPC::Config::CONFIGURATIONS_PATH + "/Project/1").
|
39
|
+
returns([200,
|
40
|
+
[{:name => "key2", :value => "value2"}],
|
41
|
+
{}])
|
42
|
+
|
43
|
+
@command.expects(:say).with("Key does not exist.")
|
44
|
+
assert_equal(@command.execute("key1=value1"), 1)
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "updating" do
|
50
|
+
setup do
|
51
|
+
@mock_client = mock("Client")
|
52
|
+
@command = EPC::Command::UpdateConfigCommand.new(@mock_client)
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
should "update keys" do
|
57
|
+
@command = EPC::Command::UpdateConfigCommand.new(@mock_client, {:required => false})
|
58
|
+
@command.expects(:extract_configuration_level).returns(["Project", 1])
|
59
|
+
|
60
|
+
@mock_client.expects(:get).with(EPC::Config::CONFIGURATIONS_PATH + "/Project/1").
|
61
|
+
returns([200,
|
62
|
+
[{:name => "key1", :value => "value2", :value_type => "data", :required => false, :id => 1, :configurable_id => 1, :configurable_type => "Project"}],
|
63
|
+
{}])
|
64
|
+
|
65
|
+
@mock_client.expects(:put).with(EPC::Config::CONFIGURATIONS_PATH+"/1",
|
66
|
+
{:name => "key1", :value => "value1", :required => false}
|
67
|
+
).returns([200, {:id => 1}, {}])
|
68
|
+
|
69
|
+
@command.expects(:say).with("key1 saved.")
|
70
|
+
assert_equal(@command.execute("key1=value1"), 200)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UpdateDeploymentprojectCommandTest < Test::Unit::TestCase
|
4
|
+
should_require_login
|
5
|
+
|
6
|
+
context "pre-execution checks" do
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@mock_client = mock("Client")
|
10
|
+
@command = EPC::Command::UpdateDeploymentprojectCommand.new(@mock_client)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "require both deployment id and project id" do
|
14
|
+
assert_raise EPC::Error::FatalError do
|
15
|
+
assert_equal(@command.execute, 1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
should "require either instance-count or uris" do
|
20
|
+
@command.options[:instances] = nil
|
21
|
+
@command.options[:uris] = nil
|
22
|
+
|
23
|
+
assert_raise EPC::Error::FatalError do
|
24
|
+
assert_equal(@command.execute(1, 1), 1)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
context "execution" do
|
31
|
+
setup do
|
32
|
+
@mock_client = mock("Client")
|
33
|
+
@command = EPC::Command::UpdateDeploymentprojectCommand.new(@mock_client)
|
34
|
+
@command.options[:instances] = 3
|
35
|
+
@command.options[:uris] = "new-uri.instance-host.com"
|
36
|
+
end
|
37
|
+
|
38
|
+
should "do the request to core" do
|
39
|
+
@command.expects(:get_deployed_project_id).with(1, :id, 1).returns(1)
|
40
|
+
@mock_client.expects(:put).with(EPC::Config::DEPLOYMENTS_PATH + "/1/deployed_projects/1", {:instances => 3, :uris => ['new-uri.instance-host.com']}).returns([404, {:message => "Not Found"}, {}])
|
41
|
+
@command.expects(:say).with("Request failed with: [Not Found]").at_least_once
|
42
|
+
assert_equal(@command.execute(1,1), 404)
|
43
|
+
end
|
44
|
+
|
45
|
+
should "should do the request to core" do
|
46
|
+
@command.expects(:get_deployed_project_id).with(1, :id, 1).returns(1)
|
47
|
+
@mock_client.expects(:put).with(EPC::Config::DEPLOYMENTS_PATH + "/1/deployed_projects/1", {:instances => 3, :uris => ['new-uri.instance-host.com']}).returns([200, {}, {}])
|
48
|
+
@command.expects(:say).with("Deployment updated")
|
49
|
+
assert_equal(@command.execute(1,1), 200)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "retrieving deployed project" do
|
54
|
+
setup do
|
55
|
+
@mock_client = mock("Client")
|
56
|
+
@command = EPC::Command::UpdateDeploymentprojectCommand.new(@mock_client)
|
57
|
+
end
|
58
|
+
|
59
|
+
should "fail if can't retrieve deployments" do
|
60
|
+
assert_raise EPC::Error::FatalError do
|
61
|
+
@mock_client.expects(:get).returns([500, {:message => "System exception"}, {}])
|
62
|
+
@command.send(:get_deployed_project_id, 1, :name, "FirstProject")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
should "return nil if response from server was blank" do
|
67
|
+
@mock_client.expects(:get).returns([200, {}, {}])
|
68
|
+
assert_equal @command.send(:get_deployed_project_id, 1, :name, "FirstProject"), nil
|
69
|
+
end
|
70
|
+
|
71
|
+
should "return the id when it finds one" do
|
72
|
+
@mock_client.expects(:get).returns([200, {:solution => {:projects => [{:id => 1, :name => "FirstProject", :deployed_project_id => 3}]}}, {}])
|
73
|
+
assert_equal @command.send(:get_deployed_project_id, 1, :name, "FirstProject"), 3
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UpdateGroupCommandTest < Test::Unit::TestCase
|
4
|
+
should_require_login
|
5
|
+
|
6
|
+
context "parameter check" do
|
7
|
+
setup do
|
8
|
+
@mock_client = mock("Client")
|
9
|
+
@command = EPC::Command::UpdateGroupCommand.new(@mock_client)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "fail if no group id/name specified" do
|
13
|
+
@command.expects(:say).with("You must specify the group id/name")
|
14
|
+
@command.expects(:say).with(EPC::Help::COMMAND_USAGES[:update_group])
|
15
|
+
|
16
|
+
assert_equal(@command.execute, 1)
|
17
|
+
end
|
18
|
+
|
19
|
+
should "fail if group id can't be determined" do
|
20
|
+
@command.expects(:get_resource_id).returns(nil)
|
21
|
+
@command.expects(:say).with("Group could not be found")
|
22
|
+
|
23
|
+
assert_equal(@command.execute("inexistent_group"), 1)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "execution" do
|
28
|
+
setup do
|
29
|
+
@mock_client = mock("Client")
|
30
|
+
@command = EPC::Command::UpdateGroupCommand.new(@mock_client)
|
31
|
+
@command.expects(:get_resource_id).returns(1)
|
32
|
+
end
|
33
|
+
|
34
|
+
should "require the user to specify a user_id to be added/removed" do
|
35
|
+
@command.expects(:say).with("You must specify a user to be added or removed")
|
36
|
+
|
37
|
+
assert_equal(@command.execute("grp"), 1)
|
38
|
+
end
|
39
|
+
|
40
|
+
should "add a user to a group" do
|
41
|
+
@command.options[:add_user] = 1
|
42
|
+
|
43
|
+
@mock_client.expects(:put).with(EPC::Config::GROUPS_PATH + "/1/add_user", {:user_id => 1}).
|
44
|
+
returns([200, {}, {}])
|
45
|
+
@command.expects(:say).with("User added to group")
|
46
|
+
assert_equal(@command.execute("grp"), 200)
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
should "remove a user from a group" do
|
51
|
+
@command.options[:remove_user] = 1
|
52
|
+
|
53
|
+
@mock_client.expects(:put).with(EPC::Config::GROUPS_PATH + "/1/remove_user", {:user_id => 1}).
|
54
|
+
returns([200, {}, {}])
|
55
|
+
@command.expects(:say).with("User removed from group")
|
56
|
+
assert_equal(@command.execute("grp"), 200)
|
57
|
+
end
|
58
|
+
|
59
|
+
should "notify on failure" do
|
60
|
+
@command.options[:add_user] = 1
|
61
|
+
|
62
|
+
@mock_client.expects(:put).with(EPC::Config::GROUPS_PATH + "/1/add_user", {:user_id => 1}).
|
63
|
+
returns([404, {:message => "Not Found"}, {}])
|
64
|
+
@command.expects(:say).with("Request failed: [Not Found]")
|
65
|
+
assert_equal(@command.execute("grp"), 404)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UpdateLibrarylanguageCommandTest < Test::Unit::TestCase
|
4
|
+
should_require_login
|
5
|
+
|
6
|
+
context "execute" do
|
7
|
+
setup do
|
8
|
+
@mock_client = mock("Client")
|
9
|
+
@command = EPC::Command::UpdateLibrarylanguageCommand.new(@mock_client)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "fail if language id can't be determined" do
|
13
|
+
@command.expects(:get_resource_id).with(EPC::Config::LIBRARY_LANGUAGES_PATH, :name, "ruby").returns(nil)
|
14
|
+
@command.expects(:say).with("Language could not be determined")
|
15
|
+
|
16
|
+
assert_equal(@command.execute("ruby", "ruby192"), 1)
|
17
|
+
end
|
18
|
+
|
19
|
+
should "fail if status is not 200" do
|
20
|
+
@mock_client.expects(:put).with(EPC::Config::LIBRARY_LANGUAGES_PATH + "/1", {:name => "ruby192"}).
|
21
|
+
returns([404, {:message => "Not Found"}, {}])
|
22
|
+
@command.expects(:say).with("Request failed: [Not Found]")
|
23
|
+
assert_equal(@command.execute(1, "ruby192"), 404)
|
24
|
+
end
|
25
|
+
|
26
|
+
should "update a language specified by id" do
|
27
|
+
@mock_client.expects(:put).with(EPC::Config::LIBRARY_LANGUAGES_PATH + "/1", {:name => "ruby"}).
|
28
|
+
returns([200, {}, {}])
|
29
|
+
@command.expects(:say).with("Language updated")
|
30
|
+
|
31
|
+
assert_equal(@command.execute(1, "ruby"), 200)
|
32
|
+
end
|
33
|
+
|
34
|
+
should "update a language specified by name" do
|
35
|
+
@command.expects(:get_resource_id).with(EPC::Config::LIBRARY_LANGUAGES_PATH, :name, "ruby").returns(1)
|
36
|
+
@mock_client.expects(:put).with(EPC::Config::LIBRARY_LANGUAGES_PATH + "/1", {:name => "ruby192"}).
|
37
|
+
returns([200, {}, {}])
|
38
|
+
@command.expects(:say).with("Language updated")
|
39
|
+
|
40
|
+
assert_equal(@command.execute("ruby", "ruby192"), 200)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UpdateLibrarysetCommandTest < Test::Unit::TestCase
|
4
|
+
should_require_login
|
5
|
+
|
6
|
+
context "execute" do
|
7
|
+
setup do
|
8
|
+
@mock_client = mock("Client")
|
9
|
+
@command = EPC::Command::UpdateLibrarysetCommand.new(@mock_client)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "fail if no parameter is specified" do
|
13
|
+
@command.expects(:say).with("You must specify the library-set")
|
14
|
+
@command.expects(:say).with(EPC::Help::COMMAND_USAGES[:update_libraryset])
|
15
|
+
assert_equal(@command.execute, 1)
|
16
|
+
end
|
17
|
+
|
18
|
+
should "fail if set id can't be determined" do
|
19
|
+
@command.expects(:get_resource_id).with(EPC::Config::LIBRARY_SETS_PATH, :name, "rubylibs", :case_sensitivity => false).returns(nil)
|
20
|
+
@command.expects(:say).with("Set could not be determined")
|
21
|
+
assert_equal(@command.execute("rubylibs"), 1)
|
22
|
+
end
|
23
|
+
|
24
|
+
context "add library" do
|
25
|
+
setup do
|
26
|
+
@command.options[:add_library] = 1
|
27
|
+
end
|
28
|
+
|
29
|
+
should "add a library when the options is given" do
|
30
|
+
@command.expects(:extract_library_id).returns(1)
|
31
|
+
@mock_client.expects(:post).with(EPC::Config::LIBRARY_SETS_PATH + "/1/attach_library/1").returns([200, {}, {}])
|
32
|
+
@command.expects(:say).with("Library [1] added to set")
|
33
|
+
assert_equal(@command.execute(1), 200)
|
34
|
+
end
|
35
|
+
|
36
|
+
should "show reason for failure" do
|
37
|
+
@command.expects(:extract_library_id).returns(1)
|
38
|
+
@mock_client.expects(:post).with(EPC::Config::LIBRARY_SETS_PATH + "/1/attach_library/1").returns([404, {:message => "Not Found"}, {}])
|
39
|
+
@command.expects(:say).with("Request failed: [Not Found]")
|
40
|
+
assert_equal(@command.execute(1), 404)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
context "remove library" do
|
46
|
+
setup do
|
47
|
+
@command.options[:remove_library] = 1
|
48
|
+
end
|
49
|
+
|
50
|
+
should "remove a library when the options is given" do
|
51
|
+
@command.expects(:extract_library_id).returns(1)
|
52
|
+
@mock_client.expects(:post).with(EPC::Config::LIBRARY_SETS_PATH + "/1/detach_library/1").returns([200, {}, {}])
|
53
|
+
@command.expects(:say).with("Library [1] removed from set")
|
54
|
+
assert_equal(@command.execute(1), 200)
|
55
|
+
end
|
56
|
+
|
57
|
+
should "show reason for failure" do
|
58
|
+
@command.expects(:extract_library_id).returns(1)
|
59
|
+
@mock_client.expects(:post).with(EPC::Config::LIBRARY_SETS_PATH + "/1/detach_library/1").returns([404, {:message => "Not Found"}, {}])
|
60
|
+
@command.expects(:say).with("Request failed: [Not Found]")
|
61
|
+
assert_equal(@command.execute(1), 404)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "adding from file" do
|
66
|
+
setup do
|
67
|
+
@command.options[:file] = "/path/to/file"
|
68
|
+
end
|
69
|
+
|
70
|
+
should "retrieve ids based on name/version/group" do
|
71
|
+
EPC::Config.expects(:read_content_as_json).with("/path/to/file").returns([{"name" => "lib1", "library_version" => "1", "group" => "grp"}])
|
72
|
+
@command.expects(:retrieve_libraries).with([{:name => "lib1", :version => "1", :group => "grp"}]).returns([1])
|
73
|
+
@mock_client.expects(:post).with(EPC::Config::LIBRARY_SETS_PATH + "/1/attach_library/1").returns([200, {}, {}])
|
74
|
+
@command.expects(:say).with("Library [1] added to set")
|
75
|
+
|
76
|
+
assert_equal(@command.execute(1), 0)
|
77
|
+
end
|
78
|
+
|
79
|
+
should "notify when a library fails to be attached" do
|
80
|
+
EPC::Config.expects(:read_content_as_json).with("/path/to/file").returns([{"name" => "lib1", "library_version" => "1", "group" => "grp"}])
|
81
|
+
@command.expects(:retrieve_libraries).with([{:name => "lib1", :version => "1", :group => "grp"}]).returns([1])
|
82
|
+
@mock_client.expects(:post).with(EPC::Config::LIBRARY_SETS_PATH + "/1/attach_library/1").returns([404, {:message => "Not Found"}, {}])
|
83
|
+
@command.expects(:say).with("Failed to add [1]: [Not Found]")
|
84
|
+
|
85
|
+
assert_equal(@command.execute(1), 1)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
context "extract library id" do
|
93
|
+
setup do
|
94
|
+
@mock_client = mock("Client")
|
95
|
+
@command = EPC::Command::UpdateLibrarysetCommand.new(@mock_client)
|
96
|
+
end
|
97
|
+
|
98
|
+
should "return then id" do
|
99
|
+
assert_equal(@command.send(:extract_library_id, "1"), 1)
|
100
|
+
end
|
101
|
+
|
102
|
+
should "raise a FatalError when a library attribute is missing" do
|
103
|
+
assert_raise EPC::Error::FatalError do
|
104
|
+
@command.send(:extract_library_id, ":1.0.0:mathlibs")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
should "determine the id based on the attributes and return it" do
|
109
|
+
@command.expects(:retrieve_libraries).returns([ 5 ])
|
110
|
+
assert_equal @command.send(:extract_library_id, "libmath:1.0.0:mathlibs"), 5
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path "../../../lib/epc", __FILE__
|
2
|
+
require "test/unit"
|
3
|
+
require 'shoulda'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
class UpdateProjectCommandTest < Test::Unit::TestCase
|
7
|
+
should_require_login
|
8
|
+
|
9
|
+
context "pre-execution checks" do
|
10
|
+
setup do
|
11
|
+
@mock_client = mock("Client")
|
12
|
+
@command = EPC::Command::UpdateProjectCommand.new(@mock_client)
|
13
|
+
end
|
14
|
+
|
15
|
+
should "fail if no project specified and can't be inferred" do
|
16
|
+
assert_raise EPC::Error::FatalError do
|
17
|
+
@command.expects(:infer_project_context).returns(nil)
|
18
|
+
@command.execute
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "updating" do
|
24
|
+
setup do
|
25
|
+
@mock_client = mock("Client")
|
26
|
+
@command = EPC::Command::UpdateProjectCommand.new(@mock_client)
|
27
|
+
@command.options[:project_name] = 1
|
28
|
+
@command.options[:solution_name] = 1
|
29
|
+
@command.expects(:infer_solution_context).returns(["1", "FirstSolution"])
|
30
|
+
@command.expects(:infer_project_context).returns(["1", "FirstProject"])
|
31
|
+
end
|
32
|
+
|
33
|
+
should "only update the allowed attributes" do
|
34
|
+
@command.expects(:say).with("Cannot update unallowed_attribute. Updatable attributes are: [project_name, project_type]")
|
35
|
+
@command.expects(:say).with(EPC::Help::COMMAND_USAGES[:update_project])
|
36
|
+
assert_equal(@command.execute("unallowed_attribute=value"), 1)
|
37
|
+
end
|
38
|
+
|
39
|
+
should "show a message if request is unsuccesful" do
|
40
|
+
@mock_client.expects(:put).with(EPC::Config::PROJECTS_PATH+"/1", {'project_name' => "new_name"}).
|
41
|
+
returns([400, {:message => "Not Found"}, {}])
|
42
|
+
@command.expects(:say).with("Update failed with: [Not Found]")
|
43
|
+
|
44
|
+
assert_equal(@command.execute("project_name=new_name"), 400)
|
45
|
+
end
|
46
|
+
|
47
|
+
should "update the project attributes" do
|
48
|
+
@mock_client.expects(:put).with(EPC::Config::PROJECTS_PATH+"/1", {'project_name' => "new_name"}).
|
49
|
+
returns([200, {}, {}])
|
50
|
+
@command.expects(:say).with("Update succesful")
|
51
|
+
|
52
|
+
assert_equal(@command.execute("project_name=new_name"), 200)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|