spring-gen 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +9 -0
  6. data/LICENSE.txt +674 -0
  7. data/README.md +133 -0
  8. data/Rakefile +1 -0
  9. data/bin/setup +7 -0
  10. data/bin/spring-gen +8 -0
  11. data/lib/command_router.rb +15 -0
  12. data/lib/commands/resource.rb +129 -0
  13. data/lib/commands/service.rb +53 -0
  14. data/lib/spring-gen/version.rb +3 -0
  15. data/lib/spring-gen.rb +5 -0
  16. data/lib/templates/layout/.gitignore +36 -0
  17. data/lib/templates/layout/build.gradle.erb +105 -0
  18. data/lib/templates/layout/intellij/config/checkstyle/checkstyle.xml +199 -0
  19. data/lib/templates/layout/intellij/config/codestyle/Codestyle.xml +34 -0
  20. data/lib/templates/layout/intellij/config/copyright/gnu.xml +6 -0
  21. data/lib/templates/layout/intellij/config/copyright/profiles_settings.xml +10 -0
  22. data/lib/templates/layout/src/java/config/AppConfig.java.erb +54 -0
  23. data/lib/templates/layout/src/java/main/App.java.erb +41 -0
  24. data/lib/templates/layout/src/resources/application.yml.erb +108 -0
  25. data/lib/templates/layout/src/resources/bootstrap.yml.erb +3 -0
  26. data/lib/templates/resource/assembler/Assembler.java.erb +57 -0
  27. data/lib/templates/resource/assembler/BaseAssembler.java.erb +95 -0
  28. data/lib/templates/resource/controller/BaseController.java.erb +66 -0
  29. data/lib/templates/resource/controller/Controller.java.erb +106 -0
  30. data/lib/templates/resource/exception/NotCreatedException.java.erb +34 -0
  31. data/lib/templates/resource/model/JpaBaseEntity.java.erb +43 -0
  32. data/lib/templates/resource/model/Model.java.erb +51 -0
  33. data/lib/templates/resource/model/MongodbBaseEntity.java.erb +33 -0
  34. data/lib/templates/resource/model/Neo4jBaseEntity.java.erb +81 -0
  35. data/lib/templates/resource/repository/Repository.java.erb +30 -0
  36. data/lib/templates/resource/resource/Resource.java.erb +48 -0
  37. data/lib/templates/resource/test/TestUtil.java.erb +85 -0
  38. data/lib/templates/resource/test/integration/jpa/IntegrationTest.java.erb +123 -0
  39. data/lib/templates/resource/test/integration/jpa/IntegrationTestConfig.java.erb +47 -0
  40. data/lib/templates/resource/test/integration/jpa/sampleData.xml.erb +20 -0
  41. data/lib/templates/resource/test/integration/mongodb/IntegrationTest.java.erb +114 -0
  42. data/lib/templates/resource/test/integration/mongodb/IntegrationTestConfig.java.erb +60 -0
  43. data/lib/templates/resource/test/integration/mongodb/SampleData.java.erb +43 -0
  44. data/lib/templates/resource/test/integration/neo4j/IntegrationTest.java.erb +123 -0
  45. data/lib/templates/resource/test/integration/neo4j/IntegrationTestConfig.java.erb +47 -0
  46. data/lib/templates/resource/test/integration/neo4j/SampleData.java.erb +23 -0
  47. data/lib/templates/resource/test/unit/assembler/AssemblerUnitTest.java.erb +52 -0
  48. data/lib/templates/resource/test/unit/assembler/AssemblerUnitTestConfig.java.erb +43 -0
  49. data/lib/templates/resource/test/unit/controller/ControllerUnitTest.java.erb +115 -0
  50. data/lib/templates/resource/test/unit/controller/ControllerUnitTestConfig.java.erb +64 -0
  51. data/lib/templates/service.yml.erb +4 -0
  52. data/lib/util.rb +39 -0
  53. data/spring-gen.gemspec +25 -0
  54. metadata +153 -0
@@ -0,0 +1,123 @@
1
+ package <%=@group_id%>.integration.<%=@model_name.downcase%>.routes;
2
+ /*
3
+ * Copyright (c) 2015 <%=@user_name%>.
4
+ * This program is free software; you can redistribute it and/or modify
5
+ * it under the terms of the GNU General Public License as published by
6
+ * the Free Software Foundation; either version 3 of the License, or
7
+ * (at your option) any later version.
8
+ * This program is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ * GNU General Public License for more details.
12
+ * You should have received a copy of the GNU General Public License
13
+ * along with this program; if not, write to the Free Software Foundation,
14
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
+ */
16
+
17
+ import static org.hamcrest.Matchers.hasSize;
18
+ import static org.hamcrest.Matchers.is;
19
+ import static org.hamcrest.Matchers.notNullValue;
20
+ import static util.TestUtil.toJson;
21
+ import static org.mockito.Matchers.any;
22
+ import static org.mockito.Matchers.eq;
23
+ import static org.mockito.Matchers.isNotNull;
24
+ import static org.mockito.Mockito.times;
25
+ import static org.mockito.Mockito.verify;
26
+ import static org.mockito.Mockito.verifyNoMoreInteractions;
27
+ import static org.mockito.Mockito.when;
28
+ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
29
+ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
30
+ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
31
+ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
32
+ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
33
+ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
34
+ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
35
+ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
36
+
37
+
38
+ import com.github.springtestdbunit.DbUnitTestExecutionListener;
39
+ import com.github.springtestdbunit.annotation.DatabaseSetup;
40
+ import <%=@group_id%>.model.<%=@model_name%>;
41
+ import <%=@group_id%>.integration.<%=@model_name.downcase%>.<%=@model_name%>IntegrationTestConfig;
42
+ import org.junit.Before;
43
+ import org.junit.Test;
44
+ import org.junit.runner.RunWith;
45
+ import org.springframework.beans.factory.annotation.Autowired;
46
+ import org.springframework.hateoas.MediaTypes;
47
+ import org.springframework.test.context.ContextConfiguration;
48
+ import org.springframework.test.context.TestExecutionListeners;
49
+ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
50
+ import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
51
+ import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
52
+ import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
53
+ import org.springframework.test.context.web.WebAppConfiguration;
54
+ import org.springframework.test.web.servlet.MockMvc;
55
+ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
56
+ import org.springframework.web.context.WebApplicationContext;
57
+ import util.TestUtil;
58
+
59
+ import static org.hamcrest.Matchers.is;
60
+ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
61
+ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
62
+ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
63
+ import static util.TestUtil.toJson;
64
+
65
+
66
+ /**
67
+ * A integration test for <%=@model_name%>s
68
+ * @author <%=@user_name%>
69
+ */
70
+ @RunWith(SpringJUnit4ClassRunner.class)
71
+ @ContextConfiguration(classes = {<%=@model_name%>IntegrationTestConfig.class})
72
+ @WebAppConfiguration
73
+ //TODO add custom sample-data in <%=@model_name.downcase%>SampleData.xml
74
+ @DatabaseSetup("/sampledata/<%=@model_name.downcase%>SampleData.xml")
75
+ @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,
76
+ DirtiesContextTestExecutionListener.class,
77
+ TransactionalTestExecutionListener.class,
78
+ DbUnitTestExecutionListener.class })
79
+ public class <%=@model_name%>IntegrationTest {
80
+
81
+ private MockMvc mockMvc;
82
+
83
+
84
+ @Autowired
85
+ private WebApplicationContext webApplicationContext;
86
+
87
+ /**
88
+ * sets up the test.
89
+ */
90
+ @Before
91
+ public void setUp() {
92
+ mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
93
+ }
94
+
95
+
96
+ @Test
97
+ public void testGet<%=@model_name%>s() throws Exception {
98
+
99
+ mockMvc.perform(get("/<%=@model_name.downcase%>s"))
100
+ .andExpect(status().isOk())
101
+ .andExpect(content().contentType(MediaTypes.HAL_JSON));
102
+ }
103
+
104
+ @Test
105
+ public void itShouldContainLinksToModulesOfficersAssistantsSelfAndRootModule()
106
+ throws Exception {
107
+ mockMvc.perform(get("/<%=@model_name.downcase%>s/1"))
108
+ .andExpect(status().isOk())
109
+ .andExpect(content().contentType(MediaTypes.HAL_JSON))
110
+ .andExpect(
111
+ jsonPath("$._links.self.href", is("http://localhost/<%=@model_name.downcase%>s/1")));
112
+ }
113
+
114
+ @Test
115
+ public void testCreate<%=@model_name%>() throws Exception {
116
+ mockMvc.perform(post("/<%=@model_name.downcase%>s")
117
+ .contentType(TestUtil.APPLICATION_JSON_UTF8)
118
+ .content(toJson(new <%=@model_name%>())))
119
+ .andExpect(status().isCreated())
120
+ .andExpect(redirectedUrl("http://localhost/<%=@model_name.downcase%>s/11"));
121
+
122
+ }
123
+ }
@@ -0,0 +1,47 @@
1
+ package <%=@group_id%>.integration.<%=@model_name.downcase%>;
2
+
3
+ /*
4
+ * Copyright (c) 2015 <%=@user_name%>.
5
+ * This program is free software; you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation; either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU General Public License for more details.
13
+ * You should have received a copy of the GNU General Public License
14
+ * along with this program; if not, write to the Free Software Foundation,
15
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
19
+ import org.springframework.boot.orm.jpa.EntityScan;
20
+ import org.springframework.context.annotation.ComponentScan;
21
+ import org.springframework.context.annotation.Configuration;
22
+ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
23
+ import org.springframework.data.web.config.EnableSpringDataWebSupport;
24
+ import org.springframework.hateoas.config.EnableHypermediaSupport;
25
+ import org.springframework.transaction.annotation.EnableTransactionManagement;
26
+ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
27
+ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
28
+
29
+ /**
30
+ * Configuration class for <%=@group_id%> integration test.
31
+ * @author <%=@user_name%>
32
+ */
33
+ @Configuration
34
+ <%if @full%>@ComponentScan(basePackages = {"<%=@group_id%>.repository",
35
+ "<%=@group_id%>.controller",
36
+ "<%=@group_id%>.assembler",
37
+ "<%=@group_id%>.resource"})
38
+ <%else%>@ComponentScan(basePackages = "<%=@group_id%>.repository")<%end%>
39
+ @EnableHypermediaSupport(type = {EnableHypermediaSupport.HypermediaType.HAL})
40
+ @EnableSpringDataWebSupport
41
+ @EnableWebMvc
42
+ @EnableAutoConfiguration
43
+ @EnableJpaRepositories(basePackages = "<%=@group_id%>.repository")
44
+ @EnableTransactionManagement
45
+ @EntityScan(basePackages = {"<%=@group_id%>.model"})
46
+ public class <%=@model_name%>IntegrationTestConfig extends WebMvcConfigurerAdapter {
47
+ }
@@ -0,0 +1,20 @@
1
+ <!--
2
+ ~ Copyright (c) 2015 <%=@user_name%>.
3
+ ~ This program is free software; you can redistribute it and/or modify
4
+ ~ it under the terms of the GNU General Public License as published by
5
+ ~ the Free Software Foundation; either version 3 of the License, or
6
+ ~ (at your option) any later version.
7
+ ~ This program is distributed in the hope that it will be useful,
8
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ ~ GNU General Public License for more details.
11
+ ~ You should have received a copy of the GNU General Public License
12
+ ~ along with this program; if not, write to the Free Software Foundation,
13
+ ~ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
14
+ -->
15
+
16
+ <dataset>
17
+ <%10.times do |i|%>
18
+ <<%=@model_name.downcase%> id="<%=i+1%>" <%@attributes.each do |a|%><%=a.name%>="<%=i+1%>" <%end%>/>
19
+ <%end%>
20
+ </dataset>
@@ -0,0 +1,114 @@
1
+ package <%=@group_id%>.integration.<%=@model_name.downcase%>;
2
+ /*
3
+ * Copyright (c) 2015 <%=@user_name%>.
4
+ * This program is free software; you can redistribute it and/or modify
5
+ * it under the terms of the GNU General Public License as published by
6
+ * the Free Software Foundation; either version 3 of the License, or
7
+ * (at your option) any later version.
8
+ * This program is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ * GNU General Public License for more details.
12
+ * You should have received a copy of the GNU General Public License
13
+ * along with this program; if not, write to the Free Software Foundation,
14
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
+ */
16
+
17
+ import static org.hamcrest.Matchers.hasSize;
18
+ import static org.hamcrest.Matchers.is;
19
+ import static org.hamcrest.Matchers.notNullValue;
20
+ import static util.TestUtil.toJson;
21
+ import static org.mockito.Matchers.any;
22
+ import static org.mockito.Matchers.eq;
23
+ import static org.mockito.Matchers.isNotNull;
24
+ import static org.mockito.Mockito.times;
25
+ import static org.mockito.Mockito.verify;
26
+ import static org.mockito.Mockito.verifyNoMoreInteractions;
27
+ import static org.mockito.Mockito.when;
28
+ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
29
+ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
30
+ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
31
+ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
32
+ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
33
+ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
34
+ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
35
+ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
36
+
37
+
38
+ import <%=@group_id%>.model.<%=@model_name%>;
39
+ import <%=@group_id%>.integration.<%=@model_name.downcase%>.<%=@model_name%>IntegrationTestConfig;
40
+ import org.junit.Before;
41
+ import org.junit.Test;
42
+ import org.junit.runner.RunWith;
43
+ import org.springframework.beans.factory.annotation.Autowired;
44
+ import org.springframework.hateoas.MediaTypes;
45
+ import org.springframework.test.context.ContextConfiguration;
46
+ import org.springframework.test.context.TestExecutionListeners;
47
+ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
48
+ import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
49
+ import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
50
+ import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
51
+ import org.springframework.test.context.web.WebAppConfiguration;
52
+ import org.springframework.test.web.servlet.MockMvc;
53
+ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
54
+ import org.springframework.web.context.WebApplicationContext;
55
+ import util.TestUtil;
56
+
57
+ import static org.hamcrest.Matchers.is;
58
+ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
59
+ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
60
+ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
61
+ import static util.TestUtil.toJson;
62
+
63
+
64
+ /**
65
+ * A integration test for <%=@model_name%>s
66
+ * @author <%=@user_name%>
67
+ */
68
+ @RunWith(SpringJUnit4ClassRunner.class)
69
+ @ContextConfiguration(classes = {<%=@model_name%>IntegrationTestConfig.class})
70
+ @WebAppConfiguration
71
+ //TODO add custom sample-data in <%=@model_name.downcase%>SampleData.java
72
+ public class <%=@model_name%>IntegrationTest {
73
+
74
+ private MockMvc mockMvc;
75
+
76
+
77
+ @Autowired
78
+ private WebApplicationContext webApplicationContext;
79
+
80
+ /**
81
+ * sets up the test.
82
+ */
83
+ @Before
84
+ public void setUp() {
85
+ mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
86
+ }
87
+
88
+
89
+ @Test
90
+ public void testGet<%=@model_name%>s() throws Exception {
91
+
92
+ mockMvc.perform(get("/<%=@model_name.downcase%>s"))
93
+ .andExpect(status().isOk())
94
+ .andExpect(content().contentType(MediaTypes.HAL_JSON));
95
+ }
96
+
97
+ @Test
98
+ public void testGetAll()
99
+ throws Exception {
100
+ mockMvc.perform(get("/<%=@model_name.downcase%>s/1"))
101
+ .andExpect(status().isOk())
102
+ .andExpect(content().contentType(MediaTypes.HAL_JSON))
103
+ .andExpect(
104
+ jsonPath("$._links.self.href", is("http://localhost/<%=@model_name.downcase%>s/1")));
105
+ }
106
+
107
+ @Test
108
+ public void testCreate<%=@model_name%>() throws Exception {
109
+ mockMvc.perform(post("/<%=@model_name.downcase%>s")
110
+ .contentType(TestUtil.APPLICATION_JSON_UTF8)
111
+ .content(toJson(new <%=@model_name%>())))
112
+ .andExpect(status().isCreated());
113
+ }
114
+ }
@@ -0,0 +1,60 @@
1
+ package <%=@group_id%>.integration.<%=@model_name.downcase%>;
2
+
3
+ /*
4
+ * Copyright (c) 2015 <%=@user_name%>.
5
+ * This program is free software; you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation; either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU General Public License for more details.
13
+ * You should have received a copy of the GNU General Public License
14
+ * along with this program; if not, write to the Free Software Foundation,
15
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+ import com.github.fakemongo.Fongo;
19
+ import com.mongodb.Mongo;
20
+ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
21
+ import org.springframework.context.annotation.Bean;
22
+ import org.springframework.context.annotation.ComponentScan;
23
+ import org.springframework.context.annotation.Configuration;
24
+ import org.springframework.data.mongodb.core.MongoTemplate;
25
+ import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
26
+ import org.springframework.data.web.config.EnableSpringDataWebSupport;
27
+ import org.springframework.hateoas.config.EnableHypermediaSupport;
28
+ import org.springframework.transaction.annotation.EnableTransactionManagement;
29
+ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
30
+ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
31
+ /**
32
+ * Configuration class for <%=@group_id%> integration test.
33
+ * @author <%=@user_name%>
34
+ */
35
+ @Configuration
36
+ <%if @full%>@ComponentScan(basePackages = {"<%=@group_id%>.repository",
37
+ "<%=@group_id%>.controller",
38
+ "<%=@group_id%>.assembler",
39
+ "<%=@group_id%>.resource",
40
+ "<%=@group_id%>.integration"})
41
+ <%else%>@ComponentScan(basePackages = {"<%=@group_id%>.repository","<%=@group_id%>.integration"})<%end%>
42
+ @EnableHypermediaSupport(type = {EnableHypermediaSupport.HypermediaType.HAL})
43
+ @EnableSpringDataWebSupport
44
+ @EnableWebMvc
45
+ @EnableAutoConfiguration
46
+ @EnableMongoRepositories(basePackages = "<%=@group_id%>.repository")
47
+ @EnableTransactionManagement
48
+ public class <%=@model_name%>IntegrationTestConfig extends WebMvcConfigurerAdapter {
49
+
50
+ @Bean
51
+ public Mongo mongo() {
52
+ Fongo fongo = new Fongo("test");
53
+ return fongo.getMongo();
54
+ }
55
+
56
+ @Bean
57
+ public MongoTemplate mongoTemplate() {
58
+ return new MongoTemplate(mongo(),"<%=@model_name%>");
59
+ }
60
+ }
@@ -0,0 +1,43 @@
1
+ package <%=@group_id%>.integration.<%=@model_name.downcase%>;
2
+
3
+ /*
4
+ * Copyright (c) 2015 <%=@user_name%>.
5
+ * This program is free software; you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation; either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU General Public License for more details.
13
+ * You should have received a copy of the GNU General Public License
14
+ * along with this program; if not, write to the Free Software Foundation,
15
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+ import org.asdf.model.<%=@model_name%>;
19
+ import org.springframework.beans.factory.annotation.Autowired;
20
+ import org.springframework.data.mongodb.core.MongoOperations;
21
+ import org.springframework.stereotype.Component;
22
+
23
+
24
+
25
+ @Component
26
+ public class <%=@model_name%>SampleData {
27
+
28
+ @Autowired
29
+ MongoOperations mongoOperations;
30
+
31
+ public void seed() {
32
+
33
+ for (int i = 0; i < 10; i++) {
34
+ <%=@model_name%> b = new <%=@model_name%>();
35
+ b.setId(String.valueOf(i));
36
+ mongoOperations.save(b);
37
+ }
38
+ }
39
+
40
+ public void destroy() {
41
+ mongoOperations.dropCollection("<%=@model_name%>");
42
+ }
43
+ }
@@ -0,0 +1,123 @@
1
+ package <%=@group_id%>.integration.<%=@model_name.downcase%>;
2
+ /*
3
+ * Copyright (c) 2015 <%=@user_name%>.
4
+ * This program is free software; you can redistribute it and/or modify
5
+ * it under the terms of the GNU General Public License as published by
6
+ * the Free Software Foundation; either version 3 of the License, or
7
+ * (at your option) any later version.
8
+ * This program is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ * GNU General Public License for more details.
12
+ * You should have received a copy of the GNU General Public License
13
+ * along with this program; if not, write to the Free Software Foundation,
14
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
+ */
16
+
17
+ import static org.hamcrest.Matchers.hasSize;
18
+ import static org.hamcrest.Matchers.is;
19
+ import static org.hamcrest.Matchers.notNullValue;
20
+ import static util.TestUtil.toJson;
21
+ import static org.mockito.Matchers.any;
22
+ import static org.mockito.Matchers.eq;
23
+ import static org.mockito.Matchers.isNotNull;
24
+ import static org.mockito.Mockito.times;
25
+ import static org.mockito.Mockito.verify;
26
+ import static org.mockito.Mockito.verifyNoMoreInteractions;
27
+ import static org.mockito.Mockito.when;
28
+ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
29
+ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
30
+ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
31
+ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
32
+ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
33
+ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
34
+ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
35
+ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
36
+
37
+
38
+ import com.github.springtestdbunit.DbUnitTestExecutionListener;
39
+ import com.github.springtestdbunit.annotation.DatabaseSetup;
40
+ import <%=@group_id%>.model.<%=@model_name%>;
41
+ import <%=@group_id%>.integration.<%=@model_name.downcase%>.<%=@model_name%>IntegrationTestConfig;
42
+ import org.junit.Before;
43
+ import org.junit.Test;
44
+ import org.junit.runner.RunWith;
45
+ import org.springframework.beans.factory.annotation.Autowired;
46
+ import org.springframework.hateoas.MediaTypes;
47
+ import org.springframework.test.context.ContextConfiguration;
48
+ import org.springframework.test.context.TestExecutionListeners;
49
+ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
50
+ import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
51
+ import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
52
+ import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
53
+ import org.springframework.test.context.web.WebAppConfiguration;
54
+ import org.springframework.test.web.servlet.MockMvc;
55
+ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
56
+ import org.springframework.web.context.WebApplicationContext;
57
+ import util.TestUtil;
58
+
59
+ import static org.hamcrest.Matchers.is;
60
+ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
61
+ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
62
+ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
63
+ import static util.TestUtil.toJson;
64
+
65
+
66
+ /**
67
+ * A integration test for <%=@model_name%>s
68
+ * @author <%=@user_name%>
69
+ */
70
+ @RunWith(SpringJUnit4ClassRunner.class)
71
+ @ContextConfiguration(classes = {<%=@model_name%>IntegrationTestConfig.class})
72
+ @WebAppConfiguration
73
+ //TODO add custom sample-data in <%=@model_name.downcase%>SampleData.xml
74
+ @DatabaseSetup("/sampledata/<%=@model_name.downcase%>SampleData.xml")
75
+ @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,
76
+ DirtiesContextTestExecutionListener.class,
77
+ TransactionalTestExecutionListener.class,
78
+ DbUnitTestExecutionListener.class })
79
+ public class <%=@model_name%>IntegrationTest {
80
+
81
+ private MockMvc mockMvc;
82
+
83
+
84
+ @Autowired
85
+ private WebApplicationContext webApplicationContext;
86
+
87
+ /**
88
+ * sets up the test.
89
+ */
90
+ @Before
91
+ public void setUp() {
92
+ mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
93
+ }
94
+
95
+
96
+ @Test
97
+ public void testGet<%=@model_name%>s() throws Exception {
98
+
99
+ mockMvc.perform(get("/<%=@model_name.downcase%>s"))
100
+ .andExpect(status().isOk())
101
+ .andExpect(content().contentType(MediaTypes.HAL_JSON));
102
+ }
103
+
104
+ @Test
105
+ public void itShouldContainLinksToModulesOfficersAssistantsSelfAndRootModule()
106
+ throws Exception {
107
+ mockMvc.perform(get("/<%=@model_name.downcase%>s/1"))
108
+ .andExpect(status().isOk())
109
+ .andExpect(content().contentType(MediaTypes.HAL_JSON))
110
+ .andExpect(
111
+ jsonPath("$._links.self.href", is("http://localhost/<%=@model_name.downcase%>s/1")));
112
+ }
113
+
114
+ @Test
115
+ public void testCreate<%=@model_name%>() throws Exception {
116
+ mockMvc.perform(post("/<%=@model_name.downcase%>s")
117
+ .contentType(TestUtil.APPLICATION_JSON_UTF8)
118
+ .content(toJson(new <%=@model_name%>())))
119
+ .andExpect(status().isCreated())
120
+ .andExpect(redirectedUrl("http://localhost/<%=@model_name.downcase%>s/11"));
121
+
122
+ }
123
+ }
@@ -0,0 +1,47 @@
1
+ package <%=@group_id%>.integration.<%=@model_name.downcase%>;
2
+
3
+ /*
4
+ * Copyright (c) 2015 <%=@user_name%>.
5
+ * This program is free software; you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation; either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU General Public License for more details.
13
+ * You should have received a copy of the GNU General Public License
14
+ * along with this program; if not, write to the Free Software Foundation,
15
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
19
+ import org.springframework.boot.orm.jpa.EntityScan;
20
+ import org.springframework.context.annotation.ComponentScan;
21
+ import org.springframework.context.annotation.Configuration;
22
+ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
23
+ import org.springframework.data.web.config.EnableSpringDataWebSupport;
24
+ import org.springframework.hateoas.config.EnableHypermediaSupport;
25
+ import org.springframework.transaction.annotation.EnableTransactionManagement;
26
+ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
27
+ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
28
+
29
+ /**
30
+ * Configuration class for <%=@group_id%> integration test.
31
+ * @author <%=@user_name%>
32
+ */
33
+ @Configuration
34
+ <%if @full%>@ComponentScan(basePackages = {"<%=@group_id%>.repository",
35
+ "<%=@group_id%>.controller",
36
+ "<%=@group_id%>.assembler",
37
+ "<%=@group_id%>.resource"})
38
+ <%else%>@ComponentScan(basePackages = "<%=@group_id%>.repository")<%end%>
39
+ @EnableHypermediaSupport(type = {EnableHypermediaSupport.HypermediaType.HAL})
40
+ @EnableSpringDataWebSupport
41
+ @EnableWebMvc
42
+ @EnableAutoConfiguration
43
+ @EnableJpaRepositories(basePackages = "<%=@group_id%>.repository")
44
+ @EnableTransactionManagement
45
+ @EntityScan(basePackages = {"<%=@group_id%>.model"})
46
+ public class <%=@model_name%>IntegrationTestConfig extends WebMvcConfigurerAdapter {
47
+ }
@@ -0,0 +1,23 @@
1
+ package <%=@group_id%>.integration.<%=@model_name.downcase%>;
2
+
3
+ /*
4
+ * Copyright (c) 2015 <%=@user_name%>.
5
+ * This program is free software; you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation; either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU General Public License for more details.
13
+ * You should have received a copy of the GNU General Public License
14
+ * along with this program; if not, write to the Free Software Foundation,
15
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+ public class SampleData {
19
+
20
+ public void seed() {
21
+
22
+ }
23
+ }
@@ -0,0 +1,52 @@
1
+ package <%=@group_id%>.unit.<%=@model_name.downcase%>.assembler;
2
+
3
+ /*
4
+ * Copyright (c) 2015 <%=@user_name%>.
5
+ * This program is free software; you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation; either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU General Public License for more details.
13
+ * You should have received a copy of the GNU General Public License
14
+ * along with this program; if not, write to the Free Software Foundation,
15
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+ import static org.junit.Assert.assertEquals;
19
+
20
+ import <%=@group_id%>.assembler.<%=@model_name%>Assembler;
21
+ import <%=@group_id%>.model.<%=@model_name%>;
22
+ import org.junit.Before;
23
+ import org.junit.Test;
24
+ import org.junit.runner.RunWith;
25
+ import org.springframework.beans.factory.annotation.Autowired;
26
+ import org.springframework.hateoas.ResourceSupport;
27
+ import org.springframework.test.context.ContextConfiguration;
28
+ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
29
+ import org.springframework.test.context.web.WebAppConfiguration;
30
+
31
+ /**
32
+ * Unit test for <%=@model_name%> assemblers.
33
+ * @author <%=@user_name%>
34
+ */
35
+ @RunWith(SpringJUnit4ClassRunner.class)
36
+ @ContextConfiguration(classes = {<%=@model_name%>AssemblerUnitTestConfig.class})
37
+ @WebAppConfiguration
38
+ public class <%=@model_name%>AssemblerUnitTest {
39
+
40
+
41
+ @Autowired
42
+ private <%=@model_name%>Assembler testInstance;
43
+
44
+
45
+ @Test
46
+ public void testToResource() throws Exception {
47
+ <%=@model_name%> instance = new <%=@model_name%>();
48
+ instance.setId(1L);
49
+ ResourceSupport resourceSupport = testInstance.toResource(instance);
50
+ assertEquals("self",resourceSupport.getId().getRel());
51
+ }
52
+ }