spring-gen 0.2.2 → 0.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09f568bcce438f10eadb24b9f744caa7ce7ea192
4
- data.tar.gz: d896cec36aded99c24308a588ac1cae35cb44b09
3
+ metadata.gz: 18946e444ddd8e8e936c8e80f5ae11eee8c1f491
4
+ data.tar.gz: b6d635ada116d41f68976848010575825cca9b07
5
5
  SHA512:
6
- metadata.gz: d5da0583538330ea77db8864df58a2017ca252595fce7ce30f96360222ff08dee2d4c34c5cb0440e10e61e3f0dfee27079ee361cf6e52c25821da5db8c8bd097
7
- data.tar.gz: d37f257a8efc153ee39a5448ca2e8d4286dfb6d6aab80eba5b156e86ee6ea8bd718e969bbc6f6a5d38edd3c23e6e9de0daa361a3bb693fe4ffa279c3d1c041ef
6
+ metadata.gz: 76472927a0b2646fdba38ec9945ea3acd12a72a180dbd44af9706832158a3e406fb4de25958e52ae38b94db2cb85ba2af3e63c5c80cfffca78cf38b1ed512490
7
+ data.tar.gz: aee3fb4f3c1c6384bc43732f4e7f2ab3e4aef7a6f7aa3e45c6c7705ab20e807654c7fd636ad337c9908a04f2d94d648f768de507fc2ee3d86287324fdf7b2c50
@@ -60,13 +60,16 @@ class Resource < Thor::Group
60
60
 
61
61
  case config.repository_technique
62
62
  when 'jpa'
63
+ @id_type = "Long"
63
64
  #TODO unify sample data. This check should not need to exist.
64
65
  template "templates/src/test/java/integration/#{config.repository_technique}/sampleData.xml.erb",
65
66
  "#{content_root}/src/test/resources/sampledata/#{@model_name.downcase}SampleData.xml"
66
67
  when "mongodb"
68
+ @id_type = "String"
67
69
  template "templates/src/test/java/integration/#{config.repository_technique}/SampleData.java.erb",
68
70
  "#{content_root}/src/test/java/#{fs_path}/integration/#{@model_name.downcase}/#{@model_name}SampleData.java"
69
71
  when "neo4j"
72
+ @id_type = "Long"
70
73
  template "templates/src/test/java/integration/#{config.repository_technique}/SampleData.java.erb",
71
74
  "#{content_root}/src/test/java/#{fs_path}/integration/#{@model_name.downcase}/#{@model_name}SampleData.java"
72
75
  else
@@ -111,4 +114,15 @@ class Resource < Thor::Group
111
114
  end
112
115
  end
113
116
 
117
+ no_tasks do
118
+ def augment_test_id(id)
119
+ case @id_type
120
+ when "String" then "String.valueOf(#{id})"
121
+ when "Long" then "Long.valueOf(#{id})"
122
+ else id
123
+ end
124
+ end
125
+ end
126
+
127
+
114
128
  end
@@ -2,7 +2,6 @@ package <%=@package%>.controller;
2
2
 
3
3
  <%=@licence%>
4
4
 
5
- import <%=@package%>.exception.NotCreatedException;
6
5
  import <%=@package%>.model.BaseEntity;
7
6
  import org.springframework.beans.factory.annotation.Autowired;
8
7
  import org.springframework.data.rest.webmvc.ResourceNotFoundException;
@@ -42,12 +41,4 @@ public abstract class BaseController {
42
41
  public String handleNotFound(ResourceNotFoundException ex) {
43
42
  return ex.toString();
44
43
  }
45
-
46
-
47
-
48
- @ExceptionHandler(NotCreatedException.class)
49
- @ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
50
- public String handleNotCreated(NotCreatedException ex) {
51
- return "couldn't create resource";
52
- }
53
44
  }
@@ -71,21 +71,22 @@ public class <%=@model_name%>Controller extends BaseController {
71
71
  * @return a response.
72
72
  */
73
73
  @RequestMapping(value = "/{id}", method = RequestMethod.GET)
74
- public ResponseEntity<<%=@model_name%>Resource> getOne(@PathVariable Long id) {
74
+ public ResponseEntity<<%=@model_name%>Resource> getOne(@PathVariable <%=@id_type%> id) {
75
75
  <%=@model_name%>Resource result
76
76
  = <%=@model_name.downcase%>Assembler.toResource(<%=@model_name.downcase%>Repository.findOne(id));
77
77
  return ResponseEntity.ok().body(result);
78
78
  }
79
79
 
80
80
  @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
81
- public ResponseEntity<?> delete(@PathVariable Long id) {
81
+ public ResponseEntity<?> delete(@PathVariable <%=@id_type%> id) {
82
82
  <%=@model_name.downcase%>Repository.delete(id);
83
83
  return ResponseEntity.noContent().build();
84
84
  }
85
85
 
86
86
  @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
87
- public ResponseEntity<?> update(@PathVariable Long id,
87
+ public ResponseEntity<?> update(@PathVariable <%=@id_type%> id,
88
88
  @RequestBody <%=@model_name%> newValues) {
89
+ newValues.setId(id);
89
90
  <%=@model_name.downcase%>Repository.save(newValues);
90
91
  return ResponseEntity.noContent().build();
91
92
  }
@@ -32,7 +32,7 @@ public class <%=@model_name%>AssemblerUnitTest {
32
32
  @Test
33
33
  public void testToResource() throws Exception {
34
34
  <%=@model_name%> instance = new <%=@model_name%>();
35
- instance.setId(1L);
35
+ instance.setId(<%=augment_test_id(1)%>);
36
36
  ResourceSupport resourceSupport = testInstance.toResource(instance);
37
37
  assertEquals("self",resourceSupport.getId().getRel());
38
38
  }
@@ -70,7 +70,7 @@ public class <%=@model_name%>ControllerUnitTest {
70
70
  List<<%=@model_name%>> sampleData = new ArrayList<>();
71
71
  for (int i = 0; i < 10; i++) {
72
72
  <%=@model_name%> instance = new <%=@model_name%>();
73
- instance.setId(i);
73
+ instance.setId(<%=augment_test_id("i")%>);
74
74
  sampleData.add(instance);
75
75
  }
76
76
  Page<<%=@model_name%>> page = new PageImpl<>(sampleData);
@@ -91,13 +91,13 @@ public class <%=@model_name%>ControllerUnitTest {
91
91
  @Test
92
92
  public void getOneShouldReturnResponseContainingTheDataOfOne<%=@model_name%>AsJson() throws Exception {
93
93
  <%=@model_name%> instance = new <%=@model_name%>();
94
- instance.setId(1L);
94
+ instance.setId(<%=augment_test_id(1)%>);
95
95
  <%=@model_name%>Resource testResource = new <%=@model_name%>Resource(instance);
96
- when(<%=@model_name.downcase%>Repository.findOne(1L)).thenReturn(instance);
96
+ when(<%=@model_name.downcase%>Repository.findOne(<%=augment_test_id(1)%>)).thenReturn(instance);
97
97
  when(<%=@model_name.downcase%>Assembler.toResource(instance)).thenReturn(testResource);
98
- ResponseEntity response = testInstance.getOne(1L);
98
+ ResponseEntity response = testInstance.getOne(<%=augment_test_id(1)%>);
99
99
  assertEquals(200,response.getStatusCode().value());
100
- verify(<%=@model_name.downcase%>Repository, times(1)).findOne(1L);
100
+ verify(<%=@model_name.downcase%>Repository, times(1)).findOne(<%=augment_test_id(1)%>);
101
101
  verify(<%=@model_name.downcase%>Assembler, times(1)).toResource(instance);
102
102
  }
103
103
  }
@@ -1,3 +1,3 @@
1
1
  module SpringGen
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spring-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rene Richter
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  version: '0'
169
169
  requirements: []
170
170
  rubyforge_project:
171
- rubygems_version: 2.4.8
171
+ rubygems_version: 2.4.6
172
172
  signing_key:
173
173
  specification_version: 4
174
174
  summary: Generator for spring microservices