epc 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. data/CHANGELOG +1 -0
  2. data/Gemfile +22 -0
  3. data/Rakefile +67 -0
  4. data/Rakefile.gem +1 -0
  5. data/bin/epc +10 -0
  6. data/lib/epc.rb +126 -0
  7. data/lib/epc/client/base_client.rb +80 -0
  8. data/lib/epc/client/http_client.rb +19 -0
  9. data/lib/epc/client/json_client.rb +48 -0
  10. data/lib/epc/command/archive_project_command.rb +24 -0
  11. data/lib/epc/command/archive_solution_command.rb +21 -0
  12. data/lib/epc/command/attach_library_command.rb +82 -0
  13. data/lib/epc/command/attach_libraryset_command.rb +32 -0
  14. data/lib/epc/command/attach_runtime_command.rb +27 -0
  15. data/lib/epc/command/base_command.rb +451 -0
  16. data/lib/epc/command/bind_service_command.rb +35 -0
  17. data/lib/epc/command/build_command.rb +83 -0
  18. data/lib/epc/command/config/create_config_command.rb +55 -0
  19. data/lib/epc/command/copy_deployment_command.rb +21 -0
  20. data/lib/epc/command/create_command.rb +13 -0
  21. data/lib/epc/command/create_dependency_command.rb +43 -0
  22. data/lib/epc/command/define_service_command.rb +37 -0
  23. data/lib/epc/command/delete_config_command.rb +63 -0
  24. data/lib/epc/command/delete_dependency_command.rb +40 -0
  25. data/lib/epc/command/delete_group_command.rb +40 -0
  26. data/lib/epc/command/delete_library_command.rb +30 -0
  27. data/lib/epc/command/delete_librarylanguage_command.rb +40 -0
  28. data/lib/epc/command/delete_libraryset_command.rb +40 -0
  29. data/lib/epc/command/delete_project_command.rb +54 -0
  30. data/lib/epc/command/delete_role_command.rb +25 -0
  31. data/lib/epc/command/delete_serviceversion_command.rb +52 -0
  32. data/lib/epc/command/delete_solution_command.rb +39 -0
  33. data/lib/epc/command/delete_user_command.rb +31 -0
  34. data/lib/epc/command/deploy_command.rb +142 -0
  35. data/lib/epc/command/deployment/create_deployment_command.rb +82 -0
  36. data/lib/epc/command/detach_library_command.rb +35 -0
  37. data/lib/epc/command/detach_libraryset_command.rb +8 -0
  38. data/lib/epc/command/group/create_group_command.rb +21 -0
  39. data/lib/epc/command/info_command.rb +11 -0
  40. data/lib/epc/command/library/create_library_command.rb +45 -0
  41. data/lib/epc/command/librarylanguage/create_librarylanguage_command.rb +24 -0
  42. data/lib/epc/command/libraryset/create_libraryset_command.rb +54 -0
  43. data/lib/epc/command/list_approvals_command.rb +27 -0
  44. data/lib/epc/command/list_attachedlibraries_command.rb +42 -0
  45. data/lib/epc/command/list_boundservices_command.rb +40 -0
  46. data/lib/epc/command/list_config_command.rb +60 -0
  47. data/lib/epc/command/list_dependencies_command.rb +43 -0
  48. data/lib/epc/command/list_deployments_command.rb +68 -0
  49. data/lib/epc/command/list_groups_command.rb +19 -0
  50. data/lib/epc/command/list_libraries_command.rb +19 -0
  51. data/lib/epc/command/list_librarylanguages_command.rb +19 -0
  52. data/lib/epc/command/list_librarysets_command.rb +26 -0
  53. data/lib/epc/command/list_objectroles_command.rb +25 -0
  54. data/lib/epc/command/list_objecttypes_command.rb +20 -0
  55. data/lib/epc/command/list_permissiongroups_command.rb +20 -0
  56. data/lib/epc/command/list_projects_command.rb +36 -0
  57. data/lib/epc/command/list_projecttypes_command.rb +20 -0
  58. data/lib/epc/command/list_rolepermissions_command.rb +21 -0
  59. data/lib/epc/command/list_roles_command.rb +26 -0
  60. data/lib/epc/command/list_runtimes_command.rb +16 -0
  61. data/lib/epc/command/list_service_types_command.rb +19 -0
  62. data/lib/epc/command/list_servicedefinitions_command.rb +19 -0
  63. data/lib/epc/command/list_serviceversions_command.rb +21 -0
  64. data/lib/epc/command/list_solutions_command.rb +25 -0
  65. data/lib/epc/command/list_stages_command.rb +21 -0
  66. data/lib/epc/command/list_users_command.rb +26 -0
  67. data/lib/epc/command/list_versions_command.rb +39 -0
  68. data/lib/epc/command/login_command.rb +32 -0
  69. data/lib/epc/command/logout_command.rb +20 -0
  70. data/lib/epc/command/objectrole/create_objectrole_command.rb +19 -0
  71. data/lib/epc/command/project/create_project_command.rb +78 -0
  72. data/lib/epc/command/pull_command.rb +209 -0
  73. data/lib/epc/command/push_command.rb +194 -0
  74. data/lib/epc/command/refresh_solution_command.rb +71 -0
  75. data/lib/epc/command/renew_command.rb +19 -0
  76. data/lib/epc/command/request_passwordchange_command.rb +23 -0
  77. data/lib/epc/command/role/create_role_command.rb +17 -0
  78. data/lib/epc/command/serviceversion/create_serviceversion_command.rb +33 -0
  79. data/lib/epc/command/show_deployment_command.rb +57 -0
  80. data/lib/epc/command/show_group_command.rb +35 -0
  81. data/lib/epc/command/show_libraryset_command.rb +54 -0
  82. data/lib/epc/command/show_project_command.rb +74 -0
  83. data/lib/epc/command/show_projecttype_command.rb +18 -0
  84. data/lib/epc/command/show_role_command.rb +46 -0
  85. data/lib/epc/command/show_solution_command.rb +54 -0
  86. data/lib/epc/command/show_user_command.rb +42 -0
  87. data/lib/epc/command/solution/create_solution_command.rb +34 -0
  88. data/lib/epc/command/solution/list_solutions_command.rb +25 -0
  89. data/lib/epc/command/solution/update_solution_command.rb +43 -0
  90. data/lib/epc/command/submit_deployment_command.rb +19 -0
  91. data/lib/epc/command/target_command.rb +26 -0
  92. data/lib/epc/command/unarchive_project_command.rb +23 -0
  93. data/lib/epc/command/unarchive_solution_command.rb +21 -0
  94. data/lib/epc/command/unbind_service_command.rb +42 -0
  95. data/lib/epc/command/undefine_service_command.rb +33 -0
  96. data/lib/epc/command/undeploy_command.rb +106 -0
  97. data/lib/epc/command/update_config_command.rb +62 -0
  98. data/lib/epc/command/update_deploymentproject_command.rb +54 -0
  99. data/lib/epc/command/update_group_command.rb +43 -0
  100. data/lib/epc/command/update_librarylanguage_command.rb +28 -0
  101. data/lib/epc/command/update_libraryset_command.rb +80 -0
  102. data/lib/epc/command/update_project_command.rb +49 -0
  103. data/lib/epc/command/update_role_command.rb +47 -0
  104. data/lib/epc/command/update_rolepermissions_command.rb +83 -0
  105. data/lib/epc/command/update_solution_command.rb +45 -0
  106. data/lib/epc/command/update_user_command.rb +57 -0
  107. data/lib/epc/command/user/create_user_command.rb +27 -0
  108. data/lib/epc/command/vote_deployment_command.rb +29 -0
  109. data/lib/epc/config.rb +245 -0
  110. data/lib/epc/error/basic_error.rb +6 -0
  111. data/lib/epc/error/fatal_error.rb +6 -0
  112. data/lib/epc/error/input_error.rb +6 -0
  113. data/lib/epc/error/internal_error.rb +6 -0
  114. data/lib/epc/help.rb +292 -0
  115. data/lib/epc/persistent_attributes.rb +18 -0
  116. data/lib/epc/runner.rb +177 -0
  117. data/lib/epc/tabular_outputter.rb +161 -0
  118. data/lib/epc/version.rb +3 -0
  119. data/lib/fixnum.rb +9 -0
  120. data/lib/object.rb +13 -0
  121. data/test/command/archive_project_command_test.rb +41 -0
  122. data/test/command/archive_solution_command_test.rb +40 -0
  123. data/test/command/attach_library_command_test.rb +124 -0
  124. data/test/command/attach_libraryset_command_test.rb +49 -0
  125. data/test/command/attach_runtime_command_test.rb +44 -0
  126. data/test/command/base_command_test.rb +276 -0
  127. data/test/command/bind_service_command_test.rb +46 -0
  128. data/test/command/build_command_test.rb +103 -0
  129. data/test/command/copy_deployment_command_test.rb +38 -0
  130. data/test/command/create_config_command_test.rb +124 -0
  131. data/test/command/create_dependency_command_test.rb +55 -0
  132. data/test/command/create_deployment_command_test.rb +136 -0
  133. data/test/command/create_group_command_test.rb +34 -0
  134. data/test/command/create_library_command_test.rb +61 -0
  135. data/test/command/create_librarylanguage_command_test.rb +51 -0
  136. data/test/command/create_libraryset_command_test.rb +81 -0
  137. data/test/command/create_objectrole_command_test.rb +37 -0
  138. data/test/command/create_project_command_test.rb +102 -0
  139. data/test/command/create_role_command_test.rb +31 -0
  140. data/test/command/create_serviceversion_command_test.rb +60 -0
  141. data/test/command/create_solution_command_test.rb +70 -0
  142. data/test/command/create_user_command_test.rb +54 -0
  143. data/test/command/define_service_command_test.rb +55 -0
  144. data/test/command/delete_config_command_test.rb +82 -0
  145. data/test/command/delete_dependency_command_test.rb +50 -0
  146. data/test/command/delete_group_command_test.rb +56 -0
  147. data/test/command/delete_library_command_test.rb +43 -0
  148. data/test/command/delete_librarylanguage_command_test.rb +55 -0
  149. data/test/command/delete_libraryset_command_test.rb +55 -0
  150. data/test/command/delete_project_command_test.rb +76 -0
  151. data/test/command/delete_role_command_test.rb +41 -0
  152. data/test/command/delete_serviceversion_command_test.rb +53 -0
  153. data/test/command/delete_solution_command_test.rb +79 -0
  154. data/test/command/delete_user_command_test.rb +56 -0
  155. data/test/command/deploy_command_test.rb +185 -0
  156. data/test/command/detach_library_command_test.rb +53 -0
  157. data/test/command/info_command_test.rb +17 -0
  158. data/test/command/list_approvals_command_test.rb +41 -0
  159. data/test/command/list_boundservices_command_test.rb +46 -0
  160. data/test/command/list_config_command_test.rb +72 -0
  161. data/test/command/list_dependencies_command_test.rb +46 -0
  162. data/test/command/list_deployments_command_test.rb +112 -0
  163. data/test/command/list_deploymentstages_command_test.rb +44 -0
  164. data/test/command/list_libraries_command_test.rb +42 -0
  165. data/test/command/list_librarylanguages_command_test.rb +34 -0
  166. data/test/command/list_librarysets_command_test.rb +33 -0
  167. data/test/command/list_objectroles_command_test.rb +41 -0
  168. data/test/command/list_objecttypes_command_test.rb +25 -0
  169. data/test/command/list_permissiongroups_command_test.rb +25 -0
  170. data/test/command/list_projects_command_test.rb +63 -0
  171. data/test/command/list_projecttypes_command_test.rb +39 -0
  172. data/test/command/list_rolepermissions_command_test.rb +39 -0
  173. data/test/command/list_roles_command_test.rb +46 -0
  174. data/test/command/list_runtimes_command_test.rb +30 -0
  175. data/test/command/list_service_types_command_test.rb +44 -0
  176. data/test/command/list_servicedefinitions_command_test.rb +44 -0
  177. data/test/command/list_serviceversions_command_test.rb +47 -0
  178. data/test/command/list_solutions_command_test.rb +48 -0
  179. data/test/command/list_users_command_test.rb +33 -0
  180. data/test/command/login_command_test.rb +83 -0
  181. data/test/command/logout_command_test.rb +30 -0
  182. data/test/command/pull_command_test.rb +229 -0
  183. data/test/command/push_command_test.rb +246 -0
  184. data/test/command/refresh_solution_command_test.rb +35 -0
  185. data/test/command/renew_command_test.rb +43 -0
  186. data/test/command/request_passwordchange_command_test.rb +31 -0
  187. data/test/command/show_group_command_test.rb +50 -0
  188. data/test/command/show_libraryset_command_test.rb +51 -0
  189. data/test/command/show_project_command_test.rb +57 -0
  190. data/test/command/show_projecttype_command_test.rb +46 -0
  191. data/test/command/show_role_command_test.rb +37 -0
  192. data/test/command/show_solution_command_test.rb +59 -0
  193. data/test/command/show_user_command_test.rb +50 -0
  194. data/test/command/submit_deployment_command_test.rb +37 -0
  195. data/test/command/target_command_test.rb +58 -0
  196. data/test/command/unarchive_project_command_test.rb +45 -0
  197. data/test/command/unarchive_solution_command_test.rb +43 -0
  198. data/test/command/unbind_service_command_test.rb +48 -0
  199. data/test/command/undefine_service_command_test.rb +49 -0
  200. data/test/command/update_config_command_test.rb +74 -0
  201. data/test/command/update_deploymentproject_command_test.rb +77 -0
  202. data/test/command/update_group_command_test.rb +69 -0
  203. data/test/command/update_librarylanguage_command_test.rb +43 -0
  204. data/test/command/update_libraryset_command_test.rb +113 -0
  205. data/test/command/update_project_command_test.rb +56 -0
  206. data/test/command/update_role_command_test.rb +42 -0
  207. data/test/command/update_rolepermissions_command_test.rb +54 -0
  208. data/test/command/update_solution_command_test.rb +58 -0
  209. data/test/command/update_user_command_test.rb +76 -0
  210. data/test/command/vote_deployment_command_test.rb +33 -0
  211. data/test/config_test.rb +70 -0
  212. data/test/successful_test.rb +21 -0
  213. data/test/test_files/pom.xml +273 -0
  214. data/test/test_helper.rb +25 -0
  215. metadata +470 -0
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+
3
+ class DeleteLibrarysetCommand < Test::Unit::TestCase
4
+ should_require_login
5
+
6
+ context "execute" do
7
+ setup do
8
+ @mock_client = mock("Client")
9
+ @command = EPC::Command::DeleteLibrarysetCommand.new(@mock_client)
10
+ end
11
+
12
+ should "fail if no names are specified" do
13
+ @command.expects(:say).with("You need to specify a set id/name")
14
+ @command.expects(:say).with(EPC::Help::COMMAND_USAGES[:delete_libraryset])
15
+ assert_equal(@command.execute, 1)
16
+ end
17
+
18
+ should "fail if set id can't be determined" do
19
+ @command.expects(:ask_yn).returns("Y")
20
+ @command.expects(:get_resource_id).with(EPC::Config::LIBRARY_SETS_PATH, :name, "rubyset").returns(nil)
21
+ @command.expects(:say).with("Set could not be determined")
22
+
23
+ assert_equal(@command.execute("rubyset"), 1)
24
+ end
25
+
26
+ should "fail if status is not 200" do
27
+ @command.expects(:ask_yn).returns("Y")
28
+ @mock_client.expects(:delete).with(EPC::Config::LIBRARY_SETS_PATH + "/1").
29
+ returns([404, {:message => "Not Found"}, {}])
30
+ @command.expects(:say).with("Request failed: [Not Found]")
31
+ assert_equal(@command.execute(1), 404)
32
+ end
33
+
34
+
35
+ should "delete a set specified by id" do
36
+ @command.expects(:ask_yn).returns("Y")
37
+ @mock_client.expects(:delete).with(EPC::Config::LIBRARY_SETS_PATH + "/1").
38
+ returns([200, {}, {}])
39
+ @command.expects(:say).with("Set deleted")
40
+
41
+ assert_equal(@command.execute(1), 200)
42
+ end
43
+
44
+
45
+ should "delete a set specified by name" do
46
+ @command.expects(:ask_yn).returns("Y")
47
+ @command.expects(:get_resource_id).with(EPC::Config::LIBRARY_SETS_PATH, :name, "rubyset").returns(1)
48
+ @mock_client.expects(:delete).with(EPC::Config::LIBRARY_SETS_PATH + "/1").
49
+ returns([200, {}, {}])
50
+ @command.expects(:say).with("Set deleted")
51
+
52
+ assert_equal(@command.execute("rubyset"), 200)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,76 @@
1
+ require File.expand_path "../../../lib/epc", __FILE__
2
+ require "test/unit"
3
+ require 'shoulda'
4
+ require 'mocha'
5
+
6
+ class DeleteProjectCommandTest < Test::Unit::TestCase
7
+ context "pre-execution checks" do
8
+ setup do
9
+ @mock_client = mock("Client")
10
+ @command = EPC::Command::DeleteProjectCommand.new(@mock_client)
11
+ end
12
+
13
+ should "fail no project specified" do
14
+ @command.expects(:infer_project_context).returns(nil)
15
+ @command.expects(:say).with("Project name could not be inferred")
16
+ @command.expects(:say).with(EPC::Help::COMMAND_USAGES[:delete_project])
17
+ assert_equal(@command.execute, 1)
18
+ end
19
+ end
20
+ context "deletion" do
21
+ setup do
22
+ @mock_client = mock("Client")
23
+ @command = EPC::Command::DeleteProjectCommand.new(@mock_client)
24
+ @command.expects(:infer_solution_context).returns([1, "FirstSolution"])
25
+ @command.expects(:infer_project_context).returns([1, "FirstProject"])
26
+ @command.expects(:ask_yn).returns("y")
27
+ end
28
+
29
+ should "fail if status is not 201" do
30
+ @mock_client.expects(:delete).with(EPC::Config::PROJECTS_PATH + "/1").
31
+ returns([404, {:message => "Not Found"}, {}])
32
+
33
+ @command.expects(:say).with("Project could not be deleted. Delete failed with: [Not Found]")
34
+ assert_equal(@command.execute, 404)
35
+ end
36
+
37
+ should "delete the project" do
38
+ @mock_client.expects(:delete).with(EPC::Config::PROJECTS_PATH + "/1").
39
+ returns([200, {}, {}])
40
+ EPC::Config.expects(:is_project_dir?).returns(true)
41
+ @command.expects(:remove_project_metadata).with(File.expand_path("."), "FirstProject")
42
+
43
+ @command.expects(:say).with("Project deleted.")
44
+ assert_equal(@command.execute, 200)
45
+ end
46
+
47
+
48
+
49
+ end
50
+
51
+ context "metadata removal" do
52
+ setup do
53
+ @mock_client = mock("Client")
54
+ @command = EPC::Command::DeleteProjectCommand.new(@mock_client)
55
+ end
56
+
57
+ should "when executed from solution directory, should delete metadata file from project directory" do
58
+ EPC::Config.expects(:is_solution_dir?).with("/path/to/solution").returns(true)
59
+ File.expects(:join).with("/path/to/solution", "project_name", ".epc_project").returns("/path/to/project/.epc_project")
60
+ FileTest.expects(:exist?).with("/path/to/project/.epc_project").returns(true)
61
+ File.expects(:delete).with("/path/to/project/.epc_project")
62
+ @command.send(:remove_project_metadata, "/path/to/solution", "project_name")
63
+ end
64
+
65
+ should "when executed from project directory, should delete metadata file" do
66
+ EPC::Config.expects(:is_solution_dir?).with("/path/to/project").returns(false)
67
+ File.expects(:join).with("/path/to/project", ".epc_project").returns("/path/to/project/.epc_project")
68
+ FileTest.expects(:exist?).with("/path/to/project/.epc_project").returns(true)
69
+ File.expects(:delete).with("/path/to/project/.epc_project")
70
+ @command.send(:remove_project_metadata, "/path/to/project", "project_name")
71
+ end
72
+
73
+ end
74
+
75
+
76
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ class DeleteRoleCommandTest < Test::Unit::TestCase
4
+ should_require_login
5
+
6
+ context "execute" do
7
+ setup do
8
+ @mock_client = mock("Client")
9
+ @command = EPC::Command::DeleteRoleCommand.new(@mock_client)
10
+ end
11
+
12
+ should "fail if status is not 200" do
13
+ @command.expects(:ask_yn).returns("Y")
14
+ @mock_client.expects(:delete).with(EPC::Config::ROLES_PATH + "/1/system/true").
15
+ returns([404, {:message => "Not Found"}, {}])
16
+ @command.expects(:say).with("Request failed: [Not Found]")
17
+ assert_equal(@command.execute(1), 404)
18
+ end
19
+
20
+
21
+ should "delete a role specified by id" do
22
+ @command.expects(:ask_yn).returns("Y")
23
+ @mock_client.expects(:delete).with(EPC::Config::ROLES_PATH + "/1/system/true").
24
+ returns([200, {}, {}])
25
+ @command.expects(:say).with("Role deleted")
26
+
27
+ assert_equal(@command.execute(1), 200)
28
+ end
29
+
30
+
31
+ should "delete a role specified by name" do
32
+ @command.expects(:ask_yn).returns("Y")
33
+ @command.expects(:retrieve_system_role_identifier).returns(1)
34
+ @mock_client.expects(:delete).with(EPC::Config::ROLES_PATH + "/1/system/true").
35
+ returns([200, {}, {}])
36
+ @command.expects(:say).with("Role deleted")
37
+
38
+ assert_equal(@command.execute("admins"), 200)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+
3
+ class DeleteServiceversionCommandTest < Test::Unit::TestCase
4
+ should_require_login
5
+
6
+ context "execute" do
7
+ setup do
8
+ @mock_client = mock("Client")
9
+ @command = EPC::Command::DeleteServiceversionCommand.new(@mock_client)
10
+ end
11
+
12
+ should "fail if no service version identifier specified" do
13
+ @command.expects(:say).with("You must specify a service version identifier")
14
+ @command.expects(:say).with(EPC::Help::COMMAND_USAGES[:delete_serviceversion])
15
+
16
+ assert_equal(@command.execute, 1)
17
+ end
18
+
19
+ should "fail if service label specified without definition_name" do
20
+ @command.expects(:ask_yn).returns("Y")
21
+ @command.expects(:say).with("You must specify the definition name")
22
+
23
+ @command.expects(:say).with(EPC::Help::COMMAND_USAGES[:delete_serviceversion])
24
+ assert_equal(@command.execute("main_db"), 1)
25
+ end
26
+
27
+ should "query core for service-version id and show a message if it can't be found" do
28
+ @command.expects(:ask_yn).returns("Y")
29
+ @mock_client.expects(:get)
30
+ @command.expects(:say).with("Service version not found.")
31
+
32
+ assert_equal(@command.execute("main_db", "definition"), 1)
33
+ end
34
+
35
+ should "fail if status is not 200" do
36
+ @command.expects(:ask_yn).returns("Y")
37
+ @mock_client.expects(:delete).with(EPC::Config::SERVICE_VERSIONS_PATH + "/1").
38
+ returns([404, {:message => "Not Found"}, {}])
39
+
40
+ @command.expects(:say).with("Request failed: [Not Found]")
41
+ assert_equal(@command.execute(1), 404)
42
+ end
43
+
44
+ should "delete the service version from core" do
45
+ @command.expects(:ask_yn).returns("Y")
46
+ @mock_client.expects(:delete).with(EPC::Config::SERVICE_VERSIONS_PATH + "/1").
47
+ returns([200, {}, {}])
48
+
49
+ @command.expects(:say).with("Service version deleted.")
50
+ assert_equal(@command.execute(1), 200)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,79 @@
1
+ require File.expand_path "../../../lib/epc", __FILE__
2
+ require "test/unit"
3
+ require 'shoulda'
4
+ require 'mocha'
5
+
6
+ class DeleteSolutionCommandTest < Test::Unit::TestCase
7
+ context "pre-execution checks" do
8
+
9
+ setup do
10
+ @mock_client = mock("Client")
11
+ @command = EPC::Command::DeleteSolutionCommand.new(@mock_client)
12
+ end
13
+
14
+ should "fail if solution id can't be determined" do
15
+ @command.expects(:infer_solution_context).returns(nil)
16
+ @command.expects(:say).with("Solution could not be inferred")
17
+
18
+ assert_equal(@command.execute("FirstSolution"), 1)
19
+ end
20
+ end
21
+
22
+ context "deletion" do
23
+ setup do
24
+ @mock_client = mock("Client")
25
+ @command = EPC::Command::DeleteSolutionCommand.new(@mock_client)
26
+ @command.expects(:infer_solution_context).returns([1, "FirstSolution"])
27
+ @command.expects(:ask).returns("y")
28
+ end
29
+
30
+ should "fail if status is not 201" do
31
+ @mock_client.expects(:delete).with(EPC::Config::SOLUTIONS_PATH + "/1").
32
+ returns([404, {:message => "Not Found"}, {}])
33
+
34
+ @command.expects(:say).with("Solution could not be deleted. Delete failed with: [Not Found]")
35
+ assert_equal(@command.execute, 404)
36
+ end
37
+
38
+
39
+ should "delete the solution" do
40
+ EPC::Config.expects(:is_project_dir?).returns(false)
41
+ EPC::Config.expects(:is_solution_dir?).returns(false)
42
+ @mock_client.expects(:delete).with(EPC::Config::SOLUTIONS_PATH + "/1").
43
+ returns([200, {}, {}])
44
+
45
+ @command.expects(:say).with("Solution deleted.")
46
+ assert_equal(@command.execute, 200)
47
+ end
48
+
49
+ should "remove solution metadata if directory is solution/project" do
50
+ EPC::Config.expects(:is_solution_dir?).returns(true)
51
+ @command.expects(:project_solution_path)
52
+ @mock_client.expects(:delete).with(EPC::Config::SOLUTIONS_PATH + "/1").
53
+ returns([200, {}, {}])
54
+
55
+ @command.expects(:remove_solution_metadata)
56
+
57
+ @command.expects(:say).with("Solution deleted.")
58
+ assert_equal(@command.execute, 200)
59
+ end
60
+
61
+ end
62
+
63
+ context "metadata removal" do
64
+ setup do
65
+ @mock_client = mock("Client")
66
+ @command = EPC::Command::DeleteSolutionCommand.new(@mock_client)
67
+ end
68
+
69
+ should "delete the project metadata files first, then the solution metadata" do
70
+ Dir.expects(:glob).with("/path/to/solution/**/").returns(["/path/to/solution/project1"])
71
+
72
+ FileTest.expects(:exist?).with("/path/to/solution/project1/.epc_project").returns(true)
73
+ File.expects(:delete).with("/path/to/solution/project1/.epc_project")
74
+ FileTest.expects(:exist?).with("/path/to/solution/.epc_solution").returns(true)
75
+ File.expects(:delete).with("/path/to/solution/.epc_solution")
76
+ @command.send(:remove_solution_metadata, "/path/to/solution")
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,56 @@
1
+ require 'test_helper'
2
+
3
+ class DeleteUserCommandTest < Test::Unit::TestCase
4
+ should_require_login
5
+
6
+ context "execute" do
7
+ setup do
8
+ @mock_client = mock("Client")
9
+ @command = EPC::Command::DeleteUserCommand.new(@mock_client)
10
+ end
11
+
12
+ should "fail if no user is specified" do
13
+ assert_raise EPC::Error::FatalError do
14
+ assert_equal(@command.execute, 1)
15
+ end
16
+ end
17
+
18
+ should "fail if status is not 200" do
19
+ @command.expects(:ask_yn).returns("Y")
20
+ @mock_client.expects(:delete).with(EPC::Config::USERS_PATH + "/1").
21
+ returns([404, {:message => "Not Found"}, {}])
22
+ @command.expects(:say).with("Request failed: [Not Found]")
23
+ assert_equal(@command.execute(1), 404)
24
+ end
25
+
26
+ should "fail if user_id can't be determined" do
27
+ @command.expects(:ask_yn).returns("Y")
28
+ @command.expects(:get_resource_id).with(EPC::Config::USERS_PATH, :email, "admin").returns(nil)
29
+ assert_raise EPC::Error::FatalError do
30
+ assert_equal(@command.execute("admin"), 1)
31
+ end
32
+ end
33
+
34
+
35
+
36
+ should "delete a user specified by id" do
37
+ @command.expects(:ask_yn).returns("Y")
38
+ @mock_client.expects(:delete).with(EPC::Config::USERS_PATH + "/1").
39
+ returns([200, {}, {}])
40
+ @command.expects(:say).with("User deleted")
41
+
42
+ assert_equal(@command.execute(1), 200)
43
+ end
44
+
45
+
46
+ should "delete a user specified by name" do
47
+ @command.expects(:ask_yn).returns("Y")
48
+ @command.expects(:get_resource_id).with(EPC::Config::USERS_PATH, :email, "admin").returns(1)
49
+ @mock_client.expects(:delete).with(EPC::Config::USERS_PATH + "/1").
50
+ returns([200, {}, {}])
51
+ @command.expects(:say).with("User deleted")
52
+
53
+ assert_equal(@command.execute("admin"), 200)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,185 @@
1
+ require 'test_helper'
2
+
3
+ class DeployCommandTest < Test::Unit::TestCase
4
+ should_require_login
5
+
6
+ context "execute" do
7
+ setup do
8
+ @mock_client = mock("Client")
9
+ @mock_config = mock("Config")
10
+ @command = EPC::Command::DeployCommand.new(@mock_client)
11
+ @deployment_hash = { :id => 1, :status => "running", }
12
+ end
13
+
14
+ should "fail if current directory is not a solution/project directory" do
15
+ EPC::Config.expects(:is_solution_dir?).returns(false)
16
+ EPC::Config.expects(:is_project_dir?).returns(false)
17
+
18
+ @command.expects(:say).with("This is not a solution directory.")
19
+ @command.execute
20
+ end
21
+
22
+ should "prompt the user about deploying the entire solution if no deployment_id specified" do
23
+ EPC::Config.expects(:is_solution_dir?).returns(true)
24
+ @command.expects(:infer_solution_context).returns([1, "FirstSolution"])
25
+ @command.expects(:ask_yn).returns("N")
26
+
27
+ assert_equal(@command.execute, 1)
28
+ end
29
+
30
+ context "atomic push/build/deploy" do
31
+ setup do
32
+ @command.options[:use_local] = true
33
+ EPC::Config.expects(:is_solution_dir?).returns(true)
34
+ @command.expects(:infer_solution_context).returns([1, "FirstSolution"])
35
+ @command.expects(:ask_yn).returns("Y")
36
+ end
37
+
38
+ should "fail if push fails" do
39
+ push_command = EPC::Command::PushCommand.new(@mock_client)
40
+ EPC::Command::PushCommand.expects(:new).returns(push_command)
41
+ push_command.expects(:execute_internal).returns(1)
42
+ assert_equal(@command.execute, 1)
43
+ end
44
+
45
+ should "fail if build fails" do
46
+ push_command = EPC::Command::PushCommand.new(@mock_client)
47
+ EPC::Command::PushCommand.expects(:new).returns(push_command)
48
+ push_command.expects(:execute_internal).returns([0, [{1 => 11}]])
49
+ build_command = EPC::Command::BuildCommand.new(@mock_client)
50
+ EPC::Command::BuildCommand.expects(:new).returns(build_command)
51
+ build_command.expects(:execute).returns(1)
52
+ assert_equal(@command.execute, 1)
53
+ end
54
+ end
55
+
56
+ should "poll" do
57
+ @command.options[:deployment_id] = 1
58
+ @command.expects(:poll_for_deployment_statuses).with(1).returns([true, @deployment_hash[:status]])
59
+ @command.expects(:say).with("Deploying 1")
60
+ @command.expects(:deploy).with(1).
61
+ returns([200, {:deployed_projects => [{ :id => 7, :status => "running" }]}])
62
+ @command.expects(:say).with("Deploying - ")
63
+ @command.expects(:display_statuses).with("running", [{ :id => 7, :status => "running" }])
64
+
65
+ assert_equal(@command.execute, 200)
66
+ end
67
+
68
+ should "report failure if it catches an exception" do
69
+ @command.options[:deployment_id] = 1
70
+ @command.expects(:poll_for_deployment_statuses).with(1).raises(StandardError.new("failed"))
71
+ @command.expects(:say).with("Deploying 1")
72
+ @command.expects(:deploy).with(1)
73
+ @command.expects(:say).with("Deploying - ")
74
+ @command.expects(:display_statuses).never
75
+ @command.expects(:say).with("Deploy failed [failed].")
76
+
77
+ assert_equal(@command.execute, 1)
78
+ end
79
+
80
+ end
81
+
82
+ context "show_deployment" do
83
+ setup do
84
+ @mock_client = mock("Client")
85
+ EPC::Config.target_file = '~/.epc_test_target'
86
+ @deployment_hash = { :id => 1, :status => "running", :projects => [{ :id => 7, :status => "running" }] }
87
+ end
88
+
89
+ should "return true if the status is 200" do
90
+ command = EPC::Command::DeployCommand.new(@mock_client)
91
+
92
+ @mock_client.expects(:get).with("/api/v1/deployments/1/status").
93
+ returns([200, @deployment_hash, {}])
94
+
95
+ status, code, deployment_status = command.send(:show_deployment, 1)
96
+
97
+ assert_equal(200, status)
98
+ assert_nil(code)
99
+ assert_equal(@deployment_hash[:status], deployment_status)
100
+ end
101
+
102
+ should "return nil status if the status is not 200" do
103
+ command = EPC::Command::DeployCommand.new(@mock_client)
104
+
105
+ @mock_client.expects(:get).with("/api/v1/deployments/1/status").
106
+ returns([404, { :message => "not found", :error_code => 901 }, {}])
107
+
108
+ status, response, deployment_status = command.send(:show_deployment, 1)
109
+
110
+ assert_equal(404, status)
111
+ assert_nil(deployment_status)
112
+ end
113
+ end
114
+
115
+ context "display_statuses" do
116
+ setup do
117
+ @mock_client = mock("Client")
118
+ @deployment_hash = { :id => 1, :status => "running", :projects => [{ :id => 7, :status => "running", :uris => ["uri_to_app"], :project_name => "FirstProject"}] }
119
+ end
120
+
121
+ should "display the status of everything in the deployment" do
122
+ command = EPC::Command::DeployCommand.new(@mock_client)
123
+
124
+ command.expects(:say).with("\nStatus = running\n")
125
+ command.expects(:say).with("FirstProject -> uri_to_app\n")
126
+
127
+ command.send(:display_statuses, @deployment_hash[:status], @deployment_hash[:projects])
128
+ end
129
+ end
130
+
131
+ context "deploy" do
132
+ setup do
133
+ @mock_client = mock("Client")
134
+ @command = EPC::Command::DeployCommand.new(@mock_client)
135
+ @response = { :id => 1 }
136
+ end
137
+
138
+ should "return true if the status is 200" do
139
+ @mock_client.expects(:put).with("/api/v1/deployments/1/deploy").
140
+ returns([200, { :deployment => @response }, {}])
141
+
142
+ status, response = @command.send(:deploy, 1)
143
+
144
+ assert_equal(200, status)
145
+ assert_equal(@response, response[:deployment])
146
+ end
147
+
148
+ should "return false if the status is not 200" do
149
+ @mock_client.expects(:put).with("/api/v1/deployments/1/deploy").
150
+ returns([404, { :message => "not found", :error_code => 901 }, {}])
151
+
152
+ assert_raise(RuntimeError) do
153
+ @command.send(:deploy, 1)
154
+ end
155
+
156
+ end
157
+ end
158
+
159
+ context "polling" do
160
+ setup do
161
+ @mock_client = mock("Client")
162
+ @command = EPC::Command::DeployCommand.new(@mock_client)
163
+ end
164
+
165
+ should "poll untill built" do
166
+ @command.expects(:show_deployment).with(1).returns([200, 1, "STARTED"])
167
+ assert_equal(@command.send(:poll_for_deployment_statuses, 1), [true, "STARTED"])
168
+ end
169
+
170
+ should "poll untill stopped" do
171
+ @command.expects(:show_deployment).with(1).returns([200, 1, "STOPPED"])
172
+ assert_equal(@command.send(:poll_for_deployment_statuses, 1), [true, "STOPPED"])
173
+ end
174
+
175
+ should "notify when poller fails" do
176
+ @command.expects(:show_deployment).with(1).returns([500, 501, nil])
177
+ @command.expects(:say).returns("Poller failure [HTTP Error(500): API error code (501)]")
178
+ @command.expects(:say).returns("Poller failed to get the deployment statuses. Aborting.")
179
+ assert_equal(@command.send(:poll_for_deployment_statuses, 1), [false, nil])
180
+ end
181
+
182
+ end
183
+
184
+
185
+ end