heroku-vraptor-scaffold 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +6 -0
  3. data/CHANGELOG.rdoc +188 -0
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +30 -0
  6. data/LICENSE +22 -0
  7. data/README.md +23 -0
  8. data/README.textile +51 -0
  9. data/Rakefile +20 -0
  10. data/bin/heroku-vraptor +8 -0
  11. data/heroku-vraptor-scaffold.gemspec +28 -0
  12. data/index.sample.html +169 -0
  13. data/lib/vraptor-scaffold.rb +14 -0
  14. data/lib/vraptor-scaffold/configuration.rb +54 -0
  15. data/lib/vraptor-scaffold/execution.rb +22 -0
  16. data/lib/vraptor-scaffold/generators/app/app_generator.rb +161 -0
  17. data/lib/vraptor-scaffold/generators/app/dependency.rb +15 -0
  18. data/lib/vraptor-scaffold/generators/app/dependency_manager.rb +32 -0
  19. data/lib/vraptor-scaffold/generators/app/templates/angular/angular.js +14327 -0
  20. data/lib/vraptor-scaffold/generators/app/templates/bootstrap/bootstrap-responsive.css +9 -0
  21. data/lib/vraptor-scaffold/generators/app/templates/bootstrap/bootstrap.css +9 -0
  22. data/lib/vraptor-scaffold/generators/app/templates/bootstrap/bootstrap.js +6 -0
  23. data/lib/vraptor-scaffold/generators/app/templates/bootstrap/glyphicons-halflings-white.png +0 -0
  24. data/lib/vraptor-scaffold/generators/app/templates/bootstrap/glyphicons-halflings.png +0 -0
  25. data/lib/vraptor-scaffold/generators/app/templates/eclipse/classpath.erb +18 -0
  26. data/lib/vraptor-scaffold/generators/app/templates/eclipse/project.erb +36 -0
  27. data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.jdt.core.prefs +8 -0
  28. data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.wst.common.component.tt +10 -0
  29. data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.wst.common.project.facet.core.xml +10 -0
  30. data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.wst.jsdt.ui.superType.container +1 -0
  31. data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.wst.jsdt.ui.superType.name +1 -0
  32. data/lib/vraptor-scaffold/generators/app/templates/heroku/Main.java +21 -0
  33. data/lib/vraptor-scaffold/generators/app/templates/heroku/Procfile +1 -0
  34. data/lib/vraptor-scaffold/generators/app/templates/jquery/jquery.min.js +4 -0
  35. data/lib/vraptor-scaffold/generators/app/templates/models/Entity.erb +46 -0
  36. data/lib/vraptor-scaffold/generators/app/templates/orm/Repository-hibernate.java.tt +50 -0
  37. data/lib/vraptor-scaffold/generators/app/templates/orm/Repository-jpa.java.tt +48 -0
  38. data/lib/vraptor-scaffold/generators/app/templates/orm/Repository-objectify.java.tt +41 -0
  39. data/lib/vraptor-scaffold/generators/app/templates/orm/hibernate.cfg.xml +7 -0
  40. data/lib/vraptor-scaffold/generators/app/templates/orm/persistence.xml +10 -0
  41. data/lib/vraptor-scaffold/generators/app/templates/pom.erb +110 -0
  42. data/lib/vraptor-scaffold/generators/app/templates/resources-test/.empty_directory +0 -0
  43. data/lib/vraptor-scaffold/generators/app/templates/resources/hibernate.properties +16 -0
  44. data/lib/vraptor-scaffold/generators/app/templates/resources/log4j.properties +4 -0
  45. data/lib/vraptor-scaffold/generators/app/templates/resources/messages.properties +0 -0
  46. data/lib/vraptor-scaffold/generators/app/templates/underscore/underscore.min.js +32 -0
  47. data/lib/vraptor-scaffold/generators/app/templates/vraptor-scaffold.erb +5 -0
  48. data/lib/vraptor-scaffold/generators/app/templates/webapp/WEB-INF/web.xml.tt +33 -0
  49. data/lib/vraptor-scaffold/generators/app/templates/webapp/images/.empty_directory +0 -0
  50. data/lib/vraptor-scaffold/generators/app/templates/webapp/index.html +24 -0
  51. data/lib/vraptor-scaffold/generators/app/templates/webapp/javascripts/utils.js +7 -0
  52. data/lib/vraptor-scaffold/generators/base.rb +16 -0
  53. data/lib/vraptor-scaffold/generators/scaffold/attribute.rb +51 -0
  54. data/lib/vraptor-scaffold/generators/scaffold/base_scaffold.rb +54 -0
  55. data/lib/vraptor-scaffold/generators/scaffold/client_generator/client_generator.rb +41 -0
  56. data/lib/vraptor-scaffold/generators/scaffold/client_generator/templates/controller.erb +75 -0
  57. data/lib/vraptor-scaffold/generators/scaffold/client_generator/templates/details.erb +16 -0
  58. data/lib/vraptor-scaffold/generators/scaffold/client_generator/templates/form.erb +39 -0
  59. data/lib/vraptor-scaffold/generators/scaffold/client_generator/templates/list.erb +40 -0
  60. data/lib/vraptor-scaffold/generators/scaffold/controller_generator/controller_generator.rb +20 -0
  61. data/lib/vraptor-scaffold/generators/scaffold/controller_generator/templates/controller.erb +77 -0
  62. data/lib/vraptor-scaffold/generators/scaffold/controller_generator/templates/controller_test.erb +12 -0
  63. data/lib/vraptor-scaffold/generators/scaffold/model_generator/model_generator.rb +26 -0
  64. data/lib/vraptor-scaffold/generators/scaffold/model_generator/templates/model.erb +32 -0
  65. data/lib/vraptor-scaffold/generators/scaffold/model_generator/templates/model_test.erb +13 -0
  66. data/lib/vraptor-scaffold/generators/scaffold/repository_generator/repository_generator.rb +32 -0
  67. data/lib/vraptor-scaffold/generators/scaffold/repository_generator/templates/repository.erb +22 -0
  68. data/lib/vraptor-scaffold/generators/scaffold/repository_generator/templates/repository_impl.erb +16 -0
  69. data/lib/vraptor-scaffold/generators/scaffold/repository_generator/templates/repository_test.erb +13 -0
  70. data/lib/vraptor-scaffold/generators/scaffold/scaffold_generator.rb +35 -0
  71. data/lib/vraptor-scaffold/runner.rb +9 -0
  72. data/lib/vraptor-scaffold/runner/commands_help.rb +13 -0
  73. data/lib/vraptor-scaffold/runner/generator.rb +15 -0
  74. data/lib/vraptor-scaffold/runner/help.rb +12 -0
  75. data/lib/vraptor-scaffold/runner/scaffold.rb +16 -0
  76. data/lib/vraptor-scaffold/version.rb +3 -0
  77. data/maven/repo/br/com/caelum/vraptor-gae/1.0/vraptor-gae-1.0.jar +0 -0
  78. data/spec/resources/vraptor-scaffold-objectify.properties +7 -0
  79. data/spec/resources/vraptor-scaffold.properties +7 -0
  80. data/spec/spec.opts +4 -0
  81. data/spec/spec_helper.rb +31 -0
  82. data/spec/vraptor-scaffold/configuration_spec.rb +146 -0
  83. data/spec/vraptor-scaffold/execution_spec.rb +51 -0
  84. data/spec/vraptor-scaffold/generators/app/app_generator_spec.rb +557 -0
  85. data/spec/vraptor-scaffold/generators/app/dependency_manager_spec.rb +34 -0
  86. data/spec/vraptor-scaffold/generators/app/dependency_spec.rb +14 -0
  87. data/spec/vraptor-scaffold/generators/app/freemarker_template_engine_spec.rb +80 -0
  88. data/spec/vraptor-scaffold/generators/app/jsp_template_engine_spec.rb +77 -0
  89. data/spec/vraptor-scaffold/generators/app/templates/Entity.java +45 -0
  90. data/spec/vraptor-scaffold/generators/app/templates/FreemarkerPathResolver.java +21 -0
  91. data/spec/vraptor-scaffold/generators/app/templates/ObjectifyFactory.java +30 -0
  92. data/spec/vraptor-scaffold/generators/app/templates/RepositoryJPA.java +48 -0
  93. data/spec/vraptor-scaffold/generators/app/templates/RepositoryObjectify.java +41 -0
  94. data/spec/vraptor-scaffold/generators/app/templates/build.gradle +60 -0
  95. data/spec/vraptor-scaffold/generators/app/templates/build.properties +18 -0
  96. data/spec/vraptor-scaffold/generators/app/templates/build.xml +146 -0
  97. data/spec/vraptor-scaffold/generators/app/templates/classpath-gae +18 -0
  98. data/spec/vraptor-scaffold/generators/app/templates/decorators-jsp.xml +7 -0
  99. data/spec/vraptor-scaffold/generators/app/templates/decorators.xml +7 -0
  100. data/spec/vraptor-scaffold/generators/app/templates/freemarker-web.xml +60 -0
  101. data/spec/vraptor-scaffold/generators/app/templates/gae-jsp-web.xml +45 -0
  102. data/spec/vraptor-scaffold/generators/app/templates/ivy-gae.xml +45 -0
  103. data/spec/vraptor-scaffold/generators/app/templates/ivy.xml +40 -0
  104. data/spec/vraptor-scaffold/generators/app/templates/jsp-web.xml +45 -0
  105. data/spec/vraptor-scaffold/generators/app/templates/pom-heroku.xml +182 -0
  106. data/spec/vraptor-scaffold/generators/app/templates/pom.xml +157 -0
  107. data/spec/vraptor-scaffold/generators/app/templates/project-gae +47 -0
  108. data/spec/vraptor-scaffold/generators/app/templates/vraptor-scaffold.properties +7 -0
  109. data/spec/vraptor-scaffold/generators/plugin/expected_configs/build.gradle +62 -0
  110. data/spec/vraptor-scaffold/generators/plugin/expected_configs/default_org_build.gradle +62 -0
  111. data/spec/vraptor-scaffold/generators/plugin/expected_configs/default_org_ivy.xml +41 -0
  112. data/spec/vraptor-scaffold/generators/plugin/expected_configs/default_org_pom.xml +152 -0
  113. data/spec/vraptor-scaffold/generators/plugin/expected_configs/ivy.xml +42 -0
  114. data/spec/vraptor-scaffold/generators/plugin/expected_configs/pom.xml +182 -0
  115. data/spec/vraptor-scaffold/generators/scaffold/attribute_spec.rb +186 -0
  116. data/spec/vraptor-scaffold/generators/scaffold/base_scaffold_spec.rb +73 -0
  117. data/spec/vraptor-scaffold/generators/scaffold/client_controller_generator/controller_generator_spec.rb +62 -0
  118. data/spec/vraptor-scaffold/generators/scaffold/client_controller_generator/templates/ProductController.java +95 -0
  119. data/spec/vraptor-scaffold/generators/scaffold/controller_generator/controller_generator_spec.rb +62 -0
  120. data/spec/vraptor-scaffold/generators/scaffold/controller_generator/templates/ProductController.java +95 -0
  121. data/spec/vraptor-scaffold/generators/scaffold/freemarker_generator/freemarker_generator_spec.rb +81 -0
  122. data/spec/vraptor-scaffold/generators/scaffold/freemarker_generator/templates/form.ftl +28 -0
  123. data/spec/vraptor-scaffold/generators/scaffold/jsp_generator/jsp_generator_spec.rb +81 -0
  124. data/spec/vraptor-scaffold/generators/scaffold/jsp_generator/templates/form.jsp +61 -0
  125. data/spec/vraptor-scaffold/generators/scaffold/model_generator/model_generator_spec.rb +54 -0
  126. data/spec/vraptor-scaffold/generators/scaffold/model_generator/objectify_model_generator_spec.rb +40 -0
  127. data/spec/vraptor-scaffold/generators/scaffold/model_generator/templates/ObjectifyFactory.java +33 -0
  128. data/spec/vraptor-scaffold/generators/scaffold/model_generator/templates/Objectify_Product.java +38 -0
  129. data/spec/vraptor-scaffold/generators/scaffold/model_generator/templates/Product.java +25 -0
  130. data/spec/vraptor-scaffold/generators/scaffold/model_generator/templates/hibernate.cfg.xml +8 -0
  131. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/objectify_repository_generator_spec.rb +33 -0
  132. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/repository_generator_spec.rb +68 -0
  133. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ClientRepository.java +22 -0
  134. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ClientRepositoryImpl.java +16 -0
  135. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/Objectify_ProductRepository.java +22 -0
  136. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/Objectify_ProductRepositoryImpl.java +16 -0
  137. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ProductRepository.java +22 -0
  138. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ProductRepositoryImpl.java +16 -0
  139. data/spec/vraptor-scaffold/generators/scaffold/scaffold_generator_spec.rb +79 -0
  140. data/spec/vraptor-scaffold/http_request_spec.rb +40 -0
  141. data/spec/vraptor-scaffold/runner/commands_help_spec.rb +12 -0
  142. data/spec/vraptor-scaffold/runner/configure_spec.rb +12 -0
  143. data/spec/vraptor-scaffold/runner/generator_spec.rb +31 -0
  144. data/spec/vraptor-scaffold/runner/help_spec.rb +29 -0
  145. data/spec/vraptor-scaffold/runner/scaffold_spec.rb +35 -0
  146. data/spec/vraptor-scaffold/runner/start_spec.rb +51 -0
  147. data/spec/vraptor-scaffold_spec.rb +4 -0
  148. metadata +261 -0
@@ -0,0 +1,146 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Configuration do
4
+
5
+ it "should configure main source" do
6
+ Configuration::MAIN_SRC.should == "src/main/java"
7
+ end
8
+
9
+ it "should configure main resources" do
10
+ Configuration::MAIN_RESOURCES.should == "src/main/resources"
11
+ end
12
+
13
+ it "should configure test source" do
14
+ Configuration::TEST_SRC.should == "src/test/java"
15
+ end
16
+
17
+ it "should configure test resources" do
18
+ Configuration::TEST_RESOURCES.should == "src/test/resources"
19
+ end
20
+
21
+ it "should configure webapp" do
22
+ Configuration::WEB_APP.should == "src/main/webapp"
23
+ end
24
+
25
+ it "should configure web-inf" do
26
+ Configuration::WEB_INF.should == "#{Configuration::WEB_APP}/WEB-INF"
27
+ end
28
+
29
+ it "should configure meta-inf" do
30
+ Configuration::META_INF.should == "#{Configuration::WEB_APP}/META-INF"
31
+ end
32
+
33
+ it "should configure scaffold properties" do
34
+ Configuration::FILENAME.should == "#{Configuration::META_INF}/vraptor-scaffold.properties"
35
+ end
36
+
37
+ context "load config file" do
38
+ before(:each) do
39
+ config = {"template_engine" => "jsp", "package" => "br.com.caelum", "orm" => "jpa", "models_package" => "model",
40
+ "controllers_package" => "controller", "repositories_package" => "repository"}
41
+ YAML.stub!(:load_file).with(Configuration::FILENAME).and_return(config)
42
+ end
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
+
60
+ it "should know template engine" do
61
+ Configuration.template_engine.should == "jsp"
62
+ end
63
+
64
+ it "should know base package" do
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
74
+ end
75
+
76
+ it "should build main class path with base package" do
77
+ Configuration.main_class_path("models", "Product.java").should == "src/main/java/br/com/caelum/models/Product.java"
78
+ end
79
+
80
+ it "should build test class path with base package" do
81
+ Configuration.test_class_path("models", "Product.java").should == "src/test/java/br/com/caelum/models/Product.java"
82
+ end
83
+ end
84
+
85
+ context "hibernate" do
86
+ before(:each) do
87
+ config = {"template_engine" => "jsp", "package" => "br.com.caelum", "orm" => "hibernate"}
88
+ YAML.stub!(:load_file).with(Configuration::FILENAME).and_return(config)
89
+ end
90
+
91
+ it "should know orm" do
92
+ Configuration.orm.should == "hibernate"
93
+ end
94
+
95
+ it "orm should be hibernate" do
96
+ Configuration.hibernate?.should be_true
97
+ end
98
+ end
99
+
100
+ context "properties without default configs" do
101
+ before(:each) do
102
+ config = {}
103
+ YAML.stub!(:load_file).with(Configuration::FILENAME).and_return(config)
104
+ end
105
+
106
+ it "should know models package" do
107
+ Configuration.models_package.should == "models"
108
+ end
109
+
110
+ it "should know controllers package" do
111
+ Configuration.controllers_package.should == "controllers"
112
+ end
113
+
114
+ it "should know repositories package" do
115
+ Configuration.repositories_package.should == "repositories"
116
+ end
117
+
118
+ it "should know full models package" do
119
+ Configuration.full_models_package.should == "app.models"
120
+ end
121
+
122
+ it "should know template engine" do
123
+ Configuration.template_engine.should == "jsp"
124
+ end
125
+
126
+ it "should know base package" do
127
+ Configuration.package.should == "app"
128
+ end
129
+
130
+ it "should know orm" do
131
+ Configuration.orm.should == "jpa"
132
+ end
133
+
134
+ it "orm cannot be hibernate" do
135
+ Configuration.hibernate?.should be_false
136
+ end
137
+
138
+ it "should build main class path with base package" do
139
+ Configuration.main_class_path("models", "Product.java").should == "src/main/java/app/models/Product.java"
140
+ end
141
+
142
+ it "should build test class path with base package" do
143
+ Configuration.test_class_path("models", "Product.java").should == "src/test/java/app/models/Product.java"
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,51 @@
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 start application when start action" do
35
+ @execution.runner_for("start").should == VraptorScaffold::Runner::Start
36
+ end
37
+
38
+ it "should be commands help when scaffold when unknown action" do
39
+ @execution.runner_for("xpto").should == VraptorScaffold::Runner::CommandsHelp
40
+ end
41
+ end
42
+
43
+ it "should discover runner and run" do
44
+ runner = mock(VraptorScaffold::Runner::Generator)
45
+ runner.stub!(:new).and_return runner
46
+ runner.should_receive(:run).with(['app'])
47
+ @execution.stub!(:runner_for).with('new').and_return(runner)
48
+ @execution.run(['new', 'app'])
49
+ end
50
+
51
+ end
@@ -0,0 +1,557 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
2
+
3
+ describe AppGenerator do
4
+
5
+ context "build new application" do
6
+ before(:all) do
7
+ @project_path = "src/vraptor-scaffold"
8
+ AppGenerator.new(@project_path, ["-b=mvn", "-r=repository", "-m=domain", "-c=control"]).invoke_all
9
+ end
10
+
11
+ after(:all) do
12
+ FileUtils.remove_dir("src")
13
+ end
14
+
15
+ it "should create directory with project name" do
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)
22
+ end
23
+
24
+ it "should create pom" do
25
+ source = File.join File.dirname(__FILE__), "templates", "pom.xml"
26
+ destination = "#{@project_path}/pom.xml"
27
+ exists_and_identical?(source, destination)
28
+ end
29
+
30
+ it "cannot create ivy.xml" do
31
+ File.exist?("#{@project_path}/ivy.xml").should be_false
32
+ end
33
+
34
+ it "cannot create build.gradle" do
35
+ File.exist?("#{@project_path}/build.gradle").should be_false
36
+ end
37
+
38
+ it "cannot create eclipse wtp" do
39
+ File.exist?("#{@project_path}/.classpath").should be_false
40
+ end
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
+
48
+ context "creating main java" do
49
+ before(:all) do
50
+ @main_java = "#{@project_path}/#{Configuration::MAIN_SRC}"
51
+ @app = "#{@main_java}/app"
52
+ end
53
+
54
+ it "should create source folder" do
55
+ File.exist?(@main_java).should be_true
56
+ end
57
+
58
+ it "should create app folder" do
59
+ File.exist?(@app).should be_true
60
+ end
61
+
62
+ it "should create controllers folder" do
63
+ File.exist?("#{@app}/control").should be_true
64
+ end
65
+
66
+ it "should create models folder" do
67
+ File.exist?("#{@app}/domain").should be_true
68
+ end
69
+
70
+ it "should create generic entity" do
71
+ source = File.join File.dirname(__FILE__), "templates", "Entity.java"
72
+ destination = "#{@app}/domain/Entity.java"
73
+ exists_and_identical?(source, destination)
74
+ end
75
+
76
+ it "should create generic repository" do
77
+ source = File.join File.dirname(__FILE__), "templates", "RepositoryJPA.java"
78
+ destination = "#{@app}/repository/Repository.java"
79
+ exists_and_identical?(source, destination)
80
+ end
81
+ end
82
+
83
+ context "creating main resources" do
84
+ before(:each) do
85
+ @main_resources = "#{@project_path}/#{Configuration::MAIN_RESOURCES}"
86
+ @meta_inf = "#{@main_resources}/META-INF"
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
115
+
116
+ it "should create resource folder" do
117
+ File.exist?(@main_resources).should be_true
118
+ end
119
+
120
+ it "should create log4j" do
121
+ source = "#{AppGenerator.source_root}/resources/log4j.properties"
122
+ destination = "#{@main_resources}/log4j.properties"
123
+ exists_and_identical?(source, destination)
124
+ end
125
+
126
+ it "should create messages.properties" do
127
+ source = "#{AppGenerator.source_root}/resources/messages.properties"
128
+ destination = "#{@main_resources}/messages.properties"
129
+ exists_and_identical?(source, destination)
130
+ end
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
+
142
+ it "should create META-INF" do
143
+ File.exist?(@meta_inf).should be_true
144
+ end
145
+
146
+ it "should create persistence.xml" do
147
+ source = "#{AppGenerator.source_root}/orm/persistence.xml"
148
+ destination = "#{@meta_inf}/persistence.xml"
149
+ exists_and_identical?(source, destination)
150
+ end
151
+ end
152
+
153
+ context "creating webapp" do
154
+ before(:all) do
155
+ @webapp = "#{@project_path}/#{Configuration::WEB_APP}"
156
+ @web_inf = "#{@project_path}/#{Configuration::WEB_INF}"
157
+ end
158
+
159
+ it "should create webapp folder" do
160
+ File.exist?(@webapp).should be_true
161
+ end
162
+
163
+ it "should create index" do
164
+ source = "#{AppGenerator.source_root}/webapp/index.jsp"
165
+ destination = "#{@webapp}/index.jsp"
166
+ exists_and_identical?(source, destination)
167
+ end
168
+
169
+ it "should create WEB-INF folder" do
170
+ File.exist?(@web_inf).should be_true
171
+ end
172
+
173
+ it "should create scaffold css" do
174
+ source = "#{AppGenerator.source_root}/webapp/stylesheets/scaffold.css"
175
+ destination = "#{@webapp}/stylesheets/scaffold.css"
176
+ exists_and_identical?(source, destination)
177
+ end
178
+
179
+ it "should create stylesheets css" do
180
+ source = "#{AppGenerator.source_root}/webapp/stylesheets/application.css"
181
+ destination = "#{@webapp}/stylesheets/application.css"
182
+ exists_and_identical?(source, destination)
183
+ end
184
+
185
+ it "should create jquery js" do
186
+ destination = "#{@webapp}/javascripts/jquery.min.js"
187
+ File.exists?(destination).should be_true
188
+ end
189
+
190
+ it "should create bootstrap files" do
191
+ bootstrap = Array.new
192
+ bootstrap << "#{@webapp}/stylesheets/bootstrap.css"
193
+ bootstrap << "#{@webapp}/javascripts/bootstrap.js"
194
+ bootstrap << "#{@webapp}/images/glyphicons-halflings-white.png"
195
+ bootstrap << "#{@webapp}/images/glyphicons-halflings.png"
196
+ bootstrap.each do |bs_file|
197
+ File.exists?(bs_file).should be_true
198
+ end
199
+ end
200
+
201
+ it "should create application js" do
202
+ destination = "#{@webapp}/javascripts/application.js"
203
+ File.exists?(destination).should be_true
204
+ end
205
+
206
+ it "should create images folder" do
207
+ File.exist?("#{@webapp}/images").should be_true
208
+ end
209
+ end
210
+
211
+ context "creating test" do
212
+ before(:all) do
213
+ @test_java = "#{@project_path}/#{Configuration::TEST_SRC}"
214
+ @test_resource = "#{@project_path}/#{Configuration::TEST_RESOURCES}"
215
+ @app = "#{@test_java}/app"
216
+ end
217
+
218
+ it "should create test source folder" do
219
+ File.exist?(@test_java).should be_true
220
+ end
221
+
222
+ it "should create app folder" do
223
+ File.exist?(@app).should be_true
224
+ end
225
+
226
+ it "should create controllers folder" do
227
+ File.exist?("#{@app}/control").should be_true
228
+ end
229
+
230
+ it "should create models folder" do
231
+ File.exist?("#{@app}/domain").should be_true
232
+ end
233
+
234
+ it "should create respositories folder" do
235
+ File.exist?("#{@app}/repository").should be_true
236
+ end
237
+
238
+ it "should create test resource folder" do
239
+ File.exist?(@test_resource).should be_true
240
+ end
241
+ end
242
+ end
243
+
244
+ context "build app with complex package" do
245
+
246
+ before(:all) do
247
+ @project_path = "src/vraptor-scaffold"
248
+ AppGenerator.new(@project_path, ["-p=br.com.caelum"]).invoke_all
249
+ @main_java = "#{@project_path}/#{Configuration::MAIN_SRC}/br/com/caelum"
250
+ @test_java = "#{@project_path}/#{Configuration::TEST_SRC}/br/com/caelum"
251
+ end
252
+
253
+ after(:all) do
254
+ FileUtils.remove_dir("src")
255
+ end
256
+
257
+ it "should create main path" do
258
+ File.exist?(@main_java).should be_true
259
+ end
260
+
261
+ it "should create test path" do
262
+ File.exist?(@test_java).should be_true
263
+ end
264
+
265
+ end
266
+
267
+ context "configuring template engine" do
268
+
269
+ before(:each) do
270
+ @project_path = "src/vraptor-scaffold"
271
+ end
272
+
273
+ after(:each) do
274
+ FileUtils.remove_dir("src")
275
+ end
276
+
277
+ it "should configure freemarker template engine" do
278
+ template = mock(FreemarkerTemplateEngine)
279
+ FreemarkerTemplateEngine.stub!(:new).and_return(template)
280
+ template.should_receive(:configure)
281
+ AppGenerator.new(@project_path, ["--template-engine=ftl"]).invoke_all
282
+ end
283
+
284
+ it "should configure jsp template engine" do
285
+ template = mock(JspTemplateEngine)
286
+ JspTemplateEngine.stub!(:new).and_return(template)
287
+ template.should_receive(:configure)
288
+ AppGenerator.new(@project_path).invoke_all
289
+ end
290
+ end
291
+
292
+ context "configuring ant application" do
293
+
294
+ before(:all) do
295
+ @project_path = "vraptor-scaffold"
296
+ AppGenerator.new(@project_path, ["-b=ant"]).invoke_all
297
+ end
298
+
299
+ after(:all) do
300
+ FileUtils.remove_dir(@project_path)
301
+ end
302
+
303
+ it "should create build.xml" do
304
+ source = File.join File.dirname(__FILE__), "templates", "build.xml"
305
+ destination = "#{@project_path}/build.xml"
306
+ exists_and_identical?(source, destination)
307
+ end
308
+
309
+ it "should create build.properties" do
310
+ source = File.join File.dirname(__FILE__), "templates", "build.properties"
311
+ destination = "#{@project_path}/build.properties"
312
+ exists_and_identical?(source, destination)
313
+ end
314
+
315
+ it "should create ivy.xml" do
316
+ source = File.join File.dirname(__FILE__), "templates", "ivy.xml"
317
+ destination = "#{@project_path}/ivy.xml"
318
+ exists_and_identical?(source, destination)
319
+ end
320
+
321
+ it "should copy ivy.jar" do
322
+ ivy = File.join @project_path, AppGenerator::IVY_JAR
323
+ File.exist?(ivy).should be_true
324
+ end
325
+
326
+ it "cannot create pom.xml" do
327
+ File.exist?("#{@project_path}/pom.xml").should be_false
328
+ end
329
+
330
+ it "cannot create build.gradle" do
331
+ File.exist?("#{@project_path}/build.gradle").should be_false
332
+ end
333
+
334
+ context "eclipse wtp configuration" do
335
+ it "should create .project" do
336
+ project = File.join @project_path, ".project"
337
+ File.exist?(project).should be_true
338
+ end
339
+
340
+ it "should create .classpath" do
341
+ class_path = File.join @project_path, ".classpath"
342
+ File.exist?(class_path).should be_true
343
+ end
344
+
345
+ it "should create .settings" do
346
+ settings = File.join @project_path, ".settings"
347
+ File.exist?(settings).should be_true
348
+ end
349
+ end
350
+ end
351
+
352
+ context "skip eclipse configuration files" do
353
+ before(:all) do
354
+ @project_path = "vraptor-scaffold"
355
+ AppGenerator.new(@project_path, ["--skip-eclipse"]).invoke_all
356
+ end
357
+
358
+ after(:all) do
359
+ FileUtils.remove_dir(@project_path)
360
+ end
361
+
362
+ it "cannot create .classpath file" do
363
+ File.exist?("#{@project_path}/.classpath").should be_false
364
+ end
365
+ end
366
+
367
+ context "configuring gradle application" do
368
+
369
+ before(:all) do
370
+ @project_path = "vraptor-scaffold"
371
+ AppGenerator.new(@project_path, ["-b=gradle"]).invoke_all
372
+ end
373
+
374
+ after(:all) do
375
+ FileUtils.remove_dir(@project_path)
376
+ end
377
+
378
+ it "should create build.gradle" do
379
+ source = File.join File.dirname(__FILE__), "templates", "build.gradle"
380
+ destination = "#{@project_path}/build.gradle"
381
+ exists_and_identical?(source, destination)
382
+ end
383
+
384
+ it "cannot create ivy.xml" do
385
+ File.exist?("#{@project_path}/ivy.xml").should be_false
386
+ end
387
+
388
+ it "cannot create pom.xml" do
389
+ File.exist?("#{@project_path}/pom.xml").should be_false
390
+ end
391
+ end
392
+
393
+ context "valid template engines" do
394
+ it "jsp should be valid" do
395
+ AppGenerator::TEMPLATE_ENGINES.include?("jsp").should be_true
396
+ end
397
+
398
+ it "freemarker should be valid" do
399
+ AppGenerator::TEMPLATE_ENGINES.include?("ftl").should be_true
400
+ end
401
+ end
402
+
403
+ context "valid build tools" do
404
+ it "ant should be valid" do
405
+ AppGenerator::BUILD_TOOLS.include?("ant").should be_true
406
+ end
407
+
408
+ it "maven should be valid" do
409
+ AppGenerator::BUILD_TOOLS.include?("mvn").should be_true
410
+ end
411
+
412
+ it "gradle should be valid" do
413
+ AppGenerator::BUILD_TOOLS.include?("gradle").should be_true
414
+ end
415
+ end
416
+
417
+ context "valid orm" do
418
+ it "jpa should be valid" do
419
+ AppGenerator::ORMS.include?("jpa").should be_true
420
+ end
421
+
422
+ it "hibernate should be valid" do
423
+ AppGenerator::ORMS.include?("hibernate").should be_true
424
+ end
425
+ end
426
+
427
+ it "should configure banner" do
428
+ AppGenerator.banner.should == "vraptor new PROJECT_PATH [options]"
429
+ end
430
+
431
+ context "validate options" do
432
+ before(:each) do
433
+ @project_path = "vraptor-scaffold"
434
+ end
435
+
436
+ it "should be invalid when build tool is not supported" do
437
+ Kernel.should_receive(:exit)
438
+ AppGenerator.new(@project_path, ["-b=maven"])
439
+ end
440
+
441
+ it "should be invalid when template engine is not supported" do
442
+ Kernel.should_receive(:exit)
443
+ AppGenerator.new(@project_path, ["-e=velocity"])
444
+ end
445
+
446
+ it "should be invalid when orm mapping is not supported" do
447
+ Kernel.should_receive(:exit)
448
+ AppGenerator.new(@project_path, ["-o=toplink"])
449
+ end
450
+
451
+ it "should be invalid when jquery version does not exist" do
452
+ Kernel.should_receive(:exit)
453
+ AppGenerator.new(@project_path, ["-j=1.x"])
454
+ end
455
+
456
+ it "should be invalid when gae and heroku are selected" do
457
+ Kernel.should_receive(:exit)
458
+ AppGenerator.new(@project_path, ["-g", "-h"])
459
+ end
460
+ end
461
+
462
+ context "heroku app" do
463
+ before(:all) do
464
+ @project_path = "heroku"
465
+ AppGenerator.new(@project_path, ["--heroku"]).invoke_all
466
+ end
467
+
468
+ after(:all) do
469
+ FileUtils.remove_dir(@project_path)
470
+ end
471
+
472
+ it "should create pom" do
473
+ source = File.join File.dirname(__FILE__), "templates", "pom-heroku.xml"
474
+ destination = "#{@project_path}/pom.xml"
475
+ exists_and_identical?(source, destination)
476
+ end
477
+
478
+ it "should create Procfile" do
479
+ File.exist?("#{@project_path}/Procfile").should be_true
480
+ end
481
+
482
+ it "should create main class to run heroku apps" do
483
+ File.exist?("#{@project_path}/src/main/java/Main.java").should be_true
484
+ end
485
+ end
486
+
487
+ context "gae app" do
488
+ before(:all) do
489
+ @project_path = "gae"
490
+ AppGenerator.new(@project_path, ["--gae"]).invoke_all
491
+ @main_java = "#{@project_path}/#{Configuration::MAIN_SRC}"
492
+ @app = "#{@main_java}/app"
493
+ end
494
+
495
+ after(:all) do
496
+ FileUtils.remove_dir(@project_path)
497
+ end
498
+
499
+ it "should create ivy.xml" do
500
+ source = File.join File.dirname(__FILE__), "templates", "ivy-gae.xml"
501
+ destination = "#{@project_path}/ivy.xml"
502
+ exists_and_identical?(source, destination)
503
+ end
504
+
505
+ it "should create ivysettings.xml" do
506
+ File.exist?("#{@project_path}/ivysettings.xml").should be_true
507
+ end
508
+
509
+ it "should not create generic entity" do
510
+ File.exist?("#{@app}/model/Entity.java").should be_false
511
+ end
512
+
513
+ it "should create appengine-web xml to run gae apps" do
514
+ File.exist?("#{@project_path}/#{Configuration::WEB_INF}/appengine-web.xml").should be_true
515
+ end
516
+
517
+ it "should create logging properties for gae apps" do
518
+ File.exist?("#{@project_path}/#{Configuration::WEB_INF}/logging.properties").should be_true
519
+ end
520
+
521
+ it "should create web.xml" do
522
+ source = File.join File.dirname(__FILE__), "templates", "gae-jsp-web.xml"
523
+ destination = "#{@project_path}/#{Configuration::WEB_INF}/web.xml"
524
+ exists_and_identical?(source, destination)
525
+ end
526
+
527
+ it "should generate a objectify repository" do
528
+ source = File.join File.dirname(__FILE__), "templates", "RepositoryObjectify.java"
529
+ destination = "#{@project_path}/#{Configuration::MAIN_SRC}/app/repositories/Repository.java"
530
+ exists_and_identical?(source, destination)
531
+ end
532
+
533
+ it "should generate a objectify resource factory" do
534
+ source = File.join File.dirname(__FILE__), "templates", "ObjectifyFactory.java"
535
+ destination = "#{@project_path}/#{Configuration::MAIN_SRC}/app/infra/ObjectifyFactory.java"
536
+ exists_and_identical?(source, destination)
537
+ end
538
+
539
+ it "should create a specific .classpath for gae" do
540
+ source = File.join File.dirname(__FILE__), "templates", "classpath-gae"
541
+ destination = "#{@project_path}/.classpath"
542
+ exists_and_identical?(source, destination)
543
+ end
544
+
545
+ it "should create a specific .project for gae" do
546
+ source = File.join File.dirname(__FILE__), "templates", "project-gae"
547
+ destination = "#{@project_path}/.project"
548
+ exists_and_identical?(source, destination)
549
+ end
550
+
551
+ it "should create .settings" do
552
+ settings = File.join @project_path, ".settings"
553
+ File.exist?(settings).should be_true
554
+ end
555
+ end
556
+
557
+ end