Migrate JUnit 3 tests to JUnit 4
This commit migrates all remaining tests from JUnit 3 to JUnit 4, with the exception of Spring's legacy JUnit 3.8 based testing framework that is still in use in the spring-orm module. Issue: SPR-13514
This commit is contained in:
parent
1580288815
commit
d5ee787e1e
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -15,21 +15,24 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.aop.support;
|
package org.springframework.aop.support;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.aop.framework.ProxyFactory;
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Colin Sampaleanu
|
* @author Colin Sampaleanu
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
*/
|
*/
|
||||||
public class ClassUtilsTests extends TestCase {
|
public class ClassUtilsTests {
|
||||||
|
|
||||||
public void testGetShortNameForCglibClass() {
|
@Test
|
||||||
|
public void getShortNameForCglibClass() {
|
||||||
TestBean tb = new TestBean();
|
TestBean tb = new TestBean();
|
||||||
ProxyFactory pf = new ProxyFactory();
|
ProxyFactory pf = new ProxyFactory();
|
||||||
pf.setTarget(tb);
|
pf.setTarget(tb);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,16 +16,18 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj.autoproxy;
|
package org.springframework.aop.aspectj.autoproxy;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Colyer
|
* @author Adrian Colyer
|
||||||
*/
|
*/
|
||||||
public class AutoProxyWithCodeStyleAspectsTests extends TestCase {
|
public class AutoProxyWithCodeStyleAspectsTests {
|
||||||
|
|
||||||
public void testNoAutoproxyingOfAjcCompiledAspects() {
|
@Test
|
||||||
|
@SuppressWarnings("resource")
|
||||||
|
public void noAutoproxyingOfAjcCompiledAspects() {
|
||||||
new ClassPathXmlApplicationContext("org/springframework/aop/aspectj/autoproxy/ajcAutoproxyTests.xml");
|
new ClassPathXmlApplicationContext("org/springframework/aop/aspectj/autoproxy/ajcAutoproxyTests.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,18 +16,17 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory.aspectj;
|
package org.springframework.beans.factory.aspectj;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
public class SpringConfiguredWithAutoProxyingTests extends TestCase {
|
public class SpringConfiguredWithAutoProxyingTests {
|
||||||
|
|
||||||
@Override
|
@Test
|
||||||
protected void setUp() throws Exception {
|
@SuppressWarnings("resource")
|
||||||
|
public void springConfiguredAndAutoProxyUsedTogether() {
|
||||||
|
// instantiation is sufficient to trigger failure if this is going to fail...
|
||||||
new ClassPathXmlApplicationContext("org/springframework/beans/factory/aspectj/springConfigured.xml");
|
new ClassPathXmlApplicationContext("org/springframework/beans/factory/aspectj/springConfigured.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSpringConfiguredAndAutoProxyUsedTogether() {
|
|
||||||
; // set up is sufficient to trigger failure if this is going to fail...
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,18 +18,21 @@ package org.springframework.beans.factory.support;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class BeanDefinitionBuilderTests extends TestCase {
|
public class BeanDefinitionBuilderTests {
|
||||||
|
|
||||||
public void testBeanClassWithSimpleProperty() {
|
@Test
|
||||||
|
public void beanClassWithSimpleProperty() {
|
||||||
String[] dependsOn = new String[] { "A", "B", "C" };
|
String[] dependsOn = new String[] { "A", "B", "C" };
|
||||||
BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class);
|
BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class);
|
||||||
bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
|
bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
|
||||||
|
@ -45,7 +48,8 @@ public class BeanDefinitionBuilderTests extends TestCase {
|
||||||
assertTrue(rbd.getPropertyValues().contains("age"));
|
assertTrue(rbd.getPropertyValues().contains("age"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBeanClassWithFactoryMethod() {
|
@Test
|
||||||
|
public void beanClassWithFactoryMethod() {
|
||||||
BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class, "create");
|
BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class, "create");
|
||||||
RootBeanDefinition rbd = (RootBeanDefinition) bdb.getBeanDefinition();
|
RootBeanDefinition rbd = (RootBeanDefinition) bdb.getBeanDefinition();
|
||||||
assertTrue(rbd.hasBeanClass());
|
assertTrue(rbd.hasBeanClass());
|
||||||
|
@ -53,14 +57,16 @@ public class BeanDefinitionBuilderTests extends TestCase {
|
||||||
assertEquals("create", rbd.getFactoryMethodName());
|
assertEquals("create", rbd.getFactoryMethodName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBeanClassName() {
|
@Test
|
||||||
|
public void beanClassName() {
|
||||||
BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class.getName());
|
BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class.getName());
|
||||||
RootBeanDefinition rbd = (RootBeanDefinition) bdb.getBeanDefinition();
|
RootBeanDefinition rbd = (RootBeanDefinition) bdb.getBeanDefinition();
|
||||||
assertFalse(rbd.hasBeanClass());
|
assertFalse(rbd.hasBeanClass());
|
||||||
assertEquals(TestBean.class.getName(), rbd.getBeanClassName());
|
assertEquals(TestBean.class.getName(), rbd.getBeanClassName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBeanClassNameWithFactoryMethod() {
|
@Test
|
||||||
|
public void beanClassNameWithFactoryMethod() {
|
||||||
BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class.getName(), "create");
|
BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class.getName(), "create");
|
||||||
RootBeanDefinition rbd = (RootBeanDefinition) bdb.getBeanDefinition();
|
RootBeanDefinition rbd = (RootBeanDefinition) bdb.getBeanDefinition();
|
||||||
assertFalse(rbd.hasBeanClass());
|
assertFalse(rbd.hasBeanClass());
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,18 +16,20 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory.support;
|
package org.springframework.beans.factory.support;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
|
||||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class BeanDefinitionTests extends TestCase {
|
public class BeanDefinitionTests {
|
||||||
|
|
||||||
public void testBeanDefinitionEquality() {
|
@Test
|
||||||
|
public void beanDefinitionEquality() {
|
||||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
|
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
|
||||||
bd.setAbstract(true);
|
bd.setAbstract(true);
|
||||||
bd.setLazyInit(true);
|
bd.setLazyInit(true);
|
||||||
|
@ -43,7 +45,8 @@ public class BeanDefinitionTests extends TestCase {
|
||||||
assertTrue(bd.hashCode() == otherBd.hashCode());
|
assertTrue(bd.hashCode() == otherBd.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBeanDefinitionEqualityWithPropertyValues() {
|
@Test
|
||||||
|
public void beanDefinitionEqualityWithPropertyValues() {
|
||||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
|
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
|
||||||
bd.getPropertyValues().add("name", "myName");
|
bd.getPropertyValues().add("name", "myName");
|
||||||
bd.getPropertyValues().add("age", "99");
|
bd.getPropertyValues().add("age", "99");
|
||||||
|
@ -60,7 +63,8 @@ public class BeanDefinitionTests extends TestCase {
|
||||||
assertTrue(bd.hashCode() == otherBd.hashCode());
|
assertTrue(bd.hashCode() == otherBd.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBeanDefinitionEqualityWithConstructorArguments() {
|
@Test
|
||||||
|
public void beanDefinitionEqualityWithConstructorArguments() {
|
||||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
|
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
|
||||||
bd.getConstructorArgumentValues().addGenericArgumentValue("test");
|
bd.getConstructorArgumentValues().addGenericArgumentValue("test");
|
||||||
bd.getConstructorArgumentValues().addIndexedArgumentValue(1, new Integer(5));
|
bd.getConstructorArgumentValues().addIndexedArgumentValue(1, new Integer(5));
|
||||||
|
@ -77,7 +81,8 @@ public class BeanDefinitionTests extends TestCase {
|
||||||
assertTrue(bd.hashCode() == otherBd.hashCode());
|
assertTrue(bd.hashCode() == otherBd.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBeanDefinitionEqualityWithTypedConstructorArguments() {
|
@Test
|
||||||
|
public void beanDefinitionEqualityWithTypedConstructorArguments() {
|
||||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
|
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
|
||||||
bd.getConstructorArgumentValues().addGenericArgumentValue("test", "int");
|
bd.getConstructorArgumentValues().addGenericArgumentValue("test", "int");
|
||||||
bd.getConstructorArgumentValues().addIndexedArgumentValue(1, new Integer(5), "long");
|
bd.getConstructorArgumentValues().addIndexedArgumentValue(1, new Integer(5), "long");
|
||||||
|
@ -95,7 +100,8 @@ public class BeanDefinitionTests extends TestCase {
|
||||||
assertTrue(bd.hashCode() == otherBd.hashCode());
|
assertTrue(bd.hashCode() == otherBd.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBeanDefinitionHolderEquality() {
|
@Test
|
||||||
|
public void beanDefinitionHolderEquality() {
|
||||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
|
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
|
||||||
bd.setAbstract(true);
|
bd.setAbstract(true);
|
||||||
bd.setLazyInit(true);
|
bd.setLazyInit(true);
|
||||||
|
@ -113,7 +119,8 @@ public class BeanDefinitionTests extends TestCase {
|
||||||
assertTrue(holder.hashCode() == otherHolder.hashCode());
|
assertTrue(holder.hashCode() == otherHolder.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBeanDefinitionMerging() {
|
@Test
|
||||||
|
public void beanDefinitionMerging() {
|
||||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
|
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
|
||||||
bd.getConstructorArgumentValues().addGenericArgumentValue("test");
|
bd.getConstructorArgumentValues().addGenericArgumentValue("test");
|
||||||
bd.getConstructorArgumentValues().addIndexedArgumentValue(1, new Integer(5));
|
bd.getConstructorArgumentValues().addIndexedArgumentValue(1, new Integer(5));
|
||||||
|
@ -124,7 +131,7 @@ public class BeanDefinitionTests extends TestCase {
|
||||||
childBd.setParentName("bd");
|
childBd.setParentName("bd");
|
||||||
|
|
||||||
RootBeanDefinition mergedBd = new RootBeanDefinition(bd);
|
RootBeanDefinition mergedBd = new RootBeanDefinition(bd);
|
||||||
mergedBd.overrideFrom((BeanDefinition) childBd);
|
mergedBd.overrideFrom(childBd);
|
||||||
assertEquals(2, mergedBd.getConstructorArgumentValues().getArgumentCount());
|
assertEquals(2, mergedBd.getConstructorArgumentValues().getArgumentCount());
|
||||||
assertEquals(2, mergedBd.getPropertyValues().size());
|
assertEquals(2, mergedBd.getPropertyValues().size());
|
||||||
assertEquals(bd, mergedBd);
|
assertEquals(bd, mergedBd);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,15 +18,20 @@ package org.springframework.beans.factory.support;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class ManagedListTests extends TestCase {
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
public class ManagedListTests {
|
||||||
|
|
||||||
public void testMergeSunnyDay() {
|
@Test
|
||||||
|
public void mergeSunnyDay() {
|
||||||
ManagedList parent = new ManagedList();
|
ManagedList parent = new ManagedList();
|
||||||
parent.add("one");
|
parent.add("one");
|
||||||
parent.add("two");
|
parent.add("two");
|
||||||
|
@ -37,36 +42,30 @@ public class ManagedListTests extends TestCase {
|
||||||
assertEquals("merge() obviously did not work.", 3, mergedList.size());
|
assertEquals("merge() obviously did not work.", 3, mergedList.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeWithNullParent() {
|
@Test
|
||||||
|
public void mergeWithNullParent() {
|
||||||
ManagedList child = new ManagedList();
|
ManagedList child = new ManagedList();
|
||||||
child.add("one");
|
child.add("one");
|
||||||
child.setMergeEnabled(true);
|
child.setMergeEnabled(true);
|
||||||
assertSame(child, child.merge(null));
|
assertSame(child, child.merge(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeNotAllowedWhenMergeNotEnabled() {
|
@Test(expected = IllegalStateException.class)
|
||||||
|
public void mergeNotAllowedWhenMergeNotEnabled() {
|
||||||
ManagedList child = new ManagedList();
|
ManagedList child = new ManagedList();
|
||||||
try {
|
child.merge(null);
|
||||||
child.merge(null);
|
|
||||||
fail("Must have failed by this point (cannot merge() when the mergeEnabled property is false.");
|
|
||||||
}
|
|
||||||
catch (IllegalStateException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeWithNonCompatibleParentType() {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void mergeWithNonCompatibleParentType() {
|
||||||
ManagedList child = new ManagedList();
|
ManagedList child = new ManagedList();
|
||||||
child.add("one");
|
child.add("one");
|
||||||
child.setMergeEnabled(true);
|
child.setMergeEnabled(true);
|
||||||
try {
|
child.merge("hello");
|
||||||
child.merge("hello");
|
|
||||||
fail("Must have failed by this point.");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeEmptyChild() {
|
@Test
|
||||||
|
public void mergeEmptyChild() {
|
||||||
ManagedList parent = new ManagedList();
|
ManagedList parent = new ManagedList();
|
||||||
parent.add("one");
|
parent.add("one");
|
||||||
parent.add("two");
|
parent.add("two");
|
||||||
|
@ -76,8 +75,9 @@ public class ManagedListTests extends TestCase {
|
||||||
assertEquals("merge() obviously did not work.", 2, mergedList.size());
|
assertEquals("merge() obviously did not work.", 2, mergedList.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeChildValuesOverrideTheParents() {
|
@Test
|
||||||
// doesn't make a whole lotta sense in the context of a list...
|
public void mergeChildValuesOverrideTheParents() {
|
||||||
|
// doesn't make much sense in the context of a list...
|
||||||
ManagedList parent = new ManagedList();
|
ManagedList parent = new ManagedList();
|
||||||
parent.add("one");
|
parent.add("one");
|
||||||
parent.add("two");
|
parent.add("two");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2007 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,15 +18,20 @@ package org.springframework.beans.factory.support;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class ManagedMapTests extends TestCase {
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
public class ManagedMapTests {
|
||||||
|
|
||||||
public void testMergeSunnyDay() {
|
@Test
|
||||||
|
public void mergeSunnyDay() {
|
||||||
ManagedMap parent = new ManagedMap();
|
ManagedMap parent = new ManagedMap();
|
||||||
parent.put("one", "one");
|
parent.put("one", "one");
|
||||||
parent.put("two", "two");
|
parent.put("two", "two");
|
||||||
|
@ -37,34 +42,27 @@ public class ManagedMapTests extends TestCase {
|
||||||
assertEquals("merge() obviously did not work.", 3, mergedMap.size());
|
assertEquals("merge() obviously did not work.", 3, mergedMap.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeWithNullParent() {
|
@Test
|
||||||
|
public void mergeWithNullParent() {
|
||||||
ManagedMap child = new ManagedMap();
|
ManagedMap child = new ManagedMap();
|
||||||
child.setMergeEnabled(true);
|
child.setMergeEnabled(true);
|
||||||
assertSame(child, child.merge(null));
|
assertSame(child, child.merge(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeWithNonCompatibleParentType() {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void mergeWithNonCompatibleParentType() {
|
||||||
ManagedMap map = new ManagedMap();
|
ManagedMap map = new ManagedMap();
|
||||||
map.setMergeEnabled(true);
|
map.setMergeEnabled(true);
|
||||||
try {
|
map.merge("hello");
|
||||||
map.merge("hello");
|
|
||||||
fail("Must have failed by this point.");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeNotAllowedWhenMergeNotEnabled() {
|
@Test(expected = IllegalStateException.class)
|
||||||
ManagedMap map = new ManagedMap();
|
public void mergeNotAllowedWhenMergeNotEnabled() {
|
||||||
try {
|
new ManagedMap().merge(null);
|
||||||
map.merge(null);
|
|
||||||
fail("Must have failed by this point (cannot merge() when the mergeEnabled property is false.");
|
|
||||||
}
|
|
||||||
catch (IllegalStateException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeEmptyChild() {
|
@Test
|
||||||
|
public void mergeEmptyChild() {
|
||||||
ManagedMap parent = new ManagedMap();
|
ManagedMap parent = new ManagedMap();
|
||||||
parent.put("one", "one");
|
parent.put("one", "one");
|
||||||
parent.put("two", "two");
|
parent.put("two", "two");
|
||||||
|
@ -74,7 +72,8 @@ public class ManagedMapTests extends TestCase {
|
||||||
assertEquals("merge() obviously did not work.", 2, mergedMap.size());
|
assertEquals("merge() obviously did not work.", 2, mergedMap.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeChildValuesOverrideTheParents() {
|
@Test
|
||||||
|
public void mergeChildValuesOverrideTheParents() {
|
||||||
ManagedMap parent = new ManagedMap();
|
ManagedMap parent = new ManagedMap();
|
||||||
parent.put("one", "one");
|
parent.put("one", "one");
|
||||||
parent.put("two", "two");
|
parent.put("two", "two");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2007 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,15 +18,20 @@ package org.springframework.beans.factory.support;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class ManagedPropertiesTests extends TestCase {
|
@SuppressWarnings("rawtypes")
|
||||||
|
public class ManagedPropertiesTests {
|
||||||
|
|
||||||
public void testMergeSunnyDay() {
|
@Test
|
||||||
|
public void mergeSunnyDay() {
|
||||||
ManagedProperties parent = new ManagedProperties();
|
ManagedProperties parent = new ManagedProperties();
|
||||||
parent.setProperty("one", "one");
|
parent.setProperty("one", "one");
|
||||||
parent.setProperty("two", "two");
|
parent.setProperty("two", "two");
|
||||||
|
@ -37,34 +42,28 @@ public class ManagedPropertiesTests extends TestCase {
|
||||||
assertEquals("merge() obviously did not work.", 3, mergedMap.size());
|
assertEquals("merge() obviously did not work.", 3, mergedMap.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeWithNullParent() {
|
@Test
|
||||||
|
public void mergeWithNullParent() {
|
||||||
ManagedProperties child = new ManagedProperties();
|
ManagedProperties child = new ManagedProperties();
|
||||||
child.setMergeEnabled(true);
|
child.setMergeEnabled(true);
|
||||||
assertSame(child, child.merge(null));
|
assertSame(child, child.merge(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeWithNonCompatibleParentType() {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void mergeWithNonCompatibleParentType() {
|
||||||
ManagedProperties map = new ManagedProperties();
|
ManagedProperties map = new ManagedProperties();
|
||||||
map.setMergeEnabled(true);
|
map.setMergeEnabled(true);
|
||||||
try {
|
map.merge("hello");
|
||||||
map.merge("hello");
|
|
||||||
fail("Must have failed by this point.");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeNotAllowedWhenMergeNotEnabled() {
|
@Test(expected = IllegalStateException.class)
|
||||||
|
public void mergeNotAllowedWhenMergeNotEnabled() {
|
||||||
ManagedProperties map = new ManagedProperties();
|
ManagedProperties map = new ManagedProperties();
|
||||||
try {
|
map.merge(null);
|
||||||
map.merge(null);
|
|
||||||
fail("Must have failed by this point (cannot merge() when the mergeEnabled property is false.");
|
|
||||||
}
|
|
||||||
catch (IllegalStateException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeEmptyChild() {
|
@Test
|
||||||
|
public void mergeEmptyChild() {
|
||||||
ManagedProperties parent = new ManagedProperties();
|
ManagedProperties parent = new ManagedProperties();
|
||||||
parent.setProperty("one", "one");
|
parent.setProperty("one", "one");
|
||||||
parent.setProperty("two", "two");
|
parent.setProperty("two", "two");
|
||||||
|
@ -74,7 +73,8 @@ public class ManagedPropertiesTests extends TestCase {
|
||||||
assertEquals("merge() obviously did not work.", 2, mergedMap.size());
|
assertEquals("merge() obviously did not work.", 2, mergedMap.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeChildValuesOverrideTheParents() {
|
@Test
|
||||||
|
public void mergeChildValuesOverrideTheParents() {
|
||||||
ManagedProperties parent = new ManagedProperties();
|
ManagedProperties parent = new ManagedProperties();
|
||||||
parent.setProperty("one", "one");
|
parent.setProperty("one", "one");
|
||||||
parent.setProperty("two", "two");
|
parent.setProperty("two", "two");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,15 +18,20 @@ package org.springframework.beans.factory.support;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class ManagedSetTests extends TestCase {
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
public class ManagedSetTests {
|
||||||
|
|
||||||
public void testMergeSunnyDay() {
|
@Test
|
||||||
|
public void mergeSunnyDay() {
|
||||||
ManagedSet parent = new ManagedSet();
|
ManagedSet parent = new ManagedSet();
|
||||||
parent.add("one");
|
parent.add("one");
|
||||||
parent.add("two");
|
parent.add("two");
|
||||||
|
@ -37,36 +42,29 @@ public class ManagedSetTests extends TestCase {
|
||||||
assertEquals("merge() obviously did not work.", 3, mergedSet.size());
|
assertEquals("merge() obviously did not work.", 3, mergedSet.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeWithNullParent() {
|
@Test
|
||||||
|
public void mergeWithNullParent() {
|
||||||
ManagedSet child = new ManagedSet();
|
ManagedSet child = new ManagedSet();
|
||||||
child.add("one");
|
child.add("one");
|
||||||
child.setMergeEnabled(true);
|
child.setMergeEnabled(true);
|
||||||
assertSame(child, child.merge(null));
|
assertSame(child, child.merge(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeNotAllowedWhenMergeNotEnabled() {
|
@Test(expected = IllegalStateException.class)
|
||||||
ManagedSet child = new ManagedSet();
|
public void mergeNotAllowedWhenMergeNotEnabled() {
|
||||||
try {
|
new ManagedSet().merge(null);
|
||||||
child.merge(null);
|
|
||||||
fail("Must have failed by this point (cannot merge() when the mergeEnabled property is false.");
|
|
||||||
}
|
|
||||||
catch (IllegalStateException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeWithNonCompatibleParentType() {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void mergeWithNonCompatibleParentType() {
|
||||||
ManagedSet child = new ManagedSet();
|
ManagedSet child = new ManagedSet();
|
||||||
child.add("one");
|
child.add("one");
|
||||||
child.setMergeEnabled(true);
|
child.setMergeEnabled(true);
|
||||||
try {
|
child.merge("hello");
|
||||||
child.merge("hello");
|
|
||||||
fail("Must have failed by this point.");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeEmptyChild() {
|
@Test
|
||||||
|
public void mergeEmptyChild() {
|
||||||
ManagedSet parent = new ManagedSet();
|
ManagedSet parent = new ManagedSet();
|
||||||
parent.add("one");
|
parent.add("one");
|
||||||
parent.add("two");
|
parent.add("two");
|
||||||
|
@ -76,7 +74,8 @@ public class ManagedSetTests extends TestCase {
|
||||||
assertEquals("merge() obviously did not work.", 2, mergedSet.size());
|
assertEquals("merge() obviously did not work.", 2, mergedSet.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeChildValuesOverrideTheParents() {
|
@Test
|
||||||
|
public void mergeChildValuesOverrideTheParents() {
|
||||||
// asserts that the set contract is not violated during a merge() operation...
|
// asserts that the set contract is not violated during a merge() operation...
|
||||||
ManagedSet parent = new ManagedSet();
|
ManagedSet parent = new ManagedSet();
|
||||||
parent.add("one");
|
parent.add("one");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,43 +16,45 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory.support;
|
package org.springframework.beans.factory.support;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
*/
|
*/
|
||||||
public class PropertiesBeanDefinitionReaderTests extends TestCase {
|
public class PropertiesBeanDefinitionReaderTests {
|
||||||
|
|
||||||
private DefaultListableBeanFactory beanFactory;
|
private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||||
|
|
||||||
private PropertiesBeanDefinitionReader reader;
|
private final PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(
|
||||||
|
beanFactory);
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
this.beanFactory = new DefaultListableBeanFactory();
|
|
||||||
this.reader = new PropertiesBeanDefinitionReader(beanFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testWithSimpleConstructorArg() {
|
@Test
|
||||||
|
public void withSimpleConstructorArg() {
|
||||||
this.reader.loadBeanDefinitions(new ClassPathResource("simpleConstructorArg.properties", getClass()));
|
this.reader.loadBeanDefinitions(new ClassPathResource("simpleConstructorArg.properties", getClass()));
|
||||||
TestBean bean = (TestBean)this.beanFactory.getBean("testBean");
|
TestBean bean = (TestBean)this.beanFactory.getBean("testBean");
|
||||||
assertEquals("Rob Harrop", bean.getName());
|
assertEquals("Rob Harrop", bean.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithConstructorArgRef() throws Exception {
|
@Test
|
||||||
|
public void withConstructorArgRef() throws Exception {
|
||||||
this.reader.loadBeanDefinitions(new ClassPathResource("refConstructorArg.properties", getClass()));
|
this.reader.loadBeanDefinitions(new ClassPathResource("refConstructorArg.properties", getClass()));
|
||||||
TestBean rob = (TestBean)this.beanFactory.getBean("rob");
|
TestBean rob = (TestBean)this.beanFactory.getBean("rob");
|
||||||
TestBean sally = (TestBean)this.beanFactory.getBean("sally");
|
TestBean sally = (TestBean)this.beanFactory.getBean("sally");
|
||||||
assertEquals(sally, rob.getSpouse());
|
assertEquals(sally, rob.getSpouse());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithMultipleConstructorsArgs() throws Exception {
|
@Test
|
||||||
|
public void withMultipleConstructorsArgs() throws Exception {
|
||||||
this.reader.loadBeanDefinitions(new ClassPathResource("multiConstructorArgs.properties", getClass()));
|
this.reader.loadBeanDefinitions(new ClassPathResource("multiConstructorArgs.properties", getClass()));
|
||||||
TestBean bean = (TestBean)this.beanFactory.getBean("testBean");
|
TestBean bean = (TestBean)this.beanFactory.getBean("testBean");
|
||||||
assertEquals("Rob Harrop", bean.getName());
|
assertEquals("Rob Harrop", bean.getName());
|
||||||
assertEquals(23, bean.getAge());
|
assertEquals(23, bean.getAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,31 +16,30 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory.wiring;
|
package org.springframework.beans.factory.wiring;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.BDDMockito.*;
|
import static org.mockito.BDDMockito.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class BeanConfigurerSupportTests extends TestCase {
|
public class BeanConfigurerSupportTests {
|
||||||
|
|
||||||
public void testSupplyIncompatibleBeanFactoryImplementation() throws Exception {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
try {
|
public void supplyIncompatibleBeanFactoryImplementation() throws Exception {
|
||||||
new StubBeanConfigurerSupport().setBeanFactory(mock(BeanFactory.class));
|
new StubBeanConfigurerSupport().setBeanFactory(mock(BeanFactory.class));
|
||||||
fail("Must have thrown an IllegalArgumentException by this point (incompatible BeanFactory implementation supplied)");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConfigureBeanDoesNothingIfBeanWiringInfoResolverResolvesToNull() throws Exception {
|
@Test
|
||||||
|
public void configureBeanDoesNothingIfBeanWiringInfoResolverResolvesToNull() throws Exception {
|
||||||
TestBean beanInstance = new TestBean();
|
TestBean beanInstance = new TestBean();
|
||||||
|
|
||||||
BeanWiringInfoResolver resolver = mock(BeanWiringInfoResolver.class);
|
BeanWiringInfoResolver resolver = mock(BeanWiringInfoResolver.class);
|
||||||
|
@ -53,14 +52,16 @@ public class BeanConfigurerSupportTests extends TestCase {
|
||||||
assertNull(beanInstance.getName());
|
assertNull(beanInstance.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConfigureBeanDoesNothingIfNoBeanFactoryHasBeenSet() throws Exception {
|
@Test
|
||||||
|
public void configureBeanDoesNothingIfNoBeanFactoryHasBeenSet() throws Exception {
|
||||||
TestBean beanInstance = new TestBean();
|
TestBean beanInstance = new TestBean();
|
||||||
BeanConfigurerSupport configurer = new StubBeanConfigurerSupport();
|
BeanConfigurerSupport configurer = new StubBeanConfigurerSupport();
|
||||||
configurer.configureBean(beanInstance);
|
configurer.configureBean(beanInstance);
|
||||||
assertNull(beanInstance.getName());
|
assertNull(beanInstance.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConfigureBeanReallyDoesDefaultToUsingTheFullyQualifiedClassNameOfTheSuppliedBeanInstance() throws Exception {
|
@Test
|
||||||
|
public void configureBeanReallyDoesDefaultToUsingTheFullyQualifiedClassNameOfTheSuppliedBeanInstance() throws Exception {
|
||||||
TestBean beanInstance = new TestBean();
|
TestBean beanInstance = new TestBean();
|
||||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class);
|
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class);
|
||||||
builder.addPropertyValue("name", "Harriet Wheeler");
|
builder.addPropertyValue("name", "Harriet Wheeler");
|
||||||
|
@ -75,7 +76,8 @@ public class BeanConfigurerSupportTests extends TestCase {
|
||||||
assertEquals("Bean is evidently not being configured (for some reason)", "Harriet Wheeler", beanInstance.getName());
|
assertEquals("Bean is evidently not being configured (for some reason)", "Harriet Wheeler", beanInstance.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConfigureBeanPerformsAutowiringByNameIfAppropriateBeanWiringInfoResolverIsPluggedIn() throws Exception {
|
@Test
|
||||||
|
public void configureBeanPerformsAutowiringByNameIfAppropriateBeanWiringInfoResolverIsPluggedIn() throws Exception {
|
||||||
TestBean beanInstance = new TestBean();
|
TestBean beanInstance = new TestBean();
|
||||||
// spouse for autowiring by name...
|
// spouse for autowiring by name...
|
||||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class);
|
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class);
|
||||||
|
@ -94,7 +96,8 @@ public class BeanConfigurerSupportTests extends TestCase {
|
||||||
assertEquals("Bean is evidently not being configured (for some reason)", "David Gavurin", beanInstance.getSpouse().getName());
|
assertEquals("Bean is evidently not being configured (for some reason)", "David Gavurin", beanInstance.getSpouse().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConfigureBeanPerformsAutowiringByTypeIfAppropriateBeanWiringInfoResolverIsPluggedIn() throws Exception {
|
@Test
|
||||||
|
public void configureBeanPerformsAutowiringByTypeIfAppropriateBeanWiringInfoResolverIsPluggedIn() throws Exception {
|
||||||
TestBean beanInstance = new TestBean();
|
TestBean beanInstance = new TestBean();
|
||||||
// spouse for autowiring by type...
|
// spouse for autowiring by type...
|
||||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class);
|
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2006 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,76 +16,63 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory.wiring;
|
package org.springframework.beans.factory.wiring;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the BeanWiringInfo class.
|
* Unit tests for the BeanWiringInfo class.
|
||||||
*
|
*
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public final class BeanWiringInfoTests extends TestCase {
|
public final class BeanWiringInfoTests {
|
||||||
|
|
||||||
public void testCtorWithNullBeanName() throws Exception {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
try {
|
public void ctorWithNullBeanName() throws Exception {
|
||||||
new BeanWiringInfo(null);
|
new BeanWiringInfo(null);
|
||||||
fail("Must have thrown an IllegalArgumentException by this point (null argument).");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCtorWithWhitespacedBeanName() throws Exception {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
try {
|
public void ctorWithWhitespacedBeanName() throws Exception {
|
||||||
new BeanWiringInfo(" \t");
|
new BeanWiringInfo(" \t");
|
||||||
fail("Must have thrown an IllegalArgumentException by this point (bean name has only whitespace).");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCtorWithEmptyBeanName() throws Exception {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
try {
|
public void ctorWithEmptyBeanName() throws Exception {
|
||||||
new BeanWiringInfo("");
|
new BeanWiringInfo("");
|
||||||
fail("Must have thrown an IllegalArgumentException by this point (bean name is empty).");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCtorWithNegativeIllegalAutowiringValue() throws Exception {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
try {
|
public void ctorWithNegativeIllegalAutowiringValue() throws Exception {
|
||||||
new BeanWiringInfo(-1, true);
|
new BeanWiringInfo(-1, true);
|
||||||
fail("Must have thrown an IllegalArgumentException by this point (out-of-range argument).");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCtorWithPositiveOutOfRangeAutowiringValue() throws Exception {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
try {
|
public void ctorWithPositiveOutOfRangeAutowiringValue() throws Exception {
|
||||||
new BeanWiringInfo(123871, true);
|
new BeanWiringInfo(123871, true);
|
||||||
fail("Must have thrown an IllegalArgumentException by this point (out-of-range argument).");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUsingAutowireCtorIndicatesAutowiring() throws Exception {
|
@Test
|
||||||
|
public void usingAutowireCtorIndicatesAutowiring() throws Exception {
|
||||||
BeanWiringInfo info = new BeanWiringInfo(BeanWiringInfo.AUTOWIRE_BY_NAME, true);
|
BeanWiringInfo info = new BeanWiringInfo(BeanWiringInfo.AUTOWIRE_BY_NAME, true);
|
||||||
assertTrue(info.indicatesAutowiring());
|
assertTrue(info.indicatesAutowiring());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUsingBeanNameCtorDoesNotIndicateAutowiring() throws Exception {
|
@Test
|
||||||
|
public void usingBeanNameCtorDoesNotIndicateAutowiring() throws Exception {
|
||||||
BeanWiringInfo info = new BeanWiringInfo("fooService");
|
BeanWiringInfo info = new BeanWiringInfo("fooService");
|
||||||
assertFalse(info.indicatesAutowiring());
|
assertFalse(info.indicatesAutowiring());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoDependencyCheckValueIsPreserved() throws Exception {
|
@Test
|
||||||
|
public void noDependencyCheckValueIsPreserved() throws Exception {
|
||||||
BeanWiringInfo info = new BeanWiringInfo(BeanWiringInfo.AUTOWIRE_BY_NAME, true);
|
BeanWiringInfo info = new BeanWiringInfo(BeanWiringInfo.AUTOWIRE_BY_NAME, true);
|
||||||
assertTrue(info.getDependencyCheck());
|
assertTrue(info.getDependencyCheck());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDependencyCheckValueIsPreserved() throws Exception {
|
@Test
|
||||||
|
public void dependencyCheckValueIsPreserved() throws Exception {
|
||||||
BeanWiringInfo info = new BeanWiringInfo(BeanWiringInfo.AUTOWIRE_BY_TYPE, false);
|
BeanWiringInfo info = new BeanWiringInfo(BeanWiringInfo.AUTOWIRE_BY_TYPE, false);
|
||||||
assertFalse(info.getDependencyCheck());
|
assertFalse(info.getDependencyCheck());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2006 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,25 +16,24 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory.wiring;
|
package org.springframework.beans.factory.wiring;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the ClassNameBeanWiringInfoResolver class.
|
* Unit tests for the ClassNameBeanWiringInfoResolver class.
|
||||||
*
|
*
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
*/
|
*/
|
||||||
public final class ClassNameBeanWiringInfoResolverTests extends TestCase {
|
public final class ClassNameBeanWiringInfoResolverTests {
|
||||||
|
|
||||||
public void testResolveWiringInfoWithNullBeanInstance() throws Exception {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
try {
|
public void resolveWiringInfoWithNullBeanInstance() throws Exception {
|
||||||
new ClassNameBeanWiringInfoResolver().resolveWiringInfo(null);
|
new ClassNameBeanWiringInfoResolver().resolveWiringInfo(null);
|
||||||
fail("Must have thrown an IllegalArgumentException by this point (null argument).");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testResolveWiringInfo() {
|
@Test
|
||||||
|
public void resolveWiringInfo() {
|
||||||
ClassNameBeanWiringInfoResolver resolver = new ClassNameBeanWiringInfoResolver();
|
ClassNameBeanWiringInfoResolver resolver = new ClassNameBeanWiringInfoResolver();
|
||||||
Long beanInstance = new Long(1);
|
Long beanInstance = new Long(1);
|
||||||
BeanWiringInfo info = resolver.resolveWiringInfo(beanInstance);
|
BeanWiringInfo info = resolver.resolveWiringInfo(beanInstance);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -19,7 +19,7 @@ package org.springframework.beans.factory.xml;
|
||||||
import java.beans.PropertyEditorSupport;
|
import java.beans.PropertyEditorSupport;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.PropertyBatchUpdateException;
|
import org.springframework.beans.PropertyBatchUpdateException;
|
||||||
|
@ -34,21 +34,24 @@ import org.springframework.tests.sample.beans.MustBeInitialized;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
import org.springframework.tests.sample.beans.factory.DummyFactory;
|
import org.springframework.tests.sample.beans.factory.DummyFactory;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subclasses must implement setUp() to initialize bean factory
|
* Subclasses must initialize the bean factory and any other variables they need.
|
||||||
* and any other variables they need.
|
|
||||||
*
|
*
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractBeanFactoryTests extends TestCase {
|
public abstract class AbstractBeanFactoryTests {
|
||||||
|
|
||||||
protected abstract BeanFactory getBeanFactory();
|
protected abstract BeanFactory getBeanFactory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Roderick beans inherits from rod, overriding name only.
|
* Roderick bean inherits from rod, overriding name only.
|
||||||
*/
|
*/
|
||||||
public void testInheritance() {
|
@Test
|
||||||
|
public void inheritance() {
|
||||||
assertTrue(getBeanFactory().containsBean("rod"));
|
assertTrue(getBeanFactory().containsBean("rod"));
|
||||||
assertTrue(getBeanFactory().containsBean("roderick"));
|
assertTrue(getBeanFactory().containsBean("roderick"));
|
||||||
TestBean rod = (TestBean) getBeanFactory().getBean("rod");
|
TestBean rod = (TestBean) getBeanFactory().getBean("rod");
|
||||||
|
@ -60,20 +63,16 @@ public abstract class AbstractBeanFactoryTests extends TestCase {
|
||||||
assertTrue("roderick.age was inherited", roderick.getAge() == rod.getAge());
|
assertTrue("roderick.age was inherited", roderick.getAge() == rod.getAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetBeanWithNullArg() {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
try {
|
public void getBeanWithNullArg() {
|
||||||
getBeanFactory().getBean((String) null);
|
getBeanFactory().getBean((String) null);
|
||||||
fail("Can't get null bean");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ex) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that InitializingBean objects receive the afterPropertiesSet() callback
|
* Test that InitializingBean objects receive the afterPropertiesSet() callback
|
||||||
*/
|
*/
|
||||||
public void testInitializingBeanCallback() {
|
@Test
|
||||||
|
public void initializingBeanCallback() {
|
||||||
MustBeInitialized mbi = (MustBeInitialized) getBeanFactory().getBean("mustBeInitialized");
|
MustBeInitialized mbi = (MustBeInitialized) getBeanFactory().getBean("mustBeInitialized");
|
||||||
// The dummy business method will throw an exception if the
|
// The dummy business method will throw an exception if the
|
||||||
// afterPropertiesSet() callback wasn't invoked
|
// afterPropertiesSet() callback wasn't invoked
|
||||||
|
@ -84,7 +83,8 @@ public abstract class AbstractBeanFactoryTests extends TestCase {
|
||||||
* Test that InitializingBean/BeanFactoryAware/DisposableBean objects receive the
|
* Test that InitializingBean/BeanFactoryAware/DisposableBean objects receive the
|
||||||
* afterPropertiesSet() callback before BeanFactoryAware callbacks
|
* afterPropertiesSet() callback before BeanFactoryAware callbacks
|
||||||
*/
|
*/
|
||||||
public void testLifecycleCallbacks() {
|
@Test
|
||||||
|
public void lifecycleCallbacks() {
|
||||||
LifecycleBean lb = (LifecycleBean) getBeanFactory().getBean("lifecycle");
|
LifecycleBean lb = (LifecycleBean) getBeanFactory().getBean("lifecycle");
|
||||||
assertEquals("lifecycle", lb.getBeanName());
|
assertEquals("lifecycle", lb.getBeanName());
|
||||||
// The dummy business method will throw an exception if the
|
// The dummy business method will throw an exception if the
|
||||||
|
@ -93,32 +93,23 @@ public abstract class AbstractBeanFactoryTests extends TestCase {
|
||||||
assertTrue("Not destroyed", !lb.isDestroyed());
|
assertTrue("Not destroyed", !lb.isDestroyed());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFindsValidInstance() {
|
@Test
|
||||||
try {
|
public void findsValidInstance() {
|
||||||
Object o = getBeanFactory().getBean("rod");
|
Object o = getBeanFactory().getBean("rod");
|
||||||
assertTrue("Rod bean is a TestBean", o instanceof TestBean);
|
assertTrue("Rod bean is a TestBean", o instanceof TestBean);
|
||||||
TestBean rod = (TestBean) o;
|
TestBean rod = (TestBean) o;
|
||||||
assertTrue("rod.name is Rod", rod.getName().equals("Rod"));
|
assertTrue("rod.name is Rod", rod.getName().equals("Rod"));
|
||||||
assertTrue("rod.age is 31", rod.getAge() == 31);
|
assertTrue("rod.age is 31", rod.getAge() == 31);
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
fail("Shouldn't throw exception on getting valid instance");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetInstanceByMatchingClass() {
|
@Test
|
||||||
try {
|
public void getInstanceByMatchingClass() {
|
||||||
Object o = getBeanFactory().getBean("rod", TestBean.class);
|
Object o = getBeanFactory().getBean("rod", TestBean.class);
|
||||||
assertTrue("Rod bean is a TestBean", o instanceof TestBean);
|
assertTrue("Rod bean is a TestBean", o instanceof TestBean);
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
fail("Shouldn't throw exception on getting valid instance with matching class");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetInstanceByNonmatchingClass() {
|
@Test
|
||||||
|
public void getInstanceByNonmatchingClass() {
|
||||||
try {
|
try {
|
||||||
getBeanFactory().getBean("rod", BeanFactory.class);
|
getBeanFactory().getBean("rod", BeanFactory.class);
|
||||||
fail("Rod bean is not of type BeanFactory; getBeanInstance(rod, BeanFactory.class) should throw BeanNotOfRequiredTypeException");
|
fail("Rod bean is not of type BeanFactory; getBeanInstance(rod, BeanFactory.class) should throw BeanNotOfRequiredTypeException");
|
||||||
|
@ -130,29 +121,22 @@ public abstract class AbstractBeanFactoryTests extends TestCase {
|
||||||
assertTrue("Exception actualType as TestBean.class", TestBean.class.isAssignableFrom(ex.getActualType()));
|
assertTrue("Exception actualType as TestBean.class", TestBean.class.isAssignableFrom(ex.getActualType()));
|
||||||
assertTrue("Actual type is correct", ex.getActualType() == getBeanFactory().getBean("rod").getClass());
|
assertTrue("Actual type is correct", ex.getActualType() == getBeanFactory().getBean("rod").getClass());
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
fail("Shouldn't throw exception on getting valid instance");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetSharedInstanceByMatchingClass() {
|
@Test
|
||||||
try {
|
public void getSharedInstanceByMatchingClass() {
|
||||||
Object o = getBeanFactory().getBean("rod", TestBean.class);
|
|
||||||
assertTrue("Rod bean is a TestBean", o instanceof TestBean);
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
fail("Shouldn't throw exception on getting valid instance with matching class");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetSharedInstanceByMatchingClassNoCatch() {
|
|
||||||
Object o = getBeanFactory().getBean("rod", TestBean.class);
|
Object o = getBeanFactory().getBean("rod", TestBean.class);
|
||||||
assertTrue("Rod bean is a TestBean", o instanceof TestBean);
|
assertTrue("Rod bean is a TestBean", o instanceof TestBean);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetSharedInstanceByNonmatchingClass() {
|
@Test
|
||||||
|
public void getSharedInstanceByMatchingClassNoCatch() {
|
||||||
|
Object o = getBeanFactory().getBean("rod", TestBean.class);
|
||||||
|
assertTrue("Rod bean is a TestBean", o instanceof TestBean);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSharedInstanceByNonmatchingClass() {
|
||||||
try {
|
try {
|
||||||
getBeanFactory().getBean("rod", BeanFactory.class);
|
getBeanFactory().getBean("rod", BeanFactory.class);
|
||||||
fail("Rod bean is not of type BeanFactory; getBeanInstance(rod, BeanFactory.class) should throw BeanNotOfRequiredTypeException");
|
fail("Rod bean is not of type BeanFactory; getBeanInstance(rod, BeanFactory.class) should throw BeanNotOfRequiredTypeException");
|
||||||
|
@ -163,27 +147,19 @@ public abstract class AbstractBeanFactoryTests extends TestCase {
|
||||||
assertTrue("Exception requiredType must be BeanFactory.class", ex.getRequiredType().equals(BeanFactory.class));
|
assertTrue("Exception requiredType must be BeanFactory.class", ex.getRequiredType().equals(BeanFactory.class));
|
||||||
assertTrue("Exception actualType as TestBean.class", TestBean.class.isAssignableFrom(ex.getActualType()));
|
assertTrue("Exception actualType as TestBean.class", TestBean.class.isAssignableFrom(ex.getActualType()));
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
fail("Shouldn't throw exception on getting valid instance");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSharedInstancesAreEqual() {
|
@Test
|
||||||
try {
|
public void sharedInstancesAreEqual() {
|
||||||
Object o = getBeanFactory().getBean("rod");
|
Object o = getBeanFactory().getBean("rod");
|
||||||
assertTrue("Rod bean1 is a TestBean", o instanceof TestBean);
|
assertTrue("Rod bean1 is a TestBean", o instanceof TestBean);
|
||||||
Object o1 = getBeanFactory().getBean("rod");
|
Object o1 = getBeanFactory().getBean("rod");
|
||||||
assertTrue("Rod bean2 is a TestBean", o1 instanceof TestBean);
|
assertTrue("Rod bean2 is a TestBean", o1 instanceof TestBean);
|
||||||
assertTrue("Object equals applies", o == o1);
|
assertTrue("Object equals applies", o == o1);
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
fail("Shouldn't throw exception on getting valid instance");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPrototypeInstancesAreIndependent() {
|
@Test
|
||||||
|
public void prototypeInstancesAreIndependent() {
|
||||||
TestBean tb1 = (TestBean) getBeanFactory().getBean("kathy");
|
TestBean tb1 = (TestBean) getBeanFactory().getBean("kathy");
|
||||||
TestBean tb2 = (TestBean) getBeanFactory().getBean("kathy");
|
TestBean tb2 = (TestBean) getBeanFactory().getBean("kathy");
|
||||||
assertTrue("ref equal DOES NOT apply", tb1 != tb2);
|
assertTrue("ref equal DOES NOT apply", tb1 != tb2);
|
||||||
|
@ -195,29 +171,18 @@ public abstract class AbstractBeanFactoryTests extends TestCase {
|
||||||
assertTrue("object equal now false", !tb1.equals(tb2));
|
assertTrue("object equal now false", !tb1.equals(tb2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNotThere() {
|
@Test(expected = BeansException.class)
|
||||||
|
public void notThere() {
|
||||||
assertFalse(getBeanFactory().containsBean("Mr Squiggle"));
|
assertFalse(getBeanFactory().containsBean("Mr Squiggle"));
|
||||||
try {
|
getBeanFactory().getBean("Mr Squiggle");
|
||||||
getBeanFactory().getBean("Mr Squiggle");
|
|
||||||
fail("Can't find missing bean");
|
|
||||||
}
|
|
||||||
catch (BeansException ex) {
|
|
||||||
//ex.printStackTrace();
|
|
||||||
//fail("Shouldn't throw exception on getting valid instance");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testValidEmpty() {
|
@Test
|
||||||
try {
|
public void validEmpty() {
|
||||||
Object o = getBeanFactory().getBean("validEmpty");
|
Object o = getBeanFactory().getBean("validEmpty");
|
||||||
assertTrue("validEmpty bean is a TestBean", o instanceof TestBean);
|
assertTrue("validEmpty bean is a TestBean", o instanceof TestBean);
|
||||||
TestBean ve = (TestBean) o;
|
TestBean ve = (TestBean) o;
|
||||||
assertTrue("Valid empty has defaults", ve.getName() == null && ve.getAge() == 0 && ve.getSpouse() == null);
|
assertTrue("Valid empty has defaults", ve.getName() == null && ve.getAge() == 0 && ve.getSpouse() == null);
|
||||||
}
|
|
||||||
catch (BeansException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
fail("Shouldn't throw exception on valid empty");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void xtestTypeMismatch() {
|
public void xtestTypeMismatch() {
|
||||||
|
@ -236,12 +201,14 @@ public abstract class AbstractBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGrandparentDefinitionFoundInBeanFactory() throws Exception {
|
@Test
|
||||||
|
public void grandparentDefinitionFoundInBeanFactory() throws Exception {
|
||||||
TestBean dad = (TestBean) getBeanFactory().getBean("father");
|
TestBean dad = (TestBean) getBeanFactory().getBean("father");
|
||||||
assertTrue("Dad has correct name", dad.getName().equals("Albert"));
|
assertTrue("Dad has correct name", dad.getName().equals("Albert"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFactorySingleton() throws Exception {
|
@Test
|
||||||
|
public void factorySingleton() throws Exception {
|
||||||
assertTrue(getBeanFactory().isSingleton("&singletonFactory"));
|
assertTrue(getBeanFactory().isSingleton("&singletonFactory"));
|
||||||
assertTrue(getBeanFactory().isSingleton("singletonFactory"));
|
assertTrue(getBeanFactory().isSingleton("singletonFactory"));
|
||||||
TestBean tb = (TestBean) getBeanFactory().getBean("singletonFactory");
|
TestBean tb = (TestBean) getBeanFactory().getBean("singletonFactory");
|
||||||
|
@ -252,7 +219,8 @@ public abstract class AbstractBeanFactoryTests extends TestCase {
|
||||||
assertTrue("FactoryBean is BeanFactoryAware", factory.getBeanFactory() != null);
|
assertTrue("FactoryBean is BeanFactoryAware", factory.getBeanFactory() != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFactoryPrototype() throws Exception {
|
@Test
|
||||||
|
public void factoryPrototype() throws Exception {
|
||||||
assertTrue(getBeanFactory().isSingleton("&prototypeFactory"));
|
assertTrue(getBeanFactory().isSingleton("&prototypeFactory"));
|
||||||
assertFalse(getBeanFactory().isSingleton("prototypeFactory"));
|
assertFalse(getBeanFactory().isSingleton("prototypeFactory"));
|
||||||
TestBean tb = (TestBean) getBeanFactory().getBean("prototypeFactory");
|
TestBean tb = (TestBean) getBeanFactory().getBean("prototypeFactory");
|
||||||
|
@ -266,16 +234,17 @@ public abstract class AbstractBeanFactoryTests extends TestCase {
|
||||||
* This is only possible if we're dealing with a factory
|
* This is only possible if we're dealing with a factory
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void testGetFactoryItself() throws Exception {
|
@Test
|
||||||
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
|
public void getFactoryItself() throws Exception {
|
||||||
assertTrue(factory != null);
|
assertNotNull(getBeanFactory().getBean("&singletonFactory"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that afterPropertiesSet gets called on factory
|
* Check that afterPropertiesSet gets called on factory
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void testFactoryIsInitialized() throws Exception {
|
@Test
|
||||||
|
public void factoryIsInitialized() throws Exception {
|
||||||
TestBean tb = (TestBean) getBeanFactory().getBean("singletonFactory");
|
TestBean tb = (TestBean) getBeanFactory().getBean("singletonFactory");
|
||||||
assertNotNull(tb);
|
assertNotNull(tb);
|
||||||
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
|
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
|
||||||
|
@ -283,22 +252,17 @@ public abstract class AbstractBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It should be illegal to dereference a normal bean
|
* It should be illegal to dereference a normal bean as a factory.
|
||||||
* as a factory
|
|
||||||
*/
|
*/
|
||||||
public void testRejectsFactoryGetOnNormalBean() {
|
@Test(expected = BeanIsNotAFactoryException.class)
|
||||||
try {
|
public void rejectsFactoryGetOnNormalBean() {
|
||||||
getBeanFactory().getBean("&rod");
|
getBeanFactory().getBean("&rod");
|
||||||
fail("Shouldn't permit factory get on normal bean");
|
|
||||||
}
|
|
||||||
catch (BeanIsNotAFactoryException ex) {
|
|
||||||
// Ok
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: refactor in AbstractBeanFactory (tests for AbstractBeanFactory)
|
// TODO: refactor in AbstractBeanFactory (tests for AbstractBeanFactory)
|
||||||
// and rename this class
|
// and rename this class
|
||||||
public void testAliasing() {
|
@Test
|
||||||
|
public void aliasing() {
|
||||||
BeanFactory bf = getBeanFactory();
|
BeanFactory bf = getBeanFactory();
|
||||||
if (!(bf instanceof ConfigurableBeanFactory)) {
|
if (!(bf instanceof ConfigurableBeanFactory)) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,11 +16,15 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory.xml;
|
package org.springframework.beans.factory.xml;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.beans.factory.ListableBeanFactory;
|
import org.springframework.beans.factory.ListableBeanFactory;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
@ -39,7 +43,8 @@ public abstract class AbstractListableBeanFactoryTests extends AbstractBeanFacto
|
||||||
/**
|
/**
|
||||||
* Subclasses can override this.
|
* Subclasses can override this.
|
||||||
*/
|
*/
|
||||||
public void testCount() {
|
@Test
|
||||||
|
public void count() {
|
||||||
assertCount(13);
|
assertCount(13);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +53,7 @@ public abstract class AbstractListableBeanFactoryTests extends AbstractBeanFacto
|
||||||
assertTrue("We should have " + count + " beans, not " + defnames.length, defnames.length == count);
|
assertTrue("We should have " + count + " beans, not " + defnames.length, defnames.length == count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void assertTestBeanCount(int count) {
|
protected void assertTestBeanCount(int count) {
|
||||||
String[] defNames = getListableBeanFactory().getBeanNamesForType(TestBean.class, true, false);
|
String[] defNames = getListableBeanFactory().getBeanNamesForType(TestBean.class, true, false);
|
||||||
assertTrue("We should have " + count + " beans for class org.springframework.tests.sample.beans.TestBean, not " +
|
assertTrue("We should have " + count + " beans for class org.springframework.tests.sample.beans.TestBean, not " +
|
||||||
defNames.length, defNames.length == count);
|
defNames.length, defNames.length == count);
|
||||||
|
@ -60,7 +65,8 @@ public abstract class AbstractListableBeanFactoryTests extends AbstractBeanFacto
|
||||||
names.length == countIncludingFactoryBeans);
|
names.length == countIncludingFactoryBeans);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetDefinitionsForNoSuchClass() {
|
@Test
|
||||||
|
public void getDefinitionsForNoSuchClass() {
|
||||||
String[] defnames = getListableBeanFactory().getBeanNamesForType(String.class);
|
String[] defnames = getListableBeanFactory().getBeanNamesForType(String.class);
|
||||||
assertTrue("No string definitions", defnames.length == 0);
|
assertTrue("No string definitions", defnames.length == 0);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +75,8 @@ public abstract class AbstractListableBeanFactoryTests extends AbstractBeanFacto
|
||||||
* Check that count refers to factory class, not bean class. (We don't know
|
* Check that count refers to factory class, not bean class. (We don't know
|
||||||
* what type factories may return, and it may even change over time.)
|
* what type factories may return, and it may even change over time.)
|
||||||
*/
|
*/
|
||||||
public void testGetCountForFactoryClass() {
|
@Test
|
||||||
|
public void getCountForFactoryClass() {
|
||||||
assertTrue("Should have 2 factories, not " +
|
assertTrue("Should have 2 factories, not " +
|
||||||
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length,
|
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length,
|
||||||
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length == 2);
|
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length == 2);
|
||||||
|
@ -79,7 +86,8 @@ public abstract class AbstractListableBeanFactoryTests extends AbstractBeanFacto
|
||||||
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length == 2);
|
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testContainsBeanDefinition() {
|
@Test
|
||||||
|
public void containsBeanDefinition() {
|
||||||
assertTrue(getListableBeanFactory().containsBeanDefinition("rod"));
|
assertTrue(getListableBeanFactory().containsBeanDefinition("rod"));
|
||||||
assertTrue(getListableBeanFactory().containsBeanDefinition("roderick"));
|
assertTrue(getListableBeanFactory().containsBeanDefinition("roderick"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory.xml;
|
package org.springframework.beans.factory.xml;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.config.PropertiesFactoryBean;
|
import org.springframework.beans.factory.config.PropertiesFactoryBean;
|
||||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||||
|
@ -25,13 +25,16 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class AutowireWithExclusionTests extends TestCase {
|
public class AutowireWithExclusionTests {
|
||||||
|
|
||||||
public void testByTypeAutowireWithAutoSelfExclusion() throws Exception {
|
@Test
|
||||||
|
public void byTypeAutowireWithAutoSelfExclusion() throws Exception {
|
||||||
CountingFactory.reset();
|
CountingFactory.reset();
|
||||||
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-exclusion.xml");
|
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-exclusion.xml");
|
||||||
beanFactory.preInstantiateSingletons();
|
beanFactory.preInstantiateSingletons();
|
||||||
|
@ -41,7 +44,8 @@ public class AutowireWithExclusionTests extends TestCase {
|
||||||
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
|
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testByTypeAutowireWithExclusion() throws Exception {
|
@Test
|
||||||
|
public void byTypeAutowireWithExclusion() throws Exception {
|
||||||
CountingFactory.reset();
|
CountingFactory.reset();
|
||||||
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-exclusion.xml");
|
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-exclusion.xml");
|
||||||
beanFactory.preInstantiateSingletons();
|
beanFactory.preInstantiateSingletons();
|
||||||
|
@ -50,7 +54,8 @@ public class AutowireWithExclusionTests extends TestCase {
|
||||||
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
|
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testByTypeAutowireWithExclusionInParentFactory() throws Exception {
|
@Test
|
||||||
|
public void byTypeAutowireWithExclusionInParentFactory() throws Exception {
|
||||||
CountingFactory.reset();
|
CountingFactory.reset();
|
||||||
DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
|
DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
|
||||||
parent.preInstantiateSingletons();
|
parent.preInstantiateSingletons();
|
||||||
|
@ -64,7 +69,8 @@ public class AutowireWithExclusionTests extends TestCase {
|
||||||
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
|
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testByTypeAutowireWithPrimaryInParentFactory() throws Exception {
|
@Test
|
||||||
|
public void byTypeAutowireWithPrimaryInParentFactory() throws Exception {
|
||||||
CountingFactory.reset();
|
CountingFactory.reset();
|
||||||
DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
|
DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
|
||||||
parent.getBeanDefinition("props1").setPrimary(true);
|
parent.getBeanDefinition("props1").setPrimary(true);
|
||||||
|
@ -82,7 +88,8 @@ public class AutowireWithExclusionTests extends TestCase {
|
||||||
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
|
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testByTypeAutowireWithPrimaryOverridingParentFactory() throws Exception {
|
@Test
|
||||||
|
public void byTypeAutowireWithPrimaryOverridingParentFactory() throws Exception {
|
||||||
CountingFactory.reset();
|
CountingFactory.reset();
|
||||||
DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
|
DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
|
||||||
parent.preInstantiateSingletons();
|
parent.preInstantiateSingletons();
|
||||||
|
@ -100,7 +107,8 @@ public class AutowireWithExclusionTests extends TestCase {
|
||||||
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
|
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testByTypeAutowireWithPrimaryInParentAndChild() throws Exception {
|
@Test
|
||||||
|
public void byTypeAutowireWithPrimaryInParentAndChild() throws Exception {
|
||||||
CountingFactory.reset();
|
CountingFactory.reset();
|
||||||
DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
|
DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
|
||||||
parent.getBeanDefinition("props1").setPrimary(true);
|
parent.getBeanDefinition("props1").setPrimary(true);
|
||||||
|
@ -119,7 +127,8 @@ public class AutowireWithExclusionTests extends TestCase {
|
||||||
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
|
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testByTypeAutowireWithInclusion() throws Exception {
|
@Test
|
||||||
|
public void byTypeAutowireWithInclusion() throws Exception {
|
||||||
CountingFactory.reset();
|
CountingFactory.reset();
|
||||||
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-inclusion.xml");
|
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-inclusion.xml");
|
||||||
beanFactory.preInstantiateSingletons();
|
beanFactory.preInstantiateSingletons();
|
||||||
|
@ -128,7 +137,8 @@ public class AutowireWithExclusionTests extends TestCase {
|
||||||
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
|
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testByTypeAutowireWithSelectiveInclusion() throws Exception {
|
@Test
|
||||||
|
public void byTypeAutowireWithSelectiveInclusion() throws Exception {
|
||||||
CountingFactory.reset();
|
CountingFactory.reset();
|
||||||
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-selective-inclusion.xml");
|
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-selective-inclusion.xml");
|
||||||
beanFactory.preInstantiateSingletons();
|
beanFactory.preInstantiateSingletons();
|
||||||
|
@ -137,7 +147,8 @@ public class AutowireWithExclusionTests extends TestCase {
|
||||||
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
|
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConstructorAutowireWithAutoSelfExclusion() throws Exception {
|
@Test
|
||||||
|
public void constructorAutowireWithAutoSelfExclusion() throws Exception {
|
||||||
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-constructor-with-exclusion.xml");
|
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-constructor-with-exclusion.xml");
|
||||||
TestBean rob = (TestBean) beanFactory.getBean("rob");
|
TestBean rob = (TestBean) beanFactory.getBean("rob");
|
||||||
TestBean sally = (TestBean) beanFactory.getBean("sally");
|
TestBean sally = (TestBean) beanFactory.getBean("sally");
|
||||||
|
@ -149,7 +160,8 @@ public class AutowireWithExclusionTests extends TestCase {
|
||||||
assertNotSame(rob.getSpouse(), rob2.getSpouse());
|
assertNotSame(rob.getSpouse(), rob2.getSpouse());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConstructorAutowireWithExclusion() throws Exception {
|
@Test
|
||||||
|
public void constructorAutowireWithExclusion() throws Exception {
|
||||||
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-constructor-with-exclusion.xml");
|
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-constructor-with-exclusion.xml");
|
||||||
TestBean rob = (TestBean) beanFactory.getBean("rob");
|
TestBean rob = (TestBean) beanFactory.getBean("rob");
|
||||||
assertEquals("props1", rob.getSomeProperties().getProperty("name"));
|
assertEquals("props1", rob.getSomeProperties().getProperty("name"));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,21 +16,25 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory.xml;
|
package org.springframework.beans.factory.xml;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class BeanNameGenerationTests extends TestCase {
|
public class BeanNameGenerationTests {
|
||||||
|
|
||||||
private DefaultListableBeanFactory beanFactory;
|
private DefaultListableBeanFactory beanFactory;
|
||||||
|
|
||||||
@Override
|
|
||||||
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
this.beanFactory = new DefaultListableBeanFactory();
|
this.beanFactory = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
|
||||||
|
@ -38,7 +42,8 @@ public class BeanNameGenerationTests extends TestCase {
|
||||||
reader.loadBeanDefinitions(new ClassPathResource("beanNameGeneration.xml", getClass()));
|
reader.loadBeanDefinitions(new ClassPathResource("beanNameGeneration.xml", getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNaming() {
|
@Test
|
||||||
|
public void naming() {
|
||||||
String className = GeneratedNameBean.class.getName();
|
String className = GeneratedNameBean.class.getName();
|
||||||
|
|
||||||
String targetName = className + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR + "0";
|
String targetName = className + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR + "0";
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -22,31 +22,36 @@ import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionReader;
|
import org.springframework.beans.factory.support.BeanDefinitionReader;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit and integration tests for the collection merging support.
|
* Unit and integration tests for the collection merging support.
|
||||||
*
|
*
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
*/
|
*/
|
||||||
public class CollectionMergingTests extends TestCase {
|
@SuppressWarnings("rawtypes")
|
||||||
|
public class CollectionMergingTests {
|
||||||
|
|
||||||
private DefaultListableBeanFactory beanFactory;
|
private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
@Before
|
||||||
this.beanFactory = new DefaultListableBeanFactory();
|
public void setUp() throws Exception {
|
||||||
BeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
|
BeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
|
||||||
reader.loadBeanDefinitions(new ClassPathResource("collectionMerging.xml", getClass()));
|
reader.loadBeanDefinitions(new ClassPathResource("collectionMerging.xml", getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeList() throws Exception {
|
@Test
|
||||||
|
public void mergeList() throws Exception {
|
||||||
TestBean bean = (TestBean) this.beanFactory.getBean("childWithList");
|
TestBean bean = (TestBean) this.beanFactory.getBean("childWithList");
|
||||||
List list = bean.getSomeList();
|
List list = bean.getSomeList();
|
||||||
assertEquals("Incorrect size", 3, list.size());
|
assertEquals("Incorrect size", 3, list.size());
|
||||||
|
@ -55,7 +60,8 @@ public class CollectionMergingTests extends TestCase {
|
||||||
assertEquals(list.get(2), "Juergen Hoeller");
|
assertEquals(list.get(2), "Juergen Hoeller");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeListWithInnerBeanAsListElement() throws Exception {
|
@Test
|
||||||
|
public void mergeListWithInnerBeanAsListElement() throws Exception {
|
||||||
TestBean bean = (TestBean) this.beanFactory.getBean("childWithListOfRefs");
|
TestBean bean = (TestBean) this.beanFactory.getBean("childWithListOfRefs");
|
||||||
List list = bean.getSomeList();
|
List list = bean.getSomeList();
|
||||||
assertNotNull(list);
|
assertNotNull(list);
|
||||||
|
@ -64,7 +70,8 @@ public class CollectionMergingTests extends TestCase {
|
||||||
assertTrue(list.get(2) instanceof TestBean);
|
assertTrue(list.get(2) instanceof TestBean);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeSet() {
|
@Test
|
||||||
|
public void mergeSet() {
|
||||||
TestBean bean = (TestBean) this.beanFactory.getBean("childWithSet");
|
TestBean bean = (TestBean) this.beanFactory.getBean("childWithSet");
|
||||||
Set set = bean.getSomeSet();
|
Set set = bean.getSomeSet();
|
||||||
assertEquals("Incorrect size", 2, set.size());
|
assertEquals("Incorrect size", 2, set.size());
|
||||||
|
@ -72,7 +79,8 @@ public class CollectionMergingTests extends TestCase {
|
||||||
assertTrue(set.contains("Sally Greenwood"));
|
assertTrue(set.contains("Sally Greenwood"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeSetWithInnerBeanAsSetElement() throws Exception {
|
@Test
|
||||||
|
public void mergeSetWithInnerBeanAsSetElement() throws Exception {
|
||||||
TestBean bean = (TestBean) this.beanFactory.getBean("childWithSetOfRefs");
|
TestBean bean = (TestBean) this.beanFactory.getBean("childWithSetOfRefs");
|
||||||
Set set = bean.getSomeSet();
|
Set set = bean.getSomeSet();
|
||||||
assertNotNull(set);
|
assertNotNull(set);
|
||||||
|
@ -85,7 +93,8 @@ public class CollectionMergingTests extends TestCase {
|
||||||
assertEquals("Sally", ((TestBean) o).getName());
|
assertEquals("Sally", ((TestBean) o).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeMap() throws Exception {
|
@Test
|
||||||
|
public void mergeMap() throws Exception {
|
||||||
TestBean bean = (TestBean) this.beanFactory.getBean("childWithMap");
|
TestBean bean = (TestBean) this.beanFactory.getBean("childWithMap");
|
||||||
Map map = bean.getSomeMap();
|
Map map = bean.getSomeMap();
|
||||||
assertEquals("Incorrect size", 3, map.size());
|
assertEquals("Incorrect size", 3, map.size());
|
||||||
|
@ -94,7 +103,8 @@ public class CollectionMergingTests extends TestCase {
|
||||||
assertEquals(map.get("Juergen"), "Eva");
|
assertEquals(map.get("Juergen"), "Eva");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeMapWithInnerBeanAsMapEntryValue() throws Exception {
|
@Test
|
||||||
|
public void mergeMapWithInnerBeanAsMapEntryValue() throws Exception {
|
||||||
TestBean bean = (TestBean) this.beanFactory.getBean("childWithMapOfRefs");
|
TestBean bean = (TestBean) this.beanFactory.getBean("childWithMapOfRefs");
|
||||||
Map map = bean.getSomeMap();
|
Map map = bean.getSomeMap();
|
||||||
assertNotNull(map);
|
assertNotNull(map);
|
||||||
|
@ -104,7 +114,8 @@ public class CollectionMergingTests extends TestCase {
|
||||||
assertEquals("Sally", ((TestBean) map.get("Rob")).getName());
|
assertEquals("Sally", ((TestBean) map.get("Rob")).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeProperties() throws Exception {
|
@Test
|
||||||
|
public void mergeProperties() throws Exception {
|
||||||
TestBean bean = (TestBean) this.beanFactory.getBean("childWithProps");
|
TestBean bean = (TestBean) this.beanFactory.getBean("childWithProps");
|
||||||
Properties props = bean.getSomeProperties();
|
Properties props = bean.getSomeProperties();
|
||||||
assertEquals("Incorrect size", 3, props.size());
|
assertEquals("Incorrect size", 3, props.size());
|
||||||
|
@ -113,8 +124,8 @@ public class CollectionMergingTests extends TestCase {
|
||||||
assertEquals(props.getProperty("Juergen"), "Eva");
|
assertEquals(props.getProperty("Juergen"), "Eva");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMergeListInConstructor() throws Exception {
|
public void mergeListInConstructor() throws Exception {
|
||||||
TestBean bean = (TestBean) this.beanFactory.getBean("childWithListInConstructor");
|
TestBean bean = (TestBean) this.beanFactory.getBean("childWithListInConstructor");
|
||||||
List list = bean.getSomeList();
|
List list = bean.getSomeList();
|
||||||
assertEquals("Incorrect size", 3, list.size());
|
assertEquals("Incorrect size", 3, list.size());
|
||||||
|
@ -123,7 +134,8 @@ public class CollectionMergingTests extends TestCase {
|
||||||
assertEquals(list.get(2), "Juergen Hoeller");
|
assertEquals(list.get(2), "Juergen Hoeller");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeListWithInnerBeanAsListElementInConstructor() throws Exception {
|
@Test
|
||||||
|
public void mergeListWithInnerBeanAsListElementInConstructor() throws Exception {
|
||||||
TestBean bean = (TestBean) this.beanFactory.getBean("childWithListOfRefsInConstructor");
|
TestBean bean = (TestBean) this.beanFactory.getBean("childWithListOfRefsInConstructor");
|
||||||
List list = bean.getSomeList();
|
List list = bean.getSomeList();
|
||||||
assertNotNull(list);
|
assertNotNull(list);
|
||||||
|
@ -132,7 +144,8 @@ public class CollectionMergingTests extends TestCase {
|
||||||
assertTrue(list.get(2) instanceof TestBean);
|
assertTrue(list.get(2) instanceof TestBean);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeSetInConstructor() {
|
@Test
|
||||||
|
public void mergeSetInConstructor() {
|
||||||
TestBean bean = (TestBean) this.beanFactory.getBean("childWithSetInConstructor");
|
TestBean bean = (TestBean) this.beanFactory.getBean("childWithSetInConstructor");
|
||||||
Set set = bean.getSomeSet();
|
Set set = bean.getSomeSet();
|
||||||
assertEquals("Incorrect size", 2, set.size());
|
assertEquals("Incorrect size", 2, set.size());
|
||||||
|
@ -140,7 +153,8 @@ public class CollectionMergingTests extends TestCase {
|
||||||
assertTrue(set.contains("Sally Greenwood"));
|
assertTrue(set.contains("Sally Greenwood"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeSetWithInnerBeanAsSetElementInConstructor() throws Exception {
|
@Test
|
||||||
|
public void mergeSetWithInnerBeanAsSetElementInConstructor() throws Exception {
|
||||||
TestBean bean = (TestBean) this.beanFactory.getBean("childWithSetOfRefsInConstructor");
|
TestBean bean = (TestBean) this.beanFactory.getBean("childWithSetOfRefsInConstructor");
|
||||||
Set set = bean.getSomeSet();
|
Set set = bean.getSomeSet();
|
||||||
assertNotNull(set);
|
assertNotNull(set);
|
||||||
|
@ -153,7 +167,8 @@ public class CollectionMergingTests extends TestCase {
|
||||||
assertEquals("Sally", ((TestBean) o).getName());
|
assertEquals("Sally", ((TestBean) o).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeMapInConstructor() throws Exception {
|
@Test
|
||||||
|
public void mergeMapInConstructor() throws Exception {
|
||||||
TestBean bean = (TestBean) this.beanFactory.getBean("childWithMapInConstructor");
|
TestBean bean = (TestBean) this.beanFactory.getBean("childWithMapInConstructor");
|
||||||
Map map = bean.getSomeMap();
|
Map map = bean.getSomeMap();
|
||||||
assertEquals("Incorrect size", 3, map.size());
|
assertEquals("Incorrect size", 3, map.size());
|
||||||
|
@ -162,7 +177,8 @@ public class CollectionMergingTests extends TestCase {
|
||||||
assertEquals(map.get("Juergen"), "Eva");
|
assertEquals(map.get("Juergen"), "Eva");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergeMapWithInnerBeanAsMapEntryValueInConstructor() throws Exception {
|
@Test
|
||||||
|
public void mergeMapWithInnerBeanAsMapEntryValueInConstructor() throws Exception {
|
||||||
TestBean bean = (TestBean) this.beanFactory.getBean("childWithMapOfRefsInConstructor");
|
TestBean bean = (TestBean) this.beanFactory.getBean("childWithMapOfRefsInConstructor");
|
||||||
Map map = bean.getSomeMap();
|
Map map = bean.getSomeMap();
|
||||||
assertNotNull(map);
|
assertNotNull(map);
|
||||||
|
@ -172,7 +188,8 @@ public class CollectionMergingTests extends TestCase {
|
||||||
assertEquals("Sally", ((TestBean) map.get("Rob")).getName());
|
assertEquals("Sally", ((TestBean) map.get("Rob")).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMergePropertiesInConstructor() throws Exception {
|
@Test
|
||||||
|
public void mergePropertiesInConstructor() throws Exception {
|
||||||
TestBean bean = (TestBean) this.beanFactory.getBean("childWithPropsInConstructor");
|
TestBean bean = (TestBean) this.beanFactory.getBean("childWithPropsInConstructor");
|
||||||
Properties props = bean.getSomeProperties();
|
Properties props = bean.getSomeProperties();
|
||||||
assertEquals("Incorrect size", 3, props.size());
|
assertEquals("Incorrect size", 3, props.size());
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,26 +16,30 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory.xml;
|
package org.springframework.beans.factory.xml;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
*/
|
*/
|
||||||
public class DefaultLifecycleMethodsTests extends TestCase {
|
public class DefaultLifecycleMethodsTests {
|
||||||
|
|
||||||
private DefaultListableBeanFactory beanFactory;
|
private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
@Before
|
||||||
this.beanFactory = new DefaultListableBeanFactory();
|
public void setUp() throws Exception {
|
||||||
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(new ClassPathResource(
|
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(new ClassPathResource(
|
||||||
"defaultLifecycleMethods.xml", getClass()));
|
"defaultLifecycleMethods.xml", getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLifecycleMethodsInvoked() {
|
@Test
|
||||||
|
public void lifecycleMethodsInvoked() {
|
||||||
LifecycleAwareBean bean = (LifecycleAwareBean) this.beanFactory.getBean("lifecycleAware");
|
LifecycleAwareBean bean = (LifecycleAwareBean) this.beanFactory.getBean("lifecycleAware");
|
||||||
assertTrue("Bean not initialized", bean.isInitCalled());
|
assertTrue("Bean not initialized", bean.isInitCalled());
|
||||||
assertFalse("Bean destroyed too early", bean.isDestroyCalled());
|
assertFalse("Bean destroyed too early", bean.isDestroyCalled());
|
||||||
|
@ -43,28 +47,25 @@ public class DefaultLifecycleMethodsTests extends TestCase {
|
||||||
assertTrue("Bean not destroyed", bean.isDestroyCalled());
|
assertTrue("Bean not destroyed", bean.isDestroyCalled());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLifecycleMethodsDisabled() throws Exception {
|
@Test
|
||||||
|
public void lifecycleMethodsDisabled() throws Exception {
|
||||||
LifecycleAwareBean bean = (LifecycleAwareBean) this.beanFactory.getBean("lifecycleMethodsDisabled");
|
LifecycleAwareBean bean = (LifecycleAwareBean) this.beanFactory.getBean("lifecycleMethodsDisabled");
|
||||||
assertFalse("Bean init method called incorrectly", bean.isInitCalled());
|
assertFalse("Bean init method called incorrectly", bean.isInitCalled());
|
||||||
this.beanFactory.destroySingletons();
|
this.beanFactory.destroySingletons();
|
||||||
assertFalse("Bean destroy method called incorrectly", bean.isDestroyCalled());
|
assertFalse("Bean destroy method called incorrectly", bean.isDestroyCalled());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIgnoreDefaultLifecycleMethods() throws Exception {
|
@Test
|
||||||
try {
|
public void ignoreDefaultLifecycleMethods() throws Exception {
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(
|
||||||
new ClassPathResource("ignoreDefaultLifecycleMethods.xml", getClass()));
|
"ignoreDefaultLifecycleMethods.xml", getClass()));
|
||||||
bf.preInstantiateSingletons();
|
bf.preInstantiateSingletons();
|
||||||
bf.destroySingletons();
|
bf.destroySingletons();
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
fail("Should ignore non-existent default lifecycle methods");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOverrideDefaultLifecycleMethods() throws Exception {
|
@Test
|
||||||
|
public void overrideDefaultLifecycleMethods() throws Exception {
|
||||||
LifecycleAwareBean bean = (LifecycleAwareBean) this.beanFactory.getBean("overrideLifecycleMethods");
|
LifecycleAwareBean bean = (LifecycleAwareBean) this.beanFactory.getBean("overrideLifecycleMethods");
|
||||||
assertFalse("Default init method called incorrectly.", bean.isInitCalled());
|
assertFalse("Default init method called incorrectly.", bean.isInitCalled());
|
||||||
assertTrue("Custom init method not called.", bean.isCustomInitCalled());
|
assertTrue("Custom init method not called.", bean.isCustomInitCalled());
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,8 +18,8 @@ package org.springframework.beans.factory.xml;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Before;
|
||||||
import org.w3c.dom.Element;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.beans.factory.config.TypedStringValue;
|
import org.springframework.beans.factory.config.TypedStringValue;
|
||||||
|
@ -32,26 +32,33 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.tests.beans.CollectingReaderEventListener;
|
import org.springframework.tests.beans.CollectingReaderEventListener;
|
||||||
|
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class EventPublicationTests extends TestCase {
|
@SuppressWarnings("rawtypes")
|
||||||
|
public class EventPublicationTests {
|
||||||
|
|
||||||
private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||||
|
|
||||||
private final CollectingReaderEventListener eventListener = new CollectingReaderEventListener();
|
private final CollectingReaderEventListener eventListener = new CollectingReaderEventListener();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
|
||||||
reader.setEventListener(this.eventListener);
|
reader.setEventListener(this.eventListener);
|
||||||
reader.setSourceExtractor(new PassThroughSourceExtractor());
|
reader.setSourceExtractor(new PassThroughSourceExtractor());
|
||||||
reader.loadBeanDefinitions(new ClassPathResource("beanEvents.xml", getClass()));
|
reader.loadBeanDefinitions(new ClassPathResource("beanEvents.xml", getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDefaultsEventReceived() throws Exception {
|
@Test
|
||||||
|
public void defaultsEventReceived() throws Exception {
|
||||||
List defaultsList = this.eventListener.getDefaults();
|
List defaultsList = this.eventListener.getDefaults();
|
||||||
assertTrue(!defaultsList.isEmpty());
|
assertTrue(!defaultsList.isEmpty());
|
||||||
assertTrue(defaultsList.get(0) instanceof DocumentDefaultsDefinition);
|
assertTrue(defaultsList.get(0) instanceof DocumentDefaultsDefinition);
|
||||||
|
@ -65,7 +72,8 @@ public class EventPublicationTests extends TestCase {
|
||||||
assertTrue(defaults.getSource() instanceof Element);
|
assertTrue(defaults.getSource() instanceof Element);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBeanEventReceived() throws Exception {
|
@Test
|
||||||
|
public void beanEventReceived() throws Exception {
|
||||||
ComponentDefinition componentDefinition1 = this.eventListener.getComponentDefinition("testBean");
|
ComponentDefinition componentDefinition1 = this.eventListener.getComponentDefinition("testBean");
|
||||||
assertTrue(componentDefinition1 instanceof BeanComponentDefinition);
|
assertTrue(componentDefinition1 instanceof BeanComponentDefinition);
|
||||||
assertEquals(1, componentDefinition1.getBeanDefinitions().length);
|
assertEquals(1, componentDefinition1.getBeanDefinitions().length);
|
||||||
|
@ -94,7 +102,8 @@ public class EventPublicationTests extends TestCase {
|
||||||
assertTrue(componentDefinition2.getSource() instanceof Element);
|
assertTrue(componentDefinition2.getSource() instanceof Element);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAliasEventReceived() throws Exception {
|
@Test
|
||||||
|
public void aliasEventReceived() throws Exception {
|
||||||
List aliases = this.eventListener.getAliases("testBean");
|
List aliases = this.eventListener.getAliases("testBean");
|
||||||
assertEquals(2, aliases.size());
|
assertEquals(2, aliases.size());
|
||||||
AliasDefinition aliasDefinition1 = (AliasDefinition) aliases.get(0);
|
AliasDefinition aliasDefinition1 = (AliasDefinition) aliases.get(0);
|
||||||
|
@ -105,7 +114,8 @@ public class EventPublicationTests extends TestCase {
|
||||||
assertTrue(aliasDefinition2.getSource() instanceof Element);
|
assertTrue(aliasDefinition2.getSource() instanceof Element);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testImportEventReceived() throws Exception {
|
@Test
|
||||||
|
public void importEventReceived() throws Exception {
|
||||||
List imports = this.eventListener.getImports();
|
List imports = this.eventListener.getImports();
|
||||||
assertEquals(1, imports.size());
|
assertEquals(1, imports.size());
|
||||||
ImportDefinition importDefinition = (ImportDefinition) imports.get(0);
|
ImportDefinition importDefinition = (ImportDefinition) imports.get(0);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,39 +16,46 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory.xml;
|
package org.springframework.beans.factory.xml;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.PropertyValue;
|
import org.springframework.beans.PropertyValue;
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
*/
|
*/
|
||||||
public class MetadataAttachmentTests extends TestCase {
|
public class MetadataAttachmentTests {
|
||||||
|
|
||||||
private DefaultListableBeanFactory beanFactory;
|
private DefaultListableBeanFactory beanFactory;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
this.beanFactory = new DefaultListableBeanFactory();
|
this.beanFactory = new DefaultListableBeanFactory();
|
||||||
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
|
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
|
||||||
new ClassPathResource("withMeta.xml", getClass()));
|
new ClassPathResource("withMeta.xml", getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMetadataAttachment() throws Exception {
|
@Test
|
||||||
|
public void metadataAttachment() throws Exception {
|
||||||
BeanDefinition beanDefinition1 = this.beanFactory.getMergedBeanDefinition("testBean1");
|
BeanDefinition beanDefinition1 = this.beanFactory.getMergedBeanDefinition("testBean1");
|
||||||
assertEquals("bar", beanDefinition1.getAttribute("foo"));
|
assertEquals("bar", beanDefinition1.getAttribute("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMetadataIsInherited() throws Exception {
|
@Test
|
||||||
|
public void metadataIsInherited() throws Exception {
|
||||||
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("testBean2");
|
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("testBean2");
|
||||||
assertEquals("Metadata not inherited", "bar", beanDefinition.getAttribute("foo"));
|
assertEquals("Metadata not inherited", "bar", beanDefinition.getAttribute("foo"));
|
||||||
assertEquals("Child metdata not attached", "123", beanDefinition.getAttribute("abc"));
|
assertEquals("Child metdata not attached", "123", beanDefinition.getAttribute("abc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPropertyMetadata() throws Exception {
|
@Test
|
||||||
|
public void propertyMetadata() throws Exception {
|
||||||
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("testBean3");
|
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("testBean3");
|
||||||
PropertyValue pv = beanDefinition.getPropertyValues().getPropertyValue("name");
|
PropertyValue pv = beanDefinition.getPropertyValues().getPropertyValue("name");
|
||||||
assertEquals("Harrop", pv.getAttribute("surname"));
|
assertEquals("Harrop", pv.getAttribute("surname"));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,20 +16,24 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory.xml;
|
package org.springframework.beans.factory.xml;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
import org.xml.sax.SAXParseException;
|
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
|
|
||||||
|
import org.xml.sax.SAXParseException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
*/
|
*/
|
||||||
public class SchemaValidationTests extends TestCase {
|
public class SchemaValidationTests {
|
||||||
|
|
||||||
public void testWithAutodetection() throws Exception {
|
@Test
|
||||||
|
public void withAutodetection() throws Exception {
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
|
||||||
try {
|
try {
|
||||||
|
@ -41,7 +45,8 @@ public class SchemaValidationTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithExplicitValidationMode() throws Exception {
|
@Test
|
||||||
|
public void withExplicitValidationMode() throws Exception {
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
|
||||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
|
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
|
||||||
|
@ -54,7 +59,8 @@ public class SchemaValidationTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLoadDefinitions() throws Exception {
|
@Test
|
||||||
|
public void loadDefinitions() throws Exception {
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
|
||||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
|
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,8 +18,7 @@ package org.springframework.beans.factory.xml;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||||
|
@ -31,49 +30,45 @@ import org.springframework.core.io.Resource;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class XmlBeanDefinitionReaderTests extends TestCase {
|
public class XmlBeanDefinitionReaderTests {
|
||||||
|
|
||||||
public void testSetParserClassSunnyDay() {
|
@Test
|
||||||
|
public void setParserClassSunnyDay() {
|
||||||
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
||||||
new XmlBeanDefinitionReader(registry).setDocumentReaderClass(DefaultBeanDefinitionDocumentReader.class);
|
new XmlBeanDefinitionReader(registry).setDocumentReaderClass(DefaultBeanDefinitionDocumentReader.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetParserClassToNull() {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
try {
|
public void setParserClassToNull() {
|
||||||
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
||||||
new XmlBeanDefinitionReader(registry).setDocumentReaderClass(null);
|
new XmlBeanDefinitionReader(registry).setDocumentReaderClass(null);
|
||||||
fail("Should have thrown IllegalArgumentException (null parserClass)");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetParserClassToUnsupportedParserType() throws Exception {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
try {
|
public void setParserClassToUnsupportedParserType() throws Exception {
|
||||||
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
||||||
new XmlBeanDefinitionReader(registry).setDocumentReaderClass(String.class);
|
new XmlBeanDefinitionReader(registry).setDocumentReaderClass(String.class);
|
||||||
fail("Should have thrown IllegalArgumentException (unsupported parserClass)");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithOpenInputStream() {
|
@Test(expected = BeanDefinitionStoreException.class)
|
||||||
try {
|
public void withOpenInputStream() {
|
||||||
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
||||||
Resource resource = new InputStreamResource(getClass().getResourceAsStream("test.xml"));
|
Resource resource = new InputStreamResource(getClass().getResourceAsStream(
|
||||||
new XmlBeanDefinitionReader(registry).loadBeanDefinitions(resource);
|
"test.xml"));
|
||||||
fail("Should have thrown BeanDefinitionStoreException (can't determine validation mode)");
|
new XmlBeanDefinitionReader(registry).loadBeanDefinitions(resource);
|
||||||
}
|
|
||||||
catch (BeanDefinitionStoreException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithOpenInputStreamAndExplicitValidationMode() {
|
@Test
|
||||||
|
public void withOpenInputStreamAndExplicitValidationMode() {
|
||||||
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
||||||
Resource resource = new InputStreamResource(getClass().getResourceAsStream("test.xml"));
|
Resource resource = new InputStreamResource(getClass().getResourceAsStream("test.xml"));
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry);
|
||||||
|
@ -82,32 +77,31 @@ public class XmlBeanDefinitionReaderTests extends TestCase {
|
||||||
testBeanDefinitions(registry);
|
testBeanDefinitions(registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithImport() {
|
@Test
|
||||||
|
public void withImport() {
|
||||||
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
||||||
Resource resource = new ClassPathResource("import.xml", getClass());
|
Resource resource = new ClassPathResource("import.xml", getClass());
|
||||||
new XmlBeanDefinitionReader(registry).loadBeanDefinitions(resource);
|
new XmlBeanDefinitionReader(registry).loadBeanDefinitions(resource);
|
||||||
testBeanDefinitions(registry);
|
testBeanDefinitions(registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithWildcardImport() {
|
@Test
|
||||||
|
public void withWildcardImport() {
|
||||||
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
||||||
Resource resource = new ClassPathResource("importPattern.xml", getClass());
|
Resource resource = new ClassPathResource("importPattern.xml", getClass());
|
||||||
new XmlBeanDefinitionReader(registry).loadBeanDefinitions(resource);
|
new XmlBeanDefinitionReader(registry).loadBeanDefinitions(resource);
|
||||||
testBeanDefinitions(registry);
|
testBeanDefinitions(registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithInputSource() {
|
@Test(expected = BeanDefinitionStoreException.class)
|
||||||
try {
|
public void withInputSource() {
|
||||||
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
||||||
InputSource resource = new InputSource(getClass().getResourceAsStream("test.xml"));
|
InputSource resource = new InputSource(getClass().getResourceAsStream("test.xml"));
|
||||||
new XmlBeanDefinitionReader(registry).loadBeanDefinitions(resource);
|
new XmlBeanDefinitionReader(registry).loadBeanDefinitions(resource);
|
||||||
fail("Should have thrown BeanDefinitionStoreException (can't determine validation mode)");
|
|
||||||
}
|
|
||||||
catch (BeanDefinitionStoreException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithInputSourceAndExplicitValidationMode() {
|
@Test
|
||||||
|
public void withInputSourceAndExplicitValidationMode() {
|
||||||
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
||||||
InputSource resource = new InputSource(getClass().getResourceAsStream("test.xml"));
|
InputSource resource = new InputSource(getClass().getResourceAsStream("test.xml"));
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry);
|
||||||
|
@ -116,7 +110,8 @@ public class XmlBeanDefinitionReaderTests extends TestCase {
|
||||||
testBeanDefinitions(registry);
|
testBeanDefinitions(registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithFreshInputStream() {
|
@Test
|
||||||
|
public void withFreshInputStream() {
|
||||||
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
||||||
Resource resource = new ClassPathResource("test.xml", getClass());
|
Resource resource = new ClassPathResource("test.xml", getClass());
|
||||||
new XmlBeanDefinitionReader(registry).loadBeanDefinitions(resource);
|
new XmlBeanDefinitionReader(registry).loadBeanDefinitions(resource);
|
||||||
|
@ -139,11 +134,13 @@ public class XmlBeanDefinitionReaderTests extends TestCase {
|
||||||
assertTrue(ObjectUtils.containsElement(aliases, "youralias"));
|
assertTrue(ObjectUtils.containsElement(aliases, "youralias"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDtdValidationAutodetect() throws Exception {
|
@Test
|
||||||
|
public void dtdValidationAutodetect() throws Exception {
|
||||||
doTestValidation("validateWithDtd.xml");
|
doTestValidation("validateWithDtd.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testXsdValidationAutodetect() throws Exception {
|
@Test
|
||||||
|
public void xsdValidationAutodetect() throws Exception {
|
||||||
doTestValidation("validateWithXsd.xml");
|
doTestValidation("validateWithXsd.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -21,6 +21,9 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.MutablePropertyValues;
|
import org.springframework.beans.MutablePropertyValues;
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
|
@ -33,18 +36,21 @@ import org.springframework.tests.sample.beans.LifecycleBean;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
import org.springframework.tests.sample.beans.factory.DummyFactory;
|
import org.springframework.tests.sample.beans.factory.DummyFactory;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 09.11.2003
|
* @since 09.11.2003
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTests {
|
public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTests {
|
||||||
|
|
||||||
private DefaultListableBeanFactory parent;
|
private DefaultListableBeanFactory parent;
|
||||||
|
|
||||||
private DefaultListableBeanFactory factory;
|
private DefaultListableBeanFactory factory;
|
||||||
|
|
||||||
@Override
|
@Before
|
||||||
protected void setUp() {
|
public void setUp() {
|
||||||
parent = new DefaultListableBeanFactory();
|
parent = new DefaultListableBeanFactory();
|
||||||
Map m = new HashMap();
|
Map m = new HashMap();
|
||||||
m.put("name", "Albert");
|
m.put("name", "Albert");
|
||||||
|
@ -86,26 +92,31 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
|
||||||
return factory;
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testCount() {
|
public void count() {
|
||||||
assertCount(24);
|
assertCount(24);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTestBeanCount() {
|
@Test
|
||||||
|
public void beanCount() {
|
||||||
assertTestBeanCount(13);
|
assertTestBeanCount(13);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLifecycleMethods() throws Exception {
|
@Test
|
||||||
|
public void lifecycleMethods() throws Exception {
|
||||||
LifecycleBean bean = (LifecycleBean) getBeanFactory().getBean("lifecycle");
|
LifecycleBean bean = (LifecycleBean) getBeanFactory().getBean("lifecycle");
|
||||||
bean.businessMethod();
|
bean.businessMethod();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testProtectedLifecycleMethods() throws Exception {
|
@Test
|
||||||
|
public void protectedLifecycleMethods() throws Exception {
|
||||||
ProtectedLifecycleBean bean = (ProtectedLifecycleBean) getBeanFactory().getBean("protectedLifecycle");
|
ProtectedLifecycleBean bean = (ProtectedLifecycleBean) getBeanFactory().getBean("protectedLifecycle");
|
||||||
bean.businessMethod();
|
bean.businessMethod();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDescriptionButNoProperties() throws Exception {
|
@Test
|
||||||
|
public void descriptionButNoProperties() throws Exception {
|
||||||
TestBean validEmpty = (TestBean) getBeanFactory().getBean("validEmptyWithDescription");
|
TestBean validEmpty = (TestBean) getBeanFactory().getBean("validEmptyWithDescription");
|
||||||
assertEquals(0, validEmpty.getAge());
|
assertEquals(0, validEmpty.getAge());
|
||||||
}
|
}
|
||||||
|
@ -113,7 +124,8 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
|
||||||
/**
|
/**
|
||||||
* Test that properties with name as well as id creating an alias up front.
|
* Test that properties with name as well as id creating an alias up front.
|
||||||
*/
|
*/
|
||||||
public void testAutoAliasing() throws Exception {
|
@Test
|
||||||
|
public void autoAliasing() throws Exception {
|
||||||
List beanNames = Arrays.asList(getListableBeanFactory().getBeanDefinitionNames());
|
List beanNames = Arrays.asList(getListableBeanFactory().getBeanDefinitionNames());
|
||||||
|
|
||||||
TestBean tb1 = (TestBean) getBeanFactory().getBean("aliased");
|
TestBean tb1 = (TestBean) getBeanFactory().getBean("aliased");
|
||||||
|
@ -172,7 +184,8 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
|
||||||
assertTrue(drs.containsKey(DummyReferencer.class.getName() + "#2"));
|
assertTrue(drs.containsKey(DummyReferencer.class.getName() + "#2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFactoryNesting() {
|
@Test
|
||||||
|
public void factoryNesting() {
|
||||||
ITestBean father = (ITestBean) getBeanFactory().getBean("father");
|
ITestBean father = (ITestBean) getBeanFactory().getBean("father");
|
||||||
assertTrue("Bean from root context", father != null);
|
assertTrue("Bean from root context", father != null);
|
||||||
|
|
||||||
|
@ -184,7 +197,8 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
|
||||||
assertTrue("Bean from root context", "Roderick".equals(rod.getName()));
|
assertTrue("Bean from root context", "Roderick".equals(rod.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFactoryReferences() {
|
@Test
|
||||||
|
public void factoryReferences() {
|
||||||
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
|
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
|
||||||
|
|
||||||
DummyReferencer ref = (DummyReferencer) getBeanFactory().getBean("factoryReferencer");
|
DummyReferencer ref = (DummyReferencer) getBeanFactory().getBean("factoryReferencer");
|
||||||
|
@ -196,7 +210,8 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
|
||||||
assertTrue(ref2.getDummyFactory() == factory);
|
assertTrue(ref2.getDummyFactory() == factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPrototypeReferences() {
|
@Test
|
||||||
|
public void prototypeReferences() {
|
||||||
// check that not broken by circular reference resolution mechanism
|
// check that not broken by circular reference resolution mechanism
|
||||||
DummyReferencer ref1 = (DummyReferencer) getBeanFactory().getBean("prototypeReferencer");
|
DummyReferencer ref1 = (DummyReferencer) getBeanFactory().getBean("prototypeReferencer");
|
||||||
assertTrue("Not referencing same bean twice", ref1.getTestBean1() != ref1.getTestBean2());
|
assertTrue("Not referencing same bean twice", ref1.getTestBean1() != ref1.getTestBean2());
|
||||||
|
@ -208,7 +223,8 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
|
||||||
assertTrue("Not referencing same bean twice", ref1.getTestBean1() != ref2.getTestBean2());
|
assertTrue("Not referencing same bean twice", ref1.getTestBean1() != ref2.getTestBean2());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBeanPostProcessor() throws Exception {
|
@Test
|
||||||
|
public void beanPostProcessor() throws Exception {
|
||||||
TestBean kerry = (TestBean) getBeanFactory().getBean("kerry");
|
TestBean kerry = (TestBean) getBeanFactory().getBean("kerry");
|
||||||
TestBean kathy = (TestBean) getBeanFactory().getBean("kathy");
|
TestBean kathy = (TestBean) getBeanFactory().getBean("kathy");
|
||||||
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
|
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
|
||||||
|
@ -219,14 +235,16 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
|
||||||
assertTrue(factoryCreated.isPostProcessed());
|
assertTrue(factoryCreated.isPostProcessed());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEmptyValues() {
|
@Test
|
||||||
|
public void emptyValues() {
|
||||||
TestBean rod = (TestBean) getBeanFactory().getBean("rod");
|
TestBean rod = (TestBean) getBeanFactory().getBean("rod");
|
||||||
TestBean kerry = (TestBean) getBeanFactory().getBean("kerry");
|
TestBean kerry = (TestBean) getBeanFactory().getBean("kerry");
|
||||||
assertTrue("Touchy is empty", "".equals(rod.getTouchy()));
|
assertTrue("Touchy is empty", "".equals(rod.getTouchy()));
|
||||||
assertTrue("Touchy is empty", "".equals(kerry.getTouchy()));
|
assertTrue("Touchy is empty", "".equals(kerry.getTouchy()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCommentsAndCdataInValue() {
|
@Test
|
||||||
|
public void commentsAndCdataInValue() {
|
||||||
TestBean bean = (TestBean) getBeanFactory().getBean("commentsInValue");
|
TestBean bean = (TestBean) getBeanFactory().getBean("commentsInValue");
|
||||||
assertEquals("Failed to handle comments and CDATA properly", "this is a <!--comment-->", bean.getName());
|
assertEquals("Failed to handle comments and CDATA properly", "this is a <!--comment-->", bean.getName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,19 +18,22 @@ package org.springframework.beans.propertyeditors;
|
||||||
|
|
||||||
import java.beans.PropertyEditor;
|
import java.beans.PropertyEditor;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the {@link ByteArrayPropertyEditor} class.
|
* Unit tests for the {@link ByteArrayPropertyEditor} class.
|
||||||
*
|
*
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
*/
|
*/
|
||||||
public final class ByteArrayPropertyEditorTests extends TestCase {
|
public final class ByteArrayPropertyEditorTests {
|
||||||
|
|
||||||
public void testSunnyDaySetAsText() throws Exception {
|
private final PropertyEditor byteEditor = new ByteArrayPropertyEditor();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sunnyDaySetAsText() throws Exception {
|
||||||
final String text = "Hideous towns make me throw... up";
|
final String text = "Hideous towns make me throw... up";
|
||||||
|
|
||||||
PropertyEditor byteEditor = new ByteArrayPropertyEditor();
|
|
||||||
byteEditor.setAsText(text);
|
byteEditor.setAsText(text);
|
||||||
|
|
||||||
Object value = byteEditor.getValue();
|
Object value = byteEditor.getValue();
|
||||||
|
@ -43,8 +46,8 @@ public final class ByteArrayPropertyEditorTests extends TestCase {
|
||||||
assertEquals(text, byteEditor.getAsText());
|
assertEquals(text, byteEditor.getAsText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetAsTextReturnsEmptyStringIfValueIsNull() throws Exception {
|
@Test
|
||||||
PropertyEditor byteEditor = new ByteArrayPropertyEditor();
|
public void getAsTextReturnsEmptyStringIfValueIsNull() throws Exception {
|
||||||
assertEquals("", byteEditor.getAsText());
|
assertEquals("", byteEditor.getAsText());
|
||||||
|
|
||||||
byteEditor.setAsText(null);
|
byteEditor.setAsText(null);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2006 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,19 +18,22 @@ package org.springframework.beans.propertyeditors;
|
||||||
|
|
||||||
import java.beans.PropertyEditor;
|
import java.beans.PropertyEditor;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the {@link CharArrayPropertyEditor} class.
|
* Unit tests for the {@link CharArrayPropertyEditor} class.
|
||||||
*
|
*
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
*/
|
*/
|
||||||
public final class CharArrayPropertyEditorTests extends TestCase {
|
public final class CharArrayPropertyEditorTests {
|
||||||
|
|
||||||
public void testSunnyDaySetAsText() throws Exception {
|
private final PropertyEditor charEditor = new CharArrayPropertyEditor();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sunnyDaySetAsText() throws Exception {
|
||||||
final String text = "Hideous towns make me throw... up";
|
final String text = "Hideous towns make me throw... up";
|
||||||
|
|
||||||
PropertyEditor charEditor = new CharArrayPropertyEditor();
|
|
||||||
charEditor.setAsText(text);
|
charEditor.setAsText(text);
|
||||||
|
|
||||||
Object value = charEditor.getValue();
|
Object value = charEditor.getValue();
|
||||||
|
@ -43,8 +46,8 @@ public final class CharArrayPropertyEditorTests extends TestCase {
|
||||||
assertEquals(text, charEditor.getAsText());
|
assertEquals(text, charEditor.getAsText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetAsTextReturnsEmptyStringIfValueIsNull() throws Exception {
|
@Test
|
||||||
PropertyEditor charEditor = new CharArrayPropertyEditor();
|
public void getAsTextReturnsEmptyStringIfValueIsNull() throws Exception {
|
||||||
assertEquals("", charEditor.getAsText());
|
assertEquals("", charEditor.getAsText());
|
||||||
|
|
||||||
charEditor.setAsText(null);
|
charEditor.setAsText(null);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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,9 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the conversion of Strings to {@link java.util.Properties} objects,
|
* Test the conversion of Strings to {@link java.util.Properties} objects,
|
||||||
|
@ -30,9 +32,10 @@ import junit.framework.TestCase;
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
*/
|
*/
|
||||||
public class PropertiesEditorTests extends TestCase {
|
public class PropertiesEditorTests {
|
||||||
|
|
||||||
public void testOneProperty() {
|
@Test
|
||||||
|
public void oneProperty() {
|
||||||
String s = "foo=bar";
|
String s = "foo=bar";
|
||||||
PropertiesEditor pe= new PropertiesEditor();
|
PropertiesEditor pe= new PropertiesEditor();
|
||||||
pe.setAsText(s);
|
pe.setAsText(s);
|
||||||
|
@ -41,7 +44,8 @@ public class PropertiesEditorTests extends TestCase {
|
||||||
assertTrue("foo=bar", p.get("foo").equals("bar"));
|
assertTrue("foo=bar", p.get("foo").equals("bar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTwoProperties() {
|
@Test
|
||||||
|
public void twoProperties() {
|
||||||
String s = "foo=bar with whitespace\n" +
|
String s = "foo=bar with whitespace\n" +
|
||||||
"me=mi";
|
"me=mi";
|
||||||
PropertiesEditor pe= new PropertiesEditor();
|
PropertiesEditor pe= new PropertiesEditor();
|
||||||
|
@ -52,7 +56,8 @@ public class PropertiesEditorTests extends TestCase {
|
||||||
assertTrue("me=mi", p.get("me").equals("mi"));
|
assertTrue("me=mi", p.get("me").equals("mi"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHandlesEqualsInValue() {
|
@Test
|
||||||
|
public void handlesEqualsInValue() {
|
||||||
String s = "foo=bar\n" +
|
String s = "foo=bar\n" +
|
||||||
"me=mi\n" +
|
"me=mi\n" +
|
||||||
"x=y=z";
|
"x=y=z";
|
||||||
|
@ -65,7 +70,8 @@ public class PropertiesEditorTests extends TestCase {
|
||||||
assertTrue("x='y=z'", p.get("x").equals("y=z"));
|
assertTrue("x='y=z'", p.get("x").equals("y=z"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHandlesEmptyProperty() {
|
@Test
|
||||||
|
public void handlesEmptyProperty() {
|
||||||
String s = "foo=bar\nme=mi\nx=";
|
String s = "foo=bar\nme=mi\nx=";
|
||||||
PropertiesEditor pe= new PropertiesEditor();
|
PropertiesEditor pe= new PropertiesEditor();
|
||||||
pe.setAsText(s);
|
pe.setAsText(s);
|
||||||
|
@ -76,7 +82,8 @@ public class PropertiesEditorTests extends TestCase {
|
||||||
assertTrue("x='y=z'", p.get("x").equals(""));
|
assertTrue("x='y=z'", p.get("x").equals(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHandlesEmptyPropertyWithoutEquals() {
|
@Test
|
||||||
|
public void handlesEmptyPropertyWithoutEquals() {
|
||||||
String s = "foo\nme=mi\nx=x";
|
String s = "foo\nme=mi\nx=x";
|
||||||
PropertiesEditor pe= new PropertiesEditor();
|
PropertiesEditor pe= new PropertiesEditor();
|
||||||
pe.setAsText(s);
|
pe.setAsText(s);
|
||||||
|
@ -89,7 +96,8 @@ public class PropertiesEditorTests extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Comments begin with #
|
* Comments begin with #
|
||||||
*/
|
*/
|
||||||
public void testIgnoresCommentLinesAndEmptyLines() {
|
@Test
|
||||||
|
public void ignoresCommentLinesAndEmptyLines() {
|
||||||
String s = "#Ignore this comment\n" +
|
String s = "#Ignore this comment\n" +
|
||||||
"foo=bar\n" +
|
"foo=bar\n" +
|
||||||
"#Another=comment more junk /\n" +
|
"#Another=comment more junk /\n" +
|
||||||
|
@ -110,7 +118,8 @@ public class PropertiesEditorTests extends TestCase {
|
||||||
* We must ensure that comment lines beginning with whitespace are
|
* We must ensure that comment lines beginning with whitespace are
|
||||||
* still ignored: The standard syntax doesn't allow this on JDK 1.3.
|
* still ignored: The standard syntax doesn't allow this on JDK 1.3.
|
||||||
*/
|
*/
|
||||||
public void testIgnoresLeadingSpacesAndTabs() {
|
@Test
|
||||||
|
public void ignoresLeadingSpacesAndTabs() {
|
||||||
String s = " #Ignore this comment\n" +
|
String s = " #Ignore this comment\n" +
|
||||||
"\t\tfoo=bar\n" +
|
"\t\tfoo=bar\n" +
|
||||||
"\t#Another comment more junk \n" +
|
"\t#Another comment more junk \n" +
|
||||||
|
@ -125,22 +134,25 @@ public class PropertiesEditorTests extends TestCase {
|
||||||
assertTrue("me=mi", p.get("me").equals("mi"));
|
assertTrue("me=mi", p.get("me").equals("mi"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNull() {
|
@Test
|
||||||
|
public void nullValue() {
|
||||||
PropertiesEditor pe= new PropertiesEditor();
|
PropertiesEditor pe= new PropertiesEditor();
|
||||||
pe.setAsText(null);
|
pe.setAsText(null);
|
||||||
Properties p = (Properties) pe.getValue();
|
Properties p = (Properties) pe.getValue();
|
||||||
assertEquals(0, p.size());
|
assertEquals(0, p.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEmptyString() {
|
@Test
|
||||||
|
public void emptyString() {
|
||||||
PropertiesEditor pe = new PropertiesEditor();
|
PropertiesEditor pe = new PropertiesEditor();
|
||||||
pe.setAsText("");
|
pe.setAsText("");
|
||||||
Properties p = (Properties) pe.getValue();
|
Properties p = (Properties) pe.getValue();
|
||||||
assertTrue("empty string means empty properties", p.isEmpty());
|
assertTrue("empty string means empty properties", p.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUsingMapAsValueSource() throws Exception {
|
@Test
|
||||||
Map map = new HashMap();
|
public void usingMapAsValueSource() throws Exception {
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
map.put("one", "1");
|
map.put("one", "1");
|
||||||
map.put("two", "2");
|
map.put("two", "2");
|
||||||
map.put("three", "3");
|
map.put("three", "3");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2007 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,15 +16,18 @@
|
||||||
|
|
||||||
package org.springframework.beans.propertyeditors;
|
package org.springframework.beans.propertyeditors;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class StringArrayPropertyEditorTests extends TestCase {
|
public class StringArrayPropertyEditorTests {
|
||||||
|
|
||||||
public void testWithDefaultSeparator() throws Exception {
|
@Test
|
||||||
|
public void withDefaultSeparator() throws Exception {
|
||||||
StringArrayPropertyEditor editor = new StringArrayPropertyEditor();
|
StringArrayPropertyEditor editor = new StringArrayPropertyEditor();
|
||||||
editor.setAsText("0,1,2");
|
editor.setAsText("0,1,2");
|
||||||
Object value = editor.getValue();
|
Object value = editor.getValue();
|
||||||
|
@ -37,7 +40,8 @@ public class StringArrayPropertyEditorTests extends TestCase {
|
||||||
assertEquals("0,1,2", editor.getAsText());
|
assertEquals("0,1,2", editor.getAsText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTrimByDefault() throws Exception {
|
@Test
|
||||||
|
public void trimByDefault() throws Exception {
|
||||||
StringArrayPropertyEditor editor = new StringArrayPropertyEditor();
|
StringArrayPropertyEditor editor = new StringArrayPropertyEditor();
|
||||||
editor.setAsText(" 0,1 , 2 ");
|
editor.setAsText(" 0,1 , 2 ");
|
||||||
Object value = editor.getValue();
|
Object value = editor.getValue();
|
||||||
|
@ -48,7 +52,8 @@ public class StringArrayPropertyEditorTests extends TestCase {
|
||||||
assertEquals("0,1,2", editor.getAsText());
|
assertEquals("0,1,2", editor.getAsText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoTrim() throws Exception {
|
@Test
|
||||||
|
public void noTrim() throws Exception {
|
||||||
StringArrayPropertyEditor editor = new StringArrayPropertyEditor(",",false,false);
|
StringArrayPropertyEditor editor = new StringArrayPropertyEditor(",",false,false);
|
||||||
editor.setAsText(" 0,1 , 2 ");
|
editor.setAsText(" 0,1 , 2 ");
|
||||||
Object value = editor.getValue();
|
Object value = editor.getValue();
|
||||||
|
@ -60,7 +65,8 @@ public class StringArrayPropertyEditorTests extends TestCase {
|
||||||
assertEquals(" 0,1 , 2 ", editor.getAsText());
|
assertEquals(" 0,1 , 2 ", editor.getAsText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithCustomSeparator() throws Exception {
|
@Test
|
||||||
|
public void withCustomSeparator() throws Exception {
|
||||||
StringArrayPropertyEditor editor = new StringArrayPropertyEditor(":");
|
StringArrayPropertyEditor editor = new StringArrayPropertyEditor(":");
|
||||||
editor.setAsText("0:1:2");
|
editor.setAsText("0:1:2");
|
||||||
Object value = editor.getValue();
|
Object value = editor.getValue();
|
||||||
|
@ -72,7 +78,8 @@ public class StringArrayPropertyEditorTests extends TestCase {
|
||||||
assertEquals("0:1:2", editor.getAsText());
|
assertEquals("0:1:2", editor.getAsText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithCharsToDelete() throws Exception {
|
@Test
|
||||||
|
public void withCharsToDelete() throws Exception {
|
||||||
StringArrayPropertyEditor editor = new StringArrayPropertyEditor(",", "\r\n", false);
|
StringArrayPropertyEditor editor = new StringArrayPropertyEditor(",", "\r\n", false);
|
||||||
editor.setAsText("0\r,1,\n2");
|
editor.setAsText("0\r,1,\n2");
|
||||||
Object value = editor.getValue();
|
Object value = editor.getValue();
|
||||||
|
@ -84,7 +91,8 @@ public class StringArrayPropertyEditorTests extends TestCase {
|
||||||
assertEquals("0,1,2", editor.getAsText());
|
assertEquals("0,1,2", editor.getAsText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithEmptyArray() throws Exception {
|
@Test
|
||||||
|
public void withEmptyArray() throws Exception {
|
||||||
StringArrayPropertyEditor editor = new StringArrayPropertyEditor();
|
StringArrayPropertyEditor editor = new StringArrayPropertyEditor();
|
||||||
editor.setAsText("");
|
editor.setAsText("");
|
||||||
Object value = editor.getValue();
|
Object value = editor.getValue();
|
||||||
|
@ -92,7 +100,8 @@ public class StringArrayPropertyEditorTests extends TestCase {
|
||||||
assertEquals(0, ((String[]) value).length);
|
assertEquals(0, ((String[]) value).length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithEmptyArrayAsNull() throws Exception {
|
@Test
|
||||||
|
public void withEmptyArrayAsNull() throws Exception {
|
||||||
StringArrayPropertyEditor editor = new StringArrayPropertyEditor(",", true);
|
StringArrayPropertyEditor editor = new StringArrayPropertyEditor(",", true);
|
||||||
editor.setAsText("");
|
editor.setAsText("");
|
||||||
assertNull(editor.getValue());
|
assertNull(editor.getValue());
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,15 +18,19 @@ package org.springframework.beans.propertyeditors;
|
||||||
|
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Nicholas Williams
|
* @author Nicholas Williams
|
||||||
*/
|
*/
|
||||||
public class ZoneIdEditorTests extends TestCase {
|
public class ZoneIdEditorTests {
|
||||||
|
|
||||||
public void testAmericaChicago() {
|
private final ZoneIdEditor editor = new ZoneIdEditor();
|
||||||
ZoneIdEditor editor = new ZoneIdEditor();
|
|
||||||
|
@Test
|
||||||
|
public void americaChicago() {
|
||||||
editor.setAsText("America/Chicago");
|
editor.setAsText("America/Chicago");
|
||||||
|
|
||||||
ZoneId zoneId = (ZoneId) editor.getValue();
|
ZoneId zoneId = (ZoneId) editor.getValue();
|
||||||
|
@ -36,8 +40,8 @@ public class ZoneIdEditorTests extends TestCase {
|
||||||
assertEquals("The text version is not correct.", "America/Chicago", editor.getAsText());
|
assertEquals("The text version is not correct.", "America/Chicago", editor.getAsText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAmericaLosAngeles() {
|
@Test
|
||||||
ZoneIdEditor editor = new ZoneIdEditor();
|
public void americaLosAngeles() {
|
||||||
editor.setAsText("America/Los_Angeles");
|
editor.setAsText("America/Los_Angeles");
|
||||||
|
|
||||||
ZoneId zoneId = (ZoneId) editor.getValue();
|
ZoneId zoneId = (ZoneId) editor.getValue();
|
||||||
|
@ -47,16 +51,14 @@ public class ZoneIdEditorTests extends TestCase {
|
||||||
assertEquals("The text version is not correct.", "America/Los_Angeles", editor.getAsText());
|
assertEquals("The text version is not correct.", "America/Los_Angeles", editor.getAsText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetNullAsText() {
|
@Test
|
||||||
ZoneIdEditor editor = new ZoneIdEditor();
|
public void getNullAsText() {
|
||||||
|
|
||||||
assertEquals("The returned value is not correct.", "", editor.getAsText());
|
assertEquals("The returned value is not correct.", "", editor.getAsText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetValueAsText() {
|
@Test
|
||||||
ZoneIdEditor editor = new ZoneIdEditor();
|
public void getValueAsText() {
|
||||||
editor.setValue(ZoneId.of("America/New_York"));
|
editor.setValue(ZoneId.of("America/New_York"));
|
||||||
|
|
||||||
assertEquals("The text version is not correct.", "America/New_York", editor.getAsText());
|
assertEquals("The text version is not correct.", "America/New_York", editor.getAsText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2005 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,18 +18,21 @@ package org.springframework.mail.javamail;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class ConfigurableMimeFileTypeMapTests extends TestCase {
|
public class ConfigurableMimeFileTypeMapTests {
|
||||||
|
|
||||||
public void testAgainstDefaultConfiguration() throws Exception {
|
@Test
|
||||||
|
public void againstDefaultConfiguration() throws Exception {
|
||||||
ConfigurableMimeFileTypeMap ftm = new ConfigurableMimeFileTypeMap();
|
ConfigurableMimeFileTypeMap ftm = new ConfigurableMimeFileTypeMap();
|
||||||
ftm.afterPropertiesSet();
|
ftm.afterPropertiesSet();
|
||||||
|
|
||||||
|
@ -41,12 +44,14 @@ public class ConfigurableMimeFileTypeMapTests extends TestCase {
|
||||||
assertEquals("Invalid default content type", "application/octet-stream", ftm.getContentType("foobar.foo"));
|
assertEquals("Invalid default content type", "application/octet-stream", ftm.getContentType("foobar.foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAgainstDefaultConfigurationWithFilePath() throws Exception {
|
@Test
|
||||||
|
public void againstDefaultConfigurationWithFilePath() throws Exception {
|
||||||
ConfigurableMimeFileTypeMap ftm = new ConfigurableMimeFileTypeMap();
|
ConfigurableMimeFileTypeMap ftm = new ConfigurableMimeFileTypeMap();
|
||||||
assertEquals("Invalid content type for HTM", "text/html", ftm.getContentType(new File("/tmp/foobar.HTM")));
|
assertEquals("Invalid content type for HTM", "text/html", ftm.getContentType(new File("/tmp/foobar.HTM")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithAdditionalMappings() throws Exception {
|
@Test
|
||||||
|
public void withAdditionalMappings() throws Exception {
|
||||||
ConfigurableMimeFileTypeMap ftm = new ConfigurableMimeFileTypeMap();
|
ConfigurableMimeFileTypeMap ftm = new ConfigurableMimeFileTypeMap();
|
||||||
ftm.setMappings(new String[] {"foo/bar HTM foo", "foo/cpp c++"});
|
ftm.setMappings(new String[] {"foo/bar HTM foo", "foo/cpp c++"});
|
||||||
ftm.afterPropertiesSet();
|
ftm.afterPropertiesSet();
|
||||||
|
@ -56,7 +61,8 @@ public class ConfigurableMimeFileTypeMapTests extends TestCase {
|
||||||
assertEquals("Invalid content type for foo - new mapping didn't work", "foo/bar", ftm.getContentType("bar.foo"));
|
assertEquals("Invalid content type for foo - new mapping didn't work", "foo/bar", ftm.getContentType("bar.foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithCustomMappingLocation() throws Exception {
|
@Test
|
||||||
|
public void withCustomMappingLocation() throws Exception {
|
||||||
Resource resource = new ClassPathResource("test.mime.types", getClass());
|
Resource resource = new ClassPathResource("test.mime.types", getClass());
|
||||||
|
|
||||||
ConfigurableMimeFileTypeMap ftm = new ConfigurableMimeFileTypeMap();
|
ConfigurableMimeFileTypeMap ftm = new ConfigurableMimeFileTypeMap();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,62 +16,62 @@
|
||||||
|
|
||||||
package org.springframework.mail.javamail;
|
package org.springframework.mail.javamail;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brian Hanafee
|
* @author Brian Hanafee
|
||||||
|
* @author Sam Brannen
|
||||||
* @since 09.07.2005
|
* @since 09.07.2005
|
||||||
*/
|
*/
|
||||||
public class InternetAddressEditorTests extends TestCase {
|
public class InternetAddressEditorTests {
|
||||||
|
|
||||||
private static final String EMPTY = "";
|
private static final String EMPTY = "";
|
||||||
private static final String SIMPLE = "nobody@nowhere.com";
|
private static final String SIMPLE = "nobody@nowhere.com";
|
||||||
private static final String BAD = "(";
|
private static final String BAD = "(";
|
||||||
|
|
||||||
private InternetAddressEditor editor;
|
private final InternetAddressEditor editor = new InternetAddressEditor();
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() {
|
|
||||||
editor = new InternetAddressEditor();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testUninitialized() {
|
@Test
|
||||||
|
public void uninitialized() {
|
||||||
assertEquals("Uninitialized editor did not return empty value string", EMPTY, editor.getAsText());
|
assertEquals("Uninitialized editor did not return empty value string", EMPTY, editor.getAsText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetNull() {
|
@Test
|
||||||
|
public void setNull() {
|
||||||
editor.setAsText(null);
|
editor.setAsText(null);
|
||||||
assertEquals("Setting null did not result in empty value string", EMPTY, editor.getAsText());
|
assertEquals("Setting null did not result in empty value string", EMPTY, editor.getAsText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetEmpty() {
|
@Test
|
||||||
|
public void setEmpty() {
|
||||||
editor.setAsText(EMPTY);
|
editor.setAsText(EMPTY);
|
||||||
assertEquals("Setting empty string did not result in empty value string", EMPTY, editor.getAsText());
|
assertEquals("Setting empty string did not result in empty value string", EMPTY, editor.getAsText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAllWhitespace() {
|
@Test
|
||||||
|
public void allWhitespace() {
|
||||||
editor.setAsText(" ");
|
editor.setAsText(" ");
|
||||||
assertEquals("All whitespace was not recognized", EMPTY, editor.getAsText());
|
assertEquals("All whitespace was not recognized", EMPTY, editor.getAsText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleGoodAddess() {
|
@Test
|
||||||
|
public void simpleGoodAddess() {
|
||||||
editor.setAsText(SIMPLE);
|
editor.setAsText(SIMPLE);
|
||||||
assertEquals("Simple email address failed", SIMPLE, editor.getAsText());
|
assertEquals("Simple email address failed", SIMPLE, editor.getAsText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExcessWhitespace() {
|
@Test
|
||||||
|
public void excessWhitespace() {
|
||||||
editor.setAsText(" " + SIMPLE + " ");
|
editor.setAsText(" " + SIMPLE + " ");
|
||||||
assertEquals("Whitespace was not stripped", SIMPLE, editor.getAsText());
|
assertEquals("Whitespace was not stripped", SIMPLE, editor.getAsText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleBadAddress() {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
try {
|
public void simpleBadAddress() {
|
||||||
editor.setAsText(BAD);
|
editor.setAsText(BAD);
|
||||||
fail("Should have failed on \"" + BAD + "\", instead got " + editor.getAsText());
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException e) {
|
|
||||||
// Passed the test
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -41,13 +41,13 @@ import net.sf.jasperreports.engine.export.JRPdfExporter;
|
||||||
import net.sf.jasperreports.engine.export.JRPdfExporterParameter;
|
import net.sf.jasperreports.engine.export.JRPdfExporterParameter;
|
||||||
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
|
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
|
||||||
import net.sf.jasperreports.engine.util.JRLoader;
|
import net.sf.jasperreports.engine.util.JRLoader;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.tests.Assume;
|
import org.springframework.tests.Assume;
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ import static org.junit.Assert.*;
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 18.11.2004
|
* @since 18.11.2004
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class JasperReportsUtilsTests {
|
public class JasperReportsUtilsTests {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
|
@ -66,7 +67,7 @@ public class JasperReportsUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenderAsCsvWithDataSource() throws Exception {
|
public void renderAsCsvWithDataSource() throws Exception {
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
JasperReportsUtils.renderAsCsv(getReport(), getParameters(), getDataSource(), writer);
|
JasperReportsUtils.renderAsCsv(getReport(), getParameters(), getDataSource(), writer);
|
||||||
String output = writer.getBuffer().toString();
|
String output = writer.getBuffer().toString();
|
||||||
|
@ -74,7 +75,7 @@ public class JasperReportsUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenderAsCsvWithCollection() throws Exception {
|
public void renderAsCsvWithCollection() throws Exception {
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
JasperReportsUtils.renderAsCsv(getReport(), getParameters(), getData(), writer);
|
JasperReportsUtils.renderAsCsv(getReport(), getParameters(), getData(), writer);
|
||||||
String output = writer.getBuffer().toString();
|
String output = writer.getBuffer().toString();
|
||||||
|
@ -82,7 +83,7 @@ public class JasperReportsUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenderAsCsvWithExporterParameters() throws Exception {
|
public void renderAsCsvWithExporterParameters() throws Exception {
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
Map<JRExporterParameter, Object> exporterParameters = new HashMap<JRExporterParameter, Object>();
|
Map<JRExporterParameter, Object> exporterParameters = new HashMap<JRExporterParameter, Object>();
|
||||||
exporterParameters.put(JRCsvExporterParameter.FIELD_DELIMITER, "~");
|
exporterParameters.put(JRCsvExporterParameter.FIELD_DELIMITER, "~");
|
||||||
|
@ -93,7 +94,7 @@ public class JasperReportsUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenderAsHtmlWithDataSource() throws Exception {
|
public void renderAsHtmlWithDataSource() throws Exception {
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
JasperReportsUtils.renderAsHtml(getReport(), getParameters(), getDataSource(), writer);
|
JasperReportsUtils.renderAsHtml(getReport(), getParameters(), getDataSource(), writer);
|
||||||
String output = writer.getBuffer().toString();
|
String output = writer.getBuffer().toString();
|
||||||
|
@ -101,7 +102,7 @@ public class JasperReportsUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenderAsHtmlWithCollection() throws Exception {
|
public void renderAsHtmlWithCollection() throws Exception {
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
JasperReportsUtils.renderAsHtml(getReport(), getParameters(), getData(), writer);
|
JasperReportsUtils.renderAsHtml(getReport(), getParameters(), getData(), writer);
|
||||||
String output = writer.getBuffer().toString();
|
String output = writer.getBuffer().toString();
|
||||||
|
@ -109,7 +110,7 @@ public class JasperReportsUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenderAsHtmlWithExporterParameters() throws Exception {
|
public void renderAsHtmlWithExporterParameters() throws Exception {
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
Map<JRExporterParameter, Object> exporterParameters = new HashMap<JRExporterParameter, Object>();
|
Map<JRExporterParameter, Object> exporterParameters = new HashMap<JRExporterParameter, Object>();
|
||||||
String uri = "/my/uri";
|
String uri = "/my/uri";
|
||||||
|
@ -121,7 +122,7 @@ public class JasperReportsUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenderAsPdfWithDataSource() throws Exception {
|
public void renderAsPdfWithDataSource() throws Exception {
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
JasperReportsUtils.renderAsPdf(getReport(), getParameters(), getDataSource(), os);
|
JasperReportsUtils.renderAsPdf(getReport(), getParameters(), getDataSource(), os);
|
||||||
byte[] output = os.toByteArray();
|
byte[] output = os.toByteArray();
|
||||||
|
@ -129,7 +130,7 @@ public class JasperReportsUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenderAsPdfWithCollection() throws Exception {
|
public void renderAsPdfWithCollection() throws Exception {
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
JasperReportsUtils.renderAsPdf(getReport(), getParameters(), getData(), os);
|
JasperReportsUtils.renderAsPdf(getReport(), getParameters(), getData(), os);
|
||||||
byte[] output = os.toByteArray();
|
byte[] output = os.toByteArray();
|
||||||
|
@ -137,7 +138,7 @@ public class JasperReportsUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenderAsPdfWithExporterParameters() throws Exception {
|
public void renderAsPdfWithExporterParameters() throws Exception {
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
Map<JRExporterParameter, Object> exporterParameters = new HashMap<JRExporterParameter, Object>();
|
Map<JRExporterParameter, Object> exporterParameters = new HashMap<JRExporterParameter, Object>();
|
||||||
exporterParameters.put(JRPdfExporterParameter.PDF_VERSION, JRPdfExporterParameter.PDF_VERSION_1_6.toString());
|
exporterParameters.put(JRPdfExporterParameter.PDF_VERSION, JRPdfExporterParameter.PDF_VERSION_1_6.toString());
|
||||||
|
@ -148,7 +149,7 @@ public class JasperReportsUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenderAsXlsWithDataSource() throws Exception {
|
public void renderAsXlsWithDataSource() throws Exception {
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
JasperReportsUtils.renderAsXls(getReport(), getParameters(), getDataSource(), os);
|
JasperReportsUtils.renderAsXls(getReport(), getParameters(), getDataSource(), os);
|
||||||
byte[] output = os.toByteArray();
|
byte[] output = os.toByteArray();
|
||||||
|
@ -156,7 +157,7 @@ public class JasperReportsUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenderAsXlsWithCollection() throws Exception {
|
public void renderAsXlsWithCollection() throws Exception {
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
JasperReportsUtils.renderAsXls(getReport(), getParameters(), getData(), os);
|
JasperReportsUtils.renderAsXls(getReport(), getParameters(), getData(), os);
|
||||||
byte[] output = os.toByteArray();
|
byte[] output = os.toByteArray();
|
||||||
|
@ -164,7 +165,7 @@ public class JasperReportsUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenderAsXlsWithExporterParameters() throws Exception {
|
public void renderAsXlsWithExporterParameters() throws Exception {
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
Map<JRExporterParameter, Object> exporterParameters = new HashMap<JRExporterParameter, Object>();
|
Map<JRExporterParameter, Object> exporterParameters = new HashMap<JRExporterParameter, Object>();
|
||||||
|
|
||||||
|
@ -178,7 +179,7 @@ public class JasperReportsUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenderWithWriter() throws Exception {
|
public void renderWithWriter() throws Exception {
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
JasperPrint print = JasperFillManager.fillReport(getReport(), getParameters(), getDataSource());
|
JasperPrint print = JasperFillManager.fillReport(getReport(), getParameters(), getDataSource());
|
||||||
JasperReportsUtils.render(new JRHtmlExporter(), print, writer);
|
JasperReportsUtils.render(new JRHtmlExporter(), print, writer);
|
||||||
|
@ -187,7 +188,7 @@ public class JasperReportsUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenderWithOutputStream() throws Exception {
|
public void renderWithOutputStream() throws Exception {
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
JasperPrint print = JasperFillManager.fillReport(getReport(), getParameters(), getDataSource());
|
JasperPrint print = JasperFillManager.fillReport(getReport(), getParameters(), getDataSource());
|
||||||
JasperReportsUtils.render(new JRPdfExporter(), print, os);
|
JasperReportsUtils.render(new JRPdfExporter(), print, os);
|
||||||
|
@ -214,6 +215,7 @@ public class JasperReportsUtilsTests {
|
||||||
assertTrue("Output should start with %PDF", translated.startsWith("%PDF"));
|
assertTrue("Output should start with %PDF", translated.startsWith("%PDF"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("resource")
|
||||||
private void assertXlsOutputCorrect(byte[] output) throws Exception {
|
private void assertXlsOutputCorrect(byte[] output) throws Exception {
|
||||||
HSSFWorkbook workbook = new HSSFWorkbook(new ByteArrayInputStream(output));
|
HSSFWorkbook workbook = new HSSFWorkbook(new ByteArrayInputStream(output));
|
||||||
HSSFSheet sheet = workbook.getSheetAt(0);
|
HSSFSheet sheet = workbook.getSheetAt(0);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -21,7 +21,6 @@ import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.annotation.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.aop.framework.Advised;
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
@ -36,25 +35,29 @@ import static org.junit.Assert.*;
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("resource")
|
||||||
public final class PropertyDependentAspectTests {
|
public final class PropertyDependentAspectTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPropertyDependentAspectWithPropertyDeclaredBeforeAdvice() throws Exception {
|
public void propertyDependentAspectWithPropertyDeclaredBeforeAdvice()
|
||||||
|
throws Exception {
|
||||||
checkXmlAspect(getClass().getSimpleName() + "-before.xml");
|
checkXmlAspect(getClass().getSimpleName() + "-before.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPropertyDependentAspectWithPropertyDeclaredAfterAdvice() throws Exception {
|
public void propertyDependentAspectWithPropertyDeclaredAfterAdvice() throws Exception {
|
||||||
checkXmlAspect(getClass().getSimpleName() + "-after.xml");
|
checkXmlAspect(getClass().getSimpleName() + "-after.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPropertyDependentAtAspectJAspectWithPropertyDeclaredBeforeAdvice() throws Exception {
|
public void propertyDependentAtAspectJAspectWithPropertyDeclaredBeforeAdvice()
|
||||||
|
throws Exception {
|
||||||
checkAtAspectJAspect(getClass().getSimpleName() + "-atAspectJ-before.xml");
|
checkAtAspectJAspect(getClass().getSimpleName() + "-atAspectJ-before.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPropertyDependentAtAspectJAspectWithPropertyDeclaredAfterAdvice() throws Exception {
|
public void propertyDependentAtAspectJAspectWithPropertyDeclaredAfterAdvice()
|
||||||
|
throws Exception {
|
||||||
checkAtAspectJAspect(getClass().getSimpleName() + "-atAspectJ-after.xml");
|
checkAtAspectJAspect(getClass().getSimpleName() + "-atAspectJ-after.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,6 +18,7 @@ package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
import org.aopalliance.intercept.MethodInterceptor;
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -27,7 +28,7 @@ import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for target selection matching (see SPR-3783).
|
* Tests for target selection matching (see SPR-3783).
|
||||||
* Thanks to Tomasz Blachowicz for the bug report!
|
* <p>Thanks to Tomasz Blachowicz for the bug report!
|
||||||
*
|
*
|
||||||
* @author Ramnivas Laddad
|
* @author Ramnivas Laddad
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
|
@ -46,6 +47,7 @@ public final class TargetPointcutSelectionTests {
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@SuppressWarnings("resource")
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
ClassPathXmlApplicationContext ctx =
|
ClassPathXmlApplicationContext ctx =
|
||||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||||
|
@ -63,7 +65,7 @@ public final class TargetPointcutSelectionTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTargetSelectionForMatchedType() {
|
public void targetSelectionForMatchedType() {
|
||||||
testImpl1.interfaceMethod();
|
testImpl1.interfaceMethod();
|
||||||
assertEquals("Should have been advised by POJO advice for impl", 1, testAspectForTestImpl1.count);
|
assertEquals("Should have been advised by POJO advice for impl", 1, testAspectForTestImpl1.count);
|
||||||
assertEquals("Should have been advised by POJO advice for base type", 1, testAspectForAbstractTestImpl.count);
|
assertEquals("Should have been advised by POJO advice for base type", 1, testAspectForAbstractTestImpl.count);
|
||||||
|
@ -71,7 +73,7 @@ public final class TargetPointcutSelectionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTargetNonSelectionForMismatchedType() {
|
public void targetNonSelectionForMismatchedType() {
|
||||||
testImpl2.interfaceMethod();
|
testImpl2.interfaceMethod();
|
||||||
assertEquals("Shouldn't have been advised by POJO advice for impl", 0, testAspectForTestImpl1.count);
|
assertEquals("Shouldn't have been advised by POJO advice for impl", 0, testAspectForTestImpl1.count);
|
||||||
assertEquals("Should have been advised by POJO advice for base type", 1, testAspectForAbstractTestImpl.count);
|
assertEquals("Should have been advised by POJO advice for base type", 1, testAspectForAbstractTestImpl.count);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -22,7 +22,6 @@ import java.lang.annotation.RetentionPolicy;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.annotation.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
@ -32,13 +31,17 @@ import static org.junit.Assert.*;
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public final class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
|
public final class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
|
||||||
public TestInterface testBean;
|
|
||||||
public TestInterface testAnnotatedClassBean;
|
|
||||||
public TestInterface testAnnotatedMethodBean;
|
|
||||||
|
|
||||||
protected Counter counter;
|
private TestInterface testBean;
|
||||||
|
|
||||||
|
private TestInterface testAnnotatedClassBean;
|
||||||
|
|
||||||
|
private TestInterface testAnnotatedMethodBean;
|
||||||
|
|
||||||
|
private Counter counter;
|
||||||
|
|
||||||
@org.junit.Before
|
@org.junit.Before
|
||||||
|
@SuppressWarnings("resource")
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
ClassPathXmlApplicationContext ctx =
|
ClassPathXmlApplicationContext ctx =
|
||||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||||
|
@ -50,56 +53,56 @@ public final class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testThisAsClassDoesNotMatch() {
|
public void thisAsClassDoesNotMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(0, counter.thisAsClassCounter);
|
assertEquals(0, counter.thisAsClassCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testThisAsInterfaceMatch() {
|
public void thisAsInterfaceMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(1, counter.thisAsInterfaceCounter);
|
assertEquals(1, counter.thisAsInterfaceCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTargetAsClassDoesMatch() {
|
public void targetAsClassDoesMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(1, counter.targetAsClassCounter);
|
assertEquals(1, counter.targetAsClassCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTargetAsInterfaceMatch() {
|
public void targetAsInterfaceMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(1, counter.targetAsInterfaceCounter);
|
assertEquals(1, counter.targetAsInterfaceCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testThisAsClassAndTargetAsClassCounterNotMatch() {
|
public void thisAsClassAndTargetAsClassCounterNotMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(0, counter.thisAsClassAndTargetAsClassCounter);
|
assertEquals(0, counter.thisAsClassAndTargetAsClassCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testThisAsInterfaceAndTargetAsInterfaceCounterMatch() {
|
public void thisAsInterfaceAndTargetAsInterfaceCounterMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(1, counter.thisAsInterfaceAndTargetAsInterfaceCounter);
|
assertEquals(1, counter.thisAsInterfaceAndTargetAsInterfaceCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testThisAsInterfaceAndTargetAsClassCounterMatch() {
|
public void thisAsInterfaceAndTargetAsClassCounterMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(1, counter.thisAsInterfaceAndTargetAsInterfaceCounter);
|
assertEquals(1, counter.thisAsInterfaceAndTargetAsInterfaceCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAtTargetClassAnnotationMatch() {
|
public void atTargetClassAnnotationMatch() {
|
||||||
testAnnotatedClassBean.doIt();
|
testAnnotatedClassBean.doIt();
|
||||||
assertEquals(1, counter.atTargetClassAnnotationCounter);
|
assertEquals(1, counter.atTargetClassAnnotationCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAtAnnotationMethodAnnotationMatch() {
|
public void atAnnotationMethodAnnotationMatch() {
|
||||||
testAnnotatedMethodBean.doIt();
|
testAnnotatedMethodBean.doIt();
|
||||||
assertEquals(1, counter.atAnnotationMethodAnnotationCounter);
|
assertEquals(1, counter.atAnnotationMethodAnnotationCounter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -22,16 +22,19 @@ import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
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.xml.AbstractListableBeanFactoryTests;
|
import org.springframework.beans.factory.xml.AbstractListableBeanFactoryTests;
|
||||||
import org.springframework.tests.sample.beans.LifecycleBean;
|
import org.springframework.tests.sample.beans.LifecycleBean;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractApplicationContextTests extends AbstractListableBeanFactoryTests {
|
public abstract class AbstractApplicationContextTests extends AbstractListableBeanFactoryTests {
|
||||||
|
|
||||||
|
@ -45,8 +48,8 @@ public abstract class AbstractApplicationContextTests extends AbstractListableBe
|
||||||
|
|
||||||
protected TestListener parentListener = new TestListener();
|
protected TestListener parentListener = new TestListener();
|
||||||
|
|
||||||
@Override
|
@Before
|
||||||
protected void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
this.applicationContext = createContext();
|
this.applicationContext = createContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +70,8 @@ public abstract class AbstractApplicationContextTests extends AbstractListableBe
|
||||||
*/
|
*/
|
||||||
protected abstract ConfigurableApplicationContext createContext() throws Exception;
|
protected abstract ConfigurableApplicationContext createContext() throws Exception;
|
||||||
|
|
||||||
public void testContextAwareSingletonWasCalledBack() throws Exception {
|
@Test
|
||||||
|
public void contextAwareSingletonWasCalledBack() throws Exception {
|
||||||
ACATester aca = (ACATester) applicationContext.getBean("aca");
|
ACATester aca = (ACATester) applicationContext.getBean("aca");
|
||||||
assertTrue("has had context set", aca.getApplicationContext() == applicationContext);
|
assertTrue("has had context set", aca.getApplicationContext() == applicationContext);
|
||||||
Object aca2 = applicationContext.getBean("aca");
|
Object aca2 = applicationContext.getBean("aca");
|
||||||
|
@ -75,7 +79,8 @@ public abstract class AbstractApplicationContextTests extends AbstractListableBe
|
||||||
assertTrue("Says is singleton", applicationContext.isSingleton("aca"));
|
assertTrue("Says is singleton", applicationContext.isSingleton("aca"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testContextAwarePrototypeWasCalledBack() throws Exception {
|
@Test
|
||||||
|
public void contextAwarePrototypeWasCalledBack() throws Exception {
|
||||||
ACATester aca = (ACATester) applicationContext.getBean("aca-prototype");
|
ACATester aca = (ACATester) applicationContext.getBean("aca-prototype");
|
||||||
assertTrue("has had context set", aca.getApplicationContext() == applicationContext);
|
assertTrue("has had context set", aca.getApplicationContext() == applicationContext);
|
||||||
Object aca2 = applicationContext.getBean("aca-prototype");
|
Object aca2 = applicationContext.getBean("aca-prototype");
|
||||||
|
@ -83,30 +88,36 @@ public abstract class AbstractApplicationContextTests extends AbstractListableBe
|
||||||
assertTrue("Says is prototype", !applicationContext.isSingleton("aca-prototype"));
|
assertTrue("Says is prototype", !applicationContext.isSingleton("aca-prototype"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParentNonNull() {
|
@Test
|
||||||
|
public void parentNonNull() {
|
||||||
assertTrue("parent isn't null", applicationContext.getParent() != null);
|
assertTrue("parent isn't null", applicationContext.getParent() != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGrandparentNull() {
|
@Test
|
||||||
|
public void grandparentNull() {
|
||||||
assertTrue("grandparent is null", applicationContext.getParent().getParent() == null);
|
assertTrue("grandparent is null", applicationContext.getParent().getParent() == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOverrideWorked() throws Exception {
|
@Test
|
||||||
|
public void overrideWorked() throws Exception {
|
||||||
TestBean rod = (TestBean) applicationContext.getParent().getBean("rod");
|
TestBean rod = (TestBean) applicationContext.getParent().getBean("rod");
|
||||||
assertTrue("Parent's name differs", rod.getName().equals("Roderick"));
|
assertTrue("Parent's name differs", rod.getName().equals("Roderick"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGrandparentDefinitionFound() throws Exception {
|
@Test
|
||||||
|
public void grandparentDefinitionFound() throws Exception {
|
||||||
TestBean dad = (TestBean) applicationContext.getBean("father");
|
TestBean dad = (TestBean) applicationContext.getBean("father");
|
||||||
assertTrue("Dad has correct name", dad.getName().equals("Albert"));
|
assertTrue("Dad has correct name", dad.getName().equals("Albert"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGrandparentTypedDefinitionFound() throws Exception {
|
@Test
|
||||||
|
public void grandparentTypedDefinitionFound() throws Exception {
|
||||||
TestBean dad = applicationContext.getBean("father", TestBean.class);
|
TestBean dad = applicationContext.getBean("father", TestBean.class);
|
||||||
assertTrue("Dad has correct name", dad.getName().equals("Albert"));
|
assertTrue("Dad has correct name", dad.getName().equals("Albert"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCloseTriggersDestroy() {
|
@Test
|
||||||
|
public void closeTriggersDestroy() {
|
||||||
LifecycleBean lb = (LifecycleBean) applicationContext.getBean("lifecycle");
|
LifecycleBean lb = (LifecycleBean) applicationContext.getBean("lifecycle");
|
||||||
assertTrue("Not destroyed", !lb.isDestroyed());
|
assertTrue("Not destroyed", !lb.isDestroyed());
|
||||||
applicationContext.close();
|
applicationContext.close();
|
||||||
|
@ -121,25 +132,21 @@ public abstract class AbstractApplicationContextTests extends AbstractListableBe
|
||||||
assertTrue("Destroyed", lb.isDestroyed());
|
assertTrue("Destroyed", lb.isDestroyed());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMessageSource() throws NoSuchMessageException {
|
@Test(expected = NoSuchMessageException.class)
|
||||||
|
public void messageSource() throws NoSuchMessageException {
|
||||||
assertEquals("message1", applicationContext.getMessage("code1", null, Locale.getDefault()));
|
assertEquals("message1", applicationContext.getMessage("code1", null, Locale.getDefault()));
|
||||||
assertEquals("message2", applicationContext.getMessage("code2", null, Locale.getDefault()));
|
assertEquals("message2", applicationContext.getMessage("code2", null, Locale.getDefault()));
|
||||||
|
|
||||||
try {
|
applicationContext.getMessage("code0", null, Locale.getDefault());
|
||||||
applicationContext.getMessage("code0", null, Locale.getDefault());
|
|
||||||
fail("looking for code0 should throw a NoSuchMessageException");
|
|
||||||
}
|
|
||||||
catch (NoSuchMessageException ex) {
|
|
||||||
// that's how it should be
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEvents() throws Exception {
|
@Test
|
||||||
|
public void events() throws Exception {
|
||||||
doTestEvents(this.listener, this.parentListener, new MyEvent(this));
|
doTestEvents(this.listener, this.parentListener, new MyEvent(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEventsWithNoSource() throws Exception {
|
public void eventsWithNoSource() throws Exception {
|
||||||
// See SPR-10945 Serialized events result in a null source
|
// See SPR-10945 Serialized events result in a null source
|
||||||
MyEvent event = new MyEvent(this);
|
MyEvent event = new MyEvent(this);
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
|
@ -162,7 +169,8 @@ public abstract class AbstractApplicationContextTests extends AbstractListableBe
|
||||||
assertTrue("1 parent events after publication", parentListener.getEventCount() == 1);
|
assertTrue("1 parent events after publication", parentListener.getEventCount() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBeanAutomaticallyHearsEvents() throws Exception {
|
@Test
|
||||||
|
public void beanAutomaticallyHearsEvents() throws Exception {
|
||||||
//String[] listenerNames = ((ListableBeanFactory) applicationContext).getBeanDefinitionNames(ApplicationListener.class);
|
//String[] listenerNames = ((ListableBeanFactory) applicationContext).getBeanDefinitionNames(ApplicationListener.class);
|
||||||
//assertTrue("listeners include beanThatListens", Arrays.asList(listenerNames).contains("beanThatListens"));
|
//assertTrue("listeners include beanThatListens", Arrays.asList(listenerNames).contains("beanThatListens"));
|
||||||
BeanThatListens b = (BeanThatListens) applicationContext.getBean("beanThatListens");
|
BeanThatListens b = (BeanThatListens) applicationContext.getBean("beanThatListens");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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,7 @@ import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
|
@ -28,11 +28,13 @@ import org.springframework.beans.factory.access.BootstrapException;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.tests.mock.jndi.SimpleNamingContextBuilder;
|
import org.springframework.tests.mock.jndi.SimpleNamingContextBuilder;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Colin Sampaleanu
|
* @author Colin Sampaleanu
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public final class ContextJndiBeanFactoryLocatorTests extends TestCase {
|
public final class ContextJndiBeanFactoryLocatorTests {
|
||||||
|
|
||||||
private static final String BEAN_FACTORY_PATH_ENVIRONMENT_KEY = "java:comp/env/ejb/BeanFactoryPath";
|
private static final String BEAN_FACTORY_PATH_ENVIRONMENT_KEY = "java:comp/env/ejb/BeanFactoryPath";
|
||||||
|
|
||||||
|
@ -45,7 +47,8 @@ public final class ContextJndiBeanFactoryLocatorTests extends TestCase {
|
||||||
private static final String PARENT_CONTEXT = FQ_PATH + CLASSNAME + "-parent.xml";
|
private static final String PARENT_CONTEXT = FQ_PATH + CLASSNAME + "-parent.xml";
|
||||||
|
|
||||||
|
|
||||||
public void testBeanFactoryPathRequiredFromJndiEnvironment() throws Exception {
|
@Test
|
||||||
|
public void beanFactoryPathRequiredFromJndiEnvironment() throws Exception {
|
||||||
// Set up initial context but don't bind anything
|
// Set up initial context but don't bind anything
|
||||||
SimpleNamingContextBuilder.emptyActivatedContextBuilder();
|
SimpleNamingContextBuilder.emptyActivatedContextBuilder();
|
||||||
|
|
||||||
|
@ -60,7 +63,8 @@ public final class ContextJndiBeanFactoryLocatorTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBeanFactoryPathFromJndiEnvironmentNotFound() throws Exception {
|
@Test
|
||||||
|
public void beanFactoryPathFromJndiEnvironmentNotFound() throws Exception {
|
||||||
SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
|
SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
|
||||||
|
|
||||||
String bogusPath = "RUBBISH/com/xxxx/framework/server/test1.xml";
|
String bogusPath = "RUBBISH/com/xxxx/framework/server/test1.xml";
|
||||||
|
@ -79,7 +83,8 @@ public final class ContextJndiBeanFactoryLocatorTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBeanFactoryPathFromJndiEnvironmentNotValidXml() throws Exception {
|
@Test
|
||||||
|
public void beanFactoryPathFromJndiEnvironmentNotValidXml() throws Exception {
|
||||||
SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
|
SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
|
||||||
|
|
||||||
String nonXmlPath = "com/xxxx/framework/server/SlsbEndpointBean.class";
|
String nonXmlPath = "com/xxxx/framework/server/SlsbEndpointBean.class";
|
||||||
|
@ -98,7 +103,8 @@ public final class ContextJndiBeanFactoryLocatorTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBeanFactoryPathFromJndiEnvironmentWithSingleFile() throws Exception {
|
@Test
|
||||||
|
public void beanFactoryPathFromJndiEnvironmentWithSingleFile() throws Exception {
|
||||||
SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
|
SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
|
||||||
|
|
||||||
// Set up initial context
|
// Set up initial context
|
||||||
|
@ -110,7 +116,8 @@ public final class ContextJndiBeanFactoryLocatorTests extends TestCase {
|
||||||
assertTrue(bf instanceof ApplicationContext);
|
assertTrue(bf instanceof ApplicationContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBeanFactoryPathFromJndiEnvironmentWithMultipleFiles() throws Exception {
|
@Test
|
||||||
|
public void beanFactoryPathFromJndiEnvironmentWithMultipleFiles() throws Exception {
|
||||||
SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
|
SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
|
||||||
|
|
||||||
String path = String.format("%s %s", COLLECTIONS_CONTEXT, PARENT_CONTEXT);
|
String path = String.format("%s %s", COLLECTIONS_CONTEXT, PARENT_CONTEXT);
|
||||||
|
|
|
@ -16,19 +16,22 @@
|
||||||
|
|
||||||
package org.springframework.context.access;
|
package org.springframework.context.access;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.springframework.beans.factory.access.BeanFactoryLocator;
|
import org.springframework.beans.factory.access.BeanFactoryLocator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Colin Sampaleanu
|
* @author Colin Sampaleanu
|
||||||
*/
|
*/
|
||||||
public class DefaultLocatorFactoryTests extends TestCase {
|
public class DefaultLocatorFactoryTests {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class to test for BeanFactoryLocator getInstance()
|
* Class to test for BeanFactoryLocator getInstance()
|
||||||
*/
|
*/
|
||||||
public void testGetInstance() {
|
@Test
|
||||||
|
public void getInstance() {
|
||||||
BeanFactoryLocator bf = DefaultLocatorFactory.getInstance();
|
BeanFactoryLocator bf = DefaultLocatorFactory.getInstance();
|
||||||
BeanFactoryLocator bf2 = DefaultLocatorFactory.getInstance();
|
BeanFactoryLocator bf2 = DefaultLocatorFactory.getInstance();
|
||||||
assertTrue(bf.equals(bf2));
|
assertTrue(bf.equals(bf2));
|
||||||
|
@ -37,7 +40,8 @@ public class DefaultLocatorFactoryTests extends TestCase {
|
||||||
/*
|
/*
|
||||||
* Class to test for BeanFactoryLocator getInstance(String)
|
* Class to test for BeanFactoryLocator getInstance(String)
|
||||||
*/
|
*/
|
||||||
public void testGetInstanceString() {
|
@Test
|
||||||
|
public void getInstanceString() {
|
||||||
BeanFactoryLocator bf = DefaultLocatorFactory.getInstance("my-bean-refs.xml");
|
BeanFactoryLocator bf = DefaultLocatorFactory.getInstance("my-bean-refs.xml");
|
||||||
BeanFactoryLocator bf2 = DefaultLocatorFactory.getInstance("my-bean-refs.xml");
|
BeanFactoryLocator bf2 = DefaultLocatorFactory.getInstance("my-bean-refs.xml");
|
||||||
assertTrue(bf.equals(bf2));
|
assertTrue(bf.equals(bf2));
|
||||||
|
|
|
@ -27,7 +27,6 @@ import org.hamcrest.Matcher;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.InOrder;
|
import org.mockito.InOrder;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
|
@ -35,7 +34,6 @@ import org.springframework.beans.factory.BeanFactoryAware;
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.context.EnvironmentAware;
|
import org.springframework.context.EnvironmentAware;
|
||||||
import org.springframework.context.MessageSource;
|
|
||||||
import org.springframework.context.ResourceLoaderAware;
|
import org.springframework.context.ResourceLoaderAware;
|
||||||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrarTests.SampleRegistrar;
|
import org.springframework.context.annotation.ImportBeanDefinitionRegistrarTests.SampleRegistrar;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
|
@ -53,6 +51,7 @@ import static org.mockito.Mockito.*;
|
||||||
*
|
*
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("resource")
|
||||||
public class ImportSelectorTests {
|
public class ImportSelectorTests {
|
||||||
|
|
||||||
static Map<Class<?>, String> importFrom = new HashMap<Class<?>, String>();
|
static Map<Class<?>, String> importFrom = new HashMap<Class<?>, String>();
|
||||||
|
@ -81,7 +80,6 @@ public class ImportSelectorTests {
|
||||||
@Test
|
@Test
|
||||||
public void invokeAwareMethodsInImportSelector() {
|
public void invokeAwareMethodsInImportSelector() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AwareConfig.class);
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AwareConfig.class);
|
||||||
context.getBean(MessageSource.class);
|
|
||||||
assertThat(SampleRegistrar.beanFactory, is((BeanFactory) context.getBeanFactory()));
|
assertThat(SampleRegistrar.beanFactory, is((BeanFactory) context.getBeanFactory()));
|
||||||
assertThat(SampleRegistrar.classLoader, is(context.getBeanFactory().getBeanClassLoader()));
|
assertThat(SampleRegistrar.classLoader, is(context.getBeanFactory().getBeanClassLoader()));
|
||||||
assertThat(SampleRegistrar.resourceLoader, is(notNullValue()));
|
assertThat(SampleRegistrar.resourceLoader, is(notNullValue()));
|
||||||
|
@ -90,7 +88,7 @@ public class ImportSelectorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void correctMetaDataOnIndirectImports() throws Exception {
|
public void correctMetaDataOnIndirectImports() throws Exception {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(IndirectConfig.class);
|
new AnnotationConfigApplicationContext(IndirectConfig.class);
|
||||||
Matcher<String> isFromIndirect = equalTo(IndirectImport.class.getName());
|
Matcher<String> isFromIndirect = equalTo(IndirectImport.class.getName());
|
||||||
assertThat(importFrom.get(ImportSelector1.class), isFromIndirect);
|
assertThat(importFrom.get(ImportSelector1.class), isFromIndirect);
|
||||||
assertThat(importFrom.get(ImportSelector2.class), isFromIndirect);
|
assertThat(importFrom.get(ImportSelector2.class), isFromIndirect);
|
||||||
|
|
|
@ -50,7 +50,7 @@ import static org.junit.Assert.*;
|
||||||
public class ImportResourceTests {
|
public class ImportResourceTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImportXml() {
|
public void importXml() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlConfig.class);
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlConfig.class);
|
||||||
assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean"));
|
assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean"));
|
||||||
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
||||||
|
@ -61,7 +61,7 @@ public class ImportResourceTests {
|
||||||
|
|
||||||
@Ignore // TODO: SPR-6310
|
@Ignore // TODO: SPR-6310
|
||||||
@Test
|
@Test
|
||||||
public void testImportXmlWithRelativePath() {
|
public void importXmlWithRelativePath() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithRelativePathConfig.class);
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithRelativePathConfig.class);
|
||||||
assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean"));
|
assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean"));
|
||||||
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
||||||
|
@ -72,7 +72,7 @@ public class ImportResourceTests {
|
||||||
|
|
||||||
@Ignore // TODO: SPR-6310
|
@Ignore // TODO: SPR-6310
|
||||||
@Test
|
@Test
|
||||||
public void testImportXmlByConvention() {
|
public void importXmlByConvention() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
|
||||||
ImportXmlByConventionConfig.class);
|
ImportXmlByConventionConfig.class);
|
||||||
assertTrue("context does not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
assertTrue("context does not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
||||||
|
@ -80,14 +80,14 @@ public class ImportResourceTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImportXmlIsInheritedFromSuperclassDeclarations() {
|
public void importXmlIsInheritedFromSuperclassDeclarations() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(FirstLevelSubConfig.class);
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(FirstLevelSubConfig.class);
|
||||||
assertTrue(ctx.containsBean("xmlDeclaredBean"));
|
assertTrue(ctx.containsBean("xmlDeclaredBean"));
|
||||||
ctx.close();
|
ctx.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImportXmlIsMergedFromSuperclassDeclarations() {
|
public void importXmlIsMergedFromSuperclassDeclarations() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SecondLevelSubConfig.class);
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SecondLevelSubConfig.class);
|
||||||
assertTrue("failed to pick up second-level-declared XML bean", ctx.containsBean("secondLevelXmlDeclaredBean"));
|
assertTrue("failed to pick up second-level-declared XML bean", ctx.containsBean("secondLevelXmlDeclaredBean"));
|
||||||
assertTrue("failed to pick up parent-declared XML bean", ctx.containsBean("xmlDeclaredBean"));
|
assertTrue("failed to pick up parent-declared XML bean", ctx.containsBean("xmlDeclaredBean"));
|
||||||
|
@ -95,7 +95,7 @@ public class ImportResourceTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImportXmlWithNamespaceConfig() {
|
public void importXmlWithNamespaceConfig() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithAopNamespaceConfig.class);
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithAopNamespaceConfig.class);
|
||||||
Object bean = ctx.getBean("proxiedXmlBean");
|
Object bean = ctx.getBean("proxiedXmlBean");
|
||||||
assertTrue(AopUtils.isAopProxy(bean));
|
assertTrue(AopUtils.isAopProxy(bean));
|
||||||
|
@ -103,7 +103,7 @@ public class ImportResourceTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImportXmlWithOtherConfigurationClass() {
|
public void importXmlWithOtherConfigurationClass() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithConfigurationClass.class);
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithConfigurationClass.class);
|
||||||
assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean"));
|
assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean"));
|
||||||
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
||||||
|
@ -114,7 +114,7 @@ public class ImportResourceTests {
|
||||||
|
|
||||||
@Ignore // TODO: SPR-6327
|
@Ignore // TODO: SPR-6327
|
||||||
@Test
|
@Test
|
||||||
public void testImportDifferentResourceTypes() {
|
public void importDifferentResourceTypes() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SubResourceConfig.class);
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SubResourceConfig.class);
|
||||||
assertTrue(ctx.containsBean("propertiesDeclaredBean"));
|
assertTrue(ctx.containsBean("propertiesDeclaredBean"));
|
||||||
assertTrue(ctx.containsBean("xmlDeclaredBean"));
|
assertTrue(ctx.containsBean("xmlDeclaredBean"));
|
||||||
|
@ -134,7 +134,7 @@ public class ImportResourceTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImportXmlWithAutowiredConfig() {
|
public void importXmlWithAutowiredConfig() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlAutowiredConfig.class);
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlAutowiredConfig.class);
|
||||||
String name = ctx.getBean("xmlBeanName", String.class);
|
String name = ctx.getBean("xmlBeanName", String.class);
|
||||||
assertThat(name, equalTo("xml.declared"));
|
assertThat(name, equalTo("xml.declared"));
|
||||||
|
@ -142,7 +142,7 @@ public class ImportResourceTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImportNonXmlResource() {
|
public void importNonXmlResource() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportNonXmlResourceConfig.class);
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportNonXmlResourceConfig.class);
|
||||||
assertTrue(ctx.containsBean("propertiesDeclaredBean"));
|
assertTrue(ctx.containsBean("propertiesDeclaredBean"));
|
||||||
ctx.close();
|
ctx.close();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.context.event;
|
package org.springframework.context.event;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
@ -24,13 +24,16 @@ import org.springframework.context.ApplicationListener;
|
||||||
import org.springframework.context.Lifecycle;
|
import org.springframework.context.Lifecycle;
|
||||||
import org.springframework.context.support.StaticApplicationContext;
|
import org.springframework.context.support.StaticApplicationContext;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class LifecycleEventTests extends TestCase {
|
public class LifecycleEventTests {
|
||||||
|
|
||||||
public void testContextStartedEvent() {
|
@Test
|
||||||
|
public void contextStartedEvent() {
|
||||||
StaticApplicationContext context = new StaticApplicationContext();
|
StaticApplicationContext context = new StaticApplicationContext();
|
||||||
context.registerSingleton("lifecycle", LifecycleTestBean.class);
|
context.registerSingleton("lifecycle", LifecycleTestBean.class);
|
||||||
context.registerSingleton("listener", LifecycleListener.class);
|
context.registerSingleton("listener", LifecycleListener.class);
|
||||||
|
@ -45,7 +48,8 @@ public class LifecycleEventTests extends TestCase {
|
||||||
assertSame(context, listener.getApplicationContext());
|
assertSame(context, listener.getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testContextStoppedEvent() {
|
@Test
|
||||||
|
public void contextStoppedEvent() {
|
||||||
StaticApplicationContext context = new StaticApplicationContext();
|
StaticApplicationContext context = new StaticApplicationContext();
|
||||||
context.registerSingleton("lifecycle", LifecycleTestBean.class);
|
context.registerSingleton("lifecycle", LifecycleTestBean.class);
|
||||||
context.registerSingleton("listener", LifecycleListener.class);
|
context.registerSingleton("listener", LifecycleListener.class);
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2015 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package org.springframework.context.support;
|
package org.springframework.context.support;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
@ -5,6 +21,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
|
|
|
@ -20,6 +20,8 @@ import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.MutablePropertyValues;
|
import org.springframework.beans.MutablePropertyValues;
|
||||||
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
|
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
|
||||||
import org.springframework.context.ACATester;
|
import org.springframework.context.ACATester;
|
||||||
|
@ -34,6 +36,8 @@ import org.springframework.core.io.Resource;
|
||||||
import org.springframework.core.io.support.EncodedResource;
|
import org.springframework.core.io.support.EncodedResource;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for static application context with custom application event multicaster.
|
* Tests for static application context with custom application event multicaster.
|
||||||
*
|
*
|
||||||
|
@ -43,7 +47,6 @@ public class StaticApplicationContextMulticasterTests extends AbstractApplicatio
|
||||||
|
|
||||||
protected StaticApplicationContext sac;
|
protected StaticApplicationContext sac;
|
||||||
|
|
||||||
/** Run for each test */
|
|
||||||
@Override
|
@Override
|
||||||
protected ConfigurableApplicationContext createContext() throws Exception {
|
protected ConfigurableApplicationContext createContext() throws Exception {
|
||||||
StaticApplicationContext parent = new StaticApplicationContext();
|
StaticApplicationContext parent = new StaticApplicationContext();
|
||||||
|
@ -74,16 +77,17 @@ public class StaticApplicationContextMulticasterTests extends AbstractApplicatio
|
||||||
return sac;
|
return sac;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Overridden */
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testCount() {
|
public void count() {
|
||||||
assertCount(15);
|
assertCount(15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testEvents() throws Exception {
|
public void events() throws Exception {
|
||||||
TestApplicationEventMulticaster.counter = 0;
|
TestApplicationEventMulticaster.counter = 0;
|
||||||
super.testEvents();
|
super.events();
|
||||||
assertEquals(1, TestApplicationEventMulticaster.counter);
|
assertEquals(1, TestApplicationEventMulticaster.counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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,6 +20,8 @@ import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.MutablePropertyValues;
|
import org.springframework.beans.MutablePropertyValues;
|
||||||
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
|
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
|
||||||
import org.springframework.context.ACATester;
|
import org.springframework.context.ACATester;
|
||||||
|
@ -38,7 +40,6 @@ public class StaticApplicationContextTests extends AbstractApplicationContextTes
|
||||||
|
|
||||||
protected StaticApplicationContext sac;
|
protected StaticApplicationContext sac;
|
||||||
|
|
||||||
/** Run for each test */
|
|
||||||
@Override
|
@Override
|
||||||
protected ConfigurableApplicationContext createContext() throws Exception {
|
protected ConfigurableApplicationContext createContext() throws Exception {
|
||||||
StaticApplicationContext parent = new StaticApplicationContext();
|
StaticApplicationContext parent = new StaticApplicationContext();
|
||||||
|
@ -66,9 +67,9 @@ public class StaticApplicationContextTests extends AbstractApplicationContextTes
|
||||||
return sac;
|
return sac;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Overridden */
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testCount() {
|
public void count() {
|
||||||
assertCount(15);
|
assertCount(15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -21,6 +21,10 @@ import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
import org.springframework.beans.MutablePropertyValues;
|
import org.springframework.beans.MutablePropertyValues;
|
||||||
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
|
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
|
||||||
import org.springframework.context.ACATester;
|
import org.springframework.context.ACATester;
|
||||||
|
@ -31,9 +35,12 @@ import org.springframework.context.MessageSourceResolvable;
|
||||||
import org.springframework.context.NoSuchMessageException;
|
import org.springframework.context.NoSuchMessageException;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class StaticMessageSourceTests extends AbstractApplicationContextTests {
|
public class StaticMessageSourceTests extends AbstractApplicationContextTests {
|
||||||
|
|
||||||
|
@ -48,27 +55,34 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
|
||||||
|
|
||||||
protected StaticApplicationContext sac;
|
protected StaticApplicationContext sac;
|
||||||
|
|
||||||
/** Overridden */
|
@Rule
|
||||||
|
public final ExpectedException exception = ExpectedException.none();
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testCount() {
|
public void count() {
|
||||||
// These are only checked for current Ctx (not parent ctx)
|
// These are only checked for current Ctx (not parent ctx)
|
||||||
assertCount(15);
|
assertCount(15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testMessageSource() throws NoSuchMessageException {
|
public void messageSource() throws NoSuchMessageException {
|
||||||
// Do nothing here since super is looking for errorCodes we
|
// Do nothing here since super is looking for errorCodes we
|
||||||
// do NOT have in the Context
|
// do NOT have in the Context
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetMessageWithDefaultPassedInAndFoundInMsgCatalog() {
|
@Test
|
||||||
|
public void getMessageWithDefaultPassedInAndFoundInMsgCatalog() {
|
||||||
// Try with Locale.US
|
// Try with Locale.US
|
||||||
assertTrue("valid msg from staticMsgSource with default msg passed in returned msg from msg catalog for Locale.US",
|
assertTrue("valid msg from staticMsgSource with default msg passed in returned msg from msg catalog for Locale.US",
|
||||||
sac.getMessage("message.format.example2", null, "This is a default msg if not found in MessageSource.", Locale.US)
|
sac.getMessage("message.format.example2", null, "This is a default msg if not found in MessageSource.", Locale.US)
|
||||||
.equals("This is a test message in the message catalog with no args."));
|
.equals("This is a test message in the message catalog with no args."));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetMessageWithDefaultPassedInAndNotFoundInMsgCatalog() {
|
@Test
|
||||||
|
public void getMessageWithDefaultPassedInAndNotFoundInMsgCatalog() {
|
||||||
// Try with Locale.US
|
// Try with Locale.US
|
||||||
assertTrue("bogus msg from staticMsgSource with default msg passed in returned default msg for Locale.US",
|
assertTrue("bogus msg from staticMsgSource with default msg passed in returned default msg for Locale.US",
|
||||||
sac.getMessage("bogus.message", null, "This is a default msg if not found in MessageSource.", Locale.US)
|
sac.getMessage("bogus.message", null, "This is a default msg if not found in MessageSource.", Locale.US)
|
||||||
|
@ -82,7 +96,8 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
|
||||||
* make sure the cache is being used properly.
|
* make sure the cache is being used properly.
|
||||||
* @see org.springframework.context.support.AbstractMessageSource for more details.
|
* @see org.springframework.context.support.AbstractMessageSource for more details.
|
||||||
*/
|
*/
|
||||||
public void testGetMessageWithMessageAlreadyLookedFor() {
|
@Test
|
||||||
|
public void getMessageWithMessageAlreadyLookedFor() {
|
||||||
Object[] arguments = {
|
Object[] arguments = {
|
||||||
new Integer(7), new Date(System.currentTimeMillis()),
|
new Integer(7), new Date(System.currentTimeMillis()),
|
||||||
"a disturbance in the Force"
|
"a disturbance in the Force"
|
||||||
|
@ -111,7 +126,8 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
|
||||||
/**
|
/**
|
||||||
* Example taken from the javadocs for the java.text.MessageFormat class
|
* Example taken from the javadocs for the java.text.MessageFormat class
|
||||||
*/
|
*/
|
||||||
public void testGetMessageWithNoDefaultPassedInAndFoundInMsgCatalog() {
|
@Test
|
||||||
|
public void getMessageWithNoDefaultPassedInAndFoundInMsgCatalog() {
|
||||||
Object[] arguments = {
|
Object[] arguments = {
|
||||||
new Integer(7), new Date(System.currentTimeMillis()),
|
new Integer(7), new Date(System.currentTimeMillis()),
|
||||||
"a disturbance in the Force"
|
"a disturbance in the Force"
|
||||||
|
@ -140,63 +156,37 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
|
||||||
.equals("This is a test message in the message catalog with no args."));
|
.equals("This is a test message in the message catalog with no args."));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetMessageWithNoDefaultPassedInAndNotFoundInMsgCatalog() {
|
@Test(expected = NoSuchMessageException.class)
|
||||||
// Expecting an exception
|
public void getMessageWithNoDefaultPassedInAndNotFoundInMsgCatalog() {
|
||||||
try {
|
// Try with Locale.US
|
||||||
// Try with Locale.US
|
sac.getMessage("bogus.message", null, Locale.US);
|
||||||
sac.getMessage("bogus.message", null, Locale.US);
|
|
||||||
|
|
||||||
fail("bogus msg from staticMsgSource for Locale.US without default msg should have thrown exception");
|
|
||||||
}
|
|
||||||
catch (NoSuchMessageException tExcept) {
|
|
||||||
assertTrue("bogus msg from staticMsgSource for Locale.US without default msg threw expected exception", true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMessageSourceResolvable() {
|
@Test
|
||||||
|
public void messageSourceResolvable() {
|
||||||
// first code valid
|
// first code valid
|
||||||
String[] codes1 = new String[] {"message.format.example3", "message.format.example2"};
|
String[] codes1 = new String[] {"message.format.example3", "message.format.example2"};
|
||||||
MessageSourceResolvable resolvable1 = new DefaultMessageSourceResolvable(codes1, null, "default");
|
MessageSourceResolvable resolvable1 = new DefaultMessageSourceResolvable(codes1, null, "default");
|
||||||
try {
|
assertTrue("correct message retrieved", MSG_TXT3_US.equals(sac.getMessage(resolvable1, Locale.US)));
|
||||||
assertTrue("correct message retrieved", MSG_TXT3_US.equals(sac.getMessage(resolvable1, Locale.US)));
|
|
||||||
}
|
|
||||||
catch (NoSuchMessageException ex) {
|
|
||||||
fail("Should not throw NoSuchMessageException");
|
|
||||||
}
|
|
||||||
|
|
||||||
// only second code valid
|
// only second code valid
|
||||||
String[] codes2 = new String[] {"message.format.example99", "message.format.example2"};
|
String[] codes2 = new String[] {"message.format.example99", "message.format.example2"};
|
||||||
MessageSourceResolvable resolvable2 = new DefaultMessageSourceResolvable(codes2, null, "default");
|
MessageSourceResolvable resolvable2 = new DefaultMessageSourceResolvable(codes2, null, "default");
|
||||||
try {
|
assertTrue("correct message retrieved", MSG_TXT2_US.equals(sac.getMessage(resolvable2, Locale.US)));
|
||||||
assertTrue("correct message retrieved", MSG_TXT2_US.equals(sac.getMessage(resolvable2, Locale.US)));
|
|
||||||
}
|
|
||||||
catch (NoSuchMessageException ex) {
|
|
||||||
fail("Should not throw NoSuchMessageException");
|
|
||||||
}
|
|
||||||
|
|
||||||
// no code valid, but default given
|
// no code valid, but default given
|
||||||
String[] codes3 = new String[] {"message.format.example99", "message.format.example98"};
|
String[] codes3 = new String[] {"message.format.example99", "message.format.example98"};
|
||||||
MessageSourceResolvable resolvable3 = new DefaultMessageSourceResolvable(codes3, null, "default");
|
MessageSourceResolvable resolvable3 = new DefaultMessageSourceResolvable(codes3, null, "default");
|
||||||
try {
|
assertTrue("correct message retrieved", "default".equals(sac.getMessage(resolvable3, Locale.US)));
|
||||||
assertTrue("correct message retrieved", "default".equals(sac.getMessage(resolvable3, Locale.US)));
|
|
||||||
}
|
|
||||||
catch (NoSuchMessageException ex) {
|
|
||||||
fail("Should not throw NoSuchMessageException");
|
|
||||||
}
|
|
||||||
|
|
||||||
// no code valid, no default
|
// no code valid, no default
|
||||||
String[] codes4 = new String[] {"message.format.example99", "message.format.example98"};
|
String[] codes4 = new String[] {"message.format.example99", "message.format.example98"};
|
||||||
MessageSourceResolvable resolvable4 = new DefaultMessageSourceResolvable(codes4);
|
MessageSourceResolvable resolvable4 = new DefaultMessageSourceResolvable(codes4);
|
||||||
try {
|
|
||||||
sac.getMessage(resolvable4, Locale.US);
|
exception.expect(NoSuchMessageException.class);
|
||||||
fail("Should have thrown NoSuchMessageException");
|
sac.getMessage(resolvable4, Locale.US);
|
||||||
}
|
|
||||||
catch (NoSuchMessageException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Run for each test */
|
|
||||||
@Override
|
@Override
|
||||||
protected ConfigurableApplicationContext createContext() throws Exception {
|
protected ConfigurableApplicationContext createContext() throws Exception {
|
||||||
StaticApplicationContext parent = new StaticApplicationContext();
|
StaticApplicationContext parent = new StaticApplicationContext();
|
||||||
|
@ -234,7 +224,8 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
|
||||||
return sac;
|
return sac;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNestedMessageSourceWithParamInChild() {
|
@Test
|
||||||
|
public void nestedMessageSourceWithParamInChild() {
|
||||||
StaticMessageSource source = new StaticMessageSource();
|
StaticMessageSource source = new StaticMessageSource();
|
||||||
StaticMessageSource parent = new StaticMessageSource();
|
StaticMessageSource parent = new StaticMessageSource();
|
||||||
source.setParentMessageSource(parent);
|
source.setParentMessageSource(parent);
|
||||||
|
@ -248,7 +239,8 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
|
||||||
assertEquals("put value here", source.getMessage(resolvable, Locale.ENGLISH));
|
assertEquals("put value here", source.getMessage(resolvable, Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNestedMessageSourceWithParamInParent() {
|
@Test
|
||||||
|
public void nestedMessageSourceWithParamInParent() {
|
||||||
StaticMessageSource source = new StaticMessageSource();
|
StaticMessageSource source = new StaticMessageSource();
|
||||||
StaticMessageSource parent = new StaticMessageSource();
|
StaticMessageSource parent = new StaticMessageSource();
|
||||||
source.setParentMessageSource(parent);
|
source.setParentMessageSource(parent);
|
||||||
|
|
|
@ -26,6 +26,8 @@ import javax.management.remote.JMXConnectorServer;
|
||||||
import javax.management.remote.JMXConnectorServerFactory;
|
import javax.management.remote.JMXConnectorServerFactory;
|
||||||
import javax.management.remote.JMXServiceURL;
|
import javax.management.remote.JMXServiceURL;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
|
||||||
import org.springframework.tests.Assume;
|
import org.springframework.tests.Assume;
|
||||||
import org.springframework.tests.TestGroup;
|
import org.springframework.tests.TestGroup;
|
||||||
import org.springframework.util.SocketUtils;
|
import org.springframework.util.SocketUtils;
|
||||||
|
@ -78,6 +80,7 @@ public class RemoteMBeanClientInterceptorTests extends MBeanClientInterceptorTes
|
||||||
return this.connector.getMBeanServerConnection();
|
return this.connector.getMBeanServerConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
@Override
|
@Override
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
if (this.connector != null) {
|
if (this.connector != null) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2007 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
@ -19,24 +19,22 @@ package org.springframework.jmx.export;
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
import org.springframework.jmx.support.ObjectNameManager;
|
import org.springframework.jmx.support.ObjectNameManager;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class LazyInitMBeanTests extends TestCase {
|
public class LazyInitMBeanTests {
|
||||||
|
|
||||||
public void testLazyInit() {
|
@Test
|
||||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getApplicationContextPath());
|
public void invokeOnLazyInitBean() throws Exception {
|
||||||
ctx.close();
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("org/springframework/jmx/export/lazyInit.xml");
|
||||||
}
|
|
||||||
|
|
||||||
public void testInvokeOnLazyInitBean() throws Exception {
|
|
||||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getApplicationContextPath());
|
|
||||||
assertFalse(ctx.getBeanFactory().containsSingleton("testBean"));
|
assertFalse(ctx.getBeanFactory().containsSingleton("testBean"));
|
||||||
assertFalse(ctx.getBeanFactory().containsSingleton("testBean2"));
|
assertFalse(ctx.getBeanFactory().containsSingleton("testBean2"));
|
||||||
try {
|
try {
|
||||||
|
@ -50,8 +48,4 @@ public class LazyInitMBeanTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getApplicationContextPath() {
|
|
||||||
return "org/springframework/jmx/export/lazyInit.xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,12 @@
|
||||||
|
|
||||||
package org.springframework.jmx.export.annotation;
|
package org.springframework.jmx.export.annotation;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
@ -29,9 +31,10 @@ import org.springframework.jmx.support.ObjectNameManager;
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class AnnotationLazyInitMBeanTests extends TestCase {
|
public class AnnotationLazyInitMBeanTests {
|
||||||
|
|
||||||
public void testLazyNaming() throws Exception {
|
@Test
|
||||||
|
public void lazyNaming() throws Exception {
|
||||||
ConfigurableApplicationContext ctx =
|
ConfigurableApplicationContext ctx =
|
||||||
new ClassPathXmlApplicationContext("org/springframework/jmx/export/annotation/lazyNaming.xml");
|
new ClassPathXmlApplicationContext("org/springframework/jmx/export/annotation/lazyNaming.xml");
|
||||||
try {
|
try {
|
||||||
|
@ -46,7 +49,8 @@ public class AnnotationLazyInitMBeanTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLazyAssembling() throws Exception {
|
@Test
|
||||||
|
public void lazyAssembling() throws Exception {
|
||||||
System.setProperty("domain", "bean");
|
System.setProperty("domain", "bean");
|
||||||
ConfigurableApplicationContext ctx =
|
ConfigurableApplicationContext ctx =
|
||||||
new ClassPathXmlApplicationContext("org/springframework/jmx/export/annotation/lazyAssembling.xml");
|
new ClassPathXmlApplicationContext("org/springframework/jmx/export/annotation/lazyAssembling.xml");
|
||||||
|
@ -79,7 +83,8 @@ public class AnnotationLazyInitMBeanTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testComponentScan() throws Exception {
|
@Test
|
||||||
|
public void componentScan() throws Exception {
|
||||||
ConfigurableApplicationContext ctx =
|
ConfigurableApplicationContext ctx =
|
||||||
new ClassPathXmlApplicationContext("org/springframework/jmx/export/annotation/componentScan.xml");
|
new ClassPathXmlApplicationContext("org/springframework/jmx/export/annotation/componentScan.xml");
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -16,16 +16,19 @@
|
||||||
|
|
||||||
package org.springframework.jmx.export.assembler;
|
package org.springframework.jmx.export.assembler;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.springframework.jmx.JmxTestBean;
|
import org.springframework.jmx.JmxTestBean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractAutodetectTests extends TestCase {
|
public abstract class AbstractAutodetectTests {
|
||||||
|
|
||||||
public void testAutodetect() throws Exception {
|
@Test
|
||||||
|
public void autodetect() throws Exception {
|
||||||
JmxTestBean bean = new JmxTestBean();
|
JmxTestBean bean = new JmxTestBean();
|
||||||
|
|
||||||
AutodetectCapableMBeanInfoAssembler assembler = getAssembler();
|
AutodetectCapableMBeanInfoAssembler assembler = getAssembler();
|
||||||
|
|
|
@ -16,16 +16,19 @@
|
||||||
|
|
||||||
package org.springframework.jmx.export.naming;
|
package org.springframework.jmx.export.naming;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractNamingStrategyTests extends TestCase {
|
public abstract class AbstractNamingStrategyTests {
|
||||||
|
|
||||||
public void testNaming() throws Exception {
|
@Test
|
||||||
|
public void naming() throws Exception {
|
||||||
ObjectNamingStrategy strat = getStrategy();
|
ObjectNamingStrategy strat = getStrategy();
|
||||||
ObjectName objectName = strat.getObjectName(getManagedResource(), getKey());
|
ObjectName objectName = strat.getObjectName(getManagedResource(), getKey());
|
||||||
assertEquals(objectName.getCanonicalName(), getCorrectObjectName());
|
assertEquals(objectName.getCanonicalName(), getCorrectObjectName());
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2007 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -19,18 +19,21 @@ package org.springframework.jmx.export.naming;
|
||||||
import javax.management.MalformedObjectNameException;
|
import javax.management.MalformedObjectNameException;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.jmx.JmxTestBean;
|
import org.springframework.jmx.JmxTestBean;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
*/
|
*/
|
||||||
public class IdentityNamingStrategyTests extends TestCase {
|
public class IdentityNamingStrategyTests {
|
||||||
|
|
||||||
public void testNaming() throws MalformedObjectNameException {
|
@Test
|
||||||
|
public void naming() throws MalformedObjectNameException {
|
||||||
JmxTestBean bean = new JmxTestBean();
|
JmxTestBean bean = new JmxTestBean();
|
||||||
IdentityNamingStrategy strategy = new IdentityNamingStrategy();
|
IdentityNamingStrategy strategy = new IdentityNamingStrategy();
|
||||||
ObjectName objectName = strategy.getObjectName(bean, "null");
|
ObjectName objectName = strategy.getObjectName(bean, "null");
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.springframework.jmx.support;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
|
||||||
import javax.management.InstanceNotFoundException;
|
import javax.management.InstanceNotFoundException;
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.MBeanServerConnection;
|
import javax.management.MBeanServerConnection;
|
||||||
|
@ -27,6 +28,7 @@ import javax.management.remote.JMXConnector;
|
||||||
import javax.management.remote.JMXConnectorFactory;
|
import javax.management.remote.JMXConnectorFactory;
|
||||||
import javax.management.remote.JMXServiceURL;
|
import javax.management.remote.JMXServiceURL;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.jmx.AbstractMBeanServerTests;
|
import org.springframework.jmx.AbstractMBeanServerTests;
|
||||||
|
@ -41,27 +43,25 @@ import static org.junit.Assert.*;
|
||||||
*
|
*
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
|
public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
|
||||||
|
|
||||||
private static final String OBJECT_NAME = "spring:type=connector,name=test";
|
private static final String OBJECT_NAME = "spring:type=connector,name=test";
|
||||||
private boolean runTests = false;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSetUp() throws Exception {
|
protected void onSetUp() throws Exception {
|
||||||
Assume.group(TestGroup.JMXMP);
|
Assume.group(TestGroup.JMXMP);
|
||||||
runTests = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
@Override
|
@Override
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
if (runTests) {
|
Assume.group(TestGroup.JMXMP, () -> super.tearDown());
|
||||||
super.tearDown();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStartupWithLocatedServer() throws Exception {
|
public void startupWithLocatedServer() throws Exception {
|
||||||
ConnectorServerFactoryBean bean = new ConnectorServerFactoryBean();
|
ConnectorServerFactoryBean bean = new ConnectorServerFactoryBean();
|
||||||
bean.afterPropertiesSet();
|
bean.afterPropertiesSet();
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStartupWithSuppliedServer() throws Exception {
|
public void startupWithSuppliedServer() throws Exception {
|
||||||
//Added a brief snooze here - seems to fix occasional
|
//Added a brief snooze here - seems to fix occasional
|
||||||
//java.net.BindException: Address already in use errors
|
//java.net.BindException: Address already in use errors
|
||||||
Thread.sleep(1);
|
Thread.sleep(1);
|
||||||
|
@ -90,7 +90,7 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRegisterWithMBeanServer() throws Exception {
|
public void registerWithMBeanServer() throws Exception {
|
||||||
//Added a brief snooze here - seems to fix occasional
|
//Added a brief snooze here - seems to fix occasional
|
||||||
//java.net.BindException: Address already in use errors
|
//java.net.BindException: Address already in use errors
|
||||||
Thread.sleep(1);
|
Thread.sleep(1);
|
||||||
|
@ -108,7 +108,7 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoRegisterWithMBeanServer() throws Exception {
|
public void noRegisterWithMBeanServer() throws Exception {
|
||||||
ConnectorServerFactoryBean bean = new ConnectorServerFactoryBean();
|
ConnectorServerFactoryBean bean = new ConnectorServerFactoryBean();
|
||||||
bean.afterPropertiesSet();
|
bean.afterPropertiesSet();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
@ -18,31 +18,39 @@ package org.springframework.jmx.support;
|
||||||
|
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.MBeanServerFactory;
|
import javax.management.MBeanServerFactory;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.util.MBeanTestUtils;
|
import org.springframework.util.MBeanTestUtils;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
*/
|
*/
|
||||||
public class MBeanServerFactoryBeanTests extends TestCase {
|
public class MBeanServerFactoryBeanTests {
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
MBeanTestUtils.resetMBeanServers();
|
MBeanTestUtils.resetMBeanServers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void tearDown() throws Exception {
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
MBeanTestUtils.resetMBeanServers();
|
MBeanTestUtils.resetMBeanServers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetObject() throws Exception {
|
@Test
|
||||||
|
public void getObject() throws Exception {
|
||||||
MBeanServerFactoryBean bean = new MBeanServerFactoryBean();
|
MBeanServerFactoryBean bean = new MBeanServerFactoryBean();
|
||||||
bean.afterPropertiesSet();
|
bean.afterPropertiesSet();
|
||||||
try {
|
try {
|
||||||
|
@ -54,7 +62,8 @@ public class MBeanServerFactoryBeanTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDefaultDomain() throws Exception {
|
@Test
|
||||||
|
public void defaultDomain() throws Exception {
|
||||||
MBeanServerFactoryBean bean = new MBeanServerFactoryBean();
|
MBeanServerFactoryBean bean = new MBeanServerFactoryBean();
|
||||||
bean.setDefaultDomain("foo");
|
bean.setDefaultDomain("foo");
|
||||||
bean.afterPropertiesSet();
|
bean.afterPropertiesSet();
|
||||||
|
@ -67,7 +76,8 @@ public class MBeanServerFactoryBeanTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithLocateExistingAndExistingServer() {
|
@Test
|
||||||
|
public void withLocateExistingAndExistingServer() {
|
||||||
MBeanServer server = MBeanServerFactory.createMBeanServer();
|
MBeanServer server = MBeanServerFactory.createMBeanServer();
|
||||||
try {
|
try {
|
||||||
MBeanServerFactoryBean bean = new MBeanServerFactoryBean();
|
MBeanServerFactoryBean bean = new MBeanServerFactoryBean();
|
||||||
|
@ -86,7 +96,8 @@ public class MBeanServerFactoryBeanTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithLocateExistingAndFallbackToPlatformServer() {
|
@Test
|
||||||
|
public void withLocateExistingAndFallbackToPlatformServer() {
|
||||||
MBeanServerFactoryBean bean = new MBeanServerFactoryBean();
|
MBeanServerFactoryBean bean = new MBeanServerFactoryBean();
|
||||||
bean.setLocateExistingServerIfPossible(true);
|
bean.setLocateExistingServerIfPossible(true);
|
||||||
bean.afterPropertiesSet();
|
bean.afterPropertiesSet();
|
||||||
|
@ -98,7 +109,8 @@ public class MBeanServerFactoryBeanTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithEmptyAgentIdAndFallbackToPlatformServer() {
|
@Test
|
||||||
|
public void withEmptyAgentIdAndFallbackToPlatformServer() {
|
||||||
MBeanServerFactoryBean bean = new MBeanServerFactoryBean();
|
MBeanServerFactoryBean bean = new MBeanServerFactoryBean();
|
||||||
bean.setAgentId("");
|
bean.setAgentId("");
|
||||||
bean.afterPropertiesSet();
|
bean.afterPropertiesSet();
|
||||||
|
@ -110,11 +122,13 @@ public class MBeanServerFactoryBeanTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateMBeanServer() throws Exception {
|
@Test
|
||||||
|
public void createMBeanServer() throws Exception {
|
||||||
testCreation(true, "The server should be available in the list");
|
testCreation(true, "The server should be available in the list");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNewMBeanServer() throws Exception {
|
@Test
|
||||||
|
public void newMBeanServer() throws Exception {
|
||||||
testCreation(false, "The server should not be available in the list");
|
testCreation(false, "The server should not be available in the list");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -29,21 +29,25 @@ import java.rmi.StubNotFoundException;
|
||||||
import java.rmi.UnknownHostException;
|
import java.rmi.UnknownHostException;
|
||||||
import java.rmi.UnmarshalException;
|
import java.rmi.UnmarshalException;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.remoting.RemoteAccessException;
|
import org.springframework.remoting.RemoteAccessException;
|
||||||
import org.springframework.remoting.RemoteConnectFailureException;
|
import org.springframework.remoting.RemoteConnectFailureException;
|
||||||
import org.springframework.remoting.RemoteProxyFailureException;
|
import org.springframework.remoting.RemoteProxyFailureException;
|
||||||
import org.springframework.remoting.support.RemoteInvocation;
|
import org.springframework.remoting.support.RemoteInvocation;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 16.05.2003
|
* @since 16.05.2003
|
||||||
*/
|
*/
|
||||||
public class RmiSupportTests extends TestCase {
|
public class RmiSupportTests {
|
||||||
|
|
||||||
public void testRmiProxyFactoryBean() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBean() throws Exception {
|
||||||
CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean();
|
CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean();
|
||||||
factory.setServiceInterface(IRemoteBean.class);
|
factory.setServiceInterface(IRemoteBean.class);
|
||||||
factory.setServiceUrl("rmi://localhost:1090/test");
|
factory.setServiceUrl("rmi://localhost:1090/test");
|
||||||
|
@ -56,35 +60,43 @@ public class RmiSupportTests extends TestCase {
|
||||||
assertEquals(1, factory.counter);
|
assertEquals(1, factory.counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithRemoteException() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithRemoteException() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithException(RemoteException.class);
|
doTestRmiProxyFactoryBeanWithException(RemoteException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithConnectException() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithConnectException() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithException(ConnectException.class);
|
doTestRmiProxyFactoryBeanWithException(ConnectException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithConnectIOException() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithConnectIOException() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithException(ConnectIOException.class);
|
doTestRmiProxyFactoryBeanWithException(ConnectIOException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithUnknownHostException() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithUnknownHostException() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithException(UnknownHostException.class);
|
doTestRmiProxyFactoryBeanWithException(UnknownHostException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithNoSuchObjectException() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithNoSuchObjectException() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithException(NoSuchObjectException.class);
|
doTestRmiProxyFactoryBeanWithException(NoSuchObjectException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithStubNotFoundException() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithStubNotFoundException() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithException(StubNotFoundException.class);
|
doTestRmiProxyFactoryBeanWithException(StubNotFoundException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithMarshalException() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithMarshalException() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithException(MarshalException.class);
|
doTestRmiProxyFactoryBeanWithException(MarshalException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithUnmarshalException() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithUnmarshalException() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithException(UnmarshalException.class);
|
doTestRmiProxyFactoryBeanWithException(UnmarshalException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,23 +122,28 @@ public class RmiSupportTests extends TestCase {
|
||||||
assertEquals(1, factory.counter);
|
assertEquals(1, factory.counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithConnectExceptionAndRefresh() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithConnectExceptionAndRefresh() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithExceptionAndRefresh(ConnectException.class);
|
doTestRmiProxyFactoryBeanWithExceptionAndRefresh(ConnectException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithConnectIOExceptionAndRefresh() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithConnectIOExceptionAndRefresh() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithExceptionAndRefresh(ConnectIOException.class);
|
doTestRmiProxyFactoryBeanWithExceptionAndRefresh(ConnectIOException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithUnknownHostExceptionAndRefresh() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithUnknownHostExceptionAndRefresh() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithExceptionAndRefresh(UnknownHostException.class);
|
doTestRmiProxyFactoryBeanWithExceptionAndRefresh(UnknownHostException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithNoSuchObjectExceptionAndRefresh() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithNoSuchObjectExceptionAndRefresh() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithExceptionAndRefresh(NoSuchObjectException.class);
|
doTestRmiProxyFactoryBeanWithExceptionAndRefresh(NoSuchObjectException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithStubNotFoundExceptionAndRefresh() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithStubNotFoundExceptionAndRefresh() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithExceptionAndRefresh(StubNotFoundException.class);
|
doTestRmiProxyFactoryBeanWithExceptionAndRefresh(StubNotFoundException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +170,8 @@ public class RmiSupportTests extends TestCase {
|
||||||
assertEquals(2, factory.counter);
|
assertEquals(2, factory.counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithBusinessInterface() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithBusinessInterface() throws Exception {
|
||||||
CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean();
|
CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean();
|
||||||
factory.setServiceInterface(IBusinessBean.class);
|
factory.setServiceInterface(IBusinessBean.class);
|
||||||
factory.setServiceUrl("rmi://localhost:1090/test");
|
factory.setServiceUrl("rmi://localhost:1090/test");
|
||||||
|
@ -166,7 +184,8 @@ public class RmiSupportTests extends TestCase {
|
||||||
assertEquals(1, factory.counter);
|
assertEquals(1, factory.counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithWrongBusinessInterface() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithWrongBusinessInterface() throws Exception {
|
||||||
CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean();
|
CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean();
|
||||||
factory.setServiceInterface(IWrongBusinessBean.class);
|
factory.setServiceInterface(IWrongBusinessBean.class);
|
||||||
factory.setServiceUrl("rmi://localhost:1090/test");
|
factory.setServiceUrl("rmi://localhost:1090/test");
|
||||||
|
@ -186,32 +205,38 @@ public class RmiSupportTests extends TestCase {
|
||||||
assertEquals(1, factory.counter);
|
assertEquals(1, factory.counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndRemoteException() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithBusinessInterfaceAndRemoteException() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
|
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
|
||||||
RemoteException.class, RemoteAccessException.class);
|
RemoteException.class, RemoteAccessException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndConnectException() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithBusinessInterfaceAndConnectException() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
|
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
|
||||||
ConnectException.class, RemoteConnectFailureException.class);
|
ConnectException.class, RemoteConnectFailureException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndConnectIOException() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithBusinessInterfaceAndConnectIOException() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
|
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
|
||||||
ConnectIOException.class, RemoteConnectFailureException.class);
|
ConnectIOException.class, RemoteConnectFailureException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndUnknownHostException() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithBusinessInterfaceAndUnknownHostException() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
|
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
|
||||||
UnknownHostException.class, RemoteConnectFailureException.class);
|
UnknownHostException.class, RemoteConnectFailureException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndNoSuchObjectExceptionException() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithBusinessInterfaceAndNoSuchObjectExceptionException() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
|
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
|
||||||
NoSuchObjectException.class, RemoteConnectFailureException.class);
|
NoSuchObjectException.class, RemoteConnectFailureException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndStubNotFoundException() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithBusinessInterfaceAndStubNotFoundException() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
|
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
|
||||||
StubNotFoundException.class, RemoteConnectFailureException.class);
|
StubNotFoundException.class, RemoteConnectFailureException.class);
|
||||||
}
|
}
|
||||||
|
@ -241,32 +266,38 @@ public class RmiSupportTests extends TestCase {
|
||||||
assertEquals(1, factory.counter);
|
assertEquals(1, factory.counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndRemoteExceptionAndRefresh() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithBusinessInterfaceAndRemoteExceptionAndRefresh() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
|
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
|
||||||
RemoteException.class, RemoteAccessException.class);
|
RemoteException.class, RemoteAccessException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndConnectExceptionAndRefresh() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithBusinessInterfaceAndConnectExceptionAndRefresh() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
|
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
|
||||||
ConnectException.class, RemoteConnectFailureException.class);
|
ConnectException.class, RemoteConnectFailureException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndConnectIOExceptionAndRefresh() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithBusinessInterfaceAndConnectIOExceptionAndRefresh() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
|
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
|
||||||
ConnectIOException.class, RemoteConnectFailureException.class);
|
ConnectIOException.class, RemoteConnectFailureException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndUnknownHostExceptionAndRefresh() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithBusinessInterfaceAndUnknownHostExceptionAndRefresh() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
|
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
|
||||||
UnknownHostException.class, RemoteConnectFailureException.class);
|
UnknownHostException.class, RemoteConnectFailureException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndNoSuchObjectExceptionAndRefresh() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithBusinessInterfaceAndNoSuchObjectExceptionAndRefresh() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
|
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
|
||||||
NoSuchObjectException.class, RemoteConnectFailureException.class);
|
NoSuchObjectException.class, RemoteConnectFailureException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndStubNotFoundExceptionAndRefresh() throws Exception {
|
@Test
|
||||||
|
public void rmiProxyFactoryBeanWithBusinessInterfaceAndStubNotFoundExceptionAndRefresh() throws Exception {
|
||||||
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
|
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
|
||||||
StubNotFoundException.class, RemoteConnectFailureException.class);
|
StubNotFoundException.class, RemoteConnectFailureException.class);
|
||||||
}
|
}
|
||||||
|
@ -302,7 +333,8 @@ public class RmiSupportTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiClientInterceptorRequiresUrl() throws Exception{
|
@Test
|
||||||
|
public void rmiClientInterceptorRequiresUrl() throws Exception{
|
||||||
RmiClientInterceptor client = new RmiClientInterceptor();
|
RmiClientInterceptor client = new RmiClientInterceptor();
|
||||||
client.setServiceInterface(IRemoteBean.class);
|
client.setServiceInterface(IRemoteBean.class);
|
||||||
|
|
||||||
|
@ -315,7 +347,8 @@ public class RmiSupportTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRemoteInvocation() throws NoSuchMethodException {
|
@Test
|
||||||
|
public void remoteInvocation() throws NoSuchMethodException {
|
||||||
// let's see if the remote invocation object works
|
// let's see if the remote invocation object works
|
||||||
|
|
||||||
final RemoteBean rb = new RemoteBean();
|
final RemoteBean rb = new RemoteBean();
|
||||||
|
@ -365,7 +398,8 @@ public class RmiSupportTests extends TestCase {
|
||||||
assertEquals(String.class, inv.getParameterTypes()[0]);
|
assertEquals(String.class, inv.getParameterTypes()[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRmiInvokerWithSpecialLocalMethods() throws Exception {
|
@Test
|
||||||
|
public void rmiInvokerWithSpecialLocalMethods() throws Exception {
|
||||||
String serviceUrl = "rmi://localhost:1090/test";
|
String serviceUrl = "rmi://localhost:1090/test";
|
||||||
RmiProxyFactoryBean factory = new RmiProxyFactoryBean() {
|
RmiProxyFactoryBean factory = new RmiProxyFactoryBean() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2007 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,14 +16,17 @@
|
||||||
|
|
||||||
package org.springframework.remoting.support;
|
package org.springframework.remoting.support;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
*/
|
*/
|
||||||
public class RemoteInvocationUtilsTests extends TestCase {
|
public class RemoteInvocationUtilsTests {
|
||||||
|
|
||||||
public void testFillInClientStackTraceIfPossibleSunnyDay() throws Exception {
|
@Test
|
||||||
|
public void fillInClientStackTraceIfPossibleSunnyDay() throws Exception {
|
||||||
try {
|
try {
|
||||||
throw new IllegalStateException("Mmm");
|
throw new IllegalStateException("Mmm");
|
||||||
}
|
}
|
||||||
|
@ -35,7 +38,8 @@ public class RemoteInvocationUtilsTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFillInClientStackTraceIfPossibleWithNullThrowable() throws Exception {
|
@Test
|
||||||
|
public void fillInClientStackTraceIfPossibleWithNullThrowable() throws Exception {
|
||||||
// just want to ensure that it doesn't bomb
|
// just want to ensure that it doesn't bomb
|
||||||
RemoteInvocationUtils.fillInClientStackTraceIfPossible(null);
|
RemoteInvocationUtils.fillInClientStackTraceIfPossible(null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2007 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,28 +16,31 @@
|
||||||
|
|
||||||
package org.springframework.scheduling.concurrent;
|
package org.springframework.scheduling.concurrent;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.core.task.NoOpRunnable;
|
import org.springframework.core.task.NoOpRunnable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
*/
|
*/
|
||||||
public class ConcurrentTaskExecutorTests extends TestCase {
|
public class ConcurrentTaskExecutorTests {
|
||||||
|
|
||||||
public void testZeroArgCtorResultsInDefaultTaskExecutorBeingUsed() throws Exception {
|
@Test
|
||||||
|
public void zeroArgCtorResultsInDefaultTaskExecutorBeingUsed() throws Exception {
|
||||||
ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor();
|
ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor();
|
||||||
// must not throw a NullPointerException
|
// must not throw a NullPointerException
|
||||||
executor.execute(new NoOpRunnable());
|
executor.execute(new NoOpRunnable());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPassingNullExecutorToCtorResultsInDefaultTaskExecutorBeingUsed() throws Exception {
|
@Test
|
||||||
|
public void passingNullExecutorToCtorResultsInDefaultTaskExecutorBeingUsed() throws Exception {
|
||||||
ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(null);
|
ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(null);
|
||||||
// must not throw a NullPointerException
|
// must not throw a NullPointerException
|
||||||
executor.execute(new NoOpRunnable());
|
executor.execute(new NoOpRunnable());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPassingNullExecutorToSetterResultsInDefaultTaskExecutorBeingUsed() throws Exception {
|
@Test
|
||||||
|
public void passingNullExecutorToSetterResultsInDefaultTaskExecutorBeingUsed() throws Exception {
|
||||||
ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor();
|
ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor();
|
||||||
executor.setConcurrentExecutor(null);
|
executor.setConcurrentExecutor(null);
|
||||||
// must not throw a NullPointerException
|
// must not throw a NullPointerException
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -19,7 +19,7 @@ package org.springframework.scripting.bsh;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.aop.support.AopUtils;
|
import org.springframework.aop.support.AopUtils;
|
||||||
import org.springframework.aop.target.dynamic.Refreshable;
|
import org.springframework.aop.target.dynamic.Refreshable;
|
||||||
|
@ -36,6 +36,7 @@ import org.springframework.scripting.TestBeanAwareMessenger;
|
||||||
import org.springframework.scripting.support.ScriptFactoryPostProcessor;
|
import org.springframework.scripting.support.ScriptFactoryPostProcessor;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.BDDMockito.*;
|
import static org.mockito.BDDMockito.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,9 +44,10 @@ import static org.mockito.BDDMockito.*;
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class BshScriptFactoryTests extends TestCase {
|
public class BshScriptFactoryTests {
|
||||||
|
|
||||||
public void testStaticScript() throws Exception {
|
@Test
|
||||||
|
public void staticScript() throws Exception {
|
||||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
|
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
|
||||||
|
|
||||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Calculator.class)).contains("calculator"));
|
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Calculator.class)).contains("calculator"));
|
||||||
|
@ -72,7 +74,8 @@ public class BshScriptFactoryTests extends TestCase {
|
||||||
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
|
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStaticScriptWithNullReturnValue() throws Exception {
|
@Test
|
||||||
|
public void staticScriptWithNullReturnValue() throws Exception {
|
||||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
|
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
|
||||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerWithConfig"));
|
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerWithConfig"));
|
||||||
|
|
||||||
|
@ -82,7 +85,8 @@ public class BshScriptFactoryTests extends TestCase {
|
||||||
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
|
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStaticScriptWithTwoInterfacesSpecified() throws Exception {
|
@Test
|
||||||
|
public void staticScriptWithTwoInterfacesSpecified() throws Exception {
|
||||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
|
||||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerWithConfigExtra"));
|
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerWithConfigExtra"));
|
||||||
|
|
||||||
|
@ -95,7 +99,8 @@ public class BshScriptFactoryTests extends TestCase {
|
||||||
assertNull(messenger.getMessage());
|
assertNull(messenger.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStaticWithScriptReturningInstance() throws Exception {
|
@Test
|
||||||
|
public void staticWithScriptReturningInstance() throws Exception {
|
||||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
|
||||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerInstance"));
|
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerInstance"));
|
||||||
|
|
||||||
|
@ -108,7 +113,8 @@ public class BshScriptFactoryTests extends TestCase {
|
||||||
assertNull(messenger.getMessage());
|
assertNull(messenger.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStaticScriptImplementingInterface() throws Exception {
|
@Test
|
||||||
|
public void staticScriptImplementingInterface() throws Exception {
|
||||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
|
||||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerImpl"));
|
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerImpl"));
|
||||||
|
|
||||||
|
@ -121,7 +127,8 @@ public class BshScriptFactoryTests extends TestCase {
|
||||||
assertNull(messenger.getMessage());
|
assertNull(messenger.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStaticPrototypeScript() throws Exception {
|
@Test
|
||||||
|
public void staticPrototypeScript() throws Exception {
|
||||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
|
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
|
||||||
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
|
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
|
||||||
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
|
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
|
||||||
|
@ -139,7 +146,8 @@ public class BshScriptFactoryTests extends TestCase {
|
||||||
assertEquals("Byebye World!", messenger2.getMessage());
|
assertEquals("Byebye World!", messenger2.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNonStaticScript() throws Exception {
|
@Test
|
||||||
|
public void nonStaticScript() throws Exception {
|
||||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshRefreshableContext.xml", getClass());
|
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshRefreshableContext.xml", getClass());
|
||||||
Messenger messenger = (Messenger) ctx.getBean("messenger");
|
Messenger messenger = (Messenger) ctx.getBean("messenger");
|
||||||
|
|
||||||
|
@ -156,7 +164,8 @@ public class BshScriptFactoryTests extends TestCase {
|
||||||
assertEquals("Incorrect refresh count", 2, refreshable.getRefreshCount());
|
assertEquals("Incorrect refresh count", 2, refreshable.getRefreshCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNonStaticPrototypeScript() throws Exception {
|
@Test
|
||||||
|
public void nonStaticPrototypeScript() throws Exception {
|
||||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshRefreshableContext.xml", getClass());
|
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshRefreshableContext.xml", getClass());
|
||||||
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
|
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
|
||||||
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
|
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
|
||||||
|
@ -179,7 +188,8 @@ public class BshScriptFactoryTests extends TestCase {
|
||||||
assertEquals("Incorrect refresh count", 2, refreshable.getRefreshCount());
|
assertEquals("Incorrect refresh count", 2, refreshable.getRefreshCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testScriptCompilationException() throws Exception {
|
@Test
|
||||||
|
public void scriptCompilationException() throws Exception {
|
||||||
try {
|
try {
|
||||||
new ClassPathXmlApplicationContext("org/springframework/scripting/bsh/bshBrokenContext.xml");
|
new ClassPathXmlApplicationContext("org/springframework/scripting/bsh/bshBrokenContext.xml");
|
||||||
fail("Must throw exception for broken script file");
|
fail("Must throw exception for broken script file");
|
||||||
|
@ -189,7 +199,8 @@ public class BshScriptFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testScriptThatCompilesButIsJustPlainBad() throws Exception {
|
@Test
|
||||||
|
public void scriptThatCompilesButIsJustPlainBad() throws Exception {
|
||||||
ScriptSource script = mock(ScriptSource.class);
|
ScriptSource script = mock(ScriptSource.class);
|
||||||
final String badScript = "String getMessage() { throw new IllegalArgumentException(); }";
|
final String badScript = "String getMessage() { throw new IllegalArgumentException(); }";
|
||||||
given(script.getScriptAsString()).willReturn(badScript);
|
given(script.getScriptAsString()).willReturn(badScript);
|
||||||
|
@ -205,7 +216,8 @@ public class BshScriptFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCtorWithNullScriptSourceLocator() throws Exception {
|
@Test
|
||||||
|
public void ctorWithNullScriptSourceLocator() throws Exception {
|
||||||
try {
|
try {
|
||||||
new BshScriptFactory(null, Messenger.class);
|
new BshScriptFactory(null, Messenger.class);
|
||||||
fail("Must have thrown exception by this point.");
|
fail("Must have thrown exception by this point.");
|
||||||
|
@ -214,7 +226,8 @@ public class BshScriptFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCtorWithEmptyScriptSourceLocator() throws Exception {
|
@Test
|
||||||
|
public void ctorWithEmptyScriptSourceLocator() throws Exception {
|
||||||
try {
|
try {
|
||||||
new BshScriptFactory("", new Class<?>[] {Messenger.class});
|
new BshScriptFactory("", new Class<?>[] {Messenger.class});
|
||||||
fail("Must have thrown exception by this point.");
|
fail("Must have thrown exception by this point.");
|
||||||
|
@ -223,7 +236,8 @@ public class BshScriptFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCtorWithWhitespacedScriptSourceLocator() throws Exception {
|
@Test
|
||||||
|
public void ctorWithWhitespacedScriptSourceLocator() throws Exception {
|
||||||
try {
|
try {
|
||||||
new BshScriptFactory("\n ", new Class<?>[] {Messenger.class});
|
new BshScriptFactory("\n ", new Class<?>[] {Messenger.class});
|
||||||
fail("Must have thrown exception by this point.");
|
fail("Must have thrown exception by this point.");
|
||||||
|
@ -232,7 +246,8 @@ public class BshScriptFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testResourceScriptFromTag() throws Exception {
|
@Test
|
||||||
|
public void resourceScriptFromTag() throws Exception {
|
||||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
|
||||||
TestBean testBean = (TestBean) ctx.getBean("testBean");
|
TestBean testBean = (TestBean) ctx.getBean("testBean");
|
||||||
|
|
||||||
|
@ -270,7 +285,8 @@ public class BshScriptFactoryTests extends TestCase {
|
||||||
assertNull(messengerInstance.getMessage());
|
assertNull(messengerInstance.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPrototypeScriptFromTag() throws Exception {
|
@Test
|
||||||
|
public void prototypeScriptFromTag() throws Exception {
|
||||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
|
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
|
||||||
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
|
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
|
||||||
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
|
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
|
||||||
|
@ -285,21 +301,24 @@ public class BshScriptFactoryTests extends TestCase {
|
||||||
assertEquals("Byebye World!", messenger2.getMessage());
|
assertEquals("Byebye World!", messenger2.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInlineScriptFromTag() throws Exception {
|
@Test
|
||||||
|
public void inlineScriptFromTag() throws Exception {
|
||||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
|
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
|
||||||
Calculator calculator = (Calculator) ctx.getBean("calculator");
|
Calculator calculator = (Calculator) ctx.getBean("calculator");
|
||||||
assertNotNull(calculator);
|
assertNotNull(calculator);
|
||||||
assertFalse(calculator instanceof Refreshable);
|
assertFalse(calculator instanceof Refreshable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRefreshableFromTag() throws Exception {
|
@Test
|
||||||
|
public void refreshableFromTag() throws Exception {
|
||||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
|
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
|
||||||
Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
|
Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
|
||||||
assertEquals("Hello World!", messenger.getMessage());
|
assertEquals("Hello World!", messenger.getMessage());
|
||||||
assertTrue("Messenger should be Refreshable", messenger instanceof Refreshable);
|
assertTrue("Messenger should be Refreshable", messenger instanceof Refreshable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testApplicationEventListener() throws Exception {
|
@Test
|
||||||
|
public void applicationEventListener() throws Exception {
|
||||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
|
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
|
||||||
Messenger eventListener = (Messenger) ctx.getBean("eventListener");
|
Messenger eventListener = (Messenger) ctx.getBean("eventListener");
|
||||||
ctx.publishEvent(new MyEvent(ctx));
|
ctx.publishEvent(new MyEvent(ctx));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,7 +18,7 @@ package org.springframework.scripting.config;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.aop.framework.Advised;
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.aop.support.AopUtils;
|
import org.springframework.aop.support.AopUtils;
|
||||||
|
@ -26,11 +26,14 @@ import org.springframework.aop.target.dynamic.AbstractRefreshableTargetSource;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class ScriptingDefaultsTests extends TestCase {
|
@SuppressWarnings("resource")
|
||||||
|
public class ScriptingDefaultsTests {
|
||||||
|
|
||||||
private static final String CONFIG =
|
private static final String CONFIG =
|
||||||
"org/springframework/scripting/config/scriptingDefaultsTests.xml";
|
"org/springframework/scripting/config/scriptingDefaultsTests.xml";
|
||||||
|
@ -39,7 +42,8 @@ public class ScriptingDefaultsTests extends TestCase {
|
||||||
"org/springframework/scripting/config/scriptingDefaultsProxyTargetClassTests.xml";
|
"org/springframework/scripting/config/scriptingDefaultsProxyTargetClassTests.xml";
|
||||||
|
|
||||||
|
|
||||||
public void testDefaultRefreshCheckDelay() throws Exception {
|
@Test
|
||||||
|
public void defaultRefreshCheckDelay() throws Exception {
|
||||||
ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
|
ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
|
||||||
Advised advised = (Advised) context.getBean("testBean");
|
Advised advised = (Advised) context.getBean("testBean");
|
||||||
AbstractRefreshableTargetSource targetSource =
|
AbstractRefreshableTargetSource targetSource =
|
||||||
|
@ -50,19 +54,22 @@ public class ScriptingDefaultsTests extends TestCase {
|
||||||
assertEquals(5000L, delay);
|
assertEquals(5000L, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDefaultInitMethod() {
|
@Test
|
||||||
|
public void defaultInitMethod() {
|
||||||
ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
|
ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
|
||||||
ITestBean testBean = (ITestBean) context.getBean("testBean");
|
ITestBean testBean = (ITestBean) context.getBean("testBean");
|
||||||
assertTrue(testBean.isInitialized());
|
assertTrue(testBean.isInitialized());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNameAsAlias() {
|
@Test
|
||||||
|
public void nameAsAlias() {
|
||||||
ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
|
ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
|
||||||
ITestBean testBean = (ITestBean) context.getBean("/url");
|
ITestBean testBean = (ITestBean) context.getBean("/url");
|
||||||
assertTrue(testBean.isInitialized());
|
assertTrue(testBean.isInitialized());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDefaultDestroyMethod() {
|
@Test
|
||||||
|
public void defaultDestroyMethod() {
|
||||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
|
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
|
||||||
ITestBean testBean = (ITestBean) context.getBean("nonRefreshableTestBean");
|
ITestBean testBean = (ITestBean) context.getBean("nonRefreshableTestBean");
|
||||||
assertFalse(testBean.isDestroyed());
|
assertFalse(testBean.isDestroyed());
|
||||||
|
@ -70,14 +77,16 @@ public class ScriptingDefaultsTests extends TestCase {
|
||||||
assertTrue(testBean.isDestroyed());
|
assertTrue(testBean.isDestroyed());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDefaultAutowire() {
|
@Test
|
||||||
|
public void defaultAutowire() {
|
||||||
ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
|
ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
|
||||||
ITestBean testBean = (ITestBean) context.getBean("testBean");
|
ITestBean testBean = (ITestBean) context.getBean("testBean");
|
||||||
ITestBean otherBean = (ITestBean) context.getBean("otherBean");
|
ITestBean otherBean = (ITestBean) context.getBean("otherBean");
|
||||||
assertEquals(otherBean, testBean.getOtherBean());
|
assertEquals(otherBean, testBean.getOtherBean());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDefaultProxyTargetClass() {
|
@Test
|
||||||
|
public void defaultProxyTargetClass() {
|
||||||
ApplicationContext context = new ClassPathXmlApplicationContext(PROXY_CONFIG);
|
ApplicationContext context = new ClassPathXmlApplicationContext(PROXY_CONFIG);
|
||||||
Object testBean = context.getBean("testBean");
|
Object testBean = context.getBean("testBean");
|
||||||
assertTrue(AopUtils.isCglibProxy(testBean));
|
assertTrue(AopUtils.isCglibProxy(testBean));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -30,14 +30,17 @@ import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class GroovyAspectTests {
|
public class GroovyAspectTests {
|
||||||
|
|
||||||
@Test
|
private final LogUserAdvice logAdvice = new LogUserAdvice();
|
||||||
public void testManualGroovyBeanWithUnconditionalPointcut() throws Exception {
|
|
||||||
LogUserAdvice logAdvice = new LogUserAdvice();
|
|
||||||
|
|
||||||
GroovyScriptFactory scriptFactory = new GroovyScriptFactory("GroovyServiceImpl.grv");
|
private final GroovyScriptFactory scriptFactory = new GroovyScriptFactory("GroovyServiceImpl.grv");
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void manualGroovyBeanWithUnconditionalPointcut() throws Exception {
|
||||||
TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
|
TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
|
||||||
new ClassPathResource("GroovyServiceImpl.grv", getClass())));
|
new ClassPathResource("GroovyServiceImpl.grv", getClass())));
|
||||||
|
|
||||||
|
@ -45,10 +48,7 @@ public class GroovyAspectTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testManualGroovyBeanWithStaticPointcut() throws Exception {
|
public void manualGroovyBeanWithStaticPointcut() throws Exception {
|
||||||
LogUserAdvice logAdvice = new LogUserAdvice();
|
|
||||||
|
|
||||||
GroovyScriptFactory scriptFactory = new GroovyScriptFactory("GroovyServiceImpl.grv");
|
|
||||||
TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
|
TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
|
||||||
new ClassPathResource("GroovyServiceImpl.grv", getClass())));
|
new ClassPathResource("GroovyServiceImpl.grv", getClass())));
|
||||||
|
|
||||||
|
@ -58,31 +58,23 @@ public class GroovyAspectTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testManualGroovyBeanWithDynamicPointcut() throws Exception {
|
public void manualGroovyBeanWithDynamicPointcut() throws Exception {
|
||||||
LogUserAdvice logAdvice = new LogUserAdvice();
|
|
||||||
|
|
||||||
GroovyScriptFactory scriptFactory = new GroovyScriptFactory("GroovyServiceImpl.grv");
|
|
||||||
TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
|
TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
|
||||||
new ClassPathResource("GroovyServiceImpl.grv", getClass())));
|
new ClassPathResource("GroovyServiceImpl.grv", getClass())));
|
||||||
|
|
||||||
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
|
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
|
||||||
pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
|
pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
|
||||||
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", false);
|
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testManualGroovyBeanWithDynamicPointcutProxyTargetClass() throws Exception {
|
public void manualGroovyBeanWithDynamicPointcutProxyTargetClass() throws Exception {
|
||||||
LogUserAdvice logAdvice = new LogUserAdvice();
|
|
||||||
|
|
||||||
GroovyScriptFactory scriptFactory = new GroovyScriptFactory("GroovyServiceImpl.grv");
|
|
||||||
TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
|
TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
|
||||||
new ClassPathResource("GroovyServiceImpl.grv", getClass())));
|
new ClassPathResource("GroovyServiceImpl.grv", getClass())));
|
||||||
|
|
||||||
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
|
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
|
||||||
pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
|
pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
|
||||||
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", true);
|
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testAdvice(Advisor advisor, LogUserAdvice logAdvice, TestService target, String message)
|
private void testAdvice(Advisor advisor, LogUserAdvice logAdvice, TestService target, String message)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,21 +16,25 @@
|
||||||
|
|
||||||
package org.springframework.scripting.groovy;
|
package org.springframework.scripting.groovy;
|
||||||
|
|
||||||
|
import groovy.lang.GroovyClassLoader;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import groovy.lang.GroovyClassLoader;
|
import org.junit.Test;
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
import org.springframework.context.support.StaticApplicationContext;
|
import org.springframework.context.support.StaticApplicationContext;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
*/
|
*/
|
||||||
public class GroovyClassLoadingTests extends TestCase {
|
public class GroovyClassLoadingTests {
|
||||||
|
|
||||||
public void testClassLoading() throws Exception {
|
@Test
|
||||||
|
@SuppressWarnings("resource")
|
||||||
|
public void classLoading() throws Exception {
|
||||||
StaticApplicationContext context = new StaticApplicationContext();
|
StaticApplicationContext context = new StaticApplicationContext();
|
||||||
|
|
||||||
GroovyClassLoader gcl = new GroovyClassLoader();
|
GroovyClassLoader gcl = new GroovyClassLoader();
|
||||||
|
@ -41,16 +45,14 @@ public class GroovyClassLoadingTests extends TestCase {
|
||||||
Object testBean1 = context.getBean("testBean");
|
Object testBean1 = context.getBean("testBean");
|
||||||
Method method1 = class1.getDeclaredMethod("myMethod", new Class<?>[0]);
|
Method method1 = class1.getDeclaredMethod("myMethod", new Class<?>[0]);
|
||||||
Object result1 = ReflectionUtils.invokeMethod(method1, testBean1);
|
Object result1 = ReflectionUtils.invokeMethod(method1, testBean1);
|
||||||
assertEquals("foo", (String) result1);
|
assertEquals("foo", result1);
|
||||||
|
|
||||||
// ### uncommenting the next line causes the test to pass for Spring > 2.0.2 ###
|
|
||||||
//context.removeBeanDefinition("testBean");
|
|
||||||
|
|
||||||
|
context.removeBeanDefinition("testBean");
|
||||||
context.registerBeanDefinition("testBean", new RootBeanDefinition(class2));
|
context.registerBeanDefinition("testBean", new RootBeanDefinition(class2));
|
||||||
Object testBean2 = context.getBean("testBean");
|
Object testBean2 = context.getBean("testBean");
|
||||||
Method method2 = class2.getDeclaredMethod("myMethod", new Class<?>[0]);
|
Method method2 = class2.getDeclaredMethod("myMethod", new Class<?>[0]);
|
||||||
Object result2 = ReflectionUtils.invokeMethod(method2, testBean2);
|
Object result2 = ReflectionUtils.invokeMethod(method2, testBean2);
|
||||||
assertEquals("bar", (String) result2);
|
assertEquals("bar", result2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2015 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package org.springframework.scripting.groovy;
|
package org.springframework.scripting.groovy;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
@ -14,15 +30,15 @@ public class LogUserAdvice implements MethodBeforeAdvice, ThrowsAdvice {
|
||||||
@Override
|
@Override
|
||||||
public void before(Method method, Object[] objects, Object o) throws Throwable {
|
public void before(Method method, Object[] objects, Object o) throws Throwable {
|
||||||
countBefore++;
|
countBefore++;
|
||||||
System.out.println("Method:"+method.getName());
|
// System.out.println("Method:" + method.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void afterThrowing(Exception e) throws Throwable {
|
public void afterThrowing(Exception e) throws Throwable {
|
||||||
countThrows++;
|
countThrows++;
|
||||||
System.out.println("***********************************************************************************");
|
// System.out.println("***********************************************************************************");
|
||||||
System.out.println("Exception caught:");
|
// System.out.println("Exception caught:");
|
||||||
System.out.println("***********************************************************************************");
|
// System.out.println("***********************************************************************************");
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,24 +16,20 @@
|
||||||
|
|
||||||
package org.springframework.scripting.support;
|
package org.springframework.scripting.support;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
|
|
||||||
import static org.mockito.BDDMockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
*/
|
*/
|
||||||
public class RefreshableScriptTargetSourceTests extends TestCase {
|
public class RefreshableScriptTargetSourceTests {
|
||||||
|
|
||||||
public void testCreateWithNullScriptSource() throws Exception {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
try {
|
public void createWithNullScriptSource() throws Exception {
|
||||||
new RefreshableScriptTargetSource(mock(BeanFactory.class), "a.bean", null, null, false);
|
new RefreshableScriptTargetSource(mock(BeanFactory.class), "a.bean", null, null, false);
|
||||||
fail("Must have failed when passed a null ScriptSource.");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -19,20 +19,22 @@ package org.springframework.scripting.support;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.core.io.ByteArrayResource;
|
import org.springframework.core.io.ByteArrayResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.BDDMockito.*;
|
import static org.mockito.BDDMockito.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class ResourceScriptSourceTests extends TestCase {
|
public class ResourceScriptSourceTests {
|
||||||
|
|
||||||
public void testDoesNotPropagateFatalExceptionOnResourceThatCannotBeResolvedToAFile() throws Exception {
|
@Test
|
||||||
|
public void doesNotPropagateFatalExceptionOnResourceThatCannotBeResolvedToAFile() throws Exception {
|
||||||
Resource resource = mock(Resource.class);
|
Resource resource = mock(Resource.class);
|
||||||
given(resource.lastModified()).willThrow(new IOException());
|
given(resource.lastModified()).willThrow(new IOException());
|
||||||
|
|
||||||
|
@ -41,13 +43,15 @@ public class ResourceScriptSourceTests extends TestCase {
|
||||||
assertEquals(0, lastModified);
|
assertEquals(0, lastModified);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBeginsInModifiedState() throws Exception {
|
@Test
|
||||||
|
public void beginsInModifiedState() throws Exception {
|
||||||
Resource resource = mock(Resource.class);
|
Resource resource = mock(Resource.class);
|
||||||
ResourceScriptSource scriptSource = new ResourceScriptSource(resource);
|
ResourceScriptSource scriptSource = new ResourceScriptSource(resource);
|
||||||
assertTrue(scriptSource.isModified());
|
assertTrue(scriptSource.isModified());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLastModifiedWorksWithResourceThatDoesNotSupportFileBasedReading() throws Exception {
|
@Test
|
||||||
|
public void lastModifiedWorksWithResourceThatDoesNotSupportFileBasedReading() throws Exception {
|
||||||
Resource resource = mock(Resource.class);
|
Resource resource = mock(Resource.class);
|
||||||
// underlying File is asked for so that the last modified time can be checked...
|
// underlying File is asked for so that the last modified time can be checked...
|
||||||
// And then mock the file changing; i.e. the File says it has been modified
|
// And then mock the file changing; i.e. the File says it has been modified
|
||||||
|
@ -65,7 +69,8 @@ public class ResourceScriptSourceTests extends TestCase {
|
||||||
assertTrue("ResourceScriptSource must report back as being modified if the underlying File resource is reporting a changed lastModified time.", scriptSource.isModified());
|
assertTrue("ResourceScriptSource must report back as being modified if the underlying File resource is reporting a changed lastModified time.", scriptSource.isModified());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLastModifiedWorksWithResourceThatDoesNotSupportFileBasedAccessAtAll() throws Exception {
|
@Test
|
||||||
|
public void lastModifiedWorksWithResourceThatDoesNotSupportFileBasedAccessAtAll() throws Exception {
|
||||||
Resource resource = new ByteArrayResource(new byte[0]);
|
Resource resource = new ByteArrayResource(new byte[0]);
|
||||||
ResourceScriptSource scriptSource = new ResourceScriptSource(resource);
|
ResourceScriptSource scriptSource = new ResourceScriptSource(resource);
|
||||||
assertTrue("ResourceScriptSource must start off in the 'isModified' state (it obviously isn't).", scriptSource.isModified());
|
assertTrue("ResourceScriptSource must start off in the 'isModified' state (it obviously isn't).", scriptSource.isModified());
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2006 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,71 +16,64 @@
|
||||||
|
|
||||||
package org.springframework.scripting.support;
|
package org.springframework.scripting.support;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the StaticScriptSource class.
|
* Unit tests for the StaticScriptSource class.
|
||||||
*
|
*
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public final class StaticScriptSourceTests extends TestCase {
|
public final class StaticScriptSourceTests {
|
||||||
|
|
||||||
private static final String SCRIPT_TEXT = "print($hello) if $true;";
|
private static final String SCRIPT_TEXT = "print($hello) if $true;";
|
||||||
|
|
||||||
|
private final StaticScriptSource source = new StaticScriptSource(SCRIPT_TEXT);
|
||||||
|
|
||||||
public void testCreateWithNullScript() throws Exception {
|
|
||||||
try {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
new StaticScriptSource(null);
|
public void createWithNullScript() throws Exception {
|
||||||
fail("Must have failed when passed a null script string.");
|
new StaticScriptSource(null);
|
||||||
}
|
|
||||||
catch (IllegalArgumentException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateWithEmptyScript() throws Exception {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
try {
|
public void createWithEmptyScript() throws Exception {
|
||||||
new StaticScriptSource("");
|
new StaticScriptSource("");
|
||||||
fail("Must have failed when passed an empty script string.");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateWithWhitespaceOnlyScript() throws Exception {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
try {
|
public void createWithWhitespaceOnlyScript() throws Exception {
|
||||||
new StaticScriptSource(" \n\n\t \t\n");
|
new StaticScriptSource(" \n\n\t \t\n");
|
||||||
fail("Must have failed when passed a whitespace-only script string.");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIsModifiedIsTrueByDefault() throws Exception {
|
@Test
|
||||||
StaticScriptSource source = new StaticScriptSource(SCRIPT_TEXT);
|
public void isModifiedIsTrueByDefault() throws Exception {
|
||||||
assertTrue("Script must be flagged as 'modified' when first created.", source.isModified());
|
assertTrue("Script must be flagged as 'modified' when first created.", source.isModified());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGettingScriptTogglesIsModified() throws Exception {
|
@Test
|
||||||
StaticScriptSource source = new StaticScriptSource(SCRIPT_TEXT);
|
public void gettingScriptTogglesIsModified() throws Exception {
|
||||||
source.getScriptAsString();
|
source.getScriptAsString();
|
||||||
assertFalse("Script must be flagged as 'not modified' after script is read.", source.isModified());
|
assertFalse("Script must be flagged as 'not modified' after script is read.", source.isModified());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGettingScriptViaToStringDoesNotToggleIsModified() throws Exception {
|
@Test
|
||||||
StaticScriptSource source = new StaticScriptSource(SCRIPT_TEXT);
|
public void gettingScriptViaToStringDoesNotToggleIsModified() throws Exception {
|
||||||
boolean isModifiedState = source.isModified();
|
boolean isModifiedState = source.isModified();
|
||||||
source.toString();
|
source.toString();
|
||||||
assertEquals("Script's 'modified' flag must not change after script is read via toString().", isModifiedState, source.isModified());
|
assertEquals("Script's 'modified' flag must not change after script is read via toString().", isModifiedState, source.isModified());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIsModifiedToggledWhenDifferentScriptIsSet() throws Exception {
|
@Test
|
||||||
StaticScriptSource source = new StaticScriptSource(SCRIPT_TEXT);
|
public void isModifiedToggledWhenDifferentScriptIsSet() throws Exception {
|
||||||
source.setScript("use warnings;");
|
source.setScript("use warnings;");
|
||||||
assertTrue("Script must be flagged as 'modified' when different script is passed in.", source.isModified());
|
assertTrue("Script must be flagged as 'modified' when different script is passed in.", source.isModified());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIsModifiedNotToggledWhenSameScriptIsSet() throws Exception {
|
@Test
|
||||||
StaticScriptSource source = new StaticScriptSource(SCRIPT_TEXT);
|
public void isModifiedNotToggledWhenSameScriptIsSet() throws Exception {
|
||||||
source.setScript(SCRIPT_TEXT);
|
source.setScript(SCRIPT_TEXT);
|
||||||
assertFalse("Script must not be flagged as 'modified' when same script is passed in.", source.isModified());
|
assertFalse("Script must not be flagged as 'modified' when same script is passed in.", source.isModified());
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class StopWatch {
|
||||||
* Construct a new stop watch. Does not start any task.
|
* Construct a new stop watch. Does not start any task.
|
||||||
*/
|
*/
|
||||||
public StopWatch() {
|
public StopWatch() {
|
||||||
this.id = "";
|
this("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,10 +16,12 @@
|
||||||
|
|
||||||
package org.springframework.core;
|
package org.springframework.core;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
|
@ -27,9 +29,10 @@ import junit.framework.TestCase;
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
* @since 28.04.2003
|
* @since 28.04.2003
|
||||||
*/
|
*/
|
||||||
public class ConstantsTests extends TestCase {
|
public class ConstantsTests {
|
||||||
|
|
||||||
public void testConstants() {
|
@Test
|
||||||
|
public void constants() {
|
||||||
Constants c = new Constants(A.class);
|
Constants c = new Constants(A.class);
|
||||||
assertEquals(A.class.getName(), c.getClassName());
|
assertEquals(A.class.getName(), c.getClassName());
|
||||||
assertEquals(9, c.getSize());
|
assertEquals(9, c.getSize());
|
||||||
|
@ -54,7 +57,8 @@ public class ConstantsTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetNames() {
|
@Test
|
||||||
|
public void getNames() {
|
||||||
Constants c = new Constants(A.class);
|
Constants c = new Constants(A.class);
|
||||||
|
|
||||||
Set<?> names = c.getNames("");
|
Set<?> names = c.getNames("");
|
||||||
|
@ -72,7 +76,8 @@ public class ConstantsTests extends TestCase {
|
||||||
assertTrue(names.contains("DOG"));
|
assertTrue(names.contains("DOG"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetValues() {
|
@Test
|
||||||
|
public void getValues() {
|
||||||
Constants c = new Constants(A.class);
|
Constants c = new Constants(A.class);
|
||||||
|
|
||||||
Set<?> values = c.getValues("");
|
Set<?> values = c.getValues("");
|
||||||
|
@ -96,7 +101,8 @@ public class ConstantsTests extends TestCase {
|
||||||
assertTrue(values.contains(new Integer(2)));
|
assertTrue(values.contains(new Integer(2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetValuesInTurkey() {
|
@Test
|
||||||
|
public void getValuesInTurkey() {
|
||||||
Locale oldLocale = Locale.getDefault();
|
Locale oldLocale = Locale.getDefault();
|
||||||
Locale.setDefault(new Locale("tr", ""));
|
Locale.setDefault(new Locale("tr", ""));
|
||||||
try {
|
try {
|
||||||
|
@ -127,7 +133,8 @@ public class ConstantsTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSuffixAccess() {
|
@Test
|
||||||
|
public void suffixAccess() {
|
||||||
Constants c = new Constants(A.class);
|
Constants c = new Constants(A.class);
|
||||||
|
|
||||||
Set<?> names = c.getNamesForSuffix("_PROPERTY");
|
Set<?> names = c.getNamesForSuffix("_PROPERTY");
|
||||||
|
@ -141,7 +148,8 @@ public class ConstantsTests extends TestCase {
|
||||||
assertTrue(values.contains(new Integer(4)));
|
assertTrue(values.contains(new Integer(4)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testToCode() {
|
@Test
|
||||||
|
public void toCode() {
|
||||||
Constants c = new Constants(A.class);
|
Constants c = new Constants(A.class);
|
||||||
|
|
||||||
assertEquals(c.toCode(new Integer(0), ""), "DOG");
|
assertEquals(c.toCode(new Integer(0), ""), "DOG");
|
||||||
|
@ -208,25 +216,29 @@ public class ConstantsTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetValuesWithNullPrefix() throws Exception {
|
@Test
|
||||||
|
public void getValuesWithNullPrefix() throws Exception {
|
||||||
Constants c = new Constants(A.class);
|
Constants c = new Constants(A.class);
|
||||||
Set<?> values = c.getValues(null);
|
Set<?> values = c.getValues(null);
|
||||||
assertEquals("Must have returned *all* public static final values", 7, values.size());
|
assertEquals("Must have returned *all* public static final values", 7, values.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetValuesWithEmptyStringPrefix() throws Exception {
|
@Test
|
||||||
|
public void getValuesWithEmptyStringPrefix() throws Exception {
|
||||||
Constants c = new Constants(A.class);
|
Constants c = new Constants(A.class);
|
||||||
Set<Object> values = c.getValues("");
|
Set<Object> values = c.getValues("");
|
||||||
assertEquals("Must have returned *all* public static final values", 7, values.size());
|
assertEquals("Must have returned *all* public static final values", 7, values.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetValuesWithWhitespacedStringPrefix() throws Exception {
|
@Test
|
||||||
|
public void getValuesWithWhitespacedStringPrefix() throws Exception {
|
||||||
Constants c = new Constants(A.class);
|
Constants c = new Constants(A.class);
|
||||||
Set<?> values = c.getValues(" ");
|
Set<?> values = c.getValues(" ");
|
||||||
assertEquals("Must have returned *all* public static final values", 7, values.size());
|
assertEquals("Must have returned *all* public static final values", 7, values.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithClassThatExposesNoConstants() throws Exception {
|
@Test
|
||||||
|
public void withClassThatExposesNoConstants() throws Exception {
|
||||||
Constants c = new Constants(NoConstants.class);
|
Constants c = new Constants(NoConstants.class);
|
||||||
assertEquals(0, c.getSize());
|
assertEquals(0, c.getSize());
|
||||||
final Set<?> values = c.getValues("");
|
final Set<?> values = c.getValues("");
|
||||||
|
@ -234,7 +246,8 @@ public class ConstantsTests extends TestCase {
|
||||||
assertEquals(0, values.size());
|
assertEquals(0, values.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCtorWithNullClass() throws Exception {
|
@Test
|
||||||
|
public void ctorWithNullClass() throws Exception {
|
||||||
try {
|
try {
|
||||||
new Constants(null);
|
new Constants(null);
|
||||||
fail("Must have thrown IllegalArgumentException");
|
fail("Must have thrown IllegalArgumentException");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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,58 +17,68 @@
|
||||||
package org.springframework.core;
|
package org.springframework.core;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
import org.springframework.tests.sample.objects.TestObject;
|
import org.springframework.tests.sample.objects.TestObject;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class ConventionsTests extends TestCase {
|
public class ConventionsTests {
|
||||||
|
|
||||||
public void testSimpleObject() {
|
@Rule
|
||||||
TestObject testObject = new TestObject();
|
public final ExpectedException exception = ExpectedException.none();
|
||||||
assertEquals("Incorrect singular variable name", "testObject", Conventions.getVariableName(testObject));
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void simpleObject() {
|
||||||
|
assertEquals("Incorrect singular variable name", "testObject", Conventions.getVariableName(new TestObject()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testArray() {
|
@Test
|
||||||
TestObject[] testObjects = new TestObject[0];
|
public void array() {
|
||||||
assertEquals("Incorrect plural array form", "testObjectList", Conventions.getVariableName(testObjects));
|
assertEquals("Incorrect plural array form", "testObjectList", Conventions.getVariableName(new TestObject[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCollections() {
|
@Test
|
||||||
List<TestObject> list = new ArrayList<TestObject>();
|
public void list() {
|
||||||
list.add(new TestObject());
|
List<TestObject> list = Arrays.asList(new TestObject());
|
||||||
assertEquals("Incorrect plural List form", "testObjectList", Conventions.getVariableName(list));
|
assertEquals("Incorrect plural List form", "testObjectList", Conventions.getVariableName(list));
|
||||||
|
|
||||||
Set<TestObject> set = new HashSet<TestObject>();
|
|
||||||
set.add(new TestObject());
|
|
||||||
assertEquals("Incorrect plural Set form", "testObjectList", Conventions.getVariableName(set));
|
|
||||||
|
|
||||||
List<?> emptyList = new ArrayList<Object>();
|
|
||||||
try {
|
|
||||||
Conventions.getVariableName(emptyList);
|
|
||||||
fail("Should not be able to generate name for empty collection");
|
|
||||||
}
|
|
||||||
catch(IllegalArgumentException ex) {
|
|
||||||
// success
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAttributeNameToPropertyName() throws Exception {
|
@Test
|
||||||
|
public void emptyList() {
|
||||||
|
exception.expect(IllegalArgumentException.class);
|
||||||
|
Conventions.getVariableName(new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void set() {
|
||||||
|
assertEquals("Incorrect plural Set form", "testObjectList", Conventions.getVariableName(Collections.singleton(new TestObject())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void attributeNameToPropertyName() throws Exception {
|
||||||
assertEquals("transactionManager", Conventions.attributeNameToPropertyName("transaction-manager"));
|
assertEquals("transactionManager", Conventions.attributeNameToPropertyName("transaction-manager"));
|
||||||
assertEquals("pointcutRef", Conventions.attributeNameToPropertyName("pointcut-ref"));
|
assertEquals("pointcutRef", Conventions.attributeNameToPropertyName("pointcut-ref"));
|
||||||
assertEquals("lookupOnStartup", Conventions.attributeNameToPropertyName("lookup-on-startup"));
|
assertEquals("lookupOnStartup", Conventions.attributeNameToPropertyName("lookup-on-startup"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetQualifiedAttributeName() throws Exception {
|
@Test
|
||||||
|
public void getQualifiedAttributeName() throws Exception {
|
||||||
String baseName = "foo";
|
String baseName = "foo";
|
||||||
Class<String> cls = String.class;
|
Class<String> cls = String.class;
|
||||||
String desiredResult = "java.lang.String.foo";
|
String desiredResult = "java.lang.String.foo";
|
||||||
assertEquals(desiredResult, Conventions.getQualifiedAttributeName(cls, baseName));
|
assertEquals(desiredResult, Conventions.getQualifiedAttributeName(cls, baseName));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -19,16 +19,19 @@ package org.springframework.core;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class NestedExceptionTests extends TestCase {
|
@SuppressWarnings("serial")
|
||||||
|
public class NestedExceptionTests {
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@Test
|
||||||
public void testNestedRuntimeExceptionWithNoRootCause() {
|
public void nestedRuntimeExceptionWithNoRootCause() {
|
||||||
String mesg = "mesg of mine";
|
String mesg = "mesg of mine";
|
||||||
// Making a class abstract doesn't _really_ prevent instantiation :-)
|
// Making a class abstract doesn't _really_ prevent instantiation :-)
|
||||||
NestedRuntimeException nex = new NestedRuntimeException(mesg) {};
|
NestedRuntimeException nex = new NestedRuntimeException(mesg) {};
|
||||||
|
@ -44,8 +47,8 @@ public class NestedExceptionTests extends TestCase {
|
||||||
assertFalse(stackTrace.indexOf(mesg) == -1);
|
assertFalse(stackTrace.indexOf(mesg) == -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@Test
|
||||||
public void testNestedRuntimeExceptionWithRootCause() {
|
public void nestedRuntimeExceptionWithRootCause() {
|
||||||
String myMessage = "mesg for this exception";
|
String myMessage = "mesg for this exception";
|
||||||
String rootCauseMesg = "this is the obscure message of the root cause";
|
String rootCauseMesg = "this is the obscure message of the root cause";
|
||||||
Exception rootCause = new Exception(rootCauseMesg);
|
Exception rootCause = new Exception(rootCauseMesg);
|
||||||
|
@ -65,8 +68,8 @@ public class NestedExceptionTests extends TestCase {
|
||||||
assertFalse(stackTrace.indexOf(rootCauseMesg) == -1);
|
assertFalse(stackTrace.indexOf(rootCauseMesg) == -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@Test
|
||||||
public void testNestedCheckedExceptionWithNoRootCause() {
|
public void nestedCheckedExceptionWithNoRootCause() {
|
||||||
String mesg = "mesg of mine";
|
String mesg = "mesg of mine";
|
||||||
// Making a class abstract doesn't _really_ prevent instantiation :-)
|
// Making a class abstract doesn't _really_ prevent instantiation :-)
|
||||||
NestedCheckedException nex = new NestedCheckedException(mesg) {};
|
NestedCheckedException nex = new NestedCheckedException(mesg) {};
|
||||||
|
@ -82,8 +85,8 @@ public class NestedExceptionTests extends TestCase {
|
||||||
assertFalse(stackTrace.indexOf(mesg) == -1);
|
assertFalse(stackTrace.indexOf(mesg) == -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@Test
|
||||||
public void testNestedCheckedExceptionWithRootCause() {
|
public void nestedCheckedExceptionWithRootCause() {
|
||||||
String myMessage = "mesg for this exception";
|
String myMessage = "mesg for this exception";
|
||||||
String rootCauseMesg = "this is the obscure message of the root cause";
|
String rootCauseMesg = "this is the obscure message of the root cause";
|
||||||
Exception rootCause = new Exception(rootCauseMesg);
|
Exception rootCause = new Exception(rootCauseMesg);
|
||||||
|
|
|
@ -23,20 +23,24 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
public class ToStringCreatorTests extends TestCase {
|
public class ToStringCreatorTests {
|
||||||
|
|
||||||
private SomeObject s1, s2, s3;
|
private SomeObject s1, s2, s3;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
s1 = new SomeObject() {
|
s1 = new SomeObject() {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -57,7 +61,8 @@ public class ToStringCreatorTests extends TestCase {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDefaultStyleMap() {
|
@Test
|
||||||
|
public void defaultStyleMap() {
|
||||||
final Map map = getMap();
|
final Map map = getMap();
|
||||||
Object stringy = new Object() {
|
Object stringy = new Object() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -78,20 +83,23 @@ public class ToStringCreatorTests extends TestCase {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDefaultStyleArray() {
|
@Test
|
||||||
|
public void defaultStyleArray() {
|
||||||
SomeObject[] array = new SomeObject[] { s1, s2, s3 };
|
SomeObject[] array = new SomeObject[] { s1, s2, s3 };
|
||||||
String str = new ToStringCreator(array).toString();
|
String str = new ToStringCreator(array).toString();
|
||||||
assertEquals("[@" + ObjectUtils.getIdentityHexString(array)
|
assertEquals("[@" + ObjectUtils.getIdentityHexString(array)
|
||||||
+ " array<ToStringCreatorTests.SomeObject>[A, B, C]]", str);
|
+ " array<ToStringCreatorTests.SomeObject>[A, B, C]]", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPrimitiveArrays() {
|
@Test
|
||||||
|
public void primitiveArrays() {
|
||||||
int[] integers = new int[] { 0, 1, 2, 3, 4 };
|
int[] integers = new int[] { 0, 1, 2, 3, 4 };
|
||||||
String str = new ToStringCreator(integers).toString();
|
String str = new ToStringCreator(integers).toString();
|
||||||
assertEquals("[@" + ObjectUtils.getIdentityHexString(integers) + " array<Integer>[0, 1, 2, 3, 4]]", str);
|
assertEquals("[@" + ObjectUtils.getIdentityHexString(integers) + " array<Integer>[0, 1, 2, 3, 4]]", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testList() {
|
@Test
|
||||||
|
public void appendList() {
|
||||||
List list = new ArrayList();
|
List list = new ArrayList();
|
||||||
list.add(s1);
|
list.add(s1);
|
||||||
list.add(s2);
|
list.add(s2);
|
||||||
|
@ -101,7 +109,8 @@ public class ToStringCreatorTests extends TestCase {
|
||||||
str);
|
str);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSet() {
|
@Test
|
||||||
|
public void appendSet() {
|
||||||
Set set = new LinkedHashSet<>(3);
|
Set set = new LinkedHashSet<>(3);
|
||||||
set.add(s1);
|
set.add(s1);
|
||||||
set.add(s2);
|
set.add(s2);
|
||||||
|
@ -111,22 +120,23 @@ public class ToStringCreatorTests extends TestCase {
|
||||||
str);
|
str);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClass() {
|
@Test
|
||||||
|
public void appendClass() {
|
||||||
String str = new ToStringCreator(this).append("myClass", this.getClass()).toString();
|
String str = new ToStringCreator(this).append("myClass", this.getClass()).toString();
|
||||||
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this)
|
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this)
|
||||||
+ " myClass = ToStringCreatorTests]", str);
|
+ " myClass = ToStringCreatorTests]", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMethod() throws Exception {
|
@Test
|
||||||
String str = new ToStringCreator(this).append("myMethod", this.getClass().getMethod("testMethod"))
|
public void appendMethod() throws Exception {
|
||||||
|
String str = new ToStringCreator(this).append("myMethod", this.getClass().getMethod("appendMethod"))
|
||||||
.toString();
|
.toString();
|
||||||
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this)
|
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this)
|
||||||
+ " myMethod = testMethod@ToStringCreatorTests]", str);
|
+ " myMethod = appendMethod@ToStringCreatorTests]", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class SomeObject {
|
public static class SomeObject {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,42 +18,56 @@ package org.springframework.core.task;
|
||||||
|
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
import org.springframework.util.ConcurrencyThrottleSupport;
|
import org.springframework.util.ConcurrencyThrottleSupport;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public final class SimpleAsyncTaskExecutorTests extends TestCase {
|
public final class SimpleAsyncTaskExecutorTests {
|
||||||
|
|
||||||
public void testCannotExecuteWhenConcurrencyIsSwitchedOff() throws Exception {
|
@Rule
|
||||||
|
public final ExpectedException exception = ExpectedException.none();
|
||||||
|
|
||||||
|
|
||||||
|
// TODO Determine why task is executed when concurrency is switched off.
|
||||||
|
@Ignore("Disabled because task is still executed when concurrency is switched off")
|
||||||
|
@Test
|
||||||
|
public void cannotExecuteWhenConcurrencyIsSwitchedOff() throws Exception {
|
||||||
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
|
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
|
||||||
executor.setConcurrencyLimit(ConcurrencyThrottleSupport.NO_CONCURRENCY);
|
executor.setConcurrencyLimit(ConcurrencyThrottleSupport.NO_CONCURRENCY);
|
||||||
assertFalse(executor.isThrottleActive());
|
assertFalse(executor.isThrottleActive());
|
||||||
try {
|
exception.expect(IllegalStateException.class);
|
||||||
executor.execute(new NoOpRunnable());
|
executor.execute(new NoOpRunnable());
|
||||||
}
|
|
||||||
catch (IllegalStateException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testThrottleIsNotActiveByDefault() throws Exception {
|
@Test
|
||||||
|
public void throttleIsNotActiveByDefault() throws Exception {
|
||||||
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
|
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
|
||||||
assertFalse("Concurrency throttle must not default to being active (on)", executor.isThrottleActive());
|
assertFalse("Concurrency throttle must not default to being active (on)", executor.isThrottleActive());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testThreadNameGetsSetCorrectly() throws Exception {
|
@Test
|
||||||
|
public void threadNameGetsSetCorrectly() throws Exception {
|
||||||
final String customPrefix = "chankPop#";
|
final String customPrefix = "chankPop#";
|
||||||
final Object monitor = new Object();
|
final Object monitor = new Object();
|
||||||
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(customPrefix);
|
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(customPrefix);
|
||||||
ThreadNameHarvester task = new ThreadNameHarvester(monitor);
|
ThreadNameHarvester task = new ThreadNameHarvester(monitor);
|
||||||
executeAndWait(executor, task, monitor);
|
executeAndWait(executor, task, monitor);
|
||||||
assertTrue(task.getThreadName().startsWith(customPrefix));
|
assertThat(task.getThreadName(), startsWith(customPrefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testThreadFactoryOverridesDefaults() throws Exception {
|
@Test
|
||||||
|
public void threadFactoryOverridesDefaults() throws Exception {
|
||||||
final Object monitor = new Object();
|
final Object monitor = new Object();
|
||||||
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(new ThreadFactory() {
|
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(new ThreadFactory() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -63,16 +77,13 @@ public final class SimpleAsyncTaskExecutorTests extends TestCase {
|
||||||
});
|
});
|
||||||
ThreadNameHarvester task = new ThreadNameHarvester(monitor);
|
ThreadNameHarvester task = new ThreadNameHarvester(monitor);
|
||||||
executeAndWait(executor, task, monitor);
|
executeAndWait(executor, task, monitor);
|
||||||
assertTrue(task.getThreadName().equals("test"));
|
assertEquals("test", task.getThreadName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testThrowsExceptionWhenSuppliedWithNullRunnable() throws Exception {
|
@Test
|
||||||
try {
|
public void throwsExceptionWhenSuppliedWithNullRunnable() throws Exception {
|
||||||
new SimpleAsyncTaskExecutor().execute(null);
|
exception.expect(IllegalArgumentException.class);
|
||||||
fail("Should have thrown IllegalArgumentException");
|
new SimpleAsyncTaskExecutor().execute(null);
|
||||||
}
|
|
||||||
catch (IllegalArgumentException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeAndWait(SimpleAsyncTaskExecutor executor, Runnable task, Object monitor) {
|
private void executeAndWait(SimpleAsyncTaskExecutor executor, Runnable task, Object monitor) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.core.type;
|
package org.springframework.core.type;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.core.type.classreading.MetadataReader;
|
import org.springframework.core.type.classreading.MetadataReader;
|
||||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||||
|
@ -24,12 +24,15 @@ import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
||||||
import org.springframework.core.type.filter.AspectJTypeFilter;
|
import org.springframework.core.type.filter.AspectJTypeFilter;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ramnivas Laddad
|
* @author Ramnivas Laddad
|
||||||
*/
|
*/
|
||||||
public class AspectJTypeFilterTests extends TestCase {
|
public class AspectJTypeFilterTests {
|
||||||
|
|
||||||
public void testNamePatternMatches() throws Exception {
|
@Test
|
||||||
|
public void namePatternMatches() throws Exception {
|
||||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
||||||
"org.springframework.core.type.AspectJTypeFilterTests.SomeClass");
|
"org.springframework.core.type.AspectJTypeFilterTests.SomeClass");
|
||||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
||||||
|
@ -40,12 +43,14 @@ public class AspectJTypeFilterTests extends TestCase {
|
||||||
"org..SomeClass");
|
"org..SomeClass");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNamePatternNoMatches() throws Exception {
|
@Test
|
||||||
|
public void namePatternNoMatches() throws Exception {
|
||||||
assertNoMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
assertNoMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
||||||
"org.springframework.core.type.AspectJTypeFilterTests.SomeClassX");
|
"org.springframework.core.type.AspectJTypeFilterTests.SomeClassX");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSubclassPatternMatches() throws Exception {
|
@Test
|
||||||
|
public void subclassPatternMatches() throws Exception {
|
||||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClass",
|
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClass",
|
||||||
"org.springframework.core.type.AspectJTypeFilterTests.SomeClass+");
|
"org.springframework.core.type.AspectJTypeFilterTests.SomeClass+");
|
||||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClass",
|
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClass",
|
||||||
|
@ -72,12 +77,14 @@ public class AspectJTypeFilterTests extends TestCase {
|
||||||
"java.lang.Object+");
|
"java.lang.Object+");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSubclassPatternNoMatches() throws Exception {
|
@Test
|
||||||
|
public void subclassPatternNoMatches() throws Exception {
|
||||||
assertNoMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClass",
|
assertNoMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClass",
|
||||||
"java.lang.String+");
|
"java.lang.String+");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAnnotationPatternMatches() throws Exception {
|
@Test
|
||||||
|
public void annotationPatternMatches() throws Exception {
|
||||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassAnnotatedWithComponent",
|
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassAnnotatedWithComponent",
|
||||||
"@org.springframework.stereotype.Component *..*");
|
"@org.springframework.stereotype.Component *..*");
|
||||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassAnnotatedWithComponent",
|
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassAnnotatedWithComponent",
|
||||||
|
@ -92,12 +99,14 @@ public class AspectJTypeFilterTests extends TestCase {
|
||||||
"@org.springframework.stereotype.Component *");
|
"@org.springframework.stereotype.Component *");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAnnotationPatternNoMathces() throws Exception {
|
@Test
|
||||||
|
public void annotationPatternNoMathces() throws Exception {
|
||||||
assertNoMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassAnnotatedWithComponent",
|
assertNoMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassAnnotatedWithComponent",
|
||||||
"@org.springframework.stereotype.Repository *..*");
|
"@org.springframework.stereotype.Repository *..*");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCompositionPatternMatches() throws Exception {
|
@Test
|
||||||
|
public void compositionPatternMatches() throws Exception {
|
||||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
||||||
"!*..SomeOtherClass");
|
"!*..SomeOtherClass");
|
||||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClassExtendingSomeClassAndImplemnentingSomeInterface",
|
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClassExtendingSomeClassAndImplemnentingSomeInterface",
|
||||||
|
@ -110,7 +119,8 @@ public class AspectJTypeFilterTests extends TestCase {
|
||||||
"|| org.springframework.core.type.AspectJTypeFilterTests.SomeClassExtendingSomeClass+");
|
"|| org.springframework.core.type.AspectJTypeFilterTests.SomeClassExtendingSomeClass+");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCompositionPatternNoMatches() throws Exception {
|
@Test
|
||||||
|
public void compositionPatternNoMatches() throws Exception {
|
||||||
assertNoMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
assertNoMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
||||||
"*..Bogus && org.springframework.core.type.AspectJTypeFilterTests.SomeClass");
|
"*..Bogus && org.springframework.core.type.AspectJTypeFilterTests.SomeClass");
|
||||||
}
|
}
|
||||||
|
@ -136,27 +146,22 @@ public class AspectJTypeFilterTests extends TestCase {
|
||||||
|
|
||||||
// We must use a standalone set of types to ensure that no one else is loading them
|
// We must use a standalone set of types to ensure that no one else is loading them
|
||||||
// and interfering with ClassloadingAssertions.assertClassNotLoaded()
|
// and interfering with ClassloadingAssertions.assertClassNotLoaded()
|
||||||
static interface SomeInterface {
|
interface SomeInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class SomeClass {
|
static class SomeClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class SomeClassExtendingSomeClass extends SomeClass {
|
static class SomeClassExtendingSomeClass extends SomeClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class SomeClassImplementingSomeInterface implements SomeInterface {
|
static class SomeClassImplementingSomeInterface implements SomeInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class SomeClassExtendingSomeClassExtendingSomeClassAndImplemnentingSomeInterface
|
static class SomeClassExtendingSomeClassExtendingSomeClassAndImplemnentingSomeInterface
|
||||||
extends SomeClassExtendingSomeClass implements SomeInterface {
|
extends SomeClassExtendingSomeClass implements SomeInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
static class SomeClassAnnotatedWithComponent {
|
static class SomeClassAnnotatedWithComponent {
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,20 +16,23 @@
|
||||||
|
|
||||||
package org.springframework.core.type;
|
package org.springframework.core.type;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.core.type.classreading.MetadataReader;
|
import org.springframework.core.type.classreading.MetadataReader;
|
||||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||||
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
||||||
import org.springframework.core.type.filter.AssignableTypeFilter;
|
import org.springframework.core.type.filter.AssignableTypeFilter;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ramnivas Laddad
|
* @author Ramnivas Laddad
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class AssignableTypeFilterTests extends TestCase {
|
public class AssignableTypeFilterTests {
|
||||||
|
|
||||||
public void testDirectMatch() throws Exception {
|
@Test
|
||||||
|
public void directMatch() throws Exception {
|
||||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||||
String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$TestNonInheritingClass";
|
String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$TestNonInheritingClass";
|
||||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
||||||
|
@ -40,7 +43,8 @@ public class AssignableTypeFilterTests extends TestCase {
|
||||||
assertTrue(matchingFilter.match(metadataReader, metadataReaderFactory));
|
assertTrue(matchingFilter.match(metadataReader, metadataReaderFactory));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInterfaceMatch() throws Exception {
|
@Test
|
||||||
|
public void interfaceMatch() throws Exception {
|
||||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||||
String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$TestInterfaceImpl";
|
String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$TestInterfaceImpl";
|
||||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
||||||
|
@ -50,7 +54,8 @@ public class AssignableTypeFilterTests extends TestCase {
|
||||||
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
|
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSuperClassMatch() throws Exception {
|
@Test
|
||||||
|
public void superClassMatch() throws Exception {
|
||||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||||
String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$SomeDaoLikeImpl";
|
String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$SomeDaoLikeImpl";
|
||||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
||||||
|
@ -60,7 +65,8 @@ public class AssignableTypeFilterTests extends TestCase {
|
||||||
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
|
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInterfaceThroughSuperClassMatch() throws Exception {
|
@Test
|
||||||
|
public void interfaceThroughSuperClassMatch() throws Exception {
|
||||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||||
String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$SomeDaoLikeImpl";
|
String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$SomeDaoLikeImpl";
|
||||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
||||||
|
@ -76,30 +82,24 @@ public class AssignableTypeFilterTests extends TestCase {
|
||||||
private static class TestNonInheritingClass {
|
private static class TestNonInheritingClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private interface TestInterface {
|
||||||
private static interface TestInterface {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static class TestInterfaceImpl implements TestInterface {
|
private static class TestInterfaceImpl implements TestInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private interface SomeDaoLikeInterface {
|
||||||
private static interface SomeDaoLikeInterface {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static class SomeDaoLikeImpl extends SimpleJdbcDaoSupport implements SomeDaoLikeInterface {
|
private static class SomeDaoLikeImpl extends SimpleJdbcDaoSupport implements SomeDaoLikeInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static interface JdbcDaoSupport {
|
private interface JdbcDaoSupport {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SimpleJdbcDaoSupport implements JdbcDaoSupport {
|
private static class SimpleJdbcDaoSupport implements JdbcDaoSupport {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2006 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -23,7 +23,9 @@ import java.io.StringReader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the FileCopyUtils class.
|
* Unit tests for the FileCopyUtils class.
|
||||||
|
@ -31,9 +33,10 @@ import junit.framework.TestCase;
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 12.03.2005
|
* @since 12.03.2005
|
||||||
*/
|
*/
|
||||||
public class FileCopyUtilsTests extends TestCase {
|
public class FileCopyUtilsTests {
|
||||||
|
|
||||||
public void testCopyFromInputStream() throws IOException {
|
@Test
|
||||||
|
public void copyFromInputStream() throws IOException {
|
||||||
byte[] content = "content".getBytes();
|
byte[] content = "content".getBytes();
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(content);
|
ByteArrayInputStream in = new ByteArrayInputStream(content);
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream(content.length);
|
ByteArrayOutputStream out = new ByteArrayOutputStream(content.length);
|
||||||
|
@ -42,21 +45,24 @@ public class FileCopyUtilsTests extends TestCase {
|
||||||
assertTrue(Arrays.equals(content, out.toByteArray()));
|
assertTrue(Arrays.equals(content, out.toByteArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCopyFromByteArray() throws IOException {
|
@Test
|
||||||
|
public void copyFromByteArray() throws IOException {
|
||||||
byte[] content = "content".getBytes();
|
byte[] content = "content".getBytes();
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream(content.length);
|
ByteArrayOutputStream out = new ByteArrayOutputStream(content.length);
|
||||||
FileCopyUtils.copy(content, out);
|
FileCopyUtils.copy(content, out);
|
||||||
assertTrue(Arrays.equals(content, out.toByteArray()));
|
assertTrue(Arrays.equals(content, out.toByteArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCopyToByteArray() throws IOException {
|
@Test
|
||||||
|
public void copyToByteArray() throws IOException {
|
||||||
byte[] content = "content".getBytes();
|
byte[] content = "content".getBytes();
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(content);
|
ByteArrayInputStream in = new ByteArrayInputStream(content);
|
||||||
byte[] result = FileCopyUtils.copyToByteArray(in);
|
byte[] result = FileCopyUtils.copyToByteArray(in);
|
||||||
assertTrue(Arrays.equals(content, result));
|
assertTrue(Arrays.equals(content, result));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCopyFromReader() throws IOException {
|
@Test
|
||||||
|
public void copyFromReader() throws IOException {
|
||||||
String content = "content";
|
String content = "content";
|
||||||
StringReader in = new StringReader(content);
|
StringReader in = new StringReader(content);
|
||||||
StringWriter out = new StringWriter();
|
StringWriter out = new StringWriter();
|
||||||
|
@ -65,14 +71,16 @@ public class FileCopyUtilsTests extends TestCase {
|
||||||
assertEquals(content, out.toString());
|
assertEquals(content, out.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCopyFromString() throws IOException {
|
@Test
|
||||||
|
public void copyFromString() throws IOException {
|
||||||
String content = "content";
|
String content = "content";
|
||||||
StringWriter out = new StringWriter();
|
StringWriter out = new StringWriter();
|
||||||
FileCopyUtils.copy(content, out);
|
FileCopyUtils.copy(content, out);
|
||||||
assertEquals(content, out.toString());
|
assertEquals(content, out.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCopyToString() throws IOException {
|
@Test
|
||||||
|
public void copyToString() throws IOException {
|
||||||
String content = "content";
|
String content = "content";
|
||||||
StringReader in = new StringReader(content);
|
StringReader in = new StringReader(content);
|
||||||
String result = FileCopyUtils.copyToString(in);
|
String result = FileCopyUtils.copyToString(in);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,14 +18,18 @@ package org.springframework.util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.After;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
*/
|
*/
|
||||||
public class FileSystemUtilsTests extends TestCase {
|
public class FileSystemUtilsTests {
|
||||||
|
|
||||||
public void testDeleteRecursively() throws Exception {
|
@Test
|
||||||
|
public void deleteRecursively() throws Exception {
|
||||||
File root = new File("./tmp/root");
|
File root = new File("./tmp/root");
|
||||||
File child = new File(root, "child");
|
File child = new File(root, "child");
|
||||||
File grandchild = new File(child, "grandchild");
|
File grandchild = new File(child, "grandchild");
|
||||||
|
@ -48,7 +52,8 @@ public class FileSystemUtilsTests extends TestCase {
|
||||||
assertFalse(bar.exists());
|
assertFalse(bar.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCopyRecursively() throws Exception {
|
@Test
|
||||||
|
public void copyRecursively() throws Exception {
|
||||||
File src = new File("./tmp/src");
|
File src = new File("./tmp/src");
|
||||||
File child = new File(src, "child");
|
File child = new File(src, "child");
|
||||||
File grandchild = new File(child, "grandchild");
|
File grandchild = new File(child, "grandchild");
|
||||||
|
@ -70,11 +75,12 @@ public class FileSystemUtilsTests extends TestCase {
|
||||||
assertTrue(new File(dest, child.getName()).exists());
|
assertTrue(new File(dest, child.getName()).exists());
|
||||||
|
|
||||||
FileSystemUtils.deleteRecursively(src);
|
FileSystemUtils.deleteRecursively(src);
|
||||||
assertTrue(!src.exists());
|
assertFalse(src.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void tearDown() throws Exception {
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
File tmp = new File("./tmp");
|
File tmp = new File("./tmp");
|
||||||
if (tmp.exists()) {
|
if (tmp.exists()) {
|
||||||
FileSystemUtils.deleteRecursively(tmp);
|
FileSystemUtils.deleteRecursively(tmp);
|
||||||
|
@ -83,7 +89,6 @@ public class FileSystemUtilsTests extends TestCase {
|
||||||
if (dest.exists()) {
|
if (dest.exists()) {
|
||||||
FileSystemUtils.deleteRecursively(dest);
|
FileSystemUtils.deleteRecursively(dest);
|
||||||
}
|
}
|
||||||
super.tearDown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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,16 +20,26 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Colin Sampaleanu
|
* @author Colin Sampaleanu
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
* @since 21.11.2003
|
* @since 21.11.2003
|
||||||
*/
|
*/
|
||||||
public class MethodInvokerTests extends TestCase {
|
public class MethodInvokerTests {
|
||||||
|
|
||||||
public void testPlainMethodInvoker() throws Exception {
|
@Rule
|
||||||
|
public final ExpectedException exception = ExpectedException.none();
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void plainMethodInvoker() throws Exception {
|
||||||
// sanity check: singleton, non-static should work
|
// sanity check: singleton, non-static should work
|
||||||
TestClass1 tc1 = new TestClass1();
|
TestClass1 tc1 = new TestClass1();
|
||||||
MethodInvoker mi = new MethodInvoker();
|
MethodInvoker mi = new MethodInvoker();
|
||||||
|
@ -59,30 +69,24 @@ public class MethodInvokerTests extends TestCase {
|
||||||
mi.setTargetClass(TestClass1.class);
|
mi.setTargetClass(TestClass1.class);
|
||||||
mi.setTargetMethod("supertypes2");
|
mi.setTargetMethod("supertypes2");
|
||||||
mi.setArguments(new Object[] {new ArrayList<>(), new ArrayList<>(), "hello", Boolean.TRUE});
|
mi.setArguments(new Object[] {new ArrayList<>(), new ArrayList<>(), "hello", Boolean.TRUE});
|
||||||
try {
|
|
||||||
mi.prepare();
|
exception.expect(NoSuchMethodException.class);
|
||||||
fail("Shouldn't have matched without argument conversion");
|
mi.prepare();
|
||||||
}
|
|
||||||
catch (NoSuchMethodException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStringWithMethodInvoker() throws Exception {
|
@Test
|
||||||
try {
|
public void stringWithMethodInvoker() throws Exception {
|
||||||
MethodInvoker methodInvoker = new MethodInvoker();
|
MethodInvoker methodInvoker = new MethodInvoker();
|
||||||
methodInvoker.setTargetObject(new Greeter());
|
methodInvoker.setTargetObject(new Greeter());
|
||||||
methodInvoker.setTargetMethod("greet");
|
methodInvoker.setTargetMethod("greet");
|
||||||
methodInvoker.setArguments(new Object[] {new String("no match")});
|
methodInvoker.setArguments(new Object[] { new String("no match") });
|
||||||
methodInvoker.prepare();
|
|
||||||
fail("Should have thrown a NoSuchMethodException");
|
exception.expect(NoSuchMethodException.class);
|
||||||
}
|
methodInvoker.prepare();
|
||||||
catch (NoSuchMethodException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPurchaserWithMethodInvoker() throws Exception {
|
@Test
|
||||||
|
public void purchaserWithMethodInvoker() throws Exception {
|
||||||
MethodInvoker methodInvoker = new MethodInvoker();
|
MethodInvoker methodInvoker = new MethodInvoker();
|
||||||
methodInvoker.setTargetObject(new Greeter());
|
methodInvoker.setTargetObject(new Greeter());
|
||||||
methodInvoker.setTargetMethod("greet");
|
methodInvoker.setTargetMethod("greet");
|
||||||
|
@ -92,7 +96,8 @@ public class MethodInvokerTests extends TestCase {
|
||||||
assertEquals("purchaser: hello", greeting);
|
assertEquals("purchaser: hello", greeting);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShopperWithMethodInvoker() throws Exception {
|
@Test
|
||||||
|
public void shopperWithMethodInvoker() throws Exception {
|
||||||
MethodInvoker methodInvoker = new MethodInvoker();
|
MethodInvoker methodInvoker = new MethodInvoker();
|
||||||
methodInvoker.setTargetObject(new Greeter());
|
methodInvoker.setTargetObject(new Greeter());
|
||||||
methodInvoker.setTargetMethod("greet");
|
methodInvoker.setTargetMethod("greet");
|
||||||
|
@ -102,7 +107,8 @@ public class MethodInvokerTests extends TestCase {
|
||||||
assertEquals("purchaser: may I help you?", greeting);
|
assertEquals("purchaser: may I help you?", greeting);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSalesmanWithMethodInvoker() throws Exception {
|
@Test
|
||||||
|
public void salesmanWithMethodInvoker() throws Exception {
|
||||||
MethodInvoker methodInvoker = new MethodInvoker();
|
MethodInvoker methodInvoker = new MethodInvoker();
|
||||||
methodInvoker.setTargetObject(new Greeter());
|
methodInvoker.setTargetObject(new Greeter());
|
||||||
methodInvoker.setTargetMethod("greet");
|
methodInvoker.setTargetMethod("greet");
|
||||||
|
@ -112,7 +118,8 @@ public class MethodInvokerTests extends TestCase {
|
||||||
assertEquals("greetable: how are sales?", greeting);
|
assertEquals("greetable: how are sales?", greeting);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCustomerWithMethodInvoker() throws Exception {
|
@Test
|
||||||
|
public void customerWithMethodInvoker() throws Exception {
|
||||||
MethodInvoker methodInvoker = new MethodInvoker();
|
MethodInvoker methodInvoker = new MethodInvoker();
|
||||||
methodInvoker.setTargetObject(new Greeter());
|
methodInvoker.setTargetObject(new Greeter());
|
||||||
methodInvoker.setTargetMethod("greet");
|
methodInvoker.setTargetMethod("greet");
|
||||||
|
@ -122,7 +129,8 @@ public class MethodInvokerTests extends TestCase {
|
||||||
assertEquals("customer: good day", greeting);
|
assertEquals("customer: good day", greeting);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRegularWithMethodInvoker() throws Exception {
|
@Test
|
||||||
|
public void regularWithMethodInvoker() throws Exception {
|
||||||
MethodInvoker methodInvoker = new MethodInvoker();
|
MethodInvoker methodInvoker = new MethodInvoker();
|
||||||
methodInvoker.setTargetObject(new Greeter());
|
methodInvoker.setTargetObject(new Greeter());
|
||||||
methodInvoker.setTargetMethod("greet");
|
methodInvoker.setTargetMethod("greet");
|
||||||
|
@ -132,7 +140,8 @@ public class MethodInvokerTests extends TestCase {
|
||||||
assertEquals("regular: welcome back Kotter", greeting);
|
assertEquals("regular: welcome back Kotter", greeting);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testVIPWithMethodInvoker() throws Exception {
|
@Test
|
||||||
|
public void vipWithMethodInvoker() throws Exception {
|
||||||
MethodInvoker methodInvoker = new MethodInvoker();
|
MethodInvoker methodInvoker = new MethodInvoker();
|
||||||
methodInvoker.setTargetObject(new Greeter());
|
methodInvoker.setTargetObject(new Greeter());
|
||||||
methodInvoker.setTargetMethod("greet");
|
methodInvoker.setTargetMethod("greet");
|
||||||
|
@ -190,7 +199,6 @@ public class MethodInvokerTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static class Greeter {
|
public static class Greeter {
|
||||||
|
|
||||||
|
@ -215,17 +223,13 @@ public class MethodInvokerTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private interface Greetable {
|
||||||
private static interface Greetable {
|
|
||||||
|
|
||||||
String getGreeting();
|
String getGreeting();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private interface Person extends Greetable {
|
||||||
private static interface Person extends Greetable {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class Purchaser implements Greetable {
|
private static class Purchaser implements Greetable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -234,7 +238,6 @@ public class MethodInvokerTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class Shopper extends Purchaser implements Person {
|
private static class Shopper extends Purchaser implements Person {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -243,7 +246,6 @@ public class MethodInvokerTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class Salesman implements Person {
|
private static class Salesman implements Person {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -252,7 +254,6 @@ public class MethodInvokerTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class Customer extends Shopper {
|
private static class Customer extends Shopper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -261,7 +262,6 @@ public class MethodInvokerTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class Regular extends Customer {
|
private static class Regular extends Customer {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
@ -276,7 +276,6 @@ public class MethodInvokerTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class VIP extends Regular {
|
private static class VIP extends Regular {
|
||||||
|
|
||||||
public VIP(String name) {
|
public VIP(String name) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2005 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -23,64 +23,74 @@ import java.io.StringReader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 11.01.2005
|
* @since 11.01.2005
|
||||||
*/
|
*/
|
||||||
public class PropertiesPersisterTests extends TestCase {
|
public class PropertiesPersisterTests {
|
||||||
|
|
||||||
public void testPropertiesPersister() throws IOException {
|
@Test
|
||||||
|
public void propertiesPersister() throws IOException {
|
||||||
String propString = "code1=message1\ncode2:message2";
|
String propString = "code1=message1\ncode2:message2";
|
||||||
Properties props = loadProperties(propString, false);
|
Properties props = loadProperties(propString, false);
|
||||||
String propCopy = storeProperties(props, null, false);
|
String propCopy = storeProperties(props, null, false);
|
||||||
loadProperties(propCopy, false);
|
loadProperties(propCopy, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPropertiesPersisterWithWhitespace() throws IOException {
|
@Test
|
||||||
|
public void propertiesPersisterWithWhitespace() throws IOException {
|
||||||
String propString = " code1\t= \tmessage1\n code2 \t :\t mess\\\n \t age2";
|
String propString = " code1\t= \tmessage1\n code2 \t :\t mess\\\n \t age2";
|
||||||
Properties props = loadProperties(propString, false);
|
Properties props = loadProperties(propString, false);
|
||||||
String propCopy = storeProperties(props, null, false);
|
String propCopy = storeProperties(props, null, false);
|
||||||
loadProperties(propCopy, false);
|
loadProperties(propCopy, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPropertiesPersisterWithHeader() throws IOException {
|
@Test
|
||||||
|
public void propertiesPersisterWithHeader() throws IOException {
|
||||||
String propString = "code1=message1\ncode2:message2";
|
String propString = "code1=message1\ncode2:message2";
|
||||||
Properties props = loadProperties(propString, false);
|
Properties props = loadProperties(propString, false);
|
||||||
String propCopy = storeProperties(props, "myHeader", false);
|
String propCopy = storeProperties(props, "myHeader", false);
|
||||||
loadProperties(propCopy, false);
|
loadProperties(propCopy, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPropertiesPersisterWithEmptyValue() throws IOException {
|
@Test
|
||||||
|
public void propertiesPersisterWithEmptyValue() throws IOException {
|
||||||
String propString = "code1=message1\ncode2:message2\ncode3=";
|
String propString = "code1=message1\ncode2:message2\ncode3=";
|
||||||
Properties props = loadProperties(propString, false);
|
Properties props = loadProperties(propString, false);
|
||||||
String propCopy = storeProperties(props, null, false);
|
String propCopy = storeProperties(props, null, false);
|
||||||
loadProperties(propCopy, false);
|
loadProperties(propCopy, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPropertiesPersisterWithReader() throws IOException {
|
@Test
|
||||||
|
public void propertiesPersisterWithReader() throws IOException {
|
||||||
String propString = "code1=message1\ncode2:message2";
|
String propString = "code1=message1\ncode2:message2";
|
||||||
Properties props = loadProperties(propString, true);
|
Properties props = loadProperties(propString, true);
|
||||||
String propCopy = storeProperties(props, null, true);
|
String propCopy = storeProperties(props, null, true);
|
||||||
loadProperties(propCopy, false);
|
loadProperties(propCopy, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPropertiesPersisterWithReaderAndWhitespace() throws IOException {
|
@Test
|
||||||
|
public void propertiesPersisterWithReaderAndWhitespace() throws IOException {
|
||||||
String propString = " code1\t= \tmessage1\n code2 \t :\t mess\\\n \t age2";
|
String propString = " code1\t= \tmessage1\n code2 \t :\t mess\\\n \t age2";
|
||||||
Properties props = loadProperties(propString, true);
|
Properties props = loadProperties(propString, true);
|
||||||
String propCopy = storeProperties(props, null, true);
|
String propCopy = storeProperties(props, null, true);
|
||||||
loadProperties(propCopy, false);
|
loadProperties(propCopy, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPropertiesPersisterWithReaderAndHeader() throws IOException {
|
@Test
|
||||||
|
public void propertiesPersisterWithReaderAndHeader() throws IOException {
|
||||||
String propString = "code1\t=\tmessage1\n code2 \t : \t message2";
|
String propString = "code1\t=\tmessage1\n code2 \t : \t message2";
|
||||||
Properties props = loadProperties(propString, true);
|
Properties props = loadProperties(propString, true);
|
||||||
String propCopy = storeProperties(props, "myHeader", true);
|
String propCopy = storeProperties(props, "myHeader", true);
|
||||||
loadProperties(propCopy, false);
|
loadProperties(propCopy, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPropertiesPersisterWithReaderAndEmptyValue() throws IOException {
|
@Test
|
||||||
|
public void propertiesPersisterWithReaderAndEmptyValue() throws IOException {
|
||||||
String propString = "code1=message1\ncode2:message2\ncode3=";
|
String propString = "code1=message1\ncode2:message2\ncode3=";
|
||||||
Properties props = loadProperties(propString, true);
|
Properties props = loadProperties(propString, true);
|
||||||
String propCopy = storeProperties(props, null, true);
|
String propCopy = storeProperties(props, null, true);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -21,14 +21,17 @@ import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLStreamHandler;
|
import java.net.URLStreamHandler;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class ResourceUtilsTests extends TestCase {
|
public class ResourceUtilsTests {
|
||||||
|
|
||||||
public void testIsJarURL() throws Exception {
|
@Test
|
||||||
|
public void isJarURL() throws Exception {
|
||||||
assertTrue(ResourceUtils.isJarURL(new URL("jar:file:myjar.jar!/mypath")));
|
assertTrue(ResourceUtils.isJarURL(new URL("jar:file:myjar.jar!/mypath")));
|
||||||
assertTrue(ResourceUtils.isJarURL(new URL(null, "zip:file:myjar.jar!/mypath", new DummyURLStreamHandler())));
|
assertTrue(ResourceUtils.isJarURL(new URL(null, "zip:file:myjar.jar!/mypath", new DummyURLStreamHandler())));
|
||||||
assertTrue(ResourceUtils.isJarURL(new URL(null, "wsjar:file:myjar.jar!/mypath", new DummyURLStreamHandler())));
|
assertTrue(ResourceUtils.isJarURL(new URL(null, "wsjar:file:myjar.jar!/mypath", new DummyURLStreamHandler())));
|
||||||
|
@ -36,7 +39,8 @@ public class ResourceUtilsTests extends TestCase {
|
||||||
assertFalse(ResourceUtils.isJarURL(new URL("http:myserver/myjar.jar")));
|
assertFalse(ResourceUtils.isJarURL(new URL("http:myserver/myjar.jar")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExtractJarFileURL() throws Exception {
|
@Test
|
||||||
|
public void extractJarFileURL() throws Exception {
|
||||||
assertEquals(new URL("file:myjar.jar"),
|
assertEquals(new URL("file:myjar.jar"),
|
||||||
ResourceUtils.extractJarFileURL(new URL("jar:file:myjar.jar!/mypath")));
|
ResourceUtils.extractJarFileURL(new URL("jar:file:myjar.jar!/mypath")));
|
||||||
assertEquals(new URL("file:/myjar.jar"),
|
assertEquals(new URL("file:/myjar.jar"),
|
||||||
|
|
|
@ -16,18 +16,26 @@
|
||||||
|
|
||||||
package org.springframework.util;
|
package org.springframework.util;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class StopWatchTests extends TestCase {
|
public class StopWatchTests {
|
||||||
|
|
||||||
/**
|
private final StopWatch sw = new StopWatch();
|
||||||
* Are timings off in JUnit?
|
|
||||||
*/
|
@Rule
|
||||||
public void testValidUsage() throws Exception {
|
public final ExpectedException exception = ExpectedException.none();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void validUsage() throws Exception {
|
||||||
String id = "myId";
|
String id = "myId";
|
||||||
StopWatch sw = new StopWatch(id);
|
StopWatch sw = new StopWatch(id);
|
||||||
long int1 = 166L;
|
long int1 = 166L;
|
||||||
|
@ -45,14 +53,18 @@ public class StopWatchTests extends TestCase {
|
||||||
// TODO are timings off in JUnit? Why do these assertions sometimes fail
|
// TODO are timings off in JUnit? Why do these assertions sometimes fail
|
||||||
// under both Ant and Eclipse?
|
// under both Ant and Eclipse?
|
||||||
|
|
||||||
//long fudgeFactor = 5L;
|
// long fudgeFactor = 5L;
|
||||||
//assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() >= int1);
|
// assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() >=
|
||||||
//assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() <= int1 + fudgeFactor);
|
// int1);
|
||||||
|
// assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() <= int1
|
||||||
|
// + fudgeFactor);
|
||||||
sw.start(name2);
|
sw.start(name2);
|
||||||
Thread.sleep(int2);
|
Thread.sleep(int2);
|
||||||
sw.stop();
|
sw.stop();
|
||||||
//assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() >= int1 + int2);
|
// assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() >= int1
|
||||||
//assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() <= int1 + int2 + fudgeFactor);
|
// + int2);
|
||||||
|
// assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() <= int1
|
||||||
|
// + int2 + fudgeFactor);
|
||||||
|
|
||||||
assertTrue(sw.getTaskCount() == 2);
|
assertTrue(sw.getTaskCount() == 2);
|
||||||
String pp = sw.prettyPrint();
|
String pp = sw.prettyPrint();
|
||||||
|
@ -72,8 +84,8 @@ public class StopWatchTests extends TestCase {
|
||||||
assertEquals(id, sw.getId());
|
assertEquals(id, sw.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testValidUsageNotKeepingTaskList() throws Exception {
|
@Test
|
||||||
StopWatch sw = new StopWatch();
|
public void validUsageNotKeepingTaskList() throws Exception {
|
||||||
sw.setKeepTaskList(false);
|
sw.setKeepTaskList(false);
|
||||||
long int1 = 166L;
|
long int1 = 166L;
|
||||||
long int2 = 45L;
|
long int2 = 45L;
|
||||||
|
@ -89,14 +101,18 @@ public class StopWatchTests extends TestCase {
|
||||||
// TODO are timings off in JUnit? Why do these assertions sometimes fail
|
// TODO are timings off in JUnit? Why do these assertions sometimes fail
|
||||||
// under both Ant and Eclipse?
|
// under both Ant and Eclipse?
|
||||||
|
|
||||||
//long fudgeFactor = 5L;
|
// long fudgeFactor = 5L;
|
||||||
//assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() >= int1);
|
// assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() >=
|
||||||
//assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() <= int1 + fudgeFactor);
|
// int1);
|
||||||
|
// assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() <= int1
|
||||||
|
// + fudgeFactor);
|
||||||
sw.start(name2);
|
sw.start(name2);
|
||||||
Thread.sleep(int2);
|
Thread.sleep(int2);
|
||||||
sw.stop();
|
sw.stop();
|
||||||
//assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() >= int1 + int2);
|
// assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() >= int1
|
||||||
//assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() <= int1 + int2 + fudgeFactor);
|
// + int2);
|
||||||
|
// assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() <= int1
|
||||||
|
// + int2 + fudgeFactor);
|
||||||
|
|
||||||
assertTrue(sw.getTaskCount() == 2);
|
assertTrue(sw.getTaskCount() == 2);
|
||||||
String pp = sw.prettyPrint();
|
String pp = sw.prettyPrint();
|
||||||
|
@ -106,50 +122,30 @@ public class StopWatchTests extends TestCase {
|
||||||
assertFalse(toString.contains(name1));
|
assertFalse(toString.contains(name1));
|
||||||
assertFalse(toString.contains(name2));
|
assertFalse(toString.contains(name2));
|
||||||
|
|
||||||
try {
|
exception.expect(UnsupportedOperationException.class);
|
||||||
sw.getTaskInfo();
|
sw.getTaskInfo();
|
||||||
fail();
|
|
||||||
}
|
|
||||||
catch (UnsupportedOperationException ex) {
|
|
||||||
// Ok
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFailureToStartBeforeGettingTimings() {
|
@Test
|
||||||
StopWatch sw = new StopWatch();
|
public void failureToStartBeforeGettingTimings() {
|
||||||
try {
|
exception.expect(IllegalStateException.class);
|
||||||
sw.getLastTaskTimeMillis();
|
sw.getLastTaskTimeMillis();
|
||||||
fail("Can't get last interval if no tests run");
|
|
||||||
}
|
|
||||||
catch (IllegalStateException ex) {
|
|
||||||
// Ok
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFailureToStartBeforeStop() {
|
@Test
|
||||||
StopWatch sw = new StopWatch();
|
public void failureToStartBeforeStop() {
|
||||||
try {
|
exception.expect(IllegalStateException.class);
|
||||||
sw.stop();
|
sw.stop();
|
||||||
fail("Can't stop without starting");
|
|
||||||
}
|
|
||||||
catch (IllegalStateException ex) {
|
|
||||||
// Ok
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRejectsStartTwice() {
|
@Test
|
||||||
StopWatch sw = new StopWatch();
|
public void rejectsStartTwice() {
|
||||||
try {
|
sw.start("");
|
||||||
sw.start("");
|
sw.stop();
|
||||||
sw.stop();
|
sw.start("");
|
||||||
sw.start("");
|
assertTrue(sw.isRunning());
|
||||||
assertTrue(sw.isRunning());
|
exception.expect(IllegalStateException.class);
|
||||||
sw.start("");
|
sw.start("");
|
||||||
fail("Can't start twice");
|
|
||||||
}
|
|
||||||
catch (IllegalStateException ex) {
|
|
||||||
// Ok
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,6 +18,7 @@ package org.springframework.util.xml;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import javax.xml.stream.XMLInputFactory;
|
import javax.xml.stream.XMLInputFactory;
|
||||||
import javax.xml.stream.XMLStreamException;
|
import javax.xml.stream.XMLStreamException;
|
||||||
import javax.xml.transform.Transformer;
|
import javax.xml.transform.Transformer;
|
||||||
|
@ -27,8 +28,15 @@ import javax.xml.transform.sax.SAXSource;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.tests.MockitoUtils;
|
||||||
|
import org.springframework.tests.MockitoUtils.InvocationArgumentsAdapter;
|
||||||
|
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.ContentHandler;
|
import org.xml.sax.ContentHandler;
|
||||||
|
@ -39,11 +47,6 @@ import org.xml.sax.ext.LexicalHandler;
|
||||||
import org.xml.sax.helpers.AttributesImpl;
|
import org.xml.sax.helpers.AttributesImpl;
|
||||||
import org.xml.sax.helpers.XMLReaderFactory;
|
import org.xml.sax.helpers.XMLReaderFactory;
|
||||||
|
|
||||||
import org.springframework.core.io.ClassPathResource;
|
|
||||||
import org.springframework.core.io.Resource;
|
|
||||||
import org.springframework.tests.MockitoUtils;
|
|
||||||
import org.springframework.tests.MockitoUtils.InvocationArgumentsAdapter;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.BDDMockito.*;
|
import static org.mockito.BDDMockito.*;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,15 +18,19 @@ package org.springframework.util.xml;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
|
||||||
import javax.xml.stream.XMLEventReader;
|
import javax.xml.stream.XMLEventReader;
|
||||||
import javax.xml.stream.XMLInputFactory;
|
import javax.xml.stream.XMLInputFactory;
|
||||||
import javax.xml.stream.XMLStreamException;
|
import javax.xml.stream.XMLStreamException;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.ContentHandler;
|
import org.xml.sax.ContentHandler;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.helpers.AttributesImpl;
|
|
||||||
|
|
||||||
import static org.mockito.BDDMockito.*;
|
import static org.mockito.Matchers.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class StaxEventXMLReaderTests extends AbstractStaxXMLReaderTestCase {
|
public class StaxEventXMLReaderTests extends AbstractStaxXMLReaderTestCase {
|
||||||
|
|
||||||
|
@ -37,7 +41,8 @@ public class StaxEventXMLReaderTests extends AbstractStaxXMLReaderTestCase {
|
||||||
return new StaxEventXMLReader(inputFactory.createXMLEventReader(inputStream));
|
return new StaxEventXMLReader(inputFactory.createXMLEventReader(inputStream));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPartial() throws Exception {
|
@Test
|
||||||
|
public void partial() throws Exception {
|
||||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||||
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(CONTENT));
|
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(CONTENT));
|
||||||
eventReader.nextTag(); // skip to root
|
eventReader.nextTag(); // skip to root
|
||||||
|
@ -46,7 +51,7 @@ public class StaxEventXMLReaderTests extends AbstractStaxXMLReaderTestCase {
|
||||||
xmlReader.setContentHandler(contentHandler);
|
xmlReader.setContentHandler(contentHandler);
|
||||||
xmlReader.parse(new InputSource());
|
xmlReader.parse(new InputSource());
|
||||||
verify(contentHandler).startDocument();
|
verify(contentHandler).startDocument();
|
||||||
verify(contentHandler).startElement("http://springframework.org/spring-ws", "child", "child", new AttributesImpl());
|
verify(contentHandler).startElement(eq("http://springframework.org/spring-ws"), eq("child"), eq("child"), any(Attributes.class));
|
||||||
verify(contentHandler).endElement("http://springframework.org/spring-ws", "child", "child");
|
verify(contentHandler).endElement("http://springframework.org/spring-ws", "child", "child");
|
||||||
verify(contentHandler).endDocument();
|
verify(contentHandler).endDocument();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,19 +18,22 @@ package org.springframework.util.xml;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
|
||||||
import javax.xml.namespace.QName;
|
import javax.xml.namespace.QName;
|
||||||
import javax.xml.stream.XMLInputFactory;
|
import javax.xml.stream.XMLInputFactory;
|
||||||
import javax.xml.stream.XMLStreamException;
|
import javax.xml.stream.XMLStreamException;
|
||||||
import javax.xml.stream.XMLStreamReader;
|
import javax.xml.stream.XMLStreamReader;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.ContentHandler;
|
import org.xml.sax.ContentHandler;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.Locator;
|
import org.xml.sax.Locator;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.BDDMockito.*;
|
import static org.mockito.Matchers.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class StaxStreamXMLReaderTests extends AbstractStaxXMLReaderTestCase {
|
public class StaxStreamXMLReaderTests extends AbstractStaxXMLReaderTestCase {
|
||||||
|
|
||||||
|
@ -42,7 +45,7 @@ public class StaxStreamXMLReaderTests extends AbstractStaxXMLReaderTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPartial() throws Exception {
|
public void partial() throws Exception {
|
||||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||||
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(CONTENT));
|
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(CONTENT));
|
||||||
streamReader.nextTag(); // skip to root
|
streamReader.nextTag(); // skip to root
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -24,7 +24,6 @@ import java.sql.Statement;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -33,30 +32,33 @@ import org.springframework.jdbc.datasource.SingleConnectionDataSource;
|
||||||
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
|
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.BDDMockito.*;
|
import static org.mockito.BDDMockito.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
* @since 02.08.2004
|
* @since 02.08.2004
|
||||||
*/
|
*/
|
||||||
public class RowMapperTests extends TestCase {
|
public class RowMapperTests {
|
||||||
|
|
||||||
private Connection connection;
|
private final Connection connection = mock(Connection.class);
|
||||||
private Statement statement;
|
|
||||||
private PreparedStatement preparedStatement;
|
|
||||||
private ResultSet resultSet;
|
|
||||||
|
|
||||||
private JdbcTemplate template;
|
private final Statement statement = mock(Statement.class);
|
||||||
|
|
||||||
|
private final PreparedStatement preparedStatement = mock(PreparedStatement.class);
|
||||||
|
|
||||||
|
private final ResultSet resultSet = mock(ResultSet.class);
|
||||||
|
|
||||||
|
private final JdbcTemplate template = new JdbcTemplate();
|
||||||
|
|
||||||
|
private final RowMapper<TestBean> testRowMapper =
|
||||||
|
(rs, rowNum) -> new TestBean(rs.getString(1), rs.getInt(2));
|
||||||
|
|
||||||
private List<TestBean> result;
|
private List<TestBean> result;
|
||||||
|
|
||||||
@Override
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws SQLException {
|
public void setUp() throws SQLException {
|
||||||
connection = mock(Connection.class);
|
|
||||||
statement = mock(Statement.class);
|
|
||||||
preparedStatement = mock(PreparedStatement.class);
|
|
||||||
resultSet = mock(ResultSet.class);
|
|
||||||
given(connection.createStatement()).willReturn(statement);
|
given(connection.createStatement()).willReturn(statement);
|
||||||
given(connection.prepareStatement(anyString())).willReturn(preparedStatement);
|
given(connection.prepareStatement(anyString())).willReturn(preparedStatement);
|
||||||
given(statement.executeQuery(anyString())).willReturn(resultSet);
|
given(statement.executeQuery(anyString())).willReturn(resultSet);
|
||||||
|
@ -64,7 +66,7 @@ public class RowMapperTests extends TestCase {
|
||||||
given(resultSet.next()).willReturn(true, true, false);
|
given(resultSet.next()).willReturn(true, true, false);
|
||||||
given(resultSet.getString(1)).willReturn("tb1", "tb2");
|
given(resultSet.getString(1)).willReturn("tb1", "tb2");
|
||||||
given(resultSet.getInt(2)).willReturn(1, 2);
|
given(resultSet.getInt(2)).willReturn(1, 2);
|
||||||
template = new JdbcTemplate();
|
|
||||||
template.setDataSource(new SingleConnectionDataSource(connection, false));
|
template.setDataSource(new SingleConnectionDataSource(connection, false));
|
||||||
template.setExceptionTranslator(new SQLStateSQLExceptionTranslator());
|
template.setExceptionTranslator(new SQLStateSQLExceptionTranslator());
|
||||||
template.afterPropertiesSet();
|
template.afterPropertiesSet();
|
||||||
|
@ -73,75 +75,57 @@ public class RowMapperTests extends TestCase {
|
||||||
@After
|
@After
|
||||||
public void verifyClosed() throws Exception {
|
public void verifyClosed() throws Exception {
|
||||||
verify(resultSet).close();
|
verify(resultSet).close();
|
||||||
verify(connection).close();
|
// verify(connection).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void verifyResults() {
|
public void verifyResults() {
|
||||||
assertTrue(result != null);
|
assertNotNull(result);
|
||||||
assertEquals(2, result.size());
|
assertEquals(2, result.size());
|
||||||
assertEquals("tb1", result.get(0).getName());
|
TestBean testBean1 = result.get(0);
|
||||||
assertEquals("tb2", result.get(1).getName());
|
TestBean testBean2 = result.get(1);
|
||||||
assertEquals(1, result.get(0).getAge());
|
assertEquals("tb1", testBean1.getName());
|
||||||
assertEquals(2, result.get(1).getAge());
|
assertEquals("tb2", testBean2.getName());
|
||||||
|
assertEquals(1, testBean1.getAge());
|
||||||
|
assertEquals(2, testBean2.getAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStaticQueryWithRowMapper() throws SQLException {
|
public void staticQueryWithRowMapper() throws SQLException {
|
||||||
result = template.query("some SQL", new TestRowMapper());
|
result = template.query("some SQL", testRowMapper);
|
||||||
verify(statement).close();
|
verify(statement).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPreparedStatementCreatorWithRowMapper() throws SQLException {
|
public void preparedStatementCreatorWithRowMapper() throws SQLException {
|
||||||
result = template.query(new PreparedStatementCreator() {
|
result = template.query(con -> preparedStatement, testRowMapper);
|
||||||
@Override
|
|
||||||
public PreparedStatement createPreparedStatement(Connection con)
|
|
||||||
throws SQLException {
|
|
||||||
return preparedStatement;
|
|
||||||
}
|
|
||||||
}, new TestRowMapper());
|
|
||||||
verify(preparedStatement).close();
|
verify(preparedStatement).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPreparedStatementSetterWithRowMapper() throws SQLException {
|
public void preparedStatementSetterWithRowMapper() throws SQLException {
|
||||||
result = template.query("some SQL", new PreparedStatementSetter() {
|
result = template.query("some SQL", ps -> ps.setString(1, "test"), testRowMapper);
|
||||||
@Override
|
|
||||||
public void setValues(PreparedStatement ps) throws SQLException {
|
|
||||||
ps.setString(1, "test");
|
|
||||||
}
|
|
||||||
}, new TestRowMapper());
|
|
||||||
verify(preparedStatement).setString(1, "test");
|
verify(preparedStatement).setString(1, "test");
|
||||||
verify(preparedStatement).close();
|
verify(preparedStatement).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueryWithArgsAndRowMapper() throws SQLException {
|
public void queryWithArgsAndRowMapper() throws SQLException {
|
||||||
result = template.query("some SQL",
|
result = template.query("some SQL", new Object[] { "test1", "test2" }, testRowMapper);
|
||||||
new Object[] { "test1", "test2" },
|
|
||||||
new TestRowMapper());
|
|
||||||
preparedStatement.setString(1, "test1");
|
preparedStatement.setString(1, "test1");
|
||||||
preparedStatement.setString(2, "test2");
|
preparedStatement.setString(2, "test2");
|
||||||
preparedStatement.close();
|
preparedStatement.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueryWithArgsAndTypesAndRowMapper() throws SQLException {
|
public void queryWithArgsAndTypesAndRowMapper() throws SQLException {
|
||||||
result = template.query("some SQL",
|
result = template.query("some SQL",
|
||||||
new Object[] { "test1", "test2" },
|
new Object[] { "test1", "test2" },
|
||||||
new int[] { Types.VARCHAR, Types.VARCHAR },
|
new int[] { Types.VARCHAR, Types.VARCHAR },
|
||||||
new TestRowMapper());
|
testRowMapper);
|
||||||
verify(preparedStatement).setString(1, "test1");
|
verify(preparedStatement).setString(1, "test1");
|
||||||
verify(preparedStatement).setString(2, "test2");
|
verify(preparedStatement).setString(2, "test2");
|
||||||
verify(preparedStatement).close();
|
verify(preparedStatement).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TestRowMapper implements RowMapper<TestBean> {
|
|
||||||
@Override
|
|
||||||
public TestBean mapRow(ResultSet rs, int rowNum) throws SQLException {
|
|
||||||
return new TestBean(rs.getString(1), rs.getInt(2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -19,9 +19,12 @@ package org.springframework.jdbc.object;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
@ -30,119 +33,90 @@ import org.springframework.jdbc.core.SqlOutParameter;
|
||||||
import org.springframework.jdbc.core.SqlParameter;
|
import org.springframework.jdbc.core.SqlParameter;
|
||||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Trevor Cook
|
* @author Trevor Cook
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class RdbmsOperationTests extends TestCase {
|
public class RdbmsOperationTests {
|
||||||
|
|
||||||
public void testEmptySql() {
|
private final TestRdbmsOperation operation = new TestRdbmsOperation();
|
||||||
TestRdbmsOperation operation = new TestRdbmsOperation();
|
|
||||||
try {
|
@Rule
|
||||||
operation.compile();
|
public final ExpectedException exception = ExpectedException.none();
|
||||||
fail("Shouldn't allow compiling without sql statement");
|
|
||||||
}
|
|
||||||
catch (InvalidDataAccessApiUsageException idaauex) {
|
@Test
|
||||||
// OK
|
public void emptySql() {
|
||||||
}
|
exception.expect(InvalidDataAccessApiUsageException.class);
|
||||||
|
operation.compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetTypeAfterCompile() {
|
@Test
|
||||||
TestRdbmsOperation operation = new TestRdbmsOperation();
|
public void setTypeAfterCompile() {
|
||||||
operation.setDataSource(new DriverManagerDataSource());
|
operation.setDataSource(new DriverManagerDataSource());
|
||||||
operation.setSql("select * from mytable");
|
operation.setSql("select * from mytable");
|
||||||
operation.compile();
|
operation.compile();
|
||||||
try {
|
exception.expect(InvalidDataAccessApiUsageException.class);
|
||||||
operation.setTypes(new int[] {Types.INTEGER });
|
operation.setTypes(new int[] { Types.INTEGER });
|
||||||
fail("Shouldn't allow setting parameters after compile");
|
|
||||||
}
|
|
||||||
catch (InvalidDataAccessApiUsageException idaauex) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeclareParameterAfterCompile() {
|
@Test
|
||||||
TestRdbmsOperation operation = new TestRdbmsOperation();
|
public void declareParameterAfterCompile() {
|
||||||
operation.setDataSource(new DriverManagerDataSource());
|
operation.setDataSource(new DriverManagerDataSource());
|
||||||
operation.setSql("select * from mytable");
|
operation.setSql("select * from mytable");
|
||||||
operation.compile();
|
operation.compile();
|
||||||
try {
|
exception.expect(InvalidDataAccessApiUsageException.class);
|
||||||
operation.declareParameter(new SqlParameter(Types.INTEGER));
|
operation.declareParameter(new SqlParameter(Types.INTEGER));
|
||||||
fail("Shouldn't allow setting parameters after compile");
|
|
||||||
}
|
|
||||||
catch (InvalidDataAccessApiUsageException idaauex) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTooFewParameters() {
|
@Test
|
||||||
TestRdbmsOperation operation = new TestRdbmsOperation();
|
public void tooFewParameters() {
|
||||||
operation.setSql("select * from mytable");
|
operation.setSql("select * from mytable");
|
||||||
operation.setTypes(new int[] { Types.INTEGER });
|
operation.setTypes(new int[] { Types.INTEGER });
|
||||||
try {
|
exception.expect(InvalidDataAccessApiUsageException.class);
|
||||||
operation.validateParameters((Object[]) null);
|
operation.validateParameters((Object[]) null);
|
||||||
fail("Shouldn't validate without enough parameters");
|
|
||||||
}
|
|
||||||
catch (InvalidDataAccessApiUsageException idaauex) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTooFewMapParameters() {
|
@Test
|
||||||
TestRdbmsOperation operation = new TestRdbmsOperation();
|
public void tooFewMapParameters() {
|
||||||
operation.setSql("select * from mytable");
|
operation.setSql("select * from mytable");
|
||||||
operation.setTypes(new int[] { Types.INTEGER });
|
operation.setTypes(new int[] { Types.INTEGER });
|
||||||
try {
|
exception.expect(InvalidDataAccessApiUsageException.class);
|
||||||
operation.validateNamedParameters((Map<String, String>) null);
|
operation.validateNamedParameters((Map<String, String>) null);
|
||||||
fail("Shouldn't validate without enough parameters");
|
|
||||||
}
|
|
||||||
catch (InvalidDataAccessApiUsageException idaauex) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOperationConfiguredViaJdbcTemplateMustGetDataSource() throws Exception {
|
@Test
|
||||||
try {
|
public void operationConfiguredViaJdbcTemplateMustGetDataSource() throws Exception {
|
||||||
TestRdbmsOperation operation = new TestRdbmsOperation();
|
operation.setSql("foo");
|
||||||
operation.setSql("foo");
|
|
||||||
operation.compile();
|
exception.expect(InvalidDataAccessApiUsageException.class);
|
||||||
fail("Can't compile without providing a DataSource for the JdbcTemplate");
|
exception.expectMessage(containsString("ataSource"));
|
||||||
}
|
operation.compile();
|
||||||
catch (InvalidDataAccessApiUsageException ex) {
|
|
||||||
// Check for helpful error message. Omit leading character
|
|
||||||
// so as not to be fussy about case
|
|
||||||
assertTrue(ex.getMessage().indexOf("ataSource") != -1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTooManyParameters() {
|
@Test
|
||||||
TestRdbmsOperation operation = new TestRdbmsOperation();
|
public void tooManyParameters() {
|
||||||
operation.setSql("select * from mytable");
|
operation.setSql("select * from mytable");
|
||||||
try {
|
exception.expect(InvalidDataAccessApiUsageException.class);
|
||||||
operation.validateParameters(new Object[] {1, 2});
|
operation.validateParameters(new Object[] { 1, 2 });
|
||||||
fail("Shouldn't validate with too many parameters");
|
|
||||||
}
|
|
||||||
catch (InvalidDataAccessApiUsageException idaauex) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUnspecifiedMapParameters() {
|
@Test
|
||||||
TestRdbmsOperation operation = new TestRdbmsOperation();
|
public void unspecifiedMapParameters() {
|
||||||
operation.setSql("select * from mytable");
|
operation.setSql("select * from mytable");
|
||||||
try {
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
Map<String, String> params = new HashMap<String, String>();
|
params.put("col1", "value");
|
||||||
params.put("col1", "value");
|
exception.expect(InvalidDataAccessApiUsageException.class);
|
||||||
operation.validateNamedParameters(params);
|
operation.validateNamedParameters(params);
|
||||||
fail("Shouldn't validate with unspecified parameters");
|
|
||||||
}
|
|
||||||
catch (InvalidDataAccessApiUsageException idaauex) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCompileTwice() {
|
@Test
|
||||||
TestRdbmsOperation operation = new TestRdbmsOperation();
|
public void compileTwice() {
|
||||||
operation.setDataSource(new DriverManagerDataSource());
|
operation.setDataSource(new DriverManagerDataSource());
|
||||||
operation.setSql("select * from mytable");
|
operation.setSql("select * from mytable");
|
||||||
operation.setTypes(null);
|
operation.setTypes(null);
|
||||||
|
@ -150,22 +124,17 @@ public class RdbmsOperationTests extends TestCase {
|
||||||
operation.compile();
|
operation.compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEmptyDataSource() {
|
@Test
|
||||||
SqlOperation operation = new SqlOperation() {
|
public void emptyDataSource() {
|
||||||
};
|
SqlOperation operation = new SqlOperation() {};
|
||||||
operation.setSql("select * from mytable");
|
operation.setSql("select * from mytable");
|
||||||
try {
|
exception.expect(InvalidDataAccessApiUsageException.class);
|
||||||
operation.compile();
|
operation.compile();
|
||||||
fail("Shouldn't allow compiling without data source");
|
|
||||||
}
|
|
||||||
catch (InvalidDataAccessApiUsageException idaauex) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParameterPropagation() {
|
@Test
|
||||||
SqlOperation operation = new SqlOperation() {
|
public void parameterPropagation() {
|
||||||
};
|
SqlOperation operation = new SqlOperation() {};
|
||||||
DataSource ds = new DriverManagerDataSource();
|
DataSource ds = new DriverManagerDataSource();
|
||||||
operation.setDataSource(ds);
|
operation.setDataSource(ds);
|
||||||
operation.setFetchSize(10);
|
operation.setFetchSize(10);
|
||||||
|
@ -176,8 +145,8 @@ public class RdbmsOperationTests extends TestCase {
|
||||||
assertEquals(20, jt.getMaxRows());
|
assertEquals(20, jt.getMaxRows());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testValidateInOutParameter() {
|
@Test
|
||||||
TestRdbmsOperation operation = new TestRdbmsOperation();
|
public void validateInOutParameter() {
|
||||||
operation.setDataSource(new DriverManagerDataSource());
|
operation.setDataSource(new DriverManagerDataSource());
|
||||||
operation.setSql("DUMMY_PROC");
|
operation.setSql("DUMMY_PROC");
|
||||||
operation.declareParameter(new SqlOutParameter("DUMMY_OUT_PARAM", Types.VARCHAR));
|
operation.declareParameter(new SqlOutParameter("DUMMY_OUT_PARAM", Types.VARCHAR));
|
||||||
|
@ -185,8 +154,8 @@ public class RdbmsOperationTests extends TestCase {
|
||||||
operation.validateParameters(new Object[] {"DUMMY_VALUE1", "DUMMY_VALUE2"});
|
operation.validateParameters(new Object[] {"DUMMY_VALUE1", "DUMMY_VALUE2"});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParametersSetWithList() {
|
@Test
|
||||||
TestRdbmsOperation operation = new TestRdbmsOperation();
|
public void parametersSetWithList() {
|
||||||
DataSource ds = new DriverManagerDataSource();
|
DataSource ds = new DriverManagerDataSource();
|
||||||
operation.setDataSource(ds);
|
operation.setDataSource(ds);
|
||||||
operation.setSql("select * from mytable where one = ? and two = ?");
|
operation.setSql("select * from mytable where one = ? and two = ?");
|
||||||
|
@ -194,14 +163,8 @@ public class RdbmsOperationTests extends TestCase {
|
||||||
new SqlParameter("one", Types.NUMERIC),
|
new SqlParameter("one", Types.NUMERIC),
|
||||||
new SqlParameter("two", Types.NUMERIC)});
|
new SqlParameter("two", Types.NUMERIC)});
|
||||||
operation.afterPropertiesSet();
|
operation.afterPropertiesSet();
|
||||||
try {
|
operation.validateParameters(new Object[] { 1, "2" });
|
||||||
operation.validateParameters(new Object[] {1, "2"});
|
assertEquals(2, operation.getDeclaredParameters().size());
|
||||||
assertEquals(2, operation.getDeclaredParameters().size());
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
catch (InvalidDataAccessApiUsageException idaauex) {
|
|
||||||
fail("Should have validated with parameters set using List: " + idaauex.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2007 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,28 +16,32 @@
|
||||||
|
|
||||||
package org.springframework.jdbc.support;
|
package org.springframework.jdbc.support;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for JdbcUtils.
|
* Unit tests for {@link JdbcUtils}.
|
||||||
*
|
*
|
||||||
* @author Thomas Risberg
|
* @author Thomas Risberg
|
||||||
*/
|
*/
|
||||||
public class JdbcUtilsTests extends TestCase {
|
public class JdbcUtilsTests {
|
||||||
|
|
||||||
public void testCommonDatabaseName() {
|
@Test
|
||||||
assertEquals("Wrong db name", "Oracle", JdbcUtils.commonDatabaseName("Oracle"));
|
public void commonDatabaseName() {
|
||||||
assertEquals("Wrong db name", "DB2", JdbcUtils.commonDatabaseName("DB2-for-Spring"));
|
assertEquals("Oracle", JdbcUtils.commonDatabaseName("Oracle"));
|
||||||
assertEquals("Wrong db name", "Sybase", JdbcUtils.commonDatabaseName("Sybase SQL Server"));
|
assertEquals("DB2", JdbcUtils.commonDatabaseName("DB2-for-Spring"));
|
||||||
assertEquals("Wrong db name", "Sybase", JdbcUtils.commonDatabaseName("Adaptive Server Enterprise"));
|
assertEquals("Sybase", JdbcUtils.commonDatabaseName("Sybase SQL Server"));
|
||||||
assertEquals("Wrong db name", "MySQL", JdbcUtils.commonDatabaseName("MySQL"));
|
assertEquals("Sybase", JdbcUtils.commonDatabaseName("Adaptive Server Enterprise"));
|
||||||
|
assertEquals("MySQL", JdbcUtils.commonDatabaseName("MySQL"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConvertUnderscoreNameToPropertyName() {
|
@Test
|
||||||
assertEquals("Wrong property name", "myName", JdbcUtils.convertUnderscoreNameToPropertyName("MY_NAME"));
|
public void convertUnderscoreNameToPropertyName() {
|
||||||
assertEquals("Wrong property name", "yourName", JdbcUtils.convertUnderscoreNameToPropertyName("yOUR_nAME"));
|
assertEquals("myName", JdbcUtils.convertUnderscoreNameToPropertyName("MY_NAME"));
|
||||||
assertEquals("Wrong property name", "AName", JdbcUtils.convertUnderscoreNameToPropertyName("a_name"));
|
assertEquals("yourName", JdbcUtils.convertUnderscoreNameToPropertyName("yOUR_nAME"));
|
||||||
assertEquals("Wrong property name", "someoneElsesName", JdbcUtils.convertUnderscoreNameToPropertyName("someone_elses_name"));
|
assertEquals("AName", JdbcUtils.convertUnderscoreNameToPropertyName("a_name"));
|
||||||
|
assertEquals("someoneElsesName", JdbcUtils.convertUnderscoreNameToPropertyName("someone_elses_name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 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,98 +17,87 @@
|
||||||
package org.springframework.jdbc.support;
|
package org.springframework.jdbc.support;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
import org.springframework.dao.DataRetrievalFailureException;
|
import org.springframework.dao.DataRetrievalFailureException;
|
||||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
import static java.util.Collections.*;
|
||||||
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for the KeyHolder and GeneratedKeyHolder
|
* Tests for {@link KeyHolder} and {@link GeneratedKeyHolder}.
|
||||||
* and it appears that JdbcUtils doesn't work exactly as documented.
|
|
||||||
*
|
*
|
||||||
* @author trisberg
|
* @author Thomas Risberg
|
||||||
* @since Jul 18, 2004
|
* @author Sam Brannen
|
||||||
|
* @since July 18, 2004
|
||||||
*/
|
*/
|
||||||
public class KeyHolderTests extends TestCase {
|
@SuppressWarnings("serial")
|
||||||
private KeyHolder kh;
|
public class KeyHolderTests {
|
||||||
|
|
||||||
@Override
|
private final KeyHolder kh = new GeneratedKeyHolder();
|
||||||
public void setUp() {
|
|
||||||
kh = new GeneratedKeyHolder();
|
@Rule
|
||||||
}
|
public final ExpectedException exception = ExpectedException.none();
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void singleKey() {
|
||||||
|
kh.getKeyList().addAll(singletonList(singletonMap("key", 1)));
|
||||||
|
|
||||||
public void testSingleKey(){
|
|
||||||
List<Map<String, Object>> l = new LinkedList<Map<String, Object>>();
|
|
||||||
Map<String, Object> m = new HashMap<String, Object>(1);
|
|
||||||
m.put("key", 1);
|
|
||||||
l.add(m);
|
|
||||||
kh.getKeyList().addAll(l);
|
|
||||||
assertEquals("single key should be returned", 1, kh.getKey().intValue());
|
assertEquals("single key should be returned", 1, kh.getKey().intValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSingleKeyNonNumeric(){
|
@Test
|
||||||
List<Map<String, Object>> l = new LinkedList<Map<String, Object>>();
|
public void singleKeyNonNumeric() {
|
||||||
Map<String, Object> m = new HashMap<String, Object>(1);
|
kh.getKeyList().addAll(singletonList(singletonMap("key", "1")));
|
||||||
m.put("key", "1");
|
|
||||||
l.add(m);
|
exception.expect(DataRetrievalFailureException.class);
|
||||||
kh.getKeyList().addAll(l);
|
exception.expectMessage(startsWith("The generated key is not of a supported numeric type."));
|
||||||
try {
|
kh.getKey().intValue();
|
||||||
kh.getKey().intValue();
|
|
||||||
}
|
|
||||||
catch (DataRetrievalFailureException e) {
|
|
||||||
assertTrue(e.getMessage().startsWith("The generated key is not of a supported numeric type."));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoKeyReturnedInMap(){
|
@Test
|
||||||
List<Map<String, Object>> l = new LinkedList<Map<String, Object>>();
|
public void noKeyReturnedInMap() {
|
||||||
Map<String, Object> m = new HashMap<String, Object>();
|
kh.getKeyList().addAll(singletonList(emptyMap()));
|
||||||
l.add(m);
|
|
||||||
kh.getKeyList().addAll(l);
|
exception.expect(DataRetrievalFailureException.class);
|
||||||
try {
|
exception.expectMessage(startsWith("Unable to retrieve the generated key."));
|
||||||
kh.getKey();
|
kh.getKey();
|
||||||
}
|
|
||||||
catch (DataRetrievalFailureException e) {
|
|
||||||
assertTrue(e.getMessage().startsWith("Unable to retrieve the generated key."));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipleKeys(){
|
@Test
|
||||||
List<Map<String, Object>> l = new LinkedList<Map<String, Object>>();
|
public void multipleKeys() {
|
||||||
Map<String, Object> m = new HashMap<String, Object>(2);
|
Map<String, Object> m = new HashMap<String, Object>() {{
|
||||||
m.put("key", 1);
|
put("key", 1);
|
||||||
m.put("seq", 2);
|
put("seq", 2);
|
||||||
l.add(m);
|
}};
|
||||||
kh.getKeyList().addAll(l);
|
kh.getKeyList().addAll(singletonList(m));
|
||||||
Map<String, Object> keyMap = kh.getKeys();
|
|
||||||
assertEquals("two keys should be in the map", 2, keyMap.size());
|
assertEquals("two keys should be in the map", 2, kh.getKeys().size());
|
||||||
try {
|
exception.expect(InvalidDataAccessApiUsageException.class);
|
||||||
kh.getKey();
|
exception.expectMessage(startsWith("The getKey method should only be used when a single key is returned."));
|
||||||
}
|
kh.getKey();
|
||||||
catch (InvalidDataAccessApiUsageException e) {
|
|
||||||
assertTrue(e.getMessage().startsWith("The getKey method should only be used when a single key is returned."));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipleKeyRows(){
|
@Test
|
||||||
List<Map<String, Object>> l = new LinkedList<Map<String, Object>>();
|
public void multipleKeyRows() {
|
||||||
Map<String, Object> m = new HashMap<String, Object>(2);
|
Map<String, Object> m = new HashMap<String, Object>() {{
|
||||||
m.put("key", 1);
|
put("key", 1);
|
||||||
m.put("seq", 2);
|
put("seq", 2);
|
||||||
l.add(m);
|
}};
|
||||||
l.add(m);
|
kh.getKeyList().addAll(asList(m, m));
|
||||||
kh.getKeyList().addAll(l);
|
|
||||||
|
|
||||||
assertEquals("two rows should be in the list", 2, kh.getKeyList().size());
|
assertEquals("two rows should be in the list", 2, kh.getKeyList().size());
|
||||||
try {
|
exception.expect(InvalidDataAccessApiUsageException.class);
|
||||||
kh.getKeys();
|
exception.expectMessage(startsWith("The getKeys method should only be used when keys for a single row are returned."));
|
||||||
}
|
kh.getKeys();
|
||||||
catch (InvalidDataAccessApiUsageException e) {
|
|
||||||
assertTrue(e.getMessage().startsWith("The getKeys method should only be used when keys for a single row are returned."));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 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,9 @@ import java.sql.BatchUpdateException;
|
||||||
import java.sql.DataTruncation;
|
import java.sql.DataTruncation;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
import org.springframework.dao.CannotAcquireLockException;
|
import org.springframework.dao.CannotAcquireLockException;
|
||||||
import org.springframework.dao.CannotSerializeTransactionException;
|
import org.springframework.dao.CannotSerializeTransactionException;
|
||||||
|
@ -32,11 +34,14 @@ import org.springframework.dao.DuplicateKeyException;
|
||||||
import org.springframework.jdbc.BadSqlGrammarException;
|
import org.springframework.jdbc.BadSqlGrammarException;
|
||||||
import org.springframework.jdbc.InvalidResultSetAccessException;
|
import org.springframework.jdbc.InvalidResultSetAccessException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class SQLErrorCodeSQLExceptionTranslatorTests extends TestCase {
|
public class SQLErrorCodeSQLExceptionTranslatorTests {
|
||||||
|
|
||||||
private static SQLErrorCodes ERROR_CODES = new SQLErrorCodes();
|
private static SQLErrorCodes ERROR_CODES = new SQLErrorCodes();
|
||||||
static {
|
static {
|
||||||
|
@ -50,7 +55,12 @@ public class SQLErrorCodeSQLExceptionTranslatorTests extends TestCase {
|
||||||
ERROR_CODES.setCannotSerializeTransactionCodes(new String[] { "9" });
|
ERROR_CODES.setCannotSerializeTransactionCodes(new String[] { "9" });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testErrorCodeTranslation() {
|
@Rule
|
||||||
|
public final ExpectedException exception = ExpectedException.none();
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void errorCodeTranslation() {
|
||||||
SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);
|
SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);
|
||||||
|
|
||||||
SQLException badSqlEx = new SQLException("", "", 1);
|
SQLException badSqlEx = new SQLException("", "", 1);
|
||||||
|
@ -90,7 +100,8 @@ public class SQLErrorCodeSQLExceptionTranslatorTests extends TestCase {
|
||||||
assertTrue(ex.getCause() == sex);
|
assertTrue(ex.getCause() == sex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBatchExceptionTranslation() {
|
@Test
|
||||||
|
public void batchExceptionTranslation() {
|
||||||
SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);
|
SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);
|
||||||
|
|
||||||
SQLException badSqlEx = new SQLException("", "", 1);
|
SQLException badSqlEx = new SQLException("", "", 1);
|
||||||
|
@ -101,7 +112,8 @@ public class SQLErrorCodeSQLExceptionTranslatorTests extends TestCase {
|
||||||
assertEquals(badSqlEx, bsgex.getSQLException());
|
assertEquals(badSqlEx, bsgex.getSQLException());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDataTruncationTranslation() {
|
@Test
|
||||||
|
public void dataTruncationTranslation() {
|
||||||
SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);
|
SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);
|
||||||
|
|
||||||
SQLException dataAccessEx = new SQLException("", "", 5);
|
SQLException dataAccessEx = new SQLException("", "", 5);
|
||||||
|
@ -111,7 +123,8 @@ public class SQLErrorCodeSQLExceptionTranslatorTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public void testCustomTranslateMethodTranslation() {
|
@Test
|
||||||
|
public void customTranslateMethodTranslation() {
|
||||||
final String TASK = "TASK";
|
final String TASK = "TASK";
|
||||||
final String SQL = "SQL SELECT *";
|
final String SQL = "SQL SELECT *";
|
||||||
final DataAccessException customDex = new DataAccessException("") {};
|
final DataAccessException customDex = new DataAccessException("") {};
|
||||||
|
@ -135,7 +148,8 @@ public class SQLErrorCodeSQLExceptionTranslatorTests extends TestCase {
|
||||||
assertEquals(intVioEx, diex.getCause());
|
assertEquals(intVioEx, diex.getCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCustomExceptionTranslation() {
|
@Test
|
||||||
|
public void customExceptionTranslation() {
|
||||||
final String TASK = "TASK";
|
final String TASK = "TASK";
|
||||||
final String SQL = "SQL SELECT *";
|
final String SQL = "SQL SELECT *";
|
||||||
final SQLErrorCodes customErrorCodes = new SQLErrorCodes();
|
final SQLErrorCodes customErrorCodes = new SQLErrorCodes();
|
||||||
|
@ -161,13 +175,8 @@ public class SQLErrorCodeSQLExceptionTranslatorTests extends TestCase {
|
||||||
assertEquals(invResEx, diex.getCause());
|
assertEquals(invResEx, diex.getCause());
|
||||||
|
|
||||||
// Shouldn't custom translate this - invalid class
|
// Shouldn't custom translate this - invalid class
|
||||||
try {
|
exception.expect(IllegalArgumentException.class);
|
||||||
customTranslation.setExceptionClass(String.class);
|
customTranslation.setExceptionClass(String.class);
|
||||||
fail("Should have thrown IllegalArgumentException");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,22 +18,22 @@ package org.springframework.jdbc.support;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.dao.TransientDataAccessResourceException;
|
import org.springframework.dao.TransientDataAccessResourceException;
|
||||||
import org.springframework.jdbc.BadSqlGrammarException;
|
import org.springframework.jdbc.BadSqlGrammarException;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to test custom SQLException translation.
|
* Unit tests for custom SQLException translation.
|
||||||
*
|
*
|
||||||
* @author Thomas Risberg
|
* @author Thomas Risberg
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
@RunWith(JUnit4.class)
|
public class SQLExceptionCustomTranslatorTests {
|
||||||
public class SQLExceptionCustomTranslatorTests extends TestCase {
|
|
||||||
|
|
||||||
private static SQLErrorCodes ERROR_CODES = new SQLErrorCodes();
|
private static SQLErrorCodes ERROR_CODES = new SQLErrorCodes();
|
||||||
|
|
||||||
|
@ -43,22 +43,23 @@ public class SQLExceptionCustomTranslatorTests extends TestCase {
|
||||||
ERROR_CODES.setCustomSqlExceptionTranslatorClass(CustomSqlExceptionTranslator.class);
|
ERROR_CODES.setCustomSqlExceptionTranslatorClass(CustomSqlExceptionTranslator.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomErrorCodeTranslation() {
|
public void badSqlGrammarException() {
|
||||||
|
SQLException badSqlGrammarExceptionEx = SQLExceptionSubclassFactory.newSQLDataException("", "", 1);
|
||||||
SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);
|
DataAccessException dae = sext.translate("task", "SQL", badSqlGrammarExceptionEx);
|
||||||
|
assertEquals(badSqlGrammarExceptionEx, dae.getCause());
|
||||||
SQLException dataIntegrityViolationEx = SQLExceptionSubclassFactory.newSQLDataException("", "", 1);
|
assertThat(dae, instanceOf(BadSqlGrammarException.class));
|
||||||
DataAccessException daeex = sext.translate("task", "SQL", dataIntegrityViolationEx);
|
|
||||||
assertEquals(dataIntegrityViolationEx, daeex.getCause());
|
|
||||||
assertTrue(daeex instanceof BadSqlGrammarException);
|
|
||||||
|
|
||||||
SQLException dataAccessResourceEx = SQLExceptionSubclassFactory.newSQLDataException("", "", 2);
|
|
||||||
DataAccessException darex = sext.translate("task", "SQL", dataAccessResourceEx);
|
|
||||||
assertEquals(dataIntegrityViolationEx, daeex.getCause());
|
|
||||||
assertTrue(darex instanceof TransientDataAccessResourceException);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
@Test
|
||||||
|
public void dataAccessResourceException() {
|
||||||
|
SQLException dataAccessResourceEx = SQLExceptionSubclassFactory.newSQLDataException("", "", 2);
|
||||||
|
DataAccessException dae = sext.translate("task", "SQL", dataAccessResourceEx);
|
||||||
|
assertEquals(dataAccessResourceEx, dae.getCause());
|
||||||
|
assertThat(dae, instanceOf(TransientDataAccessResourceException.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ package org.springframework.jdbc.support;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.dao.ConcurrencyFailureException;
|
import org.springframework.dao.ConcurrencyFailureException;
|
||||||
import org.springframework.dao.DataAccessResourceFailureException;
|
import org.springframework.dao.DataAccessResourceFailureException;
|
||||||
|
@ -30,10 +30,12 @@ import org.springframework.dao.RecoverableDataAccessException;
|
||||||
import org.springframework.dao.TransientDataAccessResourceException;
|
import org.springframework.dao.TransientDataAccessResourceException;
|
||||||
import org.springframework.jdbc.BadSqlGrammarException;
|
import org.springframework.jdbc.BadSqlGrammarException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Thomas Risberg
|
* @author Thomas Risberg
|
||||||
*/
|
*/
|
||||||
public class SQLExceptionSubclassTranslatorTests extends TestCase {
|
public class SQLExceptionSubclassTranslatorTests {
|
||||||
|
|
||||||
private static SQLErrorCodes ERROR_CODES = new SQLErrorCodes();
|
private static SQLErrorCodes ERROR_CODES = new SQLErrorCodes();
|
||||||
|
|
||||||
|
@ -42,7 +44,8 @@ public class SQLExceptionSubclassTranslatorTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testErrorCodeTranslation() {
|
@Test
|
||||||
|
public void errorCodeTranslation() {
|
||||||
SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);
|
SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);
|
||||||
|
|
||||||
SQLException dataIntegrityViolationEx = SQLExceptionSubclassFactory.newSQLDataException("", "", 0);
|
SQLException dataIntegrityViolationEx = SQLExceptionSubclassFactory.newSQLDataException("", "", 0);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -18,25 +18,27 @@ package org.springframework.jdbc.support;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.jdbc.BadSqlGrammarException;
|
import org.springframework.jdbc.BadSqlGrammarException;
|
||||||
import org.springframework.jdbc.UncategorizedSQLException;
|
import org.springframework.jdbc.UncategorizedSQLException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @since 13-Jan-03
|
* @since 13-Jan-03
|
||||||
*/
|
*/
|
||||||
public class SQLStateExceptionTranslatorTests extends TestCase {
|
public class SQLStateExceptionTranslatorTests {
|
||||||
|
|
||||||
private SQLStateSQLExceptionTranslator trans = new SQLStateSQLExceptionTranslator();
|
private static final String sql = "SELECT FOO FROM BAR";
|
||||||
|
|
||||||
|
private final SQLStateSQLExceptionTranslator trans = new SQLStateSQLExceptionTranslator();
|
||||||
|
|
||||||
// ALSO CHECK CHAIN of SQLExceptions!?
|
// ALSO CHECK CHAIN of SQLExceptions!?
|
||||||
// also allow chain of translators? default if can't do specific?
|
// also allow chain of translators? default if can't do specific?
|
||||||
|
|
||||||
public void testBadSqlGrammar() {
|
@Test
|
||||||
String sql = "SELECT FOO FROM BAR";
|
public void badSqlGrammar() {
|
||||||
SQLException sex = new SQLException("Message", "42001", 1);
|
SQLException sex = new SQLException("Message", "42001", 1);
|
||||||
try {
|
try {
|
||||||
throw this.trans.translate("task", sql, sex);
|
throw this.trans.translate("task", sql, sex);
|
||||||
|
@ -48,8 +50,8 @@ public class SQLStateExceptionTranslatorTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInvalidSqlStateCode() {
|
@Test
|
||||||
String sql = "SELECT FOO FROM BAR";
|
public void invalidSqlStateCode() {
|
||||||
SQLException sex = new SQLException("Message", "NO SUCH CODE", 1);
|
SQLException sex = new SQLException("Message", "NO SUCH CODE", 1);
|
||||||
try {
|
try {
|
||||||
throw this.trans.translate("task", sql, sex);
|
throw this.trans.translate("task", sql, sex);
|
||||||
|
@ -62,11 +64,12 @@ public class SQLStateExceptionTranslatorTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PostgreSQL can return null
|
* PostgreSQL can return null.
|
||||||
* SAP DB can apparently return empty SQL code
|
* SAP DB can apparently return empty SQL code.
|
||||||
* Bug 729170
|
* Bug 729170
|
||||||
*/
|
*/
|
||||||
public void testMalformedSqlStateCodes() {
|
@Test
|
||||||
|
public void malformedSqlStateCodes() {
|
||||||
SQLException sex = new SQLException("Message", null, 1);
|
SQLException sex = new SQLException("Message", null, 1);
|
||||||
testMalformedSqlStateCode(sex);
|
testMalformedSqlStateCode(sex);
|
||||||
|
|
||||||
|
@ -80,7 +83,6 @@ public class SQLStateExceptionTranslatorTests extends TestCase {
|
||||||
|
|
||||||
|
|
||||||
private void testMalformedSqlStateCode(SQLException sex) {
|
private void testMalformedSqlStateCode(SQLException sex) {
|
||||||
String sql = "SELECT FOO FROM BAR";
|
|
||||||
try {
|
try {
|
||||||
throw this.trans.translate("task", sql, sex);
|
throw this.trans.translate("task", sql, sex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -19,35 +19,34 @@ package org.springframework.jms.listener.endpoint;
|
||||||
import javax.jms.Destination;
|
import javax.jms.Destination;
|
||||||
import javax.jms.Session;
|
import javax.jms.Session;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.jca.StubResourceAdapter;
|
import org.springframework.jca.StubResourceAdapter;
|
||||||
import org.springframework.jms.StubQueue;
|
import org.springframework.jms.StubQueue;
|
||||||
import org.springframework.jms.support.destination.DestinationResolver;
|
import org.springframework.jms.support.destination.DestinationResolver;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.BDDMockito.*;
|
import static org.mockito.BDDMockito.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Agim Emruli
|
* @author Agim Emruli
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class DefaultJmsActivationSpecFactoryTests extends TestCase {
|
public class DefaultJmsActivationSpecFactoryTests {
|
||||||
|
|
||||||
private JmsActivationSpecConfig activationSpecConfig;
|
private final JmsActivationSpecConfig activationSpecConfig = new JmsActivationSpecConfig() {{
|
||||||
|
setMaxConcurrency(5);
|
||||||
|
setPrefetchSize(3);
|
||||||
|
setAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
|
||||||
|
setClientId("clientid");
|
||||||
|
setDestinationName("destinationname");
|
||||||
|
setDurableSubscriptionName("durableSubscriptionName");
|
||||||
|
setMessageSelector("selector");
|
||||||
|
}};
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
activationSpecConfig = new JmsActivationSpecConfig();
|
|
||||||
activationSpecConfig.setMaxConcurrency(5);
|
|
||||||
activationSpecConfig.setPrefetchSize(3);
|
|
||||||
activationSpecConfig.setAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
|
|
||||||
activationSpecConfig.setClientId("clientid");
|
|
||||||
activationSpecConfig.setDestinationName("destinationname");
|
|
||||||
activationSpecConfig.setDurableSubscriptionName("durableSubscriptionName");
|
|
||||||
activationSpecConfig.setMessageSelector("selector");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testActiveMQResourceAdapterSetup() {
|
@Test
|
||||||
|
public void activeMQResourceAdapterSetup() {
|
||||||
activationSpecConfig.setAcknowledgeMode(Session.SESSION_TRANSACTED);
|
activationSpecConfig.setAcknowledgeMode(Session.SESSION_TRANSACTED);
|
||||||
JmsActivationSpecFactory activationSpecFactory = new DefaultJmsActivationSpecFactory();
|
JmsActivationSpecFactory activationSpecFactory = new DefaultJmsActivationSpecFactory();
|
||||||
StubActiveMQActivationSpec spec = (StubActiveMQActivationSpec) activationSpecFactory.createActivationSpec(
|
StubActiveMQActivationSpec spec = (StubActiveMQActivationSpec) activationSpecFactory.createActivationSpec(
|
||||||
|
@ -58,7 +57,8 @@ public class DefaultJmsActivationSpecFactoryTests extends TestCase {
|
||||||
assertTrue(spec.isUseRAManagedTransaction());
|
assertTrue(spec.isUseRAManagedTransaction());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWebSphereResourceAdapterSetup() throws Exception {
|
@Test
|
||||||
|
public void webSphereResourceAdapterSetup() throws Exception {
|
||||||
Destination destination = new StubQueue();
|
Destination destination = new StubQueue();
|
||||||
|
|
||||||
DestinationResolver destinationResolver = mock(DestinationResolver.class);
|
DestinationResolver destinationResolver = mock(DestinationResolver.class);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -24,43 +24,48 @@ import javax.jms.Session;
|
||||||
import javax.jms.Topic;
|
import javax.jms.Topic;
|
||||||
import javax.jms.TopicSession;
|
import javax.jms.TopicSession;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.jms.StubQueue;
|
import org.springframework.jms.StubQueue;
|
||||||
import org.springframework.jms.StubTopic;
|
import org.springframework.jms.StubTopic;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.BDDMockito.*;
|
import static org.mockito.BDDMockito.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
*/
|
*/
|
||||||
public class DynamicDestinationResolverTests extends TestCase {
|
public class DynamicDestinationResolverTests {
|
||||||
|
|
||||||
private static final String DESTINATION_NAME = "foo";
|
private static final String DESTINATION_NAME = "foo";
|
||||||
|
|
||||||
|
|
||||||
public void testResolveWithPubSubTopicSession() throws Exception {
|
@Test
|
||||||
|
public void resolveWithPubSubTopicSession() throws Exception {
|
||||||
Topic expectedDestination = new StubTopic();
|
Topic expectedDestination = new StubTopic();
|
||||||
TopicSession session = mock(TopicSession.class);
|
TopicSession session = mock(TopicSession.class);
|
||||||
given(session.createTopic(DESTINATION_NAME)).willReturn(expectedDestination);
|
given(session.createTopic(DESTINATION_NAME)).willReturn(expectedDestination);
|
||||||
testResolveDestination(session, expectedDestination, true);
|
testResolveDestination(session, expectedDestination, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testResolveWithPubSubVanillaSession() throws Exception {
|
@Test
|
||||||
|
public void resolveWithPubSubVanillaSession() throws Exception {
|
||||||
Topic expectedDestination = new StubTopic();
|
Topic expectedDestination = new StubTopic();
|
||||||
Session session = mock(Session.class);
|
Session session = mock(Session.class);
|
||||||
given(session.createTopic(DESTINATION_NAME)).willReturn(expectedDestination);
|
given(session.createTopic(DESTINATION_NAME)).willReturn(expectedDestination);
|
||||||
testResolveDestination(session, expectedDestination, true);
|
testResolveDestination(session, expectedDestination, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testResolveWithPointToPointQueueSession() throws Exception {
|
@Test
|
||||||
|
public void resolveWithPointToPointQueueSession() throws Exception {
|
||||||
Queue expectedDestination = new StubQueue();
|
Queue expectedDestination = new StubQueue();
|
||||||
Session session = mock(QueueSession.class);
|
Session session = mock(QueueSession.class);
|
||||||
given(session.createQueue(DESTINATION_NAME)).willReturn(expectedDestination);
|
given(session.createQueue(DESTINATION_NAME)).willReturn(expectedDestination);
|
||||||
testResolveDestination(session, expectedDestination, false);
|
testResolveDestination(session, expectedDestination, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testResolveWithPointToPointVanillaSession() throws Exception {
|
@Test
|
||||||
|
public void resolveWithPointToPointVanillaSession() throws Exception {
|
||||||
Queue expectedDestination = new StubQueue();
|
Queue expectedDestination = new StubQueue();
|
||||||
Session session = mock(Session.class);
|
Session session = mock(Session.class);
|
||||||
given(session.createQueue(DESTINATION_NAME)).willReturn(expectedDestination);
|
given(session.createQueue(DESTINATION_NAME)).willReturn(expectedDestination);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -16,18 +16,24 @@
|
||||||
|
|
||||||
package org.springframework.orm.hibernate3.support;
|
package org.springframework.orm.hibernate3.support;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.aop.framework.ProxyFactory;
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
import org.springframework.aop.scope.ScopedObject;
|
import org.springframework.aop.scope.ScopedObject;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Unit tests for {@link ScopedBeanInterceptor}.
|
||||||
|
*
|
||||||
* @author Costin Leau
|
* @author Costin Leau
|
||||||
*/
|
*/
|
||||||
public class ScopedBeanInterceptorTests extends TestCase {
|
public class ScopedBeanInterceptorTests {
|
||||||
|
|
||||||
public void testInterceptorWithPlainObject() throws Exception {
|
private final ScopedBeanInterceptor interceptor = new ScopedBeanInterceptor();
|
||||||
ScopedBeanInterceptor interceptor = new ScopedBeanInterceptor();
|
|
||||||
|
@Test
|
||||||
|
public void interceptorWithPlainObject() throws Exception {
|
||||||
final Object realObject = new Object();
|
final Object realObject = new Object();
|
||||||
|
|
||||||
ScopedObject scoped = new ScopedObject() {
|
ScopedObject scoped = new ScopedObject() {
|
||||||
|
@ -42,12 +48,12 @@ public class ScopedBeanInterceptorTests extends TestCase {
|
||||||
};
|
};
|
||||||
|
|
||||||
// default contract is to return null for default behavior
|
// default contract is to return null for default behavior
|
||||||
assertEquals(null, interceptor.getEntityName(realObject));
|
assertNull(interceptor.getEntityName(realObject));
|
||||||
assertEquals(realObject.getClass().getName(), interceptor.getEntityName(scoped));
|
assertEquals(realObject.getClass().getName(), interceptor.getEntityName(scoped));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInterceptorWithCglibProxy() throws Exception {
|
@Test
|
||||||
ScopedBeanInterceptor interceptor = new ScopedBeanInterceptor();
|
public void interceptorWithCglibProxy() throws Exception {
|
||||||
final Object realObject = new Object();
|
final Object realObject = new Object();
|
||||||
ProxyFactory proxyFactory = new ProxyFactory();
|
ProxyFactory proxyFactory = new ProxyFactory();
|
||||||
proxyFactory.setTarget(realObject);
|
proxyFactory.setTarget(realObject);
|
||||||
|
|
|
@ -14,12 +14,11 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.test.annotation;
|
package org.springframework.test;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
|
||||||
import org.springframework.transaction.TransactionDefinition;
|
import org.springframework.transaction.TransactionDefinition;
|
||||||
import org.springframework.transaction.annotation.AnnotationTransactionAttributeSource;
|
import org.springframework.transaction.annotation.AnnotationTransactionAttributeSource;
|
||||||
import org.springframework.transaction.interceptor.TransactionAttributeSource;
|
import org.springframework.transaction.interceptor.TransactionAttributeSource;
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -212,8 +212,8 @@ public abstract class AbstractDependencyInjectionSpringContextTests extends Abst
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initManagedVariableNames() throws IllegalAccessException {
|
private void initManagedVariableNames() throws IllegalAccessException {
|
||||||
List managedVarNames = new LinkedList();
|
List<String> managedVarNames = new LinkedList<>();
|
||||||
Class clazz = getClass();
|
Class<?> clazz = getClass();
|
||||||
do {
|
do {
|
||||||
Field[] fields = clazz.getDeclaredFields();
|
Field[] fields = clazz.getDeclaredFields();
|
||||||
if (this.logger.isDebugEnabled()) {
|
if (this.logger.isDebugEnabled()) {
|
||||||
|
@ -243,7 +243,7 @@ public abstract class AbstractDependencyInjectionSpringContextTests extends Abst
|
||||||
clazz = clazz.getSuperclass();
|
clazz = clazz.getSuperclass();
|
||||||
} while (!clazz.equals(AbstractDependencyInjectionSpringContextTests.class));
|
} while (!clazz.equals(AbstractDependencyInjectionSpringContextTests.class));
|
||||||
|
|
||||||
this.managedVariableNames = (String[]) managedVarNames.toArray(new String[managedVarNames.size()]);
|
this.managedVariableNames = managedVarNames.toArray(new String[managedVarNames.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isProtectedInstanceField(Field field) {
|
private boolean isProtectedInstanceField(Field field) {
|
||||||
|
@ -277,12 +277,12 @@ public abstract class AbstractDependencyInjectionSpringContextTests extends Abst
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Field findField(Class clazz, String name) throws NoSuchFieldException {
|
private Field findField(Class<?> clazz, String name) throws NoSuchFieldException {
|
||||||
try {
|
try {
|
||||||
return clazz.getDeclaredField(name);
|
return clazz.getDeclaredField(name);
|
||||||
}
|
}
|
||||||
catch (NoSuchFieldException ex) {
|
catch (NoSuchFieldException ex) {
|
||||||
Class superclass = clazz.getSuperclass();
|
Class<?> superclass = clazz.getSuperclass();
|
||||||
if (superclass != AbstractSpringContextTests.class) {
|
if (superclass != AbstractSpringContextTests.class) {
|
||||||
return findField(superclass, name);
|
return findField(superclass, name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -71,7 +71,7 @@ import org.springframework.util.StringUtils;
|
||||||
* ({@link org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests})
|
* ({@link org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests})
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract class AbstractSingleSpringContextTests extends AbstractSpringContextTests {
|
abstract class AbstractSingleSpringContextTests extends AbstractSpringContextTests {
|
||||||
|
|
||||||
/** Application context this test will run against */
|
/** Application context this test will run against */
|
||||||
protected ConfigurableApplicationContext applicationContext;
|
protected ConfigurableApplicationContext applicationContext;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -19,6 +19,11 @@ package org.springframework.test;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
@ -54,6 +59,7 @@ import org.springframework.util.StringUtils;
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @since 1.1.1
|
* @since 1.1.1
|
||||||
|
* @see #isDisabledInThisEnvironment
|
||||||
* @see AbstractSingleSpringContextTests
|
* @see AbstractSingleSpringContextTests
|
||||||
* @see AbstractDependencyInjectionSpringContextTests
|
* @see AbstractDependencyInjectionSpringContextTests
|
||||||
* @see AbstractTransactionalSpringContextTests
|
* @see AbstractTransactionalSpringContextTests
|
||||||
|
@ -62,7 +68,10 @@ import org.springframework.util.StringUtils;
|
||||||
* ({@link org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests})
|
* ({@link org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests})
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract class AbstractSpringContextTests extends ConditionalTestCase {
|
abstract class AbstractSpringContextTests extends TestCase {
|
||||||
|
|
||||||
|
/** Logger available to subclasses */
|
||||||
|
protected final Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map of context keys returned by subclasses of this class, to Spring
|
* Map of context keys returned by subclasses of this class, to Spring
|
||||||
|
@ -72,6 +81,14 @@ public abstract class AbstractSpringContextTests extends ConditionalTestCase {
|
||||||
private static Map<String, ConfigurableApplicationContext> contextKeyToContextMap =
|
private static Map<String, ConfigurableApplicationContext> contextKeyToContextMap =
|
||||||
new HashMap<String, ConfigurableApplicationContext>();
|
new HashMap<String, ConfigurableApplicationContext>();
|
||||||
|
|
||||||
|
private static int disabledTestCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the number of tests disabled in this environment.
|
||||||
|
*/
|
||||||
|
public static int getDisabledTestCount() {
|
||||||
|
return disabledTestCount;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor for AbstractSpringContextTests.
|
* Default constructor for AbstractSpringContextTests.
|
||||||
|
@ -86,6 +103,39 @@ public abstract class AbstractSpringContextTests extends ConditionalTestCase {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void runBare() throws Throwable {
|
||||||
|
// getName will return the name of the method being run
|
||||||
|
if (isDisabledInThisEnvironment(getName())) {
|
||||||
|
recordDisabled();
|
||||||
|
this.logger.info("**** " + getClass().getName() + "." + getName()
|
||||||
|
+ " is disabled in this environment: " + "Total disabled tests = "
|
||||||
|
+ getDisabledTestCount());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Let JUnit handle execution
|
||||||
|
super.runBare();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should this test run?
|
||||||
|
*
|
||||||
|
* @param testMethodName name of the test method
|
||||||
|
* @return whether the test should execute in the current environment
|
||||||
|
*/
|
||||||
|
protected boolean isDisabledInThisEnvironment(String testMethodName) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Record a disabled test.
|
||||||
|
*
|
||||||
|
* @return the current disabled test count
|
||||||
|
*/
|
||||||
|
protected int recordDisabled() {
|
||||||
|
return ++disabledTestCount;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Explicitly add an ApplicationContext instance under a given key.
|
* Explicitly add an ApplicationContext instance under a given key.
|
||||||
|
|
|
@ -43,7 +43,7 @@ import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||||
* ({@link org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests})
|
* ({@link org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests})
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract class AbstractTransactionalDataSourceSpringContextTests extends AbstractTransactionalSpringContextTests {
|
abstract class AbstractTransactionalDataSourceSpringContextTests extends AbstractTransactionalSpringContextTests {
|
||||||
|
|
||||||
protected JdbcTemplate jdbcTemplate;
|
protected JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
|
@ -83,7 +83,7 @@ import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||||
* ({@link org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests})
|
* ({@link org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests})
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract class AbstractTransactionalSpringContextTests extends AbstractDependencyInjectionSpringContextTests {
|
abstract class AbstractTransactionalSpringContextTests extends AbstractDependencyInjectionSpringContextTests {
|
||||||
|
|
||||||
/** The transaction manager to use */
|
/** The transaction manager to use */
|
||||||
protected PlatformTransactionManager transactionManager;
|
protected PlatformTransactionManager transactionManager;
|
||||||
|
|
|
@ -1,102 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2002-2014 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.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.test;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is only used within tests in the spring-orm module.
|
|
||||||
*
|
|
||||||
* <p>Superclass for JUnit 3.8 based tests that allows conditional test execution
|
|
||||||
* at the individual test method level. The
|
|
||||||
* {@link #isDisabledInThisEnvironment(String) isDisabledInThisEnvironment()}
|
|
||||||
* method is invoked before the execution of each test method. Subclasses can
|
|
||||||
* override that method to return whether or not the given test should be
|
|
||||||
* executed. Note that the tests will still appear to have executed and passed;
|
|
||||||
* however, log output will show that the test was not executed.
|
|
||||||
*
|
|
||||||
* @author Rod Johnson
|
|
||||||
* @since 2.0
|
|
||||||
* @see #isDisabledInThisEnvironment
|
|
||||||
* @deprecated as of Spring 3.0, in favor of using the listener-based test context framework
|
|
||||||
* ({@link org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests})
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public abstract class ConditionalTestCase extends TestCase {
|
|
||||||
|
|
||||||
private static int disabledTestCount;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the number of tests disabled in this environment.
|
|
||||||
*/
|
|
||||||
public static int getDisabledTestCount() {
|
|
||||||
return disabledTestCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Logger available to subclasses */
|
|
||||||
protected final Log logger = LogFactory.getLog(getClass());
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default constructor for ConditionalTestCase.
|
|
||||||
*/
|
|
||||||
public ConditionalTestCase() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for ConditionalTestCase with a JUnit name.
|
|
||||||
*/
|
|
||||||
public ConditionalTestCase(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void runBare() throws Throwable {
|
|
||||||
// getName will return the name of the method being run
|
|
||||||
if (isDisabledInThisEnvironment(getName())) {
|
|
||||||
recordDisabled();
|
|
||||||
this.logger.info("**** " + getClass().getName() + "." + getName() + " is disabled in this environment: "
|
|
||||||
+ "Total disabled tests = " + getDisabledTestCount());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Let JUnit handle execution
|
|
||||||
super.runBare();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should this test run?
|
|
||||||
* @param testMethodName name of the test method
|
|
||||||
* @return whether the test should execute in the current environment
|
|
||||||
*/
|
|
||||||
protected boolean isDisabledInThisEnvironment(String testMethodName) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Record a disabled test.
|
|
||||||
* @return the current disabled test count
|
|
||||||
*/
|
|
||||||
protected int recordDisabled() {
|
|
||||||
return ++disabledTestCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -23,6 +23,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
|
|
||||||
|
@ -45,7 +46,8 @@ import org.springframework.orm.jpa.ExtendedEntityManagerCreator;
|
||||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||||
import org.springframework.orm.jpa.SharedEntityManagerCreator;
|
import org.springframework.orm.jpa.SharedEntityManagerCreator;
|
||||||
import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager;
|
import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager;
|
||||||
import org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests;
|
import org.springframework.test.AbstractAnnotationAwareTransactionalTests;
|
||||||
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -261,6 +263,7 @@ public abstract class AbstractJpaTests extends AbstractAnnotationAwareTransactio
|
||||||
/* AbstractSpringContextTests.addContext(Object, ApplicationContext) */
|
/* AbstractSpringContextTests.addContext(Object, ApplicationContext) */
|
||||||
Class applicationContextClass = shadowingClassLoader.loadClass(ConfigurableApplicationContext.class.getName());
|
Class applicationContextClass = shadowingClassLoader.loadClass(ConfigurableApplicationContext.class.getName());
|
||||||
Method addContextMethod = shadowedTestClass.getMethod("addContext", Object.class, applicationContextClass);
|
Method addContextMethod = shadowedTestClass.getMethod("addContext", Object.class, applicationContextClass);
|
||||||
|
ReflectionUtils.makeAccessible(addContextMethod);
|
||||||
addContextMethod.invoke(shadowedTestCase, configLocations, cachedContext);
|
addContextMethod.invoke(shadowedTestCase, configLocations, cachedContext);
|
||||||
|
|
||||||
// Invoke tests on shadowed test case
|
// Invoke tests on shadowed test case
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue