类org.springframework.context.support.GenericGroovyApplicationContext源码实例Demo

下面列出了怎么用org.springframework.context.support.GenericGroovyApplicationContext的API类实例代码及写法,或者点击链接到github查看源代码。

@Test
@SuppressWarnings("resource")
public void verifyScriptUsingGenericGroovyApplicationContext() {
	ApplicationContext ctx = new GenericGroovyApplicationContext(getClass(), "context.groovy");

	String foo = ctx.getBean("foo", String.class);
	assertEquals("Foo", foo);

	String bar = ctx.getBean("bar", String.class);
	assertEquals("Bar", bar);

	Pet pet = ctx.getBean(Pet.class);
	assertNotNull("pet", pet);
	assertEquals("Dogbert", pet.getName());

	Employee employee = ctx.getBean(Employee.class);
	assertNotNull("employee", employee);
	assertEquals("Dilbert", employee.getName());
	assertEquals("???", employee.getCompany());
}
 
@Test
@SuppressWarnings("resource")
public void verifyScriptUsingGenericGroovyApplicationContext() {
	ApplicationContext ctx = new GenericGroovyApplicationContext(getClass(), "context.groovy");

	String foo = ctx.getBean("foo", String.class);
	assertEquals("Foo", foo);

	String bar = ctx.getBean("bar", String.class);
	assertEquals("Bar", bar);

	Pet pet = ctx.getBean(Pet.class);
	assertNotNull("pet", pet);
	assertEquals("Dogbert", pet.getName());

	Employee employee = ctx.getBean(Employee.class);
	assertNotNull("employee", employee);
	assertEquals("Dilbert", employee.getName());
	assertEquals("???", employee.getCompany());
}
 
@Test
@SuppressWarnings("resource")
public void verifyScriptUsingGenericGroovyApplicationContext() {
	ApplicationContext ctx = new GenericGroovyApplicationContext(getClass(), "context.groovy");

	String foo = ctx.getBean("foo", String.class);
	assertEquals("Foo", foo);

	String bar = ctx.getBean("bar", String.class);
	assertEquals("Bar", bar);

	Pet pet = ctx.getBean(Pet.class);
	assertNotNull("pet", pet);
	assertEquals("Dogbert", pet.getName());

	Employee employee = ctx.getBean(Employee.class);
	assertNotNull("employee", employee);
	assertEquals("Dilbert", employee.getName());
	assertEquals("???", employee.getCompany());
}
 
@Test
public void testLoadingConfigFile() {
	GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext(
			"org/springframework/context/groovy/applicationContext.groovy");

	Object framework = ctx.getBean("framework");
	assertNotNull("could not find framework bean", framework);
	assertEquals("Grails", framework);
}
 
@Test
public void testLoadingMultipleConfigFiles() {
	GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext(
			"org/springframework/context/groovy/applicationContext2.groovy",
			"org/springframework/context/groovy/applicationContext.groovy");

	Object framework = ctx.getBean("framework");
	assertNotNull("could not find framework bean", framework);
	assertEquals("Grails", framework);

	Object company = ctx.getBean("company");
	assertNotNull("could not find company bean", company);
	assertEquals("SpringSource", company);
}
 
@Test
public void testLoadingMultipleConfigFilesWithRelativeClass() {
	GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext();
	ctx.load(GroovyApplicationContextTests.class, "applicationContext2.groovy", "applicationContext.groovy");
	ctx.refresh();

	Object framework = ctx.getBean("framework");
	assertNotNull("could not find framework bean", framework);
	assertEquals("Grails", framework);

	Object company = ctx.getBean("company");
	assertNotNull("could not find company bean", company);
	assertEquals("SpringSource", company);
}
 
@Test
public void testLoadingConfigFile() {
	GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext(
			"org/springframework/context/groovy/applicationContext.groovy");

	Object framework = ctx.getBean("framework");
	assertNotNull("could not find framework bean", framework);
	assertEquals("Grails", framework);
}
 
@Test
public void testLoadingMultipleConfigFiles() {
	GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext(
			"org/springframework/context/groovy/applicationContext2.groovy",
			"org/springframework/context/groovy/applicationContext.groovy");

	Object framework = ctx.getBean("framework");
	assertNotNull("could not find framework bean", framework);
	assertEquals("Grails", framework);

	Object company = ctx.getBean("company");
	assertNotNull("could not find company bean", company);
	assertEquals("SpringSource", company);
}
 
@Test
public void testLoadingMultipleConfigFilesWithRelativeClass() {
	GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext();
	ctx.load(GroovyApplicationContextTests.class, "applicationContext2.groovy", "applicationContext.groovy");
	ctx.refresh();

	Object framework = ctx.getBean("framework");
	assertNotNull("could not find framework bean", framework);
	assertEquals("Grails", framework);

	Object company = ctx.getBean("company");
	assertNotNull("could not find company bean", company);
	assertEquals("SpringSource", company);
}
 
@Test
public void testLoadingConfigFile() {
	GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext(
			"org/springframework/context/groovy/applicationContext.groovy");

	Object framework = ctx.getBean("framework");
	assertNotNull("could not find framework bean", framework);
	assertEquals("Grails", framework);
}
 
@Test
public void testLoadingMultipleConfigFiles() {
	GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext(
			"org/springframework/context/groovy/applicationContext2.groovy",
			"org/springframework/context/groovy/applicationContext.groovy");

	Object framework = ctx.getBean("framework");
	assertNotNull("could not find framework bean", framework);
	assertEquals("Grails", framework);

	Object company = ctx.getBean("company");
	assertNotNull("could not find company bean", company);
	assertEquals("SpringSource", company);
}
 
@Test
public void testLoadingMultipleConfigFilesWithRelativeClass() {
	GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext();
	ctx.load(GroovyApplicationContextTests.class, "applicationContext2.groovy", "applicationContext.groovy");
	ctx.refresh();

	Object framework = ctx.getBean("framework");
	assertNotNull("could not find framework bean", framework);
	assertEquals("Grails", framework);

	Object company = ctx.getBean("company");
	assertNotNull("could not find company bean", company);
	assertEquals("SpringSource", company);
}
 
源代码13 项目: tutorials   文件: GroovyConfigurationUnitTest.java
@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());
}
 
源代码14 项目: tutorials   文件: GroovyConfigurationUnitTest.java
@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());
}
 
@Test(expected = BeanDefinitionParsingException.class)
public void testConfigFileParsingError() {
	new GenericGroovyApplicationContext("org/springframework/context/groovy/applicationContext-error.groovy");
}
 
@Test(expected = BeanDefinitionParsingException.class)
public void testConfigFileParsingError() {
	new GenericGroovyApplicationContext("org/springframework/context/groovy/applicationContext-error.groovy");
}
 
@Test(expected = BeanDefinitionParsingException.class)
public void testConfigFileParsingError() {
	new GenericGroovyApplicationContext("org/springframework/context/groovy/applicationContext-error.groovy");
}
 
 同包方法