spring-gen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,66 @@
1
+ package <%=@group_id%>.controller;
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 <%=@group_id%>.exception.NotCreatedException;
19
+ import <%=@group_id%>.model.BaseEntity;
20
+ import org.springframework.beans.factory.annotation.Autowired;
21
+ import org.springframework.data.rest.webmvc.ResourceNotFoundException;
22
+ import org.springframework.hateoas.EntityLinks;
23
+ import org.springframework.http.HttpStatus;
24
+ import org.springframework.http.ResponseEntity;
25
+ import org.springframework.stereotype.Component;
26
+ import org.springframework.web.bind.annotation.ExceptionHandler;
27
+ import org.springframework.web.bind.annotation.ResponseStatus;
28
+
29
+ /**
30
+ * A basecontroller for shared functionality.
31
+ *
32
+ * @author <%=@user_name%>
33
+ */
34
+ @Component
35
+ public abstract class BaseController {
36
+
37
+ @Autowired
38
+ EntityLinks entityLinks;
39
+ /**
40
+ * A conviniencemethod for creating new Entities.
41
+ *
42
+ * @param newEntity The entity that should be created
43
+ * @param <T> Type of the entity that should get created
44
+ * @return The formal Response for the childcontroller.
45
+ */
46
+ public <T extends BaseEntity> ResponseEntity<?> createEntity(T newEntity) {
47
+
48
+ return ResponseEntity
49
+ .created(entityLinks.linkForSingleResource(newEntity).toUri()).build();
50
+ }
51
+
52
+
53
+ @ExceptionHandler(ResourceNotFoundException.class)
54
+ @ResponseStatus(HttpStatus.NOT_FOUND)
55
+ public String handleNotFound(ResourceNotFoundException ex) {
56
+ return ex.toString();
57
+ }
58
+
59
+
60
+
61
+ @ExceptionHandler(NotCreatedException.class)
62
+ @ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
63
+ public String handleNotCreated(NotCreatedException ex) {
64
+ return "couldn't create resource";
65
+ }
66
+ }
@@ -0,0 +1,106 @@
1
+ package <%=@group_id%>.controller;
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 <%=@group_id%>.assembler.<%=@model_name%>Assembler;
19
+ import <%=@group_id%>.model.<%=@model_name%>;
20
+ import <%=@group_id%>.resource.<%=@model_name%>Resource;
21
+ import <%=@group_id%>.repository.<%=@model_name%>Repository;
22
+ import org.springframework.beans.factory.annotation.Autowired;
23
+ import org.springframework.data.domain.Page;
24
+ import org.springframework.data.domain.Pageable;
25
+ import org.springframework.data.web.PageableDefault;
26
+ import org.springframework.data.web.PagedResourcesAssembler;
27
+ import org.springframework.hateoas.ExposesResourceFor;
28
+ import org.springframework.hateoas.PagedResources;
29
+ import org.springframework.http.ResponseEntity;
30
+ import org.springframework.web.bind.annotation.PathVariable;
31
+ import org.springframework.web.bind.annotation.RequestBody;
32
+ import org.springframework.web.bind.annotation.RequestMapping;
33
+ import org.springframework.web.bind.annotation.RequestMethod;
34
+ import org.springframework.web.bind.annotation.RestController;
35
+
36
+
37
+ /**
38
+ * A controller for <%=@model_name%> Routes.
39
+ * @author <%=@user_name%>
40
+ */
41
+ @RestController
42
+ @RequestMapping("/<%=@model_name.downcase%>s")
43
+ @ExposesResourceFor(<%=@model_name%>.class)
44
+ public class <%=@model_name%>Controller extends BaseController {
45
+
46
+ @Autowired
47
+ <%=@model_name%>Assembler <%=@model_name.downcase%>Assembler;
48
+
49
+ @Autowired
50
+ <%=@model_name%>Repository <%=@model_name.downcase%>Repository;
51
+
52
+
53
+ /**
54
+ * Returns a list of <%=@model_name.downcase%>s.
55
+ *
56
+ * @param pageable The number of items, gotten through the url
57
+ * @param assembler the assembler injected by spring.
58
+ * @return a Resource representing the page.
59
+ */
60
+ @RequestMapping(method = RequestMethod.GET)
61
+ public PagedResources<<%=@model_name%>> getAll(@PageableDefault(size = 20, page = 0)
62
+ Pageable pageable,
63
+ PagedResourcesAssembler assembler) {
64
+
65
+ Page<<%=@model_name%>> pageResult = this.<%=@model_name.downcase%>Repository.findAll(pageable);
66
+ return assembler.toResource(pageResult, <%=@model_name.downcase%>Assembler);
67
+ }
68
+
69
+ /**
70
+ * @param entity the <%=@model_name.downcase%> from the post-request. This <%=@model_name.downcase%> is deserialized by
71
+ * jackson.
72
+ * @return A respoonse containing a link to the new resource.
73
+ */
74
+ @RequestMapping(method = RequestMethod.POST)
75
+ public ResponseEntity<?> create(@RequestBody <%=@model_name%> entity) {
76
+ return super.createEntity(this.<%=@model_name.downcase%>Repository.save(entity));
77
+ }
78
+
79
+ /**
80
+ * Returns one <%=@model_name%>.
81
+ *
82
+ * @param id the id of the topic to return.
83
+ * @return a response.
84
+ */
85
+ @RequestMapping(value = "/{id}", method = RequestMethod.GET)
86
+ public ResponseEntity<<%=@model_name%>Resource> getOne(@PathVariable Long id) {
87
+ <%=@model_name%>Resource result
88
+ = <%=@model_name.downcase%>Assembler.toResource(<%=@model_name.downcase%>Repository.findOne(id));
89
+ return ResponseEntity.ok().body(result);
90
+ }
91
+
92
+ @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
93
+ public ResponseEntity<?> delete(@PathVariable Long id) {
94
+ <%=@model_name.downcase%>Repository.delete(id);
95
+ return ResponseEntity.noContent().build();
96
+ }
97
+
98
+ @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
99
+ public ResponseEntity<?> update(@PathVariable Long id,
100
+ @RequestBody <%=@model_name%> newValues) {
101
+ <%=@model_name.downcase%>Repository.save(newValues);
102
+ return ResponseEntity.noContent().build();
103
+ }
104
+
105
+
106
+ }
@@ -0,0 +1,34 @@
1
+ package <%=@group_id%>.exception;
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
+ /**
19
+ * Exception that gets thrown, when the entity couldn't get created.
20
+ * Violation of constraints can be a reason.
21
+ *
22
+ * @author <%=@user_name%> Richte
23
+ */
24
+ public class NotCreatedException extends RuntimeException {
25
+
26
+ public NotCreatedException(String message) {
27
+ super(message);
28
+ }
29
+
30
+ public NotCreatedException() {
31
+ }
32
+
33
+
34
+ }
@@ -0,0 +1,43 @@
1
+ package <%=@group_id%>.model;
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.hateoas.Identifiable;
19
+
20
+ import javax.persistence.GeneratedValue;
21
+ import javax.persistence.Id;
22
+ import javax.persistence.MappedSuperclass;
23
+
24
+
25
+ /**
26
+ * A jpa-base entity.
27
+ * @author <%=@user_name%>
28
+ */
29
+ @MappedSuperclass
30
+ public class BaseEntity implements Identifiable<Long> {
31
+
32
+ @Id
33
+ @GeneratedValue
34
+ private long id;
35
+
36
+ public Long getId() {
37
+ return id;
38
+ }
39
+
40
+ public void setId(long id) {
41
+ this.id = id;
42
+ }
43
+ }
@@ -0,0 +1,51 @@
1
+ package <%=@group_id%>.model;
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
+ <%=@annotation_import%>
19
+
20
+ /**
21
+ * Entity that represents <%=@model_name%>s.
22
+ * @author <%=@user_name%>
23
+ */
24
+ <%=@entity_annotation%>
25
+ public class <%=@model_name%> extends BaseEntity {
26
+
27
+ <%@attributes.each do |attribute| %>private <%="#{attribute.data_type} #{attribute.name}"%>;
28
+ <%end%>
29
+
30
+ public <%=@model_name%>(){}
31
+
32
+
33
+ /**
34
+ * a convenience constructor.
35
+ */
36
+ public <%=@model_name%>(<%=@attributes.map {|attribute| "#{attribute.data_type} #{attribute.name}"}.join(',')%>) {
37
+
38
+ <%@attributes.each do |attribute|%>this.<%=attribute.name%> = <%=attribute.name%>;
39
+ <%end%>
40
+ }
41
+
42
+ <%@attributes.each do |attribute| %>
43
+ public void <%="set#{attribute.name.capitalize}(#{attribute.data_type} #{attribute.name})"%> {
44
+ this.<%=attribute.name%> = <%=attribute.name%>;
45
+ }
46
+
47
+ public <%="#{attribute.data_type} get#{attribute.name.capitalize}"%>() {
48
+ return this.<%=attribute.name%>;
49
+ }
50
+ <%end%>
51
+ }
@@ -0,0 +1,33 @@
1
+ package <%=@group_id%>.model;
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
+ import org.springframework.hateoas.Identifiable;
18
+ /**
19
+ * A mongodb-base entity.
20
+ * @author <%=@user_name%>
21
+ */
22
+ public class BaseEntity implements Identifiable<String> {
23
+
24
+ private String id;
25
+
26
+ public String getId() {
27
+ return id;
28
+ }
29
+
30
+ public void setId(String id) {
31
+ this.id = id;
32
+ }
33
+ }
@@ -0,0 +1,81 @@
1
+ package <%=@group_id%>.model;
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.fasterxml.jackson.annotation.JsonIdentityInfo;
19
+ import com.fasterxml.jackson.annotation.JsonInclude;
20
+ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
21
+
22
+ import org.neo4j.ogm.annotation.GraphId;
23
+ import org.neo4j.ogm.annotation.NodeEntity;
24
+ import org.springframework.hateoas.Identifiable;
25
+
26
+ /**
27
+ * Base entity for neo4j entities.
28
+ *
29
+ * @author <%=@user_name%>
30
+ */
31
+ @NodeEntity
32
+ @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class)
33
+ @JsonInclude(JsonInclude.Include.NON_NULL)
34
+ public abstract class BaseEntity implements Identifiable<Long> {
35
+
36
+ @GraphId
37
+ private Long nodeId;
38
+
39
+ private long id;
40
+
41
+ public Long getNodeId() {
42
+ return nodeId;
43
+ }
44
+
45
+ public void setNodeId(Long nodeId) {
46
+ this.nodeId = nodeId;
47
+ }
48
+
49
+ public Long getId() {
50
+ return id;
51
+ }
52
+
53
+ public void setId(long id) {
54
+ this.id = id;
55
+ }
56
+
57
+
58
+ @Override
59
+ public boolean equals(Object other) {
60
+ if (this == other) {
61
+ return true;
62
+ }
63
+
64
+ if (other == null || getClass() != other.getClass()) {
65
+ return false;
66
+ }
67
+
68
+ BaseEntity entity = (BaseEntity) other;
69
+ if (id == 0) {
70
+ return super.equals(other);
71
+ }
72
+ return id == entity.getId();
73
+
74
+ }
75
+
76
+ @Override
77
+ public int hashCode() {
78
+ return (int)id;
79
+ }
80
+
81
+ }
@@ -0,0 +1,30 @@
1
+ package <%=@group_id%>.repository;
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 <%=@group_id%>.model.<%=@model_name%>;
19
+ import org.springframework.stereotype.Repository;
20
+ import org.springframework.data.<%=@repository_import%>;
21
+
22
+
23
+
24
+ /**
25
+ * A repository for <%=@model_name%>s
26
+ * @author <%=@user_name%>
27
+ */
28
+ public interface <%=@model_name%>Repository extends <%=@repository_type%> {
29
+
30
+ }
@@ -0,0 +1,48 @@
1
+ package <%=@group_id%>.resource;
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 <%=@group_id%>.model.<%=@model_name%>;
19
+ import org.springframework.hateoas.ResourceSupport;
20
+
21
+ /**
22
+ * A <%=@model_name%>-resource.
23
+ * @author <%=@user_name%>
24
+ */
25
+ public class <%=@model_name%>Resource extends ResourceSupport {
26
+ <%@attributes.each do |attribute| %>
27
+ private <%="#{attribute.data_type} #{attribute.name}"%>;
28
+ <%end%>
29
+
30
+ /**
31
+ * Reads all attributes from entity that should get serialized.
32
+ */
33
+ public <%=@model_name%>Resource( <%=@model_name%> entity) {
34
+ <%@attributes.each do |attribute| %>
35
+ this.<%=attribute.name%> = entity.get<%=attribute.name.capitalize%>();
36
+ <%end%>
37
+ }
38
+
39
+ <%@attributes.each do |attribute| %>
40
+ public void <%="set#{attribute.name.capitalize}(#{attribute.data_type} #{attribute.name})"%> {
41
+ this.<%=attribute.name%> = <%=attribute.name%>;
42
+ }
43
+
44
+ public <%="#{attribute.data_type} get#{attribute.name.capitalize}"%>() {
45
+ return this.<%=attribute.name%>;
46
+ }
47
+ <%end%>
48
+ }
@@ -0,0 +1,85 @@
1
+ package util;
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.fasterxml.jackson.core.JsonProcessingException;
19
+ import com.fasterxml.jackson.databind.ObjectMapper;
20
+ import <%=@group_id%>.model.BaseEntity;
21
+ import org.springframework.cloud.client.ServiceInstance;
22
+ import org.springframework.http.MediaType;
23
+
24
+ import java.net.URI;
25
+ import java.nio.charset.Charset;
26
+
27
+ /**
28
+ * Utility class for testing.
29
+ * @author <%=@user_name%>
30
+ */
31
+ public class TestUtil {
32
+
33
+ public static final MediaType APPLICATION_JSON_UTF8 =
34
+ new MediaType(MediaType.APPLICATION_JSON.getType(),
35
+ MediaType.APPLICATION_JSON.getSubtype(),
36
+ Charset.forName("utf8"));
37
+
38
+ /**
39
+ * Converts an object to json (as bytes).
40
+ *
41
+ * @param object the object to convert
42
+ * @return JSON as bytes.
43
+ * @throws JsonProcessingException thrown by jackson objectmapper
44
+ */
45
+ public static byte[] toJson(BaseEntity object) throws JsonProcessingException {
46
+ ObjectMapper mapper = new ObjectMapper();
47
+ return mapper.writeValueAsBytes(object);
48
+ }
49
+
50
+
51
+ /**
52
+ * Mocks a ServiceInstance.
53
+ * @param serviceName the name of the service.
54
+ * @return the mock.
55
+ */
56
+ public static ServiceInstance mockServiceInstance(String serviceName) {
57
+ ServiceInstance result = new ServiceInstance() {
58
+ @Override
59
+ public String getServiceId() {
60
+ return serviceName;
61
+ }
62
+
63
+ @Override
64
+ public String getHost() {
65
+ return "localhost";
66
+ }
67
+
68
+ @Override
69
+ public int getPort() {
70
+ return 80;
71
+ }
72
+
73
+ @Override
74
+ public boolean isSecure() {
75
+ return false;
76
+ }
77
+
78
+ @Override
79
+ public URI getUri() {
80
+ return URI.create("http://localhost/" + serviceName);
81
+ }
82
+ };
83
+ return result;
84
+ }
85
+ }