revised use of id and display name (id may be null; SPR-5761)
This commit is contained in:
parent
da4f1d0eb7
commit
a3af9e7330
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2009 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -137,6 +137,7 @@ public abstract class AbstractRefreshableConfigApplicationContext extends Abstra
|
||||||
public void setBeanName(String name) {
|
public void setBeanName(String name) {
|
||||||
if (!this.setIdCalled) {
|
if (!this.setIdCalled) {
|
||||||
super.setId(name);
|
super.setId(name);
|
||||||
|
setDisplayName("ApplicationContext '" + name + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2009 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -17,8 +17,8 @@
|
||||||
package org.springframework.context.access;
|
package org.springframework.context.access;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.access.BeanFactoryLocator;
|
import org.springframework.beans.factory.access.BeanFactoryLocator;
|
||||||
import org.springframework.beans.factory.access.BeanFactoryReference;
|
import org.springframework.beans.factory.access.BeanFactoryReference;
|
||||||
|
|
@ -58,11 +58,11 @@ public class ContextSingletonBeanFactoryLocatorTests extends SingletonBeanFactor
|
||||||
BeanFactory fac = bfr.getFactory();
|
BeanFactory fac = bfr.getFactory();
|
||||||
assertTrue(fac instanceof ApplicationContext);
|
assertTrue(fac instanceof ApplicationContext);
|
||||||
assertEquals("a.qualified.name.of.some.sort", ((ApplicationContext) fac).getId());
|
assertEquals("a.qualified.name.of.some.sort", ((ApplicationContext) fac).getId());
|
||||||
assertEquals("a.qualified.name.of.some.sort", ((ApplicationContext) fac).getDisplayName());
|
assertTrue(((ApplicationContext) fac).getDisplayName().contains("a.qualified.name.of.some.sort"));
|
||||||
BeanFactoryReference bfr2 = facLoc.useBeanFactory("another.qualified.name");
|
BeanFactoryReference bfr2 = facLoc.useBeanFactory("another.qualified.name");
|
||||||
BeanFactory fac2 = bfr2.getFactory();
|
BeanFactory fac2 = bfr2.getFactory();
|
||||||
assertEquals("another.qualified.name", ((ApplicationContext) fac2).getId());
|
assertEquals("another.qualified.name", ((ApplicationContext) fac2).getId());
|
||||||
assertEquals("another.qualified.name", ((ApplicationContext) fac2).getDisplayName());
|
assertTrue(((ApplicationContext) fac2).getDisplayName().contains("another.qualified.name"));
|
||||||
assertTrue(fac2 instanceof ApplicationContext);
|
assertTrue(fac2 instanceof ApplicationContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,8 +133,8 @@ public final class ClassPathXmlApplicationContextTests {
|
||||||
}
|
}
|
||||||
catch (BeanCreationException ex) {
|
catch (BeanCreationException ex) {
|
||||||
assertTrue(ex.contains(TypeMismatchException.class));
|
assertTrue(ex.contains(TypeMismatchException.class));
|
||||||
assertTrue(ex.toString().indexOf("someMessageSource") != -1);
|
assertTrue(ex.toString().contains("someMessageSource"));
|
||||||
assertTrue(ex.toString().indexOf("useCodeAsDefaultMessage") != -1);
|
assertTrue(ex.toString().contains("useCodeAsDefaultMessage"));
|
||||||
checkExceptionFromInvalidValueType(ex);
|
checkExceptionFromInvalidValueType(ex);
|
||||||
checkExceptionFromInvalidValueType(new ExceptionInInitializerError(ex));
|
checkExceptionFromInvalidValueType(new ExceptionInInitializerError(ex));
|
||||||
assertFalse(context.isActive());
|
assertFalse(context.isActive());
|
||||||
|
|
@ -146,8 +146,8 @@ public final class ClassPathXmlApplicationContextTests {
|
||||||
ex.printStackTrace(new PrintStream(baos));
|
ex.printStackTrace(new PrintStream(baos));
|
||||||
String dump = FileCopyUtils.copyToString(
|
String dump = FileCopyUtils.copyToString(
|
||||||
new InputStreamReader(new ByteArrayInputStream(baos.toByteArray())));
|
new InputStreamReader(new ByteArrayInputStream(baos.toByteArray())));
|
||||||
assertTrue(dump.indexOf("someMessageSource") != -1);
|
assertTrue(dump.contains("someMessageSource"));
|
||||||
assertTrue(dump.indexOf("useCodeAsDefaultMessage") != -1);
|
assertTrue(dump.contains("useCodeAsDefaultMessage"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -381,13 +381,14 @@ public final class ClassPathXmlApplicationContextTests {
|
||||||
public void testGenericApplicationContextWithXmlBeanDefinitionsAndSpecifiedId() {
|
public void testGenericApplicationContextWithXmlBeanDefinitionsAndSpecifiedId() {
|
||||||
GenericApplicationContext ctx = new GenericApplicationContext();
|
GenericApplicationContext ctx = new GenericApplicationContext();
|
||||||
ctx.setId("testContext");
|
ctx.setId("testContext");
|
||||||
|
ctx.setDisplayName("Test Context");
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
|
||||||
reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_B, getClass()));
|
reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_B, getClass()));
|
||||||
reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_C, getClass()));
|
reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_C, getClass()));
|
||||||
reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_A, getClass()));
|
reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_A, getClass()));
|
||||||
ctx.refresh();
|
ctx.refresh();
|
||||||
assertEquals("testContext", ctx.getId());
|
assertEquals("testContext", ctx.getId());
|
||||||
assertEquals("testContext", ctx.getDisplayName());
|
assertEquals("Test Context", ctx.getDisplayName());
|
||||||
assertTrue(ctx.containsBean("service"));
|
assertTrue(ctx.containsBean("service"));
|
||||||
assertTrue(ctx.containsBean("logicOne"));
|
assertTrue(ctx.containsBean("logicOne"));
|
||||||
assertTrue(ctx.containsBean("logicTwo"));
|
assertTrue(ctx.containsBean("logicTwo"));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue