springmvc-scaffold 1.0.1
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 +7 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +45 -0
- data/README.markdown +31 -0
- data/Rakefile +9 -0
- data/bin/springmvc +7 -0
- data/lib/springmvc-scaffold.rb +14 -0
- data/lib/springmvc-scaffold/configuration.rb +50 -0
- data/lib/springmvc-scaffold/execution.rb +20 -0
- data/lib/springmvc-scaffold/generators/app/app_generator.rb +123 -0
- data/lib/springmvc-scaffold/generators/app/dependencies.rb +26 -0
- data/lib/springmvc-scaffold/generators/app/dependency.rb +15 -0
- data/lib/springmvc-scaffold/generators/app/templates/build.gradle.erb +56 -0
- data/lib/springmvc-scaffold/generators/app/templates/models/Entity.erb +46 -0
- data/lib/springmvc-scaffold/generators/app/templates/orm/Repository-hibernate.java.tt +51 -0
- data/lib/springmvc-scaffold/generators/app/templates/orm/Repository-jpa.java.tt +49 -0
- data/lib/springmvc-scaffold/generators/app/templates/pom.erb +95 -0
- data/lib/springmvc-scaffold/generators/app/templates/resources/hibernate.properties +16 -0
- data/lib/springmvc-scaffold/generators/app/templates/resources/log4j.properties +4 -0
- data/lib/springmvc-scaffold/generators/app/templates/resources/messages.properties +0 -0
- data/lib/springmvc-scaffold/generators/app/templates/springmvc-scaffold.erb +6 -0
- data/lib/springmvc-scaffold/generators/app/templates/webapp/.bowerrc +3 -0
- data/lib/springmvc-scaffold/generators/app/templates/webapp/WEB-INF/jsp/decorators/main.jsp +15 -0
- data/lib/springmvc-scaffold/generators/app/templates/webapp/WEB-INF/jsp/prelude.jspf +4 -0
- data/lib/springmvc-scaffold/generators/app/templates/webapp/WEB-INF/sitemesh3.xml +3 -0
- data/lib/springmvc-scaffold/generators/app/templates/webapp/WEB-INF/spring-servlet.xml.tt +42 -0
- data/lib/springmvc-scaffold/generators/app/templates/webapp/WEB-INF/web.xml.tt +52 -0
- data/lib/springmvc-scaffold/generators/app/templates/webapp/bower.json.tt +7 -0
- data/lib/springmvc-scaffold/generators/app/templates/webapp/stylesheets/application.css +38 -0
- data/lib/springmvc-scaffold/generators/base.rb +17 -0
- data/lib/springmvc-scaffold/generators/scaffold/attribute.rb +68 -0
- data/lib/springmvc-scaffold/generators/scaffold/base_scaffold.rb +54 -0
- data/lib/springmvc-scaffold/generators/scaffold/controller/controller_generator.rb +20 -0
- data/lib/springmvc-scaffold/generators/scaffold/controller/templates/controller.erb +126 -0
- data/lib/springmvc-scaffold/generators/scaffold/controller/templates/controller_test.erb +13 -0
- data/lib/springmvc-scaffold/generators/scaffold/imports.rb +18 -0
- data/lib/springmvc-scaffold/generators/scaffold/jsp/jsp_generator.rb +40 -0
- data/lib/springmvc-scaffold/generators/scaffold/jsp/templates/edit.erb +15 -0
- data/lib/springmvc-scaffold/generators/scaffold/jsp/templates/form.erb +14 -0
- data/lib/springmvc-scaffold/generators/scaffold/jsp/templates/index.erb +38 -0
- data/lib/springmvc-scaffold/generators/scaffold/jsp/templates/new.erb +14 -0
- data/lib/springmvc-scaffold/generators/scaffold/jsp/templates/show.erb +16 -0
- data/lib/springmvc-scaffold/generators/scaffold/model/model_generator.rb +16 -0
- data/lib/springmvc-scaffold/generators/scaffold/model/templates/model.erb +22 -0
- data/lib/springmvc-scaffold/generators/scaffold/model/templates/model_test.erb +13 -0
- data/lib/springmvc-scaffold/generators/scaffold/repository/repository_generator.rb +30 -0
- data/lib/springmvc-scaffold/generators/scaffold/repository/templates/repository.erb +18 -0
- data/lib/springmvc-scaffold/generators/scaffold/repository/templates/repository_test.erb +13 -0
- data/lib/springmvc-scaffold/generators/scaffold/scaffold_generator.rb +31 -0
- data/lib/springmvc-scaffold/runner.rb +7 -0
- data/lib/springmvc-scaffold/runner/commands_help.rb +11 -0
- data/lib/springmvc-scaffold/runner/generator.rb +14 -0
- data/lib/springmvc-scaffold/runner/help.rb +10 -0
- data/lib/springmvc-scaffold/runner/scaffold.rb +15 -0
- data/lib/springmvc-scaffold/version.rb +3 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/springmvc-scaffold/configuration_spec.rb +124 -0
- data/spec/springmvc-scaffold/execution_spec.rb +40 -0
- data/spec/springmvc-scaffold/generators/app/app_generator_spec.rb +226 -0
- data/spec/springmvc-scaffold/generators/app/dependency_spec.rb +14 -0
- data/spec/springmvc-scaffold/generators/app/templates/Entity.java +46 -0
- data/spec/springmvc-scaffold/generators/app/templates/RepositoryJPA.java +49 -0
- data/spec/springmvc-scaffold/generators/app/templates/build.gradle +59 -0
- data/spec/springmvc-scaffold/generators/app/templates/pom.xml +146 -0
- data/spec/springmvc-scaffold/generators/app/templates/springmvc-scaffold.properties +6 -0
- data/spec/springmvc-scaffold/generators/scaffold/attribute_spec.rb +215 -0
- data/spec/springmvc-scaffold/generators/scaffold/base_scaffold_spec.rb +70 -0
- data/spec/springmvc-scaffold/generators/scaffold/controller/controller_generator_spec.rb +53 -0
- data/spec/springmvc-scaffold/generators/scaffold/controller/templates/ProductsController.java +97 -0
- data/spec/springmvc-scaffold/generators/scaffold/imports_spec.rb +9 -0
- data/spec/springmvc-scaffold/generators/scaffold/jsp/jsp_generator_spec.rb +46 -0
- data/spec/springmvc-scaffold/generators/scaffold/jsp/templates/form.jsp +25 -0
- data/spec/springmvc-scaffold/generators/scaffold/model/model_generator_spec.rb +28 -0
- data/spec/springmvc-scaffold/generators/scaffold/model/templates/Product.java +43 -0
- data/spec/springmvc-scaffold/generators/scaffold/repository/repository_generator_spec.rb +49 -0
- data/spec/springmvc-scaffold/generators/scaffold/repository/templates/Clients.java +16 -0
- data/spec/springmvc-scaffold/generators/scaffold/repository/templates/Products.java +10 -0
- data/spec/springmvc-scaffold/generators/scaffold/scaffold_generator_spec.rb +60 -0
- data/spec/springmvc-scaffold/runner/commands_help_spec.rb +13 -0
- data/spec/springmvc-scaffold/runner/generator_spec.rb +21 -0
- data/spec/springmvc-scaffold/runner/help_spec.rb +22 -0
- data/spec/springmvc-scaffold/runner/scaffold_spec.rb +36 -0
- data/spec/springmvc-scaffold_spec.rb +4 -0
- data/springmvc-scaffold.gemspec +27 -0
- metadata +185 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
|
|
2
|
+
|
|
3
|
+
describe Dependency do
|
|
4
|
+
|
|
5
|
+
it "should has exclusions" do
|
|
6
|
+
dependency = described_class.new("org.springframework", "spring-web", "4.0.0", [described_class.new("org.springframework", "spring-orm")])
|
|
7
|
+
expect(dependency.has_exclusions?).to be true
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "cannot has exclusions" do
|
|
11
|
+
dependency = described_class.new("org.springframework", "spring-web", "3.0.0")
|
|
12
|
+
expect(dependency.has_exclusions?).to be false
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
package app.models;
|
|
2
|
+
|
|
3
|
+
import javax.persistence.GeneratedValue;
|
|
4
|
+
import javax.persistence.Id;
|
|
5
|
+
import javax.persistence.MappedSuperclass;
|
|
6
|
+
|
|
7
|
+
@MappedSuperclass
|
|
8
|
+
public class Entity {
|
|
9
|
+
|
|
10
|
+
@Id
|
|
11
|
+
@GeneratedValue
|
|
12
|
+
private Long id;
|
|
13
|
+
|
|
14
|
+
public void setId(Long id) {
|
|
15
|
+
this.id = id;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public Long getId() {
|
|
19
|
+
return id;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Override
|
|
23
|
+
public boolean equals(Object obj) {
|
|
24
|
+
if (obj == null) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (this == obj) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
if (getClass() != obj.getClass()) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
final Entity other = (Entity) obj;
|
|
34
|
+
if (id != other.id && (id == null || !id.equals(other.id))) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Override
|
|
41
|
+
public int hashCode() {
|
|
42
|
+
int hash = 7;
|
|
43
|
+
hash = 17 * hash + (this.getId() != null ? this.getId().hashCode() : 0);
|
|
44
|
+
return hash;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
package app.repositories;
|
|
2
|
+
|
|
3
|
+
import java.lang.reflect.ParameterizedType;
|
|
4
|
+
import java.util.List;
|
|
5
|
+
|
|
6
|
+
import javax.persistence.EntityManager;
|
|
7
|
+
import javax.persistence.PersistenceContext;
|
|
8
|
+
|
|
9
|
+
import org.springframework.transaction.annotation.Transactional;
|
|
10
|
+
|
|
11
|
+
@Transactional
|
|
12
|
+
public abstract class GenericRepository<T> {
|
|
13
|
+
|
|
14
|
+
protected EntityManager em;
|
|
15
|
+
protected final Class<T> clazz;
|
|
16
|
+
|
|
17
|
+
protected GenericRepository() {
|
|
18
|
+
@SuppressWarnings("unchecked")
|
|
19
|
+
Class<T> clazz = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
|
|
20
|
+
|
|
21
|
+
this.clazz = clazz;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@PersistenceContext
|
|
25
|
+
public void setEntityManager(EntityManager em) {
|
|
26
|
+
this.em = em;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public void add(T entity) {
|
|
30
|
+
em.persist(entity);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public T update(T entity) {
|
|
34
|
+
return em.merge(entity);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public void remove(Long id) {
|
|
38
|
+
em.remove(get(id));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public T get(Long id) {
|
|
42
|
+
return em.find(clazz, id);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@SuppressWarnings("unchecked")
|
|
46
|
+
public List<T> all() {
|
|
47
|
+
return em.createQuery("from " + clazz.getName()).getResultList();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
repositories {
|
|
2
|
+
mavenCentral()
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
apply plugin: 'java'
|
|
6
|
+
apply plugin: 'war'
|
|
7
|
+
apply plugin: 'jetty'
|
|
8
|
+
apply plugin: 'eclipse'
|
|
9
|
+
|
|
10
|
+
sourceCompatibility = 1.6
|
|
11
|
+
targetCompatibility = 1.6
|
|
12
|
+
version = '1.0'
|
|
13
|
+
|
|
14
|
+
sourceSets {
|
|
15
|
+
main {
|
|
16
|
+
java {
|
|
17
|
+
srcDir 'src/main/java'
|
|
18
|
+
}
|
|
19
|
+
resources {
|
|
20
|
+
srcDir 'src/main/resources'
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
test {
|
|
24
|
+
java {
|
|
25
|
+
srcDir 'src/test/java'
|
|
26
|
+
}
|
|
27
|
+
resources {
|
|
28
|
+
srcDir 'src/test/resources'
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
sourceSets.main.output.classesDir = new File('src/main/webapp/WEB-INF/classes')
|
|
34
|
+
|
|
35
|
+
jettyRun.scanIntervalSeconds=3
|
|
36
|
+
jettyRun.contextPath = '/'
|
|
37
|
+
[jettyRunWar,jettyStop]*.stopPort = 8081
|
|
38
|
+
[jettyRunWar,jettyStop]*.stopKey = 'stopKey'
|
|
39
|
+
|
|
40
|
+
dependencies {
|
|
41
|
+
compile group: 'org.springframework', name: 'spring-webmvc', version: '4.1.3.RELEASE'
|
|
42
|
+
compile group: 'org.springframework', name: 'spring-orm', version: '4.1.3.RELEASE'
|
|
43
|
+
compile group: 'javax.servlet', name: 'jstl', version: '1.2'
|
|
44
|
+
compile group: 'org.hsqldb', name: 'hsqldb', version: '2.3.2'
|
|
45
|
+
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '4.3.7.Final'
|
|
46
|
+
compile group: 'org.hibernate', name: 'hibernate-c3p0', version: '4.3.7.Final'
|
|
47
|
+
compile group: 'org.hibernate', name: 'hibernate-validator', version: '5.1.3.Final'
|
|
48
|
+
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.7'
|
|
49
|
+
compile group: 'joda-time', name: 'joda-time', version: '2.5'
|
|
50
|
+
compile group: 'org.sitemesh', name: 'sitemesh', version: '3.0.0'
|
|
51
|
+
|
|
52
|
+
//Provided dependencies
|
|
53
|
+
providedCompile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
|
|
54
|
+
providedCompile group: 'javax.servlet.jsp', name: 'jsp-api', version: '2.2'
|
|
55
|
+
|
|
56
|
+
//Test dependencies
|
|
57
|
+
testCompile group: 'junit', name: 'junit', version: '4.11'
|
|
58
|
+
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.8'
|
|
59
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
2
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
|
3
|
+
<modelVersion>4.0.0</modelVersion>
|
|
4
|
+
<groupId>springmvc-scaffold</groupId>
|
|
5
|
+
<artifactId>springmvc-scaffold</artifactId>
|
|
6
|
+
<packaging>war</packaging>
|
|
7
|
+
<version>0.0.1-SNAPSHOT</version>
|
|
8
|
+
<name>springmvc-scaffold</name>
|
|
9
|
+
|
|
10
|
+
<properties>
|
|
11
|
+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
12
|
+
</properties>
|
|
13
|
+
|
|
14
|
+
<build>
|
|
15
|
+
<outputDirectory>${basedir}/src/main/webapp/WEB-INF/classes</outputDirectory>
|
|
16
|
+
<plugins>
|
|
17
|
+
<plugin>
|
|
18
|
+
<artifactId>maven-compiler-plugin</artifactId>
|
|
19
|
+
<version>3.2</version>
|
|
20
|
+
<configuration>
|
|
21
|
+
<source>1.7</source>
|
|
22
|
+
<target>1.7</target>
|
|
23
|
+
<encoding>UTF-8</encoding>
|
|
24
|
+
</configuration>
|
|
25
|
+
</plugin>
|
|
26
|
+
<plugin>
|
|
27
|
+
<artifactId>maven-eclipse-plugin</artifactId>
|
|
28
|
+
<version>2.9</version>
|
|
29
|
+
<configuration>
|
|
30
|
+
<downloadSources>true</downloadSources>
|
|
31
|
+
<downloadJavadocs>true</downloadJavadocs>
|
|
32
|
+
<wtpversion>2.0</wtpversion>
|
|
33
|
+
</configuration>
|
|
34
|
+
</plugin>
|
|
35
|
+
<plugin>
|
|
36
|
+
<groupId>org.apache.maven.plugins</groupId>
|
|
37
|
+
<artifactId>maven-war-plugin</artifactId>
|
|
38
|
+
<version>2.5</version>
|
|
39
|
+
</plugin>
|
|
40
|
+
<plugin>
|
|
41
|
+
<groupId>org.eclipse.jetty</groupId>
|
|
42
|
+
<artifactId>jetty-maven-plugin</artifactId>
|
|
43
|
+
<version>9.2.5.v20141112</version>
|
|
44
|
+
<configuration>
|
|
45
|
+
<scanIntervalSeconds>3</scanIntervalSeconds>
|
|
46
|
+
<stopKey>foo</stopKey>
|
|
47
|
+
<stopPort>9999</stopPort>
|
|
48
|
+
<webAppConfig>
|
|
49
|
+
<contextPath>/</contextPath>
|
|
50
|
+
</webAppConfig>
|
|
51
|
+
</configuration>
|
|
52
|
+
</plugin>
|
|
53
|
+
</plugins>
|
|
54
|
+
</build>
|
|
55
|
+
|
|
56
|
+
<dependencies>
|
|
57
|
+
<dependency>
|
|
58
|
+
<groupId>org.springframework</groupId>
|
|
59
|
+
<artifactId>spring-webmvc</artifactId>
|
|
60
|
+
<version>4.1.3.RELEASE</version>
|
|
61
|
+
</dependency>
|
|
62
|
+
<dependency>
|
|
63
|
+
<groupId>org.springframework</groupId>
|
|
64
|
+
<artifactId>spring-orm</artifactId>
|
|
65
|
+
<version>4.1.3.RELEASE</version>
|
|
66
|
+
</dependency>
|
|
67
|
+
<dependency>
|
|
68
|
+
<groupId>javax.servlet</groupId>
|
|
69
|
+
<artifactId>jstl</artifactId>
|
|
70
|
+
<version>1.2</version>
|
|
71
|
+
</dependency>
|
|
72
|
+
<dependency>
|
|
73
|
+
<groupId>org.hsqldb</groupId>
|
|
74
|
+
<artifactId>hsqldb</artifactId>
|
|
75
|
+
<version>2.3.2</version>
|
|
76
|
+
</dependency>
|
|
77
|
+
<dependency>
|
|
78
|
+
<groupId>org.hibernate</groupId>
|
|
79
|
+
<artifactId>hibernate-entitymanager</artifactId>
|
|
80
|
+
<version>4.3.7.Final</version>
|
|
81
|
+
</dependency>
|
|
82
|
+
<dependency>
|
|
83
|
+
<groupId>org.hibernate</groupId>
|
|
84
|
+
<artifactId>hibernate-c3p0</artifactId>
|
|
85
|
+
<version>4.3.7.Final</version>
|
|
86
|
+
</dependency>
|
|
87
|
+
<dependency>
|
|
88
|
+
<groupId>org.hibernate</groupId>
|
|
89
|
+
<artifactId>hibernate-validator</artifactId>
|
|
90
|
+
<version>5.1.3.Final</version>
|
|
91
|
+
</dependency>
|
|
92
|
+
<dependency>
|
|
93
|
+
<groupId>org.slf4j</groupId>
|
|
94
|
+
<artifactId>slf4j-log4j12</artifactId>
|
|
95
|
+
<version>1.7.7</version>
|
|
96
|
+
</dependency>
|
|
97
|
+
<dependency>
|
|
98
|
+
<groupId>joda-time</groupId>
|
|
99
|
+
<artifactId>joda-time</artifactId>
|
|
100
|
+
<version>2.5</version>
|
|
101
|
+
</dependency>
|
|
102
|
+
<dependency>
|
|
103
|
+
<groupId>org.sitemesh</groupId>
|
|
104
|
+
<artifactId>sitemesh</artifactId>
|
|
105
|
+
<version>3.0.0</version>
|
|
106
|
+
</dependency>
|
|
107
|
+
|
|
108
|
+
<!-- Test dependencies -->
|
|
109
|
+
<dependency>
|
|
110
|
+
<groupId>junit</groupId>
|
|
111
|
+
<artifactId>junit</artifactId>
|
|
112
|
+
<version>4.11</version>
|
|
113
|
+
<scope>test</scope>
|
|
114
|
+
</dependency>
|
|
115
|
+
<dependency>
|
|
116
|
+
<groupId>org.mockito</groupId>
|
|
117
|
+
<artifactId>mockito-all</artifactId>
|
|
118
|
+
<version>1.10.8</version>
|
|
119
|
+
<scope>test</scope>
|
|
120
|
+
</dependency>
|
|
121
|
+
|
|
122
|
+
<!-- Provided dependencies -->
|
|
123
|
+
<dependency>
|
|
124
|
+
<groupId>javax.servlet</groupId>
|
|
125
|
+
<artifactId>servlet-api</artifactId>
|
|
126
|
+
<version>2.5</version>
|
|
127
|
+
<scope>provided</scope>
|
|
128
|
+
</dependency>
|
|
129
|
+
<dependency>
|
|
130
|
+
<groupId>javax.servlet.jsp</groupId>
|
|
131
|
+
<artifactId>jsp-api</artifactId>
|
|
132
|
+
<version>2.2</version>
|
|
133
|
+
<scope>provided</scope>
|
|
134
|
+
</dependency>
|
|
135
|
+
</dependencies>
|
|
136
|
+
|
|
137
|
+
<reporting>
|
|
138
|
+
<plugins>
|
|
139
|
+
<plugin>
|
|
140
|
+
<groupId>org.codehaus.mojo</groupId>
|
|
141
|
+
<artifactId>cobertura-maven-plugin</artifactId>
|
|
142
|
+
<version>2.6</version>
|
|
143
|
+
</plugin>
|
|
144
|
+
</plugins>
|
|
145
|
+
</reporting>
|
|
146
|
+
</project>
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
|
|
2
|
+
|
|
3
|
+
describe Attribute do
|
|
4
|
+
|
|
5
|
+
context "getter name" do
|
|
6
|
+
it "'is' to boolean attributes" do
|
|
7
|
+
expect(described_class.new("active", "boolean").getter_name).to eq "isActive"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "'get' otherwise" do
|
|
11
|
+
expect(described_class.new("description", "string").getter_name).to eq "getDescription"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "setter name" do
|
|
16
|
+
expect(described_class.new("name", "string").setter_name).to eq "setName"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context "declaration" do
|
|
20
|
+
it "includes java type and attribute name" do
|
|
21
|
+
expect(described_class.new("name", "text").declaration). to eq "String name"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context "initialize attribute" do
|
|
26
|
+
context "downcase name" do
|
|
27
|
+
it "should downcase all words" do
|
|
28
|
+
expect(described_class.new("VALUE", "double").name).to eq "value"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "should camelize composed name" do
|
|
32
|
+
expect(described_class.new("MyItem", "double").name).to eq "myItem"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "should camelize composed name" do
|
|
36
|
+
expect(described_class.new("myItem", "double").name).to eq "myItem"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should keep name in downcase" do
|
|
40
|
+
expect(described_class.new("value", "double").name).to eq "value"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should downcase type" do
|
|
45
|
+
expect(described_class.new("value", "DoublE").type).to eq "double"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context "supported types" do
|
|
50
|
+
subject(:valid_types) { described_class::VALID_TYPES }
|
|
51
|
+
|
|
52
|
+
it "supports boolean" do
|
|
53
|
+
expect(valid_types.include?("boolean")).to be true
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "supports double" do
|
|
57
|
+
expect(valid_types.include?("double")).to be true
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "supports string" do
|
|
61
|
+
expect(valid_types.include?("string")).to be true
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "supports float" do
|
|
65
|
+
expect(valid_types.include?("float")).to be true
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "supports short" do
|
|
69
|
+
expect(valid_types.include?("short")).to be true
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "supports integer" do
|
|
73
|
+
expect(valid_types.include?("integer")).to be true
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "supports long" do
|
|
77
|
+
expect(valid_types.include?("long")).to be true
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "supports text" do
|
|
81
|
+
expect(valid_types.include?("text")).to be true
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "supports date" do
|
|
85
|
+
expect(valid_types.include?("date")).to be true
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "do not support other" do
|
|
89
|
+
expect(valid_types.include?("other")).to be false
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
context "html_input" do
|
|
94
|
+
it "knows html input to boolean" do
|
|
95
|
+
expect(described_class.new("flag", "boolean").html_input).to eq "checkbox"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "knows html input to string" do
|
|
99
|
+
expect(described_class.new("name", "string").html_input).to eq "input"
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "knows html input to double" do
|
|
103
|
+
expect(described_class.new("name", "double").html_input).to eq "input"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it "knows html input to float" do
|
|
107
|
+
expect(described_class.new("name", "float").html_input).to eq "input"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "knows html input to short" do
|
|
111
|
+
expect(described_class.new("name", "short").html_input).to eq "input"
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "knows html input to integer" do
|
|
115
|
+
expect(described_class.new("name", "integer").html_input).to eq "input"
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it "knows html input to long" do
|
|
119
|
+
expect(described_class.new("name", "long").html_input).to eq "input"
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "knows html input to text" do
|
|
123
|
+
expect(described_class.new("name", "text").html_input).to eq "textarea"
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "knows html input to date" do
|
|
127
|
+
expect(described_class.new("price", "date").html_input).to eq "input"
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
context "java type" do
|
|
132
|
+
it "knows correct java type to boolean" do
|
|
133
|
+
expect(described_class.new("flag", "boolean").java_type).to eq "boolean"
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "knows correct java type to text" do
|
|
137
|
+
expect(described_class.new("description", "text").java_type).to eq "String"
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it "knows correct java type to string" do
|
|
141
|
+
expect(described_class.new("name", "string").java_type).to eq "String"
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it "knows correct java type to double" do
|
|
145
|
+
expect(described_class.new("name", "double").java_type).to eq "Double"
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it "knows correct java type to float" do
|
|
149
|
+
expect(described_class.new("name", "float").java_type).to eq "Float"
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it "knows correct java type to short" do
|
|
153
|
+
expect(described_class.new("name", "short").java_type).to eq "Short"
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it "knows correct java type to integer" do
|
|
157
|
+
expect(described_class.new("name", "integer").java_type).to eq "Integer"
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
it "knows correct java type to long" do
|
|
161
|
+
expect(described_class.new("name", "long").java_type).to eq "Long"
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it "knows correct java type to Date" do
|
|
165
|
+
expect(described_class.new("price", "date").java_type).to eq "Date"
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it "knows correct type to relationship many to one" do
|
|
169
|
+
expect(described_class.new("product", "references").java_type).to eq "Product"
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
context "validate" do
|
|
174
|
+
it "should be valid when attribute is supported" do
|
|
175
|
+
expect(Kernel).to_not receive(:exit)
|
|
176
|
+
described_class::VALID_TYPES.each do |type|
|
|
177
|
+
described_class.new("name", type)
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it "cannot be valid when attribute is not supported" do
|
|
182
|
+
expect(Kernel).to receive(:exit)
|
|
183
|
+
described_class.new("name", "char")
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it "should be valid when attribute is upper case" do
|
|
187
|
+
expect(Kernel).to_not receive(:exit)
|
|
188
|
+
described_class.new("name", "String")
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
context "boolean?" do
|
|
193
|
+
it "should be boolean when type is boolean" do
|
|
194
|
+
expect(described_class.new("flag", "boolean").boolean?).to be true
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
it "cannot be boolean otherwise" do
|
|
198
|
+
expect(described_class.new("flag", "short").boolean?).to be false
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
context "html label" do
|
|
203
|
+
it "should humanize composed name" do
|
|
204
|
+
expect(described_class.new("MyItem", "double").html_label).to eq "My item"
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
it "should humanize composed name" do
|
|
208
|
+
expect(described_class.new("myItem", "double").html_label).to eq "My item"
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
it "should humanize single name" do
|
|
212
|
+
expect(described_class.new("item", "double").html_label).to eq "Item"
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
end
|