vraptor-scaffold 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. data/.travis.yml +7 -0
  2. data/CHANGELOG.rdoc +164 -0
  3. data/Gemfile.lock +5 -8
  4. data/README.textile +20 -7
  5. data/bin/vraptor +1 -1
  6. data/index.sample.html +169 -0
  7. data/lib/vraptor-scaffold.rb +10 -29
  8. data/lib/vraptor-scaffold/configuration.rb +27 -4
  9. data/lib/vraptor-scaffold/execution.rb +24 -0
  10. data/lib/vraptor-scaffold/generators/app/app_generator.rb +196 -0
  11. data/lib/vraptor-scaffold/generators/{app_generator → app}/dependency.rb +0 -0
  12. data/lib/vraptor-scaffold/generators/app/dependency_manager.rb +53 -0
  13. data/lib/vraptor-scaffold/generators/{app_generator → app}/freemarker_template_engine.rb +0 -0
  14. data/lib/vraptor-scaffold/generators/{app_generator → app}/jsp_template_engine.rb +0 -0
  15. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/build.gradle.erb +19 -1
  16. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/build.properties.erb +0 -0
  17. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/build.xml +6 -2
  18. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/decorators.erb +0 -0
  19. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/eclipse/classpath.erb +0 -5
  20. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/eclipse/project.erb +0 -0
  21. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/eclipse/settings/org.eclipse.jdt.core.prefs +0 -0
  22. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/eclipse/settings/org.eclipse.wst.common.component.tt +0 -0
  23. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/eclipse/settings/org.eclipse.wst.common.project.facet.core.xml +0 -0
  24. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/eclipse/settings/org.eclipse.wst.jsdt.ui.superType.container +0 -0
  25. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/eclipse/settings/org.eclipse.wst.jsdt.ui.superType.name +0 -0
  26. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/freemarker/freemarker-web.xml +0 -0
  27. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/freemarker/infrastructure/FreemarkerPathResolver.java.tt +0 -0
  28. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/freemarker/macros/html.ftl +0 -0
  29. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/freemarker/main.ftl +0 -0
  30. data/lib/vraptor-scaffold/generators/app/templates/heroku/Main.java +21 -0
  31. data/lib/vraptor-scaffold/generators/app/templates/heroku/Procfile +1 -0
  32. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/ivy-2.2.0.jar +0 -0
  33. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/ivy.erb +1 -1
  34. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/jsp/jsp-web.xml +0 -0
  35. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/jsp/main.jsp +2 -2
  36. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/jsp/prelude.jspf +0 -0
  37. data/lib/vraptor-scaffold/generators/{app_generator/templates/src/models/Entity.java.tt → app/templates/models/Entity.erb} +1 -1
  38. data/lib/vraptor-scaffold/generators/app/templates/orm/Repository-hibernate.java.tt +50 -0
  39. data/lib/vraptor-scaffold/generators/{app_generator/templates/src/repositories/Repository.java.tt → app/templates/orm/Repository-jpa.java.tt} +3 -3
  40. data/lib/vraptor-scaffold/generators/app/templates/orm/hibernate.cfg.xml +7 -0
  41. data/lib/vraptor-scaffold/generators/app/templates/orm/persistence.xml +10 -0
  42. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/pom.erb +29 -13
  43. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/resources-test/.empty_directory +0 -0
  44. data/lib/vraptor-scaffold/generators/app/templates/resources/hibernate.properties +16 -0
  45. data/lib/vraptor-scaffold/generators/app/templates/resources/log4j.properties +4 -0
  46. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/resources/messages.properties +0 -0
  47. data/lib/vraptor-scaffold/generators/app/templates/vraptor-scaffold.erb +7 -0
  48. data/lib/vraptor-scaffold/generators/{app_generator/templates/webapp/WEB-INF/web.xml → app/templates/webapp/WEB-INF/web.xml.tt} +2 -2
  49. data/lib/vraptor-scaffold/generators/{app_generator/templates/src-test/controllers → app/templates/webapp/images}/.empty_directory +0 -0
  50. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/webapp/index.jsp +0 -0
  51. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/webapp/stylesheets/common.css +0 -0
  52. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/webapp/stylesheets/scaffold.css +0 -0
  53. data/lib/vraptor-scaffold/generators/{app_generator → app}/templates/webapp/stylesheets/stylesheets.css +0 -0
  54. data/lib/vraptor-scaffold/generators/plugin/plugin_generator.rb +42 -0
  55. data/lib/vraptor-scaffold/generators/plugin/vraptor_gem.rb +36 -0
  56. data/lib/vraptor-scaffold/generators/{scaffold_generator → scaffold}/attribute.rb +1 -1
  57. data/lib/vraptor-scaffold/generators/{scaffold_generator → scaffold}/base_scaffold.rb +6 -2
  58. data/lib/vraptor-scaffold/generators/{scaffold_generator → scaffold}/controller_generator/controller_generator.rb +3 -3
  59. data/lib/vraptor-scaffold/generators/{scaffold_generator → scaffold}/controller_generator/templates/controller.erb +3 -3
  60. data/lib/vraptor-scaffold/generators/{scaffold_generator → scaffold}/controller_generator/templates/controller_test.erb +1 -1
  61. data/lib/vraptor-scaffold/generators/scaffold/model_generator/model_generator.rb +20 -0
  62. data/lib/vraptor-scaffold/generators/{scaffold_generator → scaffold}/model_generator/templates/model.erb +3 -3
  63. data/lib/vraptor-scaffold/generators/{scaffold_generator → scaffold}/model_generator/templates/model_test.erb +1 -1
  64. data/lib/vraptor-scaffold/generators/scaffold/repository_generator/repository_generator.rb +27 -0
  65. data/lib/vraptor-scaffold/generators/{scaffold_generator → scaffold}/repository_generator/templates/repository.erb +3 -3
  66. data/lib/vraptor-scaffold/generators/scaffold/repository_generator/templates/repository_impl.erb +16 -0
  67. data/lib/vraptor-scaffold/generators/{scaffold_generator → scaffold}/repository_generator/templates/repository_test.erb +1 -1
  68. data/lib/vraptor-scaffold/generators/{scaffold_generator → scaffold}/scaffold_generator.rb +0 -0
  69. data/lib/vraptor-scaffold/generators/scaffold/template_engine_generator/freemarker_generator/freemarker_generator.rb +18 -0
  70. data/lib/vraptor-scaffold/generators/{scaffold_generator → scaffold/template_engine_generator}/freemarker_generator/templates/edit.erb +0 -0
  71. data/lib/vraptor-scaffold/generators/{scaffold_generator → scaffold/template_engine_generator}/freemarker_generator/templates/form.erb +4 -4
  72. data/lib/vraptor-scaffold/generators/scaffold/template_engine_generator/freemarker_generator/templates/index.erb +36 -0
  73. data/lib/vraptor-scaffold/generators/{scaffold_generator → scaffold/template_engine_generator}/freemarker_generator/templates/new.erb +0 -0
  74. data/lib/vraptor-scaffold/generators/scaffold/template_engine_generator/freemarker_generator/templates/show.erb +14 -0
  75. data/lib/vraptor-scaffold/generators/scaffold/template_engine_generator/jsp_generator/jsp_generator.rb +18 -0
  76. data/lib/vraptor-scaffold/generators/{scaffold_generator → scaffold/template_engine_generator}/jsp_generator/templates/edit.erb +0 -0
  77. data/lib/vraptor-scaffold/generators/{scaffold_generator → scaffold/template_engine_generator}/jsp_generator/templates/form.erb +4 -4
  78. data/lib/vraptor-scaffold/generators/{scaffold_generator → scaffold/template_engine_generator}/jsp_generator/templates/index.erb +6 -6
  79. data/lib/vraptor-scaffold/generators/{scaffold_generator → scaffold/template_engine_generator}/jsp_generator/templates/new.erb +0 -0
  80. data/lib/vraptor-scaffold/generators/scaffold/template_engine_generator/jsp_generator/templates/show.erb +14 -0
  81. data/lib/vraptor-scaffold/generators/scaffold/template_engine_generator/template_engine_generator.rb +21 -0
  82. data/lib/vraptor-scaffold/load_paths.rb +13 -21
  83. data/lib/vraptor-scaffold/runner.rb +11 -0
  84. data/lib/vraptor-scaffold/runner/commands_help.rb +13 -0
  85. data/lib/vraptor-scaffold/runner/configure.rb +21 -0
  86. data/lib/vraptor-scaffold/runner/generator.rb +15 -0
  87. data/lib/vraptor-scaffold/runner/help.rb +12 -0
  88. data/lib/vraptor-scaffold/runner/plugin.rb +19 -0
  89. data/lib/vraptor-scaffold/runner/scaffold.rb +16 -0
  90. data/lib/vraptor-scaffold/version.rb +1 -1
  91. data/spec/resources/vraptor-scaffold.properties +5 -0
  92. data/spec/simple_custom_plugin.rb +10 -0
  93. data/spec/spec_helper.rb +5 -6
  94. data/spec/vraptor-scaffold/configuration_spec.rb +88 -4
  95. data/spec/vraptor-scaffold/execution_spec.rb +47 -0
  96. data/spec/vraptor-scaffold/generators/{app_generator → app}/app_generator_spec.rb +136 -54
  97. data/spec/vraptor-scaffold/generators/{app_generator → app}/dependency_manager_spec.rb +1 -1
  98. data/spec/vraptor-scaffold/generators/{app_generator → app}/dependency_spec.rb +0 -0
  99. data/spec/vraptor-scaffold/generators/{app_generator → app}/freemarker_template_engine_spec.rb +1 -1
  100. data/spec/vraptor-scaffold/generators/{app_generator → app}/jsp_template_engine_spec.rb +0 -0
  101. data/spec/vraptor-scaffold/generators/{app_generator → app}/templates/Entity.java +1 -1
  102. data/spec/vraptor-scaffold/generators/{app_generator → app}/templates/FreemarkerPathResolver.java +0 -0
  103. data/spec/vraptor-scaffold/generators/{app_generator → app}/templates/Repository.java +3 -3
  104. data/spec/vraptor-scaffold/generators/{app_generator → app}/templates/build.gradle +24 -5
  105. data/spec/vraptor-scaffold/generators/{app_generator → app}/templates/build.properties +0 -0
  106. data/spec/vraptor-scaffold/generators/{app_generator → app}/templates/decorators-jsp.xml +0 -0
  107. data/spec/vraptor-scaffold/generators/{app_generator → app}/templates/decorators.xml +0 -0
  108. data/spec/vraptor-scaffold/generators/{app_generator → app}/templates/freemarker-web.xml +2 -2
  109. data/spec/vraptor-scaffold/generators/{app_generator → app}/templates/ivy.xml +6 -5
  110. data/spec/vraptor-scaffold/generators/{app_generator → app}/templates/jsp-web.xml +1 -1
  111. data/spec/vraptor-scaffold/generators/app/templates/pom-heroku.xml +168 -0
  112. data/spec/vraptor-scaffold/generators/{app_generator → app}/templates/pom.xml +11 -14
  113. data/spec/vraptor-scaffold/generators/app/templates/vraptor-scaffold.properties +7 -0
  114. data/spec/vraptor-scaffold/generators/plugin/expected_configs/build.gradle +61 -0
  115. data/spec/vraptor-scaffold/generators/plugin/expected_configs/default_org_build.gradle +61 -0
  116. data/spec/vraptor-scaffold/generators/plugin/expected_configs/default_org_ivy.xml +40 -0
  117. data/spec/vraptor-scaffold/generators/plugin/expected_configs/default_org_pom.xml +147 -0
  118. data/spec/vraptor-scaffold/generators/plugin/expected_configs/ivy.xml +40 -0
  119. data/spec/vraptor-scaffold/generators/plugin/expected_configs/pom.xml +147 -0
  120. data/spec/vraptor-scaffold/generators/plugin/plugin_generator_spec.rb +130 -0
  121. data/spec/vraptor-scaffold/generators/{scaffold_generator → scaffold}/attribute_spec.rb +13 -9
  122. data/spec/vraptor-scaffold/generators/scaffold/base_scaffold_spec.rb +73 -0
  123. data/spec/vraptor-scaffold/generators/{scaffold_generator → scaffold}/controller_generator/controller_generator_spec.rb +18 -9
  124. data/spec/vraptor-scaffold/generators/{scaffold_generator → scaffold}/controller_generator/templates/ProductController.java +3 -3
  125. data/spec/vraptor-scaffold/generators/scaffold/freemarker_generator/freemarker_generator_spec.rb +74 -0
  126. data/spec/vraptor-scaffold/generators/scaffold/jsp_generator/jsp_generator_spec.rb +75 -0
  127. data/spec/vraptor-scaffold/generators/scaffold/model_generator/model_generator_spec.rb +50 -0
  128. data/spec/vraptor-scaffold/generators/{scaffold_generator → scaffold}/model_generator/templates/Product.java +6 -6
  129. data/spec/vraptor-scaffold/generators/scaffold/model_generator/templates/hibernate.cfg.xml +8 -0
  130. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/repository_generator_spec.rb +60 -0
  131. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ClientRepository.java +22 -0
  132. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ClientRepositoryImpl.java +16 -0
  133. data/spec/vraptor-scaffold/generators/{scaffold_generator → scaffold}/repository_generator/templates/ProductRepository.java +3 -3
  134. data/spec/vraptor-scaffold/generators/{scaffold_generator → scaffold}/repository_generator/templates/ProductRepositoryImpl.java +3 -3
  135. data/spec/vraptor-scaffold/generators/{scaffold_generator → scaffold}/scaffold_generator_spec.rb +0 -0
  136. data/spec/vraptor-scaffold/runner/commands_help_spec.rb +12 -0
  137. data/spec/vraptor-scaffold/runner/configure_spec.rb +12 -0
  138. data/spec/vraptor-scaffold/runner/generator_spec.rb +31 -0
  139. data/spec/vraptor-scaffold/runner/help_spec.rb +29 -0
  140. data/spec/vraptor-scaffold/runner/plugin_spec.rb +45 -0
  141. data/spec/vraptor-scaffold/runner/scaffold_spec.rb +35 -0
  142. data/spec/vraptor-scaffold_spec.rb +1 -94
  143. data/vraptor-scaffold.gemspec +3 -3
  144. metadata +137 -140
  145. data/History.txt +0 -128
  146. data/lib/vraptor-scaffold/generators/app_generator/app_generator.rb +0 -102
  147. data/lib/vraptor-scaffold/generators/app_generator/dependency_manager.rb +0 -37
  148. data/lib/vraptor-scaffold/generators/app_generator/templates/ivysettings.xml +0 -9
  149. data/lib/vraptor-scaffold/generators/app_generator/templates/resources/META-INF/persistence.xml +0 -20
  150. data/lib/vraptor-scaffold/generators/app_generator/templates/resources/log4j.properties +0 -4
  151. data/lib/vraptor-scaffold/generators/app_generator/templates/src-test/models/.empty_directory +0 -0
  152. data/lib/vraptor-scaffold/generators/app_generator/templates/src-test/repositories/.empty_directory +0 -0
  153. data/lib/vraptor-scaffold/generators/app_generator/templates/src/controllers/.empty_directory +0 -0
  154. data/lib/vraptor-scaffold/generators/app_generator/templates/vraptor-scaffold.erb +0 -2
  155. data/lib/vraptor-scaffold/generators/app_generator/templates/webapp/images/.empty_directory +0 -0
  156. data/lib/vraptor-scaffold/generators/app_generator/templates/webapp/javascripts/application.js +0 -0
  157. data/lib/vraptor-scaffold/generators/app_generator/templates/webapp/javascripts/jquery.min.js +0 -16
  158. data/lib/vraptor-scaffold/generators/scaffold_generator/freemarker_generator/freemarker_generator.rb +0 -22
  159. data/lib/vraptor-scaffold/generators/scaffold_generator/freemarker_generator/templates/index.erb +0 -36
  160. data/lib/vraptor-scaffold/generators/scaffold_generator/freemarker_generator/templates/show.erb +0 -14
  161. data/lib/vraptor-scaffold/generators/scaffold_generator/jsp_generator/jsp_generator.rb +0 -22
  162. data/lib/vraptor-scaffold/generators/scaffold_generator/jsp_generator/templates/show.erb +0 -14
  163. data/lib/vraptor-scaffold/generators/scaffold_generator/model_generator/model_generator.rb +0 -11
  164. data/lib/vraptor-scaffold/generators/scaffold_generator/repository_generator/repository_generator.rb +0 -12
  165. data/lib/vraptor-scaffold/generators/scaffold_generator/repository_generator/templates/repository_impl.erb +0 -16
  166. data/spec/vraptor-scaffold/generators/scaffold_generator/base_scaffold_spec.rb +0 -41
  167. data/spec/vraptor-scaffold/generators/scaffold_generator/freemarker_generator/freemarker_generator_spec.rb +0 -36
  168. data/spec/vraptor-scaffold/generators/scaffold_generator/jsp_generator/jsp_generator_spec.rb +0 -34
  169. data/spec/vraptor-scaffold/generators/scaffold_generator/model_generator/model_generator_spec.rb +0 -25
  170. data/spec/vraptor-scaffold/generators/scaffold_generator/repository_generator/repository_generator_spec.rb +0 -31
@@ -1,3 +1,3 @@
1
1
  module VraptorScaffold
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,2 +1,7 @@
1
+ build_tool: mvn
1
2
  package: app
2
3
  template_engine: jsp
4
+ orm: jpa
5
+ models_package: model
6
+ controllers_package: controller
7
+ repositories_package: repository
@@ -0,0 +1,10 @@
1
+ class SimpleCustomPlugin
2
+ attr_reader :invoked, :args
3
+ def initialize(args)
4
+ @args = args
5
+ end
6
+ def invoke_all
7
+ @invoked = true
8
+ self
9
+ end
10
+ end
@@ -3,7 +3,7 @@ require 'spec/autorun'
3
3
  require File.dirname(__FILE__) + '/../lib/vraptor-scaffold'
4
4
 
5
5
  def build_attributes
6
- [Attribute.new("name", "string"), Attribute.new("flag", "boolean")]
6
+ [Attribute.new("name", "string"), Attribute.new("myFlag", "boolean")]
7
7
  end
8
8
 
9
9
  def mock_config_file
@@ -11,9 +11,8 @@ def mock_config_file
11
11
  Configuration.stub!(:config).and_return(file)
12
12
  end
13
13
 
14
- def exists_and_identical?(source, destination)
15
- File.exists?(destination).should be_true
16
- FileUtils.should be_identical(source, destination)
14
+ def exists_and_identical?(source, created)
15
+ c = File.open(created).read.gsub( /\r/m, "" )
16
+ c2 = File.open(source).read.gsub( /\r/m, "" )
17
+ c.should be == c2
17
18
  end
18
-
19
-
@@ -30,22 +30,47 @@ describe Configuration do
30
30
  Configuration::META_INF.should == "#{Configuration::WEB_APP}/META-INF"
31
31
  end
32
32
 
33
- it "should configure properties name" do
33
+ it "should configure scaffold properties" do
34
34
  Configuration::FILENAME.should == "#{Configuration::META_INF}/vraptor-scaffold.properties"
35
35
  end
36
36
 
37
37
  context "load config file" do
38
38
  before(:each) do
39
- config = {"template_engine" => "jsp", "package" => "br.com.caelum"}
39
+ config = {"template_engine" => "jsp", "package" => "br.com.caelum", "orm" => "jpa", "models_package" => "model",
40
+ "controllers_package" => "controller", "repositories_package" => "repository"}
40
41
  YAML.stub!(:load_file).with(Configuration::FILENAME).and_return(config)
41
42
  end
42
43
 
44
+ it "should know models package" do
45
+ Configuration.models_package.should == "model"
46
+ end
47
+
48
+ it "should know controllers package" do
49
+ Configuration.controllers_package.should == "controller"
50
+ end
51
+
52
+ it "should know repositories package" do
53
+ Configuration.repositories_package.should == "repository"
54
+ end
55
+
56
+ it "should know full models package" do
57
+ Configuration.full_models_package.should == "br.com.caelum.model"
58
+ end
59
+
43
60
  it "should know template engine" do
44
- Configuration.template_engine.should == "jsp"
61
+ Configuration.template_engine.should == "jsp"
45
62
  end
46
63
 
47
64
  it "should know base package" do
48
- Configuration.package.should == "br.com.caelum"
65
+ Configuration.package.should == "br.com.caelum"
66
+ end
67
+
68
+ it "should know orm" do
69
+ Configuration.orm.should == "jpa"
70
+ end
71
+
72
+ it "orm cannot be hibernate" do
73
+ Configuration.hibernate?.should be_false
49
74
  end
50
75
 
51
76
  it "should build main class path with base package" do
@@ -56,4 +81,63 @@ describe Configuration do
56
81
  Configuration.test_class_path("models", "Product.java").should == "src/test/java/br/com/caelum/models/Product.java"
57
82
  end
58
83
  end
84
+ context "hibernate" do
85
+ before(:each) do
86
+ config = {"template_engine" => "jsp", "package" => "br.com.caelum", "orm" => "hibernate"}
87
+ YAML.stub!(:load_file).with(Configuration::FILENAME).and_return(config)
88
+ end
89
+ it "should know orm" do
90
+ Configuration.orm.should == "hibernate"
91
+ end
92
+
93
+ it "orm should be hibernate" do
94
+ Configuration.hibernate?.should be_true
95
+ end
96
+ end
97
+ context "properties without default configs" do
98
+ before(:each) do
99
+ config = {}
100
+ YAML.stub!(:load_file).with(Configuration::FILENAME).and_return(config)
101
+ end
102
+
103
+ it "should know models package" do
104
+ Configuration.models_package.should == "models"
105
+ end
106
+
107
+ it "should know controllers package" do
108
+ Configuration.controllers_package.should == "controllers"
109
+ end
110
+
111
+ it "should know repositories package" do
112
+ Configuration.repositories_package.should == "repositories"
113
+ end
114
+
115
+ it "should know full models package" do
116
+ Configuration.full_models_package.should == "app.models"
117
+ end
118
+
119
+ it "should know template engine" do
120
+ Configuration.template_engine.should == "jsp"
121
+ end
122
+
123
+ it "should know base package" do
124
+ Configuration.package.should == "app"
125
+ end
126
+
127
+ it "should know orm" do
128
+ Configuration.orm.should == "jpa"
129
+ end
130
+
131
+ it "orm cannot be hibernate" do
132
+ Configuration.hibernate?.should be_false
133
+ end
134
+
135
+ it "should build main class path with base package" do
136
+ Configuration.main_class_path("models", "Product.java").should == "src/main/java/app/models/Product.java"
137
+ end
138
+
139
+ it "should build test class path with base package" do
140
+ Configuration.test_class_path("models", "Product.java").should == "src/test/java/app/models/Product.java"
141
+ end
142
+ end
59
143
  end
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+
3
+ describe VraptorScaffold::Execution do
4
+
5
+ before(:each) do
6
+ @execution = VraptorScaffold::Execution.new
7
+ end
8
+
9
+ context "discover runner for action" do
10
+ it "should be commands help when no action" do
11
+ @execution.runner_for(nil).should == VraptorScaffold::Runner::CommandsHelp
12
+ end
13
+
14
+ it "should be app generator when -h action" do
15
+ @execution.runner_for("-h").should == VraptorScaffold::Runner::Generator
16
+ end
17
+
18
+ it "should be app generator when --help action" do
19
+ @execution.runner_for("--help").should == VraptorScaffold::Runner::Generator
20
+ end
21
+
22
+ it "should be app generator when new action" do
23
+ @execution.runner_for("new").should == VraptorScaffold::Runner::Generator
24
+ end
25
+
26
+ it "should be app generator when scaffold action" do
27
+ @execution.runner_for("scaffold").should == VraptorScaffold::Runner::Scaffold
28
+ end
29
+
30
+ it "should be plugin generator when plugin action" do
31
+ @execution.runner_for("plugin").should == VraptorScaffold::Runner::Plugin
32
+ end
33
+
34
+ it "should be commands help when scaffold when unknown action" do
35
+ @execution.runner_for("xpto").should == VraptorScaffold::Runner::CommandsHelp
36
+ end
37
+ end
38
+
39
+ it "should discover runner and run" do
40
+ runner = mock(VraptorScaffold::Runner::Generator)
41
+ runner.stub!(:new).and_return runner
42
+ runner.should_receive(:run).with(['app'])
43
+ @execution.stub!(:runner_for).with('new').and_return(runner)
44
+ @execution.run(['new', 'app'])
45
+ end
46
+
47
+ end
@@ -5,7 +5,7 @@ describe AppGenerator do
5
5
  context "build new application" do
6
6
  before(:all) do
7
7
  @project_path = "src/vraptor-scaffold"
8
- AppGenerator.new(@project_path, ["-b=mvn"]).invoke_all
8
+ AppGenerator.new(@project_path, ["-b=mvn", "-r=repository", "-m=domain", "-c=control"]).invoke_all
9
9
  end
10
10
 
11
11
  after(:all) do
@@ -13,7 +13,12 @@ describe AppGenerator do
13
13
  end
14
14
 
15
15
  it "should create directory with project name" do
16
- File.exist?(@project_path).should be_true
16
+ File.exist?(@project_path).should be_true
17
+ end
18
+
19
+ it "should be invalid when project name already exist" do
20
+ Kernel.should_receive(:exit)
21
+ AppGenerator.new(@project_path)
17
22
  end
18
23
 
19
24
  it "should create pom" do
@@ -23,7 +28,7 @@ describe AppGenerator do
23
28
  end
24
29
 
25
30
  it "cannot create ivy.xml" do
26
- File.exist?("#{@project_path}/ivy.xml").should be_false
31
+ File.exist?("#{@project_path}/ivy.xml").should be_false
27
32
  end
28
33
 
29
34
  it "cannot create build.gradle" do
@@ -34,6 +39,12 @@ describe AppGenerator do
34
39
  File.exist?("#{@project_path}/.classpath").should be_false
35
40
  end
36
41
 
42
+ it "should configure vraptor-scaffold.properties" do
43
+ source = File.join File.dirname(__FILE__), "templates", "vraptor-scaffold.properties"
44
+ destination = "#{@project_path}/#{Configuration::FILENAME}"
45
+ exists_and_identical?(source, destination)
46
+ end
47
+
37
48
  context "creating main java" do
38
49
  before(:all) do
39
50
  @main_java = "#{@project_path}/#{Configuration::MAIN_SRC}"
@@ -41,42 +52,69 @@ describe AppGenerator do
41
52
  end
42
53
 
43
54
  it "should create source folder" do
44
- File.exist?(@main_java).should be_true
55
+ File.exist?(@main_java).should be_true
45
56
  end
46
57
 
47
58
  it "should create app folder" do
48
- File.exist?(@app).should be_true
59
+ File.exist?(@app).should be_true
49
60
  end
50
61
 
51
62
  it "should create controllers folder" do
52
- File.exist?("#{@app}/controllers").should be_true
63
+ File.exist?("#{@app}/control").should be_true
53
64
  end
54
65
 
55
66
  it "should create models folder" do
56
- File.exist?("#{@app}/models").should be_true
67
+ File.exist?("#{@app}/domain").should be_true
57
68
  end
58
69
 
59
70
  it "should create generic entity" do
60
71
  source = File.join File.dirname(__FILE__), "templates", "Entity.java"
61
- destination = "#{@app}/models/Entity.java"
72
+ destination = "#{@app}/domain/Entity.java"
62
73
  exists_and_identical?(source, destination)
63
74
  end
64
75
 
65
76
  it "should create generic repository" do
66
77
  source = File.join File.dirname(__FILE__), "templates", "Repository.java"
67
- destination = "#{@app}/repositories/Repository.java"
78
+ destination = "#{@app}/repository/Repository.java"
68
79
  exists_and_identical?(source, destination)
69
80
  end
70
81
  end
71
82
 
72
83
  context "creating main resources" do
73
- before(:all) do
84
+ before(:each) do
74
85
  @main_resources = "#{@project_path}/#{Configuration::MAIN_RESOURCES}"
75
86
  @meta_inf = "#{@main_resources}/META-INF"
76
- end
87
+ end
88
+
89
+ context "hibernate orm" do
90
+ before(:all) do
91
+ @project_path = "src/vraptor-scaffold-hibernate"
92
+ @main_resources = "#{@project_path}/#{Configuration::MAIN_RESOURCES}"
93
+ @meta_inf = "#{@main_resources}/META-INF"
94
+ AppGenerator.new(@project_path, ["--orm=hibernate"]).invoke_all
95
+ end
96
+
97
+ after(:all) do
98
+ FileUtils.remove_dir("src/vraptor-scaffold-hibernate")
99
+ end
100
+
101
+ it "should create hibernate.cfg.xml" do
102
+ source = "#{AppGenerator.source_root}/orm/hibernate.cfg.xml"
103
+ destination = "#{@main_resources}/hibernate.cfg.xml"
104
+ exists_and_identical?(source, destination)
105
+ end
106
+
107
+ it "cannot create META-INF" do
108
+ File.exist?(@meta_inf).should be_false
109
+ end
110
+
111
+ it "cannot create persistence.xml" do
112
+ File.exist?("#{@meta_inf}/persistence.xml").should be_false
113
+ end
114
+ end
77
115
 
78
116
  it "should create resource folder" do
79
- File.exist?(@main_resources).should be_true
117
+ File.exist?(@main_resources).should be_true
80
118
  end
81
119
 
82
120
  it "should create log4j" do
@@ -85,18 +123,28 @@ describe AppGenerator do
85
123
  exists_and_identical?(source, destination)
86
124
  end
87
125
 
88
- it "should create messages resource" do
126
+ it "should create messages.properties" do
89
127
  source = "#{AppGenerator.source_root}/resources/messages.properties"
90
128
  destination = "#{@main_resources}/messages.properties"
91
129
  exists_and_identical?(source, destination)
92
130
  end
93
131
 
132
+ it "should create hibernate.properties" do
133
+ source = "#{AppGenerator.source_root}/resources/hibernate.properties"
134
+ destination = "#{@main_resources}/hibernate.properties"
135
+ exists_and_identical?(source, destination)
136
+ end
137
+
138
+ it "cannot create hibernate.cfg.xml" do
139
+ File.exist?("#{@main_resources}/hibernate.cfg.xml").should be_false
140
+ end
141
+
94
142
  it "should create META-INF" do
95
- File.exist?(@meta_inf).should be_true
143
+ File.exist?(@meta_inf).should be_true
96
144
  end
97
145
 
98
146
  it "should create persistence.xml" do
99
- source = "#{AppGenerator.source_root}/resources/META-INF/persistence.xml"
147
+ source = "#{AppGenerator.source_root}/orm/persistence.xml"
100
148
  destination = "#{@meta_inf}/persistence.xml"
101
149
  exists_and_identical?(source, destination)
102
150
  end
@@ -106,10 +154,10 @@ describe AppGenerator do
106
154
  before(:all) do
107
155
  @webapp = "#{@project_path}/#{Configuration::WEB_APP}"
108
156
  @web_inf = "#{@project_path}/#{Configuration::WEB_INF}"
109
- end
157
+ end
110
158
 
111
159
  it "should create webapp folder" do
112
- File.exist?(@webapp).should be_true
160
+ File.exist?(@webapp).should be_true
113
161
  end
114
162
 
115
163
  it "should create index" do
@@ -119,7 +167,7 @@ describe AppGenerator do
119
167
  end
120
168
 
121
169
  it "should create WEB-INF folder" do
122
- File.exist?(@web_inf).should be_true
170
+ File.exist?(@web_inf).should be_true
123
171
  end
124
172
 
125
173
  it "should create scaffold css" do
@@ -141,19 +189,17 @@ describe AppGenerator do
141
189
  end
142
190
 
143
191
  it "should create jquery js" do
144
- source = "#{AppGenerator.source_root}/webapp/javascripts/jquery.min.js"
145
192
  destination = "#{@webapp}/javascripts/jquery.min.js"
146
- exists_and_identical?(source, destination)
193
+ File.exists?(destination).should be_true
147
194
  end
148
195
 
149
196
  it "should create application js" do
150
- source = "#{AppGenerator.source_root}/webapp/javascripts/application.js"
151
197
  destination = "#{@webapp}/javascripts/application.js"
152
- exists_and_identical?(source, destination)
198
+ File.exists?(destination).should be_true
153
199
  end
154
200
 
155
201
  it "should create images folder" do
156
- File.exist?("#{@webapp}/images").should be_true
202
+ File.exist?("#{@webapp}/images").should be_true
157
203
  end
158
204
  end
159
205
 
@@ -165,29 +211,29 @@ describe AppGenerator do
165
211
  end
166
212
 
167
213
  it "should create test source folder" do
168
- File.exist?(@test_java).should be_true
214
+ File.exist?(@test_java).should be_true
169
215
  end
170
216
 
171
217
  it "should create app folder" do
172
- File.exist?(@app).should be_true
218
+ File.exist?(@app).should be_true
173
219
  end
174
220
 
175
221
  it "should create controllers folder" do
176
- File.exist?("#{@app}/controllers").should be_true
222
+ File.exist?("#{@app}/control").should be_true
177
223
  end
178
224
 
179
225
  it "should create models folder" do
180
- File.exist?("#{@app}/models").should be_true
226
+ File.exist?("#{@app}/domain").should be_true
181
227
  end
182
228
 
183
229
  it "should create respositories folder" do
184
- File.exist?("#{@app}/repositories").should be_true
185
- end
230
+ File.exist?("#{@app}/repository").should be_true
231
+ end
186
232
 
187
233
  it "should create test resource folder" do
188
- File.exist?(@test_resource).should be_true
234
+ File.exist?(@test_resource).should be_true
189
235
  end
190
- end
236
+ end
191
237
  end
192
238
 
193
239
  context "build app with complex package" do
@@ -204,11 +250,11 @@ describe AppGenerator do
204
250
  end
205
251
 
206
252
  it "should create main path" do
207
- File.exist?(@main_java).should be_true
253
+ File.exist?(@main_java).should be_true
208
254
  end
209
255
 
210
256
  it "should create test path" do
211
- File.exist?(@test_java).should be_true
257
+ File.exist?(@test_java).should be_true
212
258
  end
213
259
 
214
260
  end
@@ -237,7 +283,7 @@ describe AppGenerator do
237
283
  AppGenerator.new(@project_path).invoke_all
238
284
  end
239
285
  end
240
-
286
+
241
287
  context "configuring ant application" do
242
288
 
243
289
  before(:all) do
@@ -266,20 +312,14 @@ describe AppGenerator do
266
312
  destination = "#{@project_path}/ivy.xml"
267
313
  exists_and_identical?(source, destination)
268
314
  end
269
-
270
- it "should create ivysettings.xml" do
271
- source = File.join AppGenerator.source_root, "ivysettings.xml"
272
- destination = "#{@project_path}/ivysettings.xml"
273
- exists_and_identical?(source, destination)
274
- end
275
315
 
276
316
  it "should copy ivy.jar" do
277
317
  ivy = File.join @project_path, AppGenerator::IVY_JAR
278
- File.exist?(ivy).should be_true
318
+ File.exist?(ivy).should be_true
279
319
  end
280
320
 
281
321
  it "cannot create pom.xml" do
282
- File.exist?("#{@project_path}/pom.xml").should be_false
322
+ File.exist?("#{@project_path}/pom.xml").should be_false
283
323
  end
284
324
 
285
325
  it "cannot create build.gradle" do
@@ -300,7 +340,7 @@ describe AppGenerator do
300
340
  it "should create .settings" do
301
341
  settings = File.join @project_path, ".settings"
302
342
  File.exist?(settings).should be_true
303
- end
343
+ end
304
344
  end
305
345
  end
306
346
 
@@ -318,7 +358,7 @@ describe AppGenerator do
318
358
  File.exist?("#{@project_path}/.classpath").should be_false
319
359
  end
320
360
  end
321
-
361
+
322
362
  context "configuring gradle application" do
323
363
 
324
364
  before(:all) do
@@ -337,11 +377,11 @@ describe AppGenerator do
337
377
  end
338
378
 
339
379
  it "cannot create ivy.xml" do
340
- File.exist?("#{@project_path}/ivy.xml").should be_false
380
+ File.exist?("#{@project_path}/ivy.xml").should be_false
341
381
  end
342
382
 
343
383
  it "cannot create pom.xml" do
344
- File.exist?("#{@project_path}/pom.xml").should be_false
384
+ File.exist?("#{@project_path}/pom.xml").should be_false
345
385
  end
346
386
  end
347
387
 
@@ -369,27 +409,69 @@ describe AppGenerator do
369
409
  end
370
410
  end
371
411
 
412
+ context "valid orm" do
413
+ it "jpa should be valid" do
414
+ AppGenerator::ORMS.include?("jpa").should be_true
415
+ end
416
+
417
+ it "hibernate should be valid" do
418
+ AppGenerator::ORMS.include?("hibernate").should be_true
419
+ end
420
+ end
421
+
372
422
  it "should configure banner" do
373
423
  AppGenerator.banner.should == "vraptor new PROJECT_PATH [options]"
374
424
  end
375
-
425
+
376
426
  context "validate options" do
377
427
  before(:each) do
378
428
  @project_path = "vraptor-scaffold"
379
429
  end
380
430
 
381
- after(:each) do
431
+ it "should be invalid when build tool is not supported" do
432
+ Kernel.should_receive(:exit)
433
+ AppGenerator.new(@project_path, ["-b=maven"])
434
+ end
435
+
436
+ it "should be invalid when template engine is not supported" do
437
+ Kernel.should_receive(:exit)
438
+ AppGenerator.new(@project_path, ["-e=velocity"])
439
+ end
440
+
441
+ it "should be invalid when orm mapping is not supported" do
442
+ Kernel.should_receive(:exit)
443
+ AppGenerator.new(@project_path, ["-o=toplink"])
444
+ end
445
+
446
+ it "should be invalid when jquery version does not exist" do
447
+ Kernel.should_receive(:exit)
448
+ AppGenerator.new(@project_path, ["-j=1.x"])
449
+ end
450
+ end
451
+
452
+ context "heroku app" do
453
+ before(:all) do
454
+ @project_path = "heroku"
455
+ AppGenerator.new(@project_path, ["--heroku"]).invoke_all
456
+ end
457
+
458
+ after(:all) do
382
459
  FileUtils.remove_dir(@project_path)
383
460
  end
384
461
 
385
- it "should be invalid when build tool is not supported" do
386
- Kernel.should_receive(:exit)
387
- AppGenerator.new(@project_path, ["-b=maven"]).invoke_all
462
+ it "should create pom" do
463
+ source = File.join File.dirname(__FILE__), "templates", "pom-heroku.xml"
464
+ destination = "#{@project_path}/pom.xml"
465
+ exists_and_identical?(source, destination)
388
466
  end
389
467
 
390
- it "should be invalid when template engine is not supported" do
391
- Kernel.should_receive(:exit)
392
- AppGenerator.new(@project_path, ["-e=velocity"]).invoke_all
468
+ it "should create Procfile" do
469
+ File.exist?("#{@project_path}/Procfile").should be_true
470
+ end
471
+
472
+ it "should create main class to run heroku apps" do
473
+ File.exist?("#{@project_path}/src/main/java/Main.java").should be_true
393
474
  end
394
475
  end
476
+
395
477
  end