Browse Source

polishing .aop tests

pull/23217/head
Chris Beams 17 years ago
parent
commit
beea69d83b
  1. 3
      org.springframework.aop/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJNamespaceHandlerTests.java
  2. 0
      org.springframework.aop/src/test/java/org/springframework/aop/config/AopNamespaceHandlerEventTests-context.xml
  3. 0
      org.springframework.aop/src/test/java/org/springframework/aop/config/AopNamespaceHandlerEventTests-directPointcutEvents.xml
  4. 0
      org.springframework.aop/src/test/java/org/springframework/aop/config/AopNamespaceHandlerEventTests-pointcutEvents.xml
  5. 0
      org.springframework.aop/src/test/java/org/springframework/aop/config/AopNamespaceHandlerEventTests-pointcutRefEvents.xml
  6. 20
      org.springframework.aop/src/test/java/org/springframework/aop/config/AopNamespaceHandlerEventTests.java
  7. 0
      org.springframework.aop/src/test/java/org/springframework/aop/config/AopNamespaceHandlerPointcutErrorTests-pointcutDuplication.xml
  8. 0
      org.springframework.aop/src/test/java/org/springframework/aop/config/AopNamespaceHandlerPointcutErrorTests-pointcutMissing.xml
  9. 15
      org.springframework.aop/src/test/java/org/springframework/aop/config/AopNamespaceHandlerPointcutErrorTests.java
  10. 0
      org.springframework.aop/src/test/java/org/springframework/aop/config/TopLevelAopTagTests-context.xml
  11. 7
      org.springframework.aop/src/test/java/org/springframework/aop/config/TopLevelAopTagTests.java
  12. 33
      org.springframework.aop/src/test/java/test/parsing/CollectingReaderEventListener.java

3
org.springframework.aop/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJNamespaceHandlerTests.java

@ -23,7 +23,6 @@ import org.junit.Test; @@ -23,7 +23,6 @@ import org.junit.Test;
import org.springframework.aop.config.AopConfigUtils;
import org.springframework.aop.config.AopNamespaceUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.parsing.CollectingReaderEventListener;
import org.springframework.beans.factory.parsing.PassThroughSourceExtractor;
import org.springframework.beans.factory.parsing.SourceExtractor;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
@ -32,6 +31,8 @@ import org.springframework.beans.factory.xml.ParserContext; @@ -32,6 +31,8 @@ import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.factory.xml.XmlReaderContext;
import test.parsing.CollectingReaderEventListener;
/**
* @author Rob Harrop
* @author Chris Beams

0
org.springframework.aop/src/test/java/org/springframework/aop/config/aopNamespaceHandlerAspectEventTests.xml → org.springframework.aop/src/test/java/org/springframework/aop/config/AopNamespaceHandlerEventTests-context.xml

0
org.springframework.aop/src/test/java/org/springframework/aop/config/aopNamespaceHandlerAdvisorWithDirectPointcutEventTests.xml → org.springframework.aop/src/test/java/org/springframework/aop/config/AopNamespaceHandlerEventTests-directPointcutEvents.xml

0
org.springframework.aop/src/test/java/org/springframework/aop/config/aopNamespaceHandlerPointcutEventTests.xml → org.springframework.aop/src/test/java/org/springframework/aop/config/AopNamespaceHandlerEventTests-pointcutEvents.xml

0
org.springframework.aop/src/test/java/org/springframework/aop/config/aopNamespaceHandlerAdvisorWithPointcutRefEventTests.xml → org.springframework.aop/src/test/java/org/springframework/aop/config/AopNamespaceHandlerEventTests-pointcutRefEvents.xml

20
org.springframework.aop/src/test/java/org/springframework/aop/config/AopNamespaceHandlerEventTests.java

@ -26,13 +26,14 @@ import org.junit.Test; @@ -26,13 +26,14 @@ import org.junit.Test;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanReference;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.parsing.CollectingReaderEventListener;
import org.springframework.beans.factory.parsing.ComponentDefinition;
import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import test.parsing.CollectingReaderEventListener;
/**
* @author Rob Harrop
* @author Juergen Hoeller
@ -40,11 +41,20 @@ import org.springframework.core.io.ClassPathResource; @@ -40,11 +41,20 @@ import org.springframework.core.io.ClassPathResource;
*/
public final class AopNamespaceHandlerEventTests {
private static final Class<?> CLASS = AopNamespaceHandlerEventTests.class;
private static final String CLASSNAME = CLASS.getSimpleName();
private static final String CONTEXT = CLASSNAME + "-context.xml";
private static final String POINTCUT_EVENTS_CONTEXT = CLASSNAME + "-pointcutEvents.xml";
private static final String POINTCUT_REF_CONTEXT = CLASSNAME + "-pointcutRefEvents.xml";
private static final String DIRECT_POINTCUT_EVENTS_CONTEXT = CLASSNAME + "-directPointcutEvents.xml";
private CollectingReaderEventListener eventListener = new CollectingReaderEventListener();
private XmlBeanDefinitionReader reader;
private DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
@Before
@ -55,7 +65,7 @@ public final class AopNamespaceHandlerEventTests { @@ -55,7 +65,7 @@ public final class AopNamespaceHandlerEventTests {
@Test
public void testPointcutEvents() throws Exception {
loadBeansFrom("aopNamespaceHandlerPointcutEventTests.xml");
loadBeansFrom(POINTCUT_EVENTS_CONTEXT);
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
assertEquals("Incorrect number of events fired", 1, componentDefinitions.length);
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
@ -79,7 +89,7 @@ public final class AopNamespaceHandlerEventTests { @@ -79,7 +89,7 @@ public final class AopNamespaceHandlerEventTests {
@Test
public void testAdvisorEventsWithPointcutRef() throws Exception {
loadBeansFrom("aopNamespaceHandlerAdvisorWithPointcutRefEventTests.xml");
loadBeansFrom(POINTCUT_REF_CONTEXT);
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
assertEquals("Incorrect number of events fired", 2, componentDefinitions.length);
@ -108,7 +118,7 @@ public final class AopNamespaceHandlerEventTests { @@ -108,7 +118,7 @@ public final class AopNamespaceHandlerEventTests {
@Test
public void testAdvisorEventsWithDirectPointcut() throws Exception {
loadBeansFrom("aopNamespaceHandlerAdvisorWithDirectPointcutEventTests.xml");
loadBeansFrom(DIRECT_POINTCUT_EVENTS_CONTEXT);
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
assertEquals("Incorrect number of events fired", 2, componentDefinitions.length);
@ -137,7 +147,7 @@ public final class AopNamespaceHandlerEventTests { @@ -137,7 +147,7 @@ public final class AopNamespaceHandlerEventTests {
@Test
public void testAspectEvent() throws Exception {
loadBeansFrom("aopNamespaceHandlerAspectEventTests.xml");
loadBeansFrom(CONTEXT);
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
assertEquals("Incorrect number of events fired", 5, componentDefinitions.length);

0
org.springframework.aop/src/test/java/org/springframework/aop/config/aopNamespaceHandlerPointcutDuplicationTests.xml → org.springframework.aop/src/test/java/org/springframework/aop/config/AopNamespaceHandlerPointcutErrorTests-pointcutDuplication.xml

0
org.springframework.aop/src/test/java/org/springframework/aop/config/aopNamespaceHandlerPointcutMissingTests.xml → org.springframework.aop/src/test/java/org/springframework/aop/config/AopNamespaceHandlerPointcutErrorTests-pointcutMissing.xml

15
org.springframework.aop/src/test/java/org/springframework/aop/config/AopNamespaceHandlerPointcutErrorTests.java

@ -29,12 +29,20 @@ import org.springframework.core.io.ClassPathResource; @@ -29,12 +29,20 @@ import org.springframework.core.io.ClassPathResource;
* @author Chris Beams
*/
public final class AopNamespaceHandlerPointcutErrorTests {
private static final Class<?> CLASS = AopNamespaceHandlerPointcutErrorTests.class;
private static final String CLASSNAME = CLASS.getSimpleName();
private static final ClassPathResource DUPLICATION_CONTEXT =
new ClassPathResource(CLASSNAME + "-pointcutDuplication.xml", CLASS);
private static final ClassPathResource MISSING_CONTEXT =
new ClassPathResource(CLASSNAME + "-pointcutMissing.xml", CLASS);
@Test
public void testDuplicatePointcutConfig() {
try {
new XmlBeanFactory(new ClassPathResource(
"org/springframework/aop/config/aopNamespaceHandlerPointcutDuplicationTests.xml"));
new XmlBeanFactory(DUPLICATION_CONTEXT);
fail("parsing should have caused a BeanDefinitionStoreException");
}
catch (BeanDefinitionStoreException ex) {
@ -45,8 +53,7 @@ public final class AopNamespaceHandlerPointcutErrorTests { @@ -45,8 +53,7 @@ public final class AopNamespaceHandlerPointcutErrorTests {
@Test
public void testMissingPointcutConfig() {
try {
new XmlBeanFactory(new ClassPathResource(
"org/springframework/aop/config/aopNamespaceHandlerPointcutMissingTests.xml"));
new XmlBeanFactory(MISSING_CONTEXT);
fail("parsing should have caused a BeanDefinitionStoreException");
}
catch (BeanDefinitionStoreException ex) {

0
org.springframework.aop/src/test/java/org/springframework/aop/config/topLevelAop.xml → org.springframework.aop/src/test/java/org/springframework/aop/config/TopLevelAopTagTests-context.xml

7
org.springframework.aop/src/test/java/org/springframework/aop/config/TopLevelAopTagTests.java

@ -27,14 +27,19 @@ import org.springframework.core.io.ClassPathResource; @@ -27,14 +27,19 @@ import org.springframework.core.io.ClassPathResource;
* Tests that the &lt;aop:config/&gt; element can be used as a top level element.
*
* @author Rob Harrop
* @author Chris Beams
*/
public final class TopLevelAopTagTests {
private static final Class<?> CLASS = TopLevelAopTagTests.class;
private static final ClassPathResource CONTEXT =
new ClassPathResource(CLASS.getSimpleName() + "-context.xml", CLASS);
@Test
public void testParse() throws Exception {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
reader.loadBeanDefinitions(new ClassPathResource("topLevelAop.xml", getClass()));
reader.loadBeanDefinitions(CONTEXT);
assertTrue(beanFactory.containsBeanDefinition("testPointcut"));
}

33
org.springframework.aop/src/test/java/org/springframework/beans/factory/parsing/CollectingReaderEventListener.java → org.springframework.aop/src/test/java/test/parsing/CollectingReaderEventListener.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,37 +14,43 @@ @@ -14,37 +14,43 @@
* limitations under the License.
*/
package org.springframework.beans.factory.parsing;
package test.parsing;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.springframework.core.CollectionFactory;
import org.springframework.beans.factory.parsing.AliasDefinition;
import org.springframework.beans.factory.parsing.ComponentDefinition;
import org.springframework.beans.factory.parsing.DefaultsDefinition;
import org.springframework.beans.factory.parsing.ImportDefinition;
import org.springframework.beans.factory.parsing.ReaderEventListener;
/**
* @author Rob Harrop
* @author Juergen Hoeller
* @author Chris Beams
*/
public class CollectingReaderEventListener implements ReaderEventListener {
private final List defaults = new LinkedList();
private final List<DefaultsDefinition> defaults = new LinkedList<DefaultsDefinition>();
private final Map componentDefinitions = CollectionFactory.createLinkedMapIfPossible(8);
private final Map<String, Object> componentDefinitions = new LinkedHashMap<String, Object>(8);
private final Map aliasMap = CollectionFactory.createLinkedMapIfPossible(8);
private final Map<String, Object> aliasMap = new LinkedHashMap<String, Object>(8);
private final List imports = new LinkedList();
private final List<ImportDefinition> imports = new LinkedList<ImportDefinition>();
public void defaultsRegistered(DefaultsDefinition defaultsDefinition) {
this.defaults.add(defaultsDefinition);
}
public List getDefaults() {
public List<DefaultsDefinition> getDefaults() {
return Collections.unmodifiableList(this.defaults);
}
@ -57,10 +63,11 @@ public class CollectingReaderEventListener implements ReaderEventListener { @@ -57,10 +63,11 @@ public class CollectingReaderEventListener implements ReaderEventListener {
}
public ComponentDefinition[] getComponentDefinitions() {
Collection collection = this.componentDefinitions.values();
return (ComponentDefinition[]) collection.toArray(new ComponentDefinition[collection.size()]);
Collection<Object> collection = this.componentDefinitions.values();
return collection.toArray(new ComponentDefinition[collection.size()]);
}
@SuppressWarnings("unchecked")
public void aliasRegistered(AliasDefinition aliasDefinition) {
List aliases = (List) this.aliasMap.get(aliasDefinition.getBeanName());
if(aliases == null) {
@ -70,8 +77,8 @@ public class CollectingReaderEventListener implements ReaderEventListener { @@ -70,8 +77,8 @@ public class CollectingReaderEventListener implements ReaderEventListener {
aliases.add(aliasDefinition);
}
public List getAliases(String beanName) {
List aliases = (List) this.aliasMap.get(beanName);
public List<?> getAliases(String beanName) {
List<?> aliases = (List<?>) this.aliasMap.get(beanName);
return aliases == null ? null : Collections.unmodifiableList(aliases);
}
@ -79,7 +86,7 @@ public class CollectingReaderEventListener implements ReaderEventListener { @@ -79,7 +86,7 @@ public class CollectingReaderEventListener implements ReaderEventListener {
this.imports.add(importDefinition);
}
public List getImports() {
public List<ImportDefinition> getImports() {
return Collections.unmodifiableList(this.imports);
}
Loading…
Cancel
Save