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,61 @@
1
+ <head>
2
+ <script src="/javascripts/Product.js"></script>
3
+ <script src="/javascripts/ProductController.js"></script>
4
+ </head>
5
+
6
+ <c:if test="${not empty errors}">
7
+ <c:forEach items="${errors}" var="error">
8
+ <div class="control-group error">
9
+ <label class="control-label" for="inputError"> ${error.category} - ${error.message}</label>
10
+ </div>
11
+ </c:forEach>
12
+ </c:if>
13
+
14
+ <script>
15
+ product = ${json};
16
+ </script>
17
+
18
+ <div class="row" ng-controller="ProductController">
19
+ <div class="span6">
20
+ <div class="well">
21
+ <form action="${pageContext.request.contextPath}/products" method="post" class="form-horizontal" id="productForm">
22
+ <fieldset>
23
+ <legend>product</legend>
24
+ <c:if test="${not empty product.id}">
25
+ <input type="hidden" name="product.id" value="${product.id}"
26
+ ng-model="product.id" />
27
+ <input type="hidden" name="_method" value="put"/>
28
+ </c:if>
29
+
30
+ <div class="control-group">
31
+ <label class="control-label" for="product.name">
32
+ Name
33
+ </label>
34
+ <div class="controls">
35
+ <input type="text" name="product.name" id="product.name" value="${product.name}"
36
+ ng-model="product.name" />
37
+ </div>
38
+ </div>
39
+ <div class="control-group">
40
+ <label class="control-label" for="product.myFlag">
41
+ My flag
42
+ </label>
43
+ <div class="controls">
44
+ <input type="text" name="product.myFlag" id="product.myFlag" value="${product.myFlag}"
45
+ ng-model="product.myFlag" />
46
+ </div>
47
+ </div>
48
+
49
+ <div class="form-actions">
50
+ <div class="pull-right">
51
+ <button type="submit" class="btn btn-primary">Save!</button>
52
+ <a href="${pageContext.request.contextPath}/products" class="btn">Cancel</a>
53
+ </div>
54
+ </div>
55
+ </fieldset>
56
+ </form>
57
+ </div>
58
+ </div>
59
+ <div class="span6"></div>
60
+ </div>
61
+
@@ -0,0 +1,54 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../../spec_helper")
2
+
3
+ describe ModelGenerator do
4
+
5
+ it "model template path" do
6
+ ModelGenerator.new("category", build_attributes).template_path.should == "src/templates/models"
7
+ end
8
+
9
+ context "jpa" do
10
+ before(:each) do
11
+ mock_config_file
12
+ @generator = ModelGenerator.new("product", build_attributes)
13
+ @generator.build
14
+ end
15
+
16
+ after(:each) do
17
+ FileUtils.remove_dir("src")
18
+ end
19
+
20
+ it "should create model" do
21
+ source = File.join File.dirname(__FILE__), "templates", "Product.java"
22
+ destination = Configuration.main_class_path "model", "Product.java"
23
+ exists_and_identical?(source, destination)
24
+ end
25
+
26
+ it "should create model test" do
27
+ test_class = Configuration.test_class_path "model", "ProductTest.java"
28
+ File.exist?(test_class).should be_true
29
+ end
30
+ end
31
+
32
+ context "hibernate" do
33
+ before(:each) do
34
+ config = {"package" => "app", "orm" => "hibernate", "models_package" => "model"}
35
+ YAML.stub!(:load_file).with(Configuration::FILENAME).and_return(config)
36
+ AppGenerator.new("src", ["-o=hibernate"]).configure_orm
37
+ FileUtils.chdir("src")
38
+ @generator = ModelGenerator.new("product", build_attributes)
39
+ @generator.build
40
+ FileUtils.chdir("..")
41
+ end
42
+
43
+ after(:each) do
44
+ FileUtils.remove_dir("src")
45
+ end
46
+
47
+ it "should map entity in hibernate.cfg.xml when orm is hibernate" do
48
+ source = File.join File.dirname(__FILE__), "templates", "hibernate.cfg.xml"
49
+ destination = File.join "src", Configuration::MAIN_RESOURCES, "hibernate.cfg.xml"
50
+ exists_and_identical?(source, destination)
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../../spec_helper")
2
+
3
+ describe ObjectifyModelGenerator do
4
+
5
+ context "objectify" do
6
+ before(:all) do
7
+ AppGenerator.new("src", ["-o=objectify", "--gae"]).invoke_all
8
+ FileUtils.chdir("src")
9
+ @generator = ObjectifyModelGenerator.new("product", build_attributes)
10
+ @generator.build
11
+ FileUtils.chdir("..")
12
+ @project_path = "src"
13
+ end
14
+
15
+ before(:each) do
16
+ mock_objectify_config_file
17
+ end
18
+
19
+ after(:all) do
20
+ FileUtils.remove_dir "src"
21
+ end
22
+
23
+ it "should create model" do
24
+ source = File.join File.dirname(__FILE__), "templates", "Objectify_Product.java"
25
+ destination = @project_path + File::Separator + Configuration.main_class_path("models", "Product.java")
26
+ exists_and_identical?(source, destination)
27
+ end
28
+
29
+ it "should create model test" do
30
+ test_class = @project_path + File::Separator + Configuration.test_class_path("models", "ProductTest.java")
31
+ File.exist?(test_class).should be_true
32
+ end
33
+
34
+ it "should map model in objetify factory" do
35
+ source = File.join File.dirname(__FILE__), "templates", "ObjectifyFactory.java"
36
+ destination = File.join "src", Configuration::MAIN_SRC, "app", "infra", "ObjectifyFactory.java"
37
+ exists_and_identical?(source, destination)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,33 @@
1
+ package app.infra;
2
+
3
+ import javax.annotation.PostConstruct;
4
+
5
+ import br.com.caelum.vraptor.ioc.Component;
6
+ import br.com.caelum.vraptor.ioc.ComponentFactory;
7
+ import br.com.caelum.vraptor.ioc.RequestScoped;
8
+
9
+ import com.googlecode.objectify.Objectify;
10
+ import com.googlecode.objectify.ObjectifyService;
11
+
12
+ import app.models.Product;
13
+
14
+ @Component
15
+ @RequestScoped
16
+ public class ObjectifyFactory implements ComponentFactory<Objectify> {
17
+
18
+ private Objectify session;
19
+
20
+ static {
21
+ ObjectifyService.register(Product.class);
22
+ }
23
+
24
+ @PostConstruct
25
+ public void abreSession() {
26
+ session = ObjectifyService.begin();
27
+ }
28
+
29
+ @Override
30
+ public Objectify getInstance() {
31
+ return session;
32
+ }
33
+ }
@@ -0,0 +1,38 @@
1
+ package app.models;
2
+
3
+ import javax.persistence.Entity;
4
+ import javax.persistence.Id;
5
+
6
+ @Entity
7
+ public class Product {
8
+
9
+ @Id
10
+ private Long id;
11
+ private String name;
12
+ private boolean myFlag;
13
+
14
+ public void setId(Long id) {
15
+ this.id = id;
16
+ }
17
+
18
+ public Long getId() {
19
+ return id;
20
+ }
21
+
22
+ public void setName(String name) {
23
+ this.name = name;
24
+ }
25
+
26
+ public String getName() {
27
+ return name;
28
+ }
29
+
30
+ public void setMyFlag(boolean myFlag) {
31
+ this.myFlag = myFlag;
32
+ }
33
+
34
+ public boolean isMyFlag() {
35
+ return myFlag;
36
+ }
37
+
38
+ }
@@ -0,0 +1,25 @@
1
+ package app.model;
2
+
3
+ @javax.persistence.Entity
4
+ public class Product extends Entity {
5
+
6
+ private String name;
7
+ private boolean myFlag;
8
+
9
+ public void setName(String name) {
10
+ this.name = name;
11
+ }
12
+
13
+ public String getName() {
14
+ return name;
15
+ }
16
+
17
+ public void setMyFlag(boolean myFlag) {
18
+ this.myFlag = myFlag;
19
+ }
20
+
21
+ public boolean isMyFlag() {
22
+ return myFlag;
23
+ }
24
+
25
+ }
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
3
+
4
+ <hibernate-configuration>
5
+ <session-factory>
6
+ <mapping class='app.model.Product'/>
7
+ </session-factory>
8
+ </hibernate-configuration>
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../../spec_helper")
2
+
3
+ describe ObjectifyRepositoryGenerator do
4
+
5
+ after(:each) do
6
+ FileUtils.remove_dir('src')
7
+ end
8
+
9
+ context "Objectify" do
10
+ before(:each) do
11
+ mock_config_file
12
+ @generator = ObjectifyRepositoryGenerator.new("product", build_attributes)
13
+ @generator.build
14
+ end
15
+
16
+ it "should create repository interface" do
17
+ source = File.join File.dirname(__FILE__), "templates", "Objectify_ProductRepository.java"
18
+ destination = Configuration.main_class_path "repository", "ProductRepository.java"
19
+ exists_and_identical?(source, destination)
20
+ end
21
+
22
+ it "should create repository impl" do
23
+ source = File.join File.dirname(__FILE__), "templates", "Objectify_ProductRepositoryImpl.java"
24
+ destination = Configuration.main_class_path "repository", "ProductRepositoryImpl.java"
25
+ exists_and_identical?(source, destination)
26
+ end
27
+
28
+ it "should create repository test" do
29
+ test_class = Configuration.test_class_path "repository", "ProductRepositoryImplTest.java"
30
+ File.exist?(test_class).should be_true
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,68 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../../spec_helper")
2
+
3
+ describe RepositoryGenerator do
4
+
5
+ it "repository template path" do
6
+ RepositoryGenerator.new("category", build_attributes).template_path.should == "src/templates/repositories"
7
+ end
8
+
9
+ context "JPA" do
10
+ before(:each) do
11
+ mock_config_file
12
+ @generator = RepositoryGenerator.new("product", build_attributes)
13
+ @generator.build
14
+ end
15
+
16
+ after(:each) do
17
+ FileUtils.remove_dir("src")
18
+ end
19
+
20
+ it "should create repository interface" do
21
+ source = File.join File.dirname(__FILE__), "templates", "ProductRepository.java"
22
+ destination = Configuration.main_class_path "repository", "ProductRepository.java"
23
+ exists_and_identical?(source, destination)
24
+ end
25
+
26
+ it "should create repository impl" do
27
+ source = File.join File.dirname(__FILE__), "templates", "ProductRepositoryImpl.java"
28
+ destination = Configuration.main_class_path "repository", "ProductRepositoryImpl.java"
29
+ exists_and_identical?(source, destination)
30
+ end
31
+
32
+ it "should create repository test" do
33
+ test_class = Configuration.test_class_path "repository", "ProductRepositoryImplTest.java"
34
+ File.exist?(test_class).should be_true
35
+ end
36
+ end
37
+
38
+ context "Hibernate" do
39
+ before(:each) do
40
+ config = {"template_engine" => "jsp", "package" => "app", "orm" => "hibernate",
41
+ "repositories_package" => "repository", "models_package" => "models"}
42
+ YAML.stub!(:load_file).with(Configuration::FILENAME).and_return(config)
43
+ @generator = RepositoryGenerator.new("client", build_attributes)
44
+ @generator.build
45
+ end
46
+
47
+ after(:each) do
48
+ FileUtils.remove_dir("src")
49
+ end
50
+
51
+ it "should create repository interface" do
52
+ source = File.join File.dirname(__FILE__), "templates", "ClientRepository.java"
53
+ destination = Configuration.main_class_path "repository", "ClientRepository.java"
54
+ exists_and_identical?(source, destination)
55
+ end
56
+
57
+ it "should create repository impl" do
58
+ source = File.join File.dirname(__FILE__), "templates", "ClientRepositoryImpl.java"
59
+ destination = Configuration.main_class_path "repository", "ClientRepositoryImpl.java"
60
+ exists_and_identical?(source, destination)
61
+ end
62
+
63
+ it "should create repository test" do
64
+ test_class = Configuration.test_class_path "repository", "ClientRepositoryImplTest.java"
65
+ File.exist?(test_class).should be_true
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,22 @@
1
+ package app.repository;
2
+
3
+ import java.util.List;
4
+
5
+ import app.models.Client;
6
+
7
+ public interface ClientRepository {
8
+ /*
9
+ * Delete the methods you don't want to expose
10
+ */
11
+
12
+ void create(Client entity);
13
+
14
+ Client update(Client entity);
15
+
16
+ void destroy(Client entity);
17
+
18
+ Client find(Long id);
19
+
20
+ List<Client> findAll();
21
+
22
+ }
@@ -0,0 +1,16 @@
1
+ package app.repository;
2
+
3
+ import org.hibernate.Session;
4
+
5
+ import br.com.caelum.vraptor.ioc.Component;
6
+ import app.models.Client;
7
+
8
+ @Component
9
+ public class ClientRepositoryImpl
10
+ extends Repository<Client, Long>
11
+ implements ClientRepository {
12
+
13
+ ClientRepositoryImpl(Session session) {
14
+ super(session);
15
+ }
16
+ }
@@ -0,0 +1,22 @@
1
+ package app.repository;
2
+
3
+ import java.util.List;
4
+
5
+ import app.model.Product;
6
+
7
+ public interface ProductRepository {
8
+ /*
9
+ * Delete the methods you don't want to expose
10
+ */
11
+
12
+ void create(Product entity);
13
+
14
+ void update(Product entity);
15
+
16
+ void destroy(Product entity);
17
+
18
+ Product find(Long id);
19
+
20
+ List<Product> findAll();
21
+
22
+ }
@@ -0,0 +1,16 @@
1
+ package app.repository;
2
+
3
+ import com.googlecode.objectify.Objectify;
4
+
5
+ import br.com.caelum.vraptor.ioc.Component;
6
+ import app.model.Product;
7
+
8
+ @Component
9
+ public class ProductRepositoryImpl
10
+ extends Repository<Product>
11
+ implements ProductRepository {
12
+
13
+ ProductRepositoryImpl(Objectify objectify) {
14
+ super(objectify);
15
+ }
16
+ }