BAEL 148 move to this repo (#2885)
This commit is contained in:
committed by
Zeger Hendrikse
parent
303db6c663
commit
fb283f35c7
@@ -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());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user