BAEL 148 move to this repo (#2885)
This commit is contained in:
parent
303db6c663
commit
fb283f35c7
@ -37,5 +37,38 @@
|
||||
<artifactId>spring-integration-groovy</artifactId>
|
||||
<version>4.3.7.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-all</artifactId>
|
||||
<version>2.4.12</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.7.0</version>
|
||||
<configuration>
|
||||
<compilerId>groovy-eclipse-compiler</compilerId>
|
||||
<verbose>true</verbose>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-eclipse-compiler</artifactId>
|
||||
<version>2.9.2-01</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-eclipse-batch</artifactId>
|
||||
<version>2.4.3-01</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
@ -0,0 +1,17 @@
|
||||
package com.baeldug.groovyconfig;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BandsBean {
|
||||
|
||||
private List<String> bandsList = new ArrayList<>();
|
||||
|
||||
public List<String> getBandsList() {
|
||||
return bandsList;
|
||||
}
|
||||
|
||||
public void setBandsList(List<String> bandsList) {
|
||||
this.bandsList = bandsList;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.baeldug.groovyconfig;
|
||||
|
||||
beans {
|
||||
javaPesronBean(JavaPersonBean) {
|
||||
firstName = 'John'
|
||||
lastName = 'Doe'
|
||||
age ='32'
|
||||
eyesColor = 'blue'
|
||||
hairColor='black'
|
||||
}
|
||||
|
||||
bandsBean(BandsBean) { bean->
|
||||
bean.scope = "singleton"
|
||||
bandsList=['Nirvana', 'Pearl Jam', 'Foo Fighters']
|
||||
}
|
||||
|
||||
registerAlias("bandsBean","bands")
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.baeldug.groovyconfig;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class JavaBeanConfig {
|
||||
|
||||
@Bean
|
||||
public JavaPersonBean javaPerson() {
|
||||
JavaPersonBean jPerson = new JavaPersonBean();
|
||||
jPerson.setFirstName("John");
|
||||
jPerson.setLastName("Doe");
|
||||
jPerson.setAge("31");
|
||||
jPerson.setEyesColor("green");
|
||||
jPerson.setHairColor("blond");
|
||||
|
||||
return jPerson;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.baeldug.groovyconfig;
|
||||
|
||||
public class JavaPersonBean {
|
||||
|
||||
public String jj;
|
||||
|
||||
private String firstName;
|
||||
|
||||
private String lastName;
|
||||
|
||||
private String age;
|
||||
|
||||
private String eyesColor;
|
||||
|
||||
private String hairColor;
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(String age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getEyesColor() {
|
||||
return eyesColor;
|
||||
}
|
||||
|
||||
public void setEyesColor(String eyesColor) {
|
||||
this.eyesColor = eyesColor;
|
||||
}
|
||||
|
||||
public String getHairColor() {
|
||||
return hairColor;
|
||||
}
|
||||
|
||||
public void setHairColor(String hairColor) {
|
||||
this.hairColor = hairColor;
|
||||
}
|
||||
|
||||
}
|
12
spring-groovy/src/main/resources/xml-bean-config.xml
Normal file
12
spring-groovy/src/main/resources/xml-bean-config.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<bean id="JavaPersonBean" class="com.baeldug.groovyconfig.JavaPersonBean">
|
||||
<property name="firstName" value="John" />
|
||||
<property name="LastName" value="Doe" />
|
||||
<property name="age" value="30" />
|
||||
<property name="eyesColor" value="brown" />
|
||||
<property name="hairColor" value="brown" />
|
||||
</bean>
|
||||
</beans>
|
@ -0,0 +1,50 @@
|
||||
package com.baeldug.groovyconfig;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.GenericGroovyApplicationContext;
|
||||
|
||||
public class GroovyConfigurationTest {
|
||||
|
||||
private static final String FILE_NAME = "GroovyBeanConfig.groovy";
|
||||
private static final String FILE_PATH = "src/main/java/com/baeldug/groovyconfig/";
|
||||
|
||||
@Test
|
||||
public void whenGroovyConfig_thenCorrectPerson() throws Exception {
|
||||
|
||||
GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext();
|
||||
ctx.load("file:" + getPathPart() + FILE_NAME);
|
||||
ctx.refresh();
|
||||
|
||||
JavaPersonBean j = ctx.getBean(JavaPersonBean.class);
|
||||
|
||||
assertEquals("32", j.getAge());
|
||||
assertEquals("blue", j.getEyesColor());
|
||||
assertEquals("black", j.getHairColor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGroovyConfig_thenCorrectListLength() throws Exception {
|
||||
|
||||
GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext();
|
||||
ctx.load("file:" + getPathPart() + FILE_NAME);
|
||||
ctx.refresh();
|
||||
|
||||
BandsBean bb = ctx.getBean(BandsBean.class);
|
||||
|
||||
assertEquals(3, bb.getBandsList()
|
||||
.size());
|
||||
}
|
||||
|
||||
private String getPathPart() {
|
||||
String pathPart = new File(".").getAbsolutePath();
|
||||
pathPart = pathPart.replace(".", "");
|
||||
pathPart = pathPart.replace("\\", "/");
|
||||
pathPart = pathPart + FILE_PATH;
|
||||
|
||||
return pathPart;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.baeldug.groovyconfig;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
public class JavaConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void whenJavaConfig_thenCorrectPerson() {
|
||||
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(JavaBeanConfig.class);
|
||||
ctx.refresh();
|
||||
|
||||
JavaPersonBean j = ctx.getBean(JavaPersonBean.class);
|
||||
|
||||
assertEquals("31", j.getAge());
|
||||
assertEquals("green", j.getEyesColor());
|
||||
assertEquals("blond", j.getHairColor());
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.baeldug.groovyconfig;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class XmlConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void whenXmlConfig_thenCorrectPerson() {
|
||||
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("xml-bean-config.xml");
|
||||
|
||||
JavaPersonBean j = (JavaPersonBean) applicationContext.getBean("JavaPersonBean");
|
||||
|
||||
assertEquals("30", j.getAge());
|
||||
assertEquals("brown", j.getEyesColor());
|
||||
assertEquals("brown", j.getHairColor());
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user