Skip to content

Commit fb283f3

Browse files
dimitarsazdovskizhendrikse
authored andcommitted
BAEL 148 move to this repo (eugenp#2885)
1 parent 303db6c commit fb283f3

9 files changed

Lines changed: 255 additions & 0 deletions

File tree

‎spring-groovy/pom.xml‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,38 @@
3737
<artifactId>spring-integration-groovy</artifactId>
3838
<version>4.3.7.RELEASE</version>
3939
</dependency>
40+
<dependency>
41+
<groupId>org.codehaus.groovy</groupId>
42+
<artifactId>groovy-all</artifactId>
43+
<version>2.4.12</version>
44+
</dependency>
4045
</dependencies>
46+
<build>
47+
<plugins>
48+
<plugin>
49+
<artifactId>maven-compiler-plugin</artifactId>
50+
<version>3.7.0</version>
51+
<configuration>
52+
<compilerId>groovy-eclipse-compiler</compilerId>
53+
<verbose>true</verbose>
54+
<source>1.8</source>
55+
<target>1.8</target>
56+
<encoding>${project.build.sourceEncoding}</encoding>
57+
</configuration>
58+
<dependencies>
59+
<dependency>
60+
<groupId>org.codehaus.groovy</groupId>
61+
<artifactId>groovy-eclipse-compiler</artifactId>
62+
<version>2.9.2-01</version>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.codehaus.groovy</groupId>
66+
<artifactId>groovy-eclipse-batch</artifactId>
67+
<version>2.4.3-01</version>
68+
</dependency>
69+
</dependencies>
70+
</plugin>
71+
72+
</plugins>
73+
</build>
4174
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldug.groovyconfig;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class BandsBean {
7+
8+
private List<String> bandsList = new ArrayList<>();
9+
10+
public List<String> getBandsList() {
11+
return bandsList;
12+
}
13+
14+
public void setBandsList(List<String> bandsList) {
15+
this.bandsList = bandsList;
16+
}
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldug.groovyconfig;
2+
3+
beans {
4+
javaPesronBean(JavaPersonBean) {
5+
firstName = 'John'
6+
lastName = 'Doe'
7+
age ='32'
8+
eyesColor = 'blue'
9+
hairColor='black'
10+
}
11+
12+
bandsBean(BandsBean) { bean->
13+
bean.scope = "singleton"
14+
bandsList=['Nirvana', 'Pearl Jam', 'Foo Fighters']
15+
}
16+
17+
registerAlias("bandsBean","bands")
18+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldug.groovyconfig;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
@Configuration
7+
public class JavaBeanConfig {
8+
9+
@Bean
10+
public JavaPersonBean javaPerson() {
11+
JavaPersonBean jPerson = new JavaPersonBean();
12+
jPerson.setFirstName("John");
13+
jPerson.setLastName("Doe");
14+
jPerson.setAge("31");
15+
jPerson.setEyesColor("green");
16+
jPerson.setHairColor("blond");
17+
18+
return jPerson;
19+
}
20+
21+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.baeldug.groovyconfig;
2+
3+
public class JavaPersonBean {
4+
5+
public String jj;
6+
7+
private String firstName;
8+
9+
private String lastName;
10+
11+
private String age;
12+
13+
private String eyesColor;
14+
15+
private String hairColor;
16+
17+
public String getFirstName() {
18+
return firstName;
19+
}
20+
21+
public void setFirstName(String firstName) {
22+
this.firstName = firstName;
23+
}
24+
25+
public String getLastName() {
26+
return lastName;
27+
}
28+
29+
public void setLastName(String lastName) {
30+
this.lastName = lastName;
31+
}
32+
33+
public String getAge() {
34+
return age;
35+
}
36+
37+
public void setAge(String age) {
38+
this.age = age;
39+
}
40+
41+
public String getEyesColor() {
42+
return eyesColor;
43+
}
44+
45+
public void setEyesColor(String eyesColor) {
46+
this.eyesColor = eyesColor;
47+
}
48+
49+
public String getHairColor() {
50+
return hairColor;
51+
}
52+
53+
public void setHairColor(String hairColor) {
54+
this.hairColor = hairColor;
55+
}
56+
57+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
5+
<bean id="JavaPersonBean" class="com.baeldug.groovyconfig.JavaPersonBean">
6+
<property name="firstName" value="John" />
7+
<property name="LastName" value="Doe" />
8+
<property name="age" value="30" />
9+
<property name="eyesColor" value="brown" />
10+
<property name="hairColor" value="brown" />
11+
</bean>
12+
</beans>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.baeldug.groovyconfig;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import java.io.File;
6+
7+
import org.junit.Test;
8+
import org.springframework.context.support.GenericGroovyApplicationContext;
9+
10+
public class GroovyConfigurationTest {
11+
12+
private static final String FILE_NAME = "GroovyBeanConfig.groovy";
13+
private static final String FILE_PATH = "src/main/java/com/baeldug/groovyconfig/";
14+
15+
@Test
16+
public void whenGroovyConfig_thenCorrectPerson() throws Exception {
17+
18+
GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext();
19+
ctx.load("file:" + getPathPart() + FILE_NAME);
20+
ctx.refresh();
21+
22+
JavaPersonBean j = ctx.getBean(JavaPersonBean.class);
23+
24+
assertEquals("32", j.getAge());
25+
assertEquals("blue", j.getEyesColor());
26+
assertEquals("black", j.getHairColor());
27+
}
28+
29+
@Test
30+
public void whenGroovyConfig_thenCorrectListLength() throws Exception {
31+
32+
GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext();
33+
ctx.load("file:" + getPathPart() + FILE_NAME);
34+
ctx.refresh();
35+
36+
BandsBean bb = ctx.getBean(BandsBean.class);
37+
38+
assertEquals(3, bb.getBandsList()
39+
.size());
40+
}
41+
42+
private String getPathPart() {
43+
String pathPart = new File(".").getAbsolutePath();
44+
pathPart = pathPart.replace(".", "");
45+
pathPart = pathPart.replace("\\", "/");
46+
pathPart = pathPart + FILE_PATH;
47+
48+
return pathPart;
49+
}
50+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.baeldug.groovyconfig;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.junit.Test;
6+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
7+
8+
public class JavaConfigurationTest {
9+
10+
@Test
11+
public void whenJavaConfig_thenCorrectPerson() {
12+
13+
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
14+
ctx.register(JavaBeanConfig.class);
15+
ctx.refresh();
16+
17+
JavaPersonBean j = ctx.getBean(JavaPersonBean.class);
18+
19+
assertEquals("31", j.getAge());
20+
assertEquals("green", j.getEyesColor());
21+
assertEquals("blond", j.getHairColor());
22+
23+
}
24+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldug.groovyconfig;
2+
3+
import static org.junit.Assert.*;
4+
5+
import org.junit.Test;
6+
import org.springframework.context.ApplicationContext;
7+
import org.springframework.context.support.ClassPathXmlApplicationContext;
8+
9+
public class XmlConfigurationTest {
10+
11+
@Test
12+
public void whenXmlConfig_thenCorrectPerson() {
13+
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("xml-bean-config.xml");
14+
15+
JavaPersonBean j = (JavaPersonBean) applicationContext.getBean("JavaPersonBean");
16+
17+
assertEquals("30", j.getAge());
18+
assertEquals("brown", j.getEyesColor());
19+
assertEquals("brown", j.getHairColor());
20+
21+
}
22+
23+
}

0 commit comments

Comments
 (0)