polishing

This commit is contained in:
Juergen Hoeller 2009-03-23 11:20:18 +00:00
parent c82a66b59c
commit 6d7bf17394
5 changed files with 44 additions and 62 deletions

View File

@ -372,13 +372,13 @@
</xsd:element> </xsd:element>
<xsd:complexType name="listenerType"> <xsd:complexType name="listenerType">
<xsd:attribute name="id" type="xsd:ID"> <xsd:attribute name="id" type="xsd:ID">
<xsd:annotation> <xsd:annotation>
<xsd:documentation><![CDATA[ <xsd:documentation><![CDATA[
The unique identifier for a listener. The unique identifier for a listener.
]]></xsd:documentation> ]]></xsd:documentation>
</xsd:annotation> </xsd:annotation>
</xsd:attribute> </xsd:attribute>
<xsd:attribute name="destination" type="xsd:string" use="required"> <xsd:attribute name="destination" type="xsd:string" use="required">
<xsd:annotation> <xsd:annotation>
<xsd:documentation><![CDATA[ <xsd:documentation><![CDATA[

View File

@ -372,13 +372,13 @@
</xsd:element> </xsd:element>
<xsd:complexType name="listenerType"> <xsd:complexType name="listenerType">
<xsd:attribute name="id" type="xsd:ID"> <xsd:attribute name="id" type="xsd:ID">
<xsd:annotation> <xsd:annotation>
<xsd:documentation><![CDATA[ <xsd:documentation><![CDATA[
The unique identifier for a listener. The unique identifier for a listener.
]]></xsd:documentation> ]]></xsd:documentation>
</xsd:annotation> </xsd:annotation>
</xsd:attribute> </xsd:attribute>
<xsd:attribute name="destination" type="xsd:string" use="required"> <xsd:attribute name="destination" type="xsd:string" use="required">
<xsd:annotation> <xsd:annotation>
<xsd:documentation><![CDATA[ <xsd:documentation><![CDATA[

View File

@ -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.
@ -20,7 +20,6 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.jms.ConnectionFactory; import javax.jms.ConnectionFactory;
import javax.jms.Message; import javax.jms.Message;
import javax.jms.MessageListener; import javax.jms.MessageListener;
@ -37,7 +36,6 @@ import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
import org.springframework.beans.factory.parsing.EmptyReaderEventListener; import org.springframework.beans.factory.parsing.EmptyReaderEventListener;
import org.springframework.beans.factory.parsing.PassThroughSourceExtractor; import org.springframework.beans.factory.parsing.PassThroughSourceExtractor;
import org.springframework.beans.factory.parsing.ReaderEventListener; import org.springframework.beans.factory.parsing.ReaderEventListener;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jca.endpoint.GenericMessageEndpointManager; import org.springframework.jca.endpoint.GenericMessageEndpointManager;
@ -76,16 +74,14 @@ public class JmsNamespaceHandlerTests extends TestCase {
} }
public void testContainerConfiguration() throws Exception { public void testContainerConfiguration() throws Exception {
Map containers = context.getBeansOfType(DefaultMessageListenerContainer.class); Map<String, DefaultMessageListenerContainer> containers = context.getBeansOfType(DefaultMessageListenerContainer.class);
ConnectionFactory defaultConnectionFactory = (ConnectionFactory) context.getBean(DEFAULT_CONNECTION_FACTORY); ConnectionFactory defaultConnectionFactory = context.getBean(DEFAULT_CONNECTION_FACTORY, ConnectionFactory.class);
ConnectionFactory explicitConnectionFactory = (ConnectionFactory) context.getBean(EXPLICIT_CONNECTION_FACTORY); ConnectionFactory explicitConnectionFactory = context.getBean(EXPLICIT_CONNECTION_FACTORY, ConnectionFactory.class);
int defaultConnectionFactoryCount = 0; int defaultConnectionFactoryCount = 0;
int explicitConnectionFactoryCount = 0; int explicitConnectionFactoryCount = 0;
Iterator iter = containers.values().iterator(); for (DefaultMessageListenerContainer container : containers.values()) {
while (iter.hasNext()) {
DefaultMessageListenerContainer container = (DefaultMessageListenerContainer) iter.next();
if (container.getConnectionFactory().equals(defaultConnectionFactory)) { if (container.getConnectionFactory().equals(defaultConnectionFactory)) {
defaultConnectionFactoryCount++; defaultConnectionFactoryCount++;
} }
@ -99,9 +95,9 @@ public class JmsNamespaceHandlerTests extends TestCase {
} }
public void testListeners() throws Exception { public void testListeners() throws Exception {
TestBean testBean1 = (TestBean) context.getBean("testBean1"); TestBean testBean1 = context.getBean("testBean1", TestBean.class);
TestBean testBean2 = (TestBean) context.getBean("testBean2"); TestBean testBean2 = context.getBean("testBean2", TestBean.class);
TestMessageListener testBean3 = (TestMessageListener) context.getBean("testBean3"); TestMessageListener testBean3 = context.getBean("testBean3", TestMessageListener.class);
assertNull(testBean1.getName()); assertNull(testBean1.getName());
assertNull(testBean2.getName()); assertNull(testBean2.getName());
@ -138,7 +134,7 @@ public class JmsNamespaceHandlerTests extends TestCase {
} }
private MessageListener getListener(String containerBeanName) { private MessageListener getListener(String containerBeanName) {
DefaultMessageListenerContainer container = (DefaultMessageListenerContainer) this.context.getBean(containerBeanName); DefaultMessageListenerContainer container = this.context.getBean(containerBeanName, DefaultMessageListenerContainer.class);
return (MessageListener) container.getMessageListener(); return (MessageListener) container.getMessageListener();
} }
@ -156,19 +152,15 @@ public class JmsNamespaceHandlerTests extends TestCase {
Iterator iterator = context.getRegisteredComponents(); Iterator iterator = context.getRegisteredComponents();
while (iterator.hasNext()) { while (iterator.hasNext()) {
ComponentDefinition compDef = (ComponentDefinition) iterator.next(); ComponentDefinition compDef = (ComponentDefinition) iterator.next();
if (compDef instanceof CompositeComponentDefinition) { assertNotNull("CompositeComponentDefinition '" + compDef.getName()+ "' has no source attachment", compDef.getSource());
assertNotNull("CompositeComponentDefinition '" + compDef.getName()+ "' has no source attachment", ((CompositeComponentDefinition) compDef).getSource());
}
validateComponentDefinition(compDef); validateComponentDefinition(compDef);
} }
} }
private void validateComponentDefinition(ComponentDefinition compDef) { private void validateComponentDefinition(ComponentDefinition compDef) {
BeanDefinition[] beanDefs = compDef.getBeanDefinitions(); BeanDefinition[] beanDefs = compDef.getBeanDefinitions();
for (int i = 0; i < beanDefs.length; i++) { for (BeanDefinition beanDef : beanDefs) {
if (beanDefs[i] instanceof AbstractBeanDefinition) { assertNotNull("BeanDefinition has no source attachment", beanDef.getSource());
assertNotNull("AbstractBeanDefinition has no source attachment", ((AbstractBeanDefinition) beanDefs[i]).getSource());
}
} }
} }
@ -189,28 +181,24 @@ public class JmsNamespaceHandlerTests extends TestCase {
*/ */
private static class ToolingTestApplicationContext extends ClassPathXmlApplicationContext { private static class ToolingTestApplicationContext extends ClassPathXmlApplicationContext {
private static final Set REGISTERED_COMPONENTS = new HashSet(); private Set<ComponentDefinition> registeredComponents;
public ToolingTestApplicationContext(String path, Class clazz) public ToolingTestApplicationContext(String path, Class clazz) {
throws BeansException {
super(path, clazz); super(path, clazz);
} }
protected void initBeanDefinitionReader( protected void initBeanDefinitionReader(XmlBeanDefinitionReader beanDefinitionReader) {
XmlBeanDefinitionReader beanDefinitionReader) { this.registeredComponents = new HashSet<ComponentDefinition>();
beanDefinitionReader.setEventListener(new StoringReaderEventListener(REGISTERED_COMPONENTS)); beanDefinitionReader.setEventListener(new StoringReaderEventListener(this.registeredComponents));
beanDefinitionReader.setSourceExtractor(new PassThroughSourceExtractor()); beanDefinitionReader.setSourceExtractor(new PassThroughSourceExtractor());
} }
public boolean containsComponentDefinition(String name) { public boolean containsComponentDefinition(String name) {
Iterator iterator = REGISTERED_COMPONENTS.iterator(); for (ComponentDefinition cd : this.registeredComponents) {
while (iterator.hasNext()) {
ComponentDefinition cd = (ComponentDefinition) iterator.next();
if (cd instanceof CompositeComponentDefinition) { if (cd instanceof CompositeComponentDefinition) {
ComponentDefinition[] innerCds = ((CompositeComponentDefinition) cd) ComponentDefinition[] innerCds = ((CompositeComponentDefinition) cd).getNestedComponents();
.getNestedComponents(); for (ComponentDefinition innerCd : innerCds) {
for (int i = 0; i < innerCds.length; i++) { if (innerCd.getName().equals(name)) {
if (innerCds[i].getName().equals(name)) {
return true; return true;
} }
} }
@ -224,19 +212,18 @@ public class JmsNamespaceHandlerTests extends TestCase {
return false; return false;
} }
public Iterator getRegisteredComponents() { public Iterator<ComponentDefinition> getRegisteredComponents() {
return REGISTERED_COMPONENTS.iterator(); return this.registeredComponents.iterator();
} }
} }
private static class StoringReaderEventListener extends EmptyReaderEventListener { private static class StoringReaderEventListener extends EmptyReaderEventListener {
protected Set registeredComponents = null; protected final Set<ComponentDefinition> registeredComponents;
public StoringReaderEventListener(Set registeredComponents) { public StoringReaderEventListener(Set<ComponentDefinition> registeredComponents) {
this.registeredComponents = registeredComponents; this.registeredComponents = registeredComponents;
this.registeredComponents.clear();
} }
public void componentRegistered(ComponentDefinition componentDefinition) { public void componentRegistered(ComponentDefinition componentDefinition) {

View File

@ -21,7 +21,7 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -30,7 +30,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
/** /**
* @author Arjen Poutsma * @author Arjen Poutsma
*/ */
public class RequestMappingInfoComparatorTest { public class RequestMappingInfoComparatorTests {
private AnnotationMethodHandlerAdapter.RequestMappingInfoComparator comparator; private AnnotationMethodHandlerAdapter.RequestMappingInfoComparator comparator;
@ -44,6 +44,7 @@ public class RequestMappingInfoComparatorTest {
private AnnotationMethodHandlerAdapter.RequestMappingInfo oneMethodTwoParamsInfo; private AnnotationMethodHandlerAdapter.RequestMappingInfo oneMethodTwoParamsInfo;
@Before @Before
public void setUp() throws NoSuchMethodException { public void setUp() throws NoSuchMethodException {
comparator = new AnnotationMethodHandlerAdapter.RequestMappingInfoComparator(new MockComparator()); comparator = new AnnotationMethodHandlerAdapter.RequestMappingInfoComparator(new MockComparator());
@ -84,6 +85,7 @@ public class RequestMappingInfoComparatorTest {
assertEquals(emptyInfo, infos.get(4)); assertEquals(emptyInfo, infos.get(4));
} }
private static class MockComparator implements Comparator<String> { private static class MockComparator implements Comparator<String> {
public int compare(String s1, String s2) { public int compare(String s1, String s2) {

View File

@ -104,6 +104,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
private List pets; private List pets;
public TestBean() { public TestBean() {
} }
@ -396,9 +397,6 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
} }
/**
* @see org.springframework.beans.ITestBean#exceptional(Throwable)
*/
public void exceptional(Throwable t) throws Throwable { public void exceptional(Throwable t) throws Throwable {
if (t != null) { if (t != null) {
throw t; throw t;
@ -408,16 +406,11 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
public void unreliableFileOperation() throws IOException { public void unreliableFileOperation() throws IOException {
throw new IOException(); throw new IOException();
} }
/**
* @see org.springframework.beans.ITestBean#returnsThis()
*/
public Object returnsThis() { public Object returnsThis() {
return this; return this;
} }
/**
* @see org.springframework.beans.IOther#absquatulate()
*/
public void absquatulate() { public void absquatulate() {
} }