Polishing
This commit is contained in:
parent
f6693e790a
commit
013c0bca92
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
@ -20,7 +20,6 @@ import org.junit.Test;
|
|||
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.tests.TestResourceUtils.*;
|
||||
|
@ -33,13 +32,11 @@ import static org.springframework.tests.TestResourceUtils.*;
|
|||
*/
|
||||
public class TopLevelAopTagTests {
|
||||
|
||||
private static final Resource CONTEXT = qualifiedResource(TopLevelAopTagTests.class, "context.xml");
|
||||
|
||||
@Test
|
||||
public void testParse() throws Exception {
|
||||
public void testParse() {
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
|
||||
reader.loadBeanDefinitions(CONTEXT);
|
||||
new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(
|
||||
qualifiedResource(TopLevelAopTagTests.class, "context.xml"));
|
||||
|
||||
assertTrue(beanFactory.containsBeanDefinition("testPointcut"));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
@ -36,6 +36,7 @@ public class PrototypeTargetTests {
|
|||
|
||||
private static final Resource CONTEXT = qualifiedResource(PrototypeTargetTests.class, "context.xml");
|
||||
|
||||
|
||||
@Test
|
||||
public void testPrototypeProxyWithPrototypeTarget() {
|
||||
TestBeanImpl.constructionCount = 0;
|
||||
|
@ -64,12 +65,15 @@ public class PrototypeTargetTests {
|
|||
assertEquals(10, interceptor.invocationCount);
|
||||
}
|
||||
|
||||
public static interface TestBean {
|
||||
public void doSomething();
|
||||
|
||||
public interface TestBean {
|
||||
|
||||
void doSomething();
|
||||
}
|
||||
|
||||
|
||||
public static class TestBeanImpl implements TestBean {
|
||||
|
||||
private static int constructionCount = 0;
|
||||
|
||||
public TestBeanImpl() {
|
||||
|
@ -83,6 +87,7 @@ public class PrototypeTargetTests {
|
|||
|
||||
|
||||
public static class TestInterceptor implements MethodInterceptor {
|
||||
|
||||
private int invocationCount = 0;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
@ -21,7 +21,6 @@ import org.junit.Test;
|
|||
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
|
@ -36,13 +35,11 @@ import static org.springframework.tests.TestResourceUtils.*;
|
|||
*/
|
||||
public class ExposeInvocationInterceptorTests {
|
||||
|
||||
private static final Resource CONTEXT =
|
||||
qualifiedResource(ExposeInvocationInterceptorTests.class, "context.xml");
|
||||
|
||||
@Test
|
||||
public void testXmlConfig() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
qualifiedResource(ExposeInvocationInterceptorTests.class, "context.xml"));
|
||||
ITestBean tb = (ITestBean) bf.getBean("proxy");
|
||||
String name = "tony";
|
||||
tb.setName(name);
|
||||
|
@ -74,6 +71,7 @@ abstract class ExposedInvocationTestBean extends TestBean {
|
|||
|
||||
|
||||
class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean {
|
||||
|
||||
@Override
|
||||
protected void assertions(MethodInvocation invocation) {
|
||||
assertTrue(invocation.getThis() == this);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
@ -22,7 +22,6 @@ import org.junit.Test;
|
|||
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.tests.TestResourceUtils.*;
|
||||
|
@ -34,16 +33,12 @@ import static org.springframework.tests.TestResourceUtils.*;
|
|||
*/
|
||||
public class ScopedProxyAutowireTests {
|
||||
|
||||
private static final Resource SCOPED_AUTOWIRE_FALSE_CONTEXT =
|
||||
qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireFalse.xml");
|
||||
private static final Resource SCOPED_AUTOWIRE_TRUE_CONTEXT =
|
||||
qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireTrue.xml");
|
||||
|
||||
|
||||
@Test
|
||||
public void testScopedProxyInheritsAutowireCandidateFalse() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(SCOPED_AUTOWIRE_FALSE_CONTEXT);
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireFalse.xml"));
|
||||
|
||||
assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, false, false)).contains("scoped"));
|
||||
assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, true, false)).contains("scoped"));
|
||||
assertFalse(bf.containsSingleton("scoped"));
|
||||
|
@ -55,7 +50,9 @@ public class ScopedProxyAutowireTests {
|
|||
@Test
|
||||
public void testScopedProxyReplacesAutowireCandidateTrue() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(SCOPED_AUTOWIRE_TRUE_CONTEXT);
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireTrue.xml"));
|
||||
|
||||
assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, true, false)).contains("scoped"));
|
||||
assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, false, false)).contains("scoped"));
|
||||
assertFalse(bf.containsSingleton("scoped"));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
@ -39,7 +39,8 @@ import static org.springframework.tests.TestResourceUtils.*;
|
|||
public class RegexpMethodPointcutAdvisorIntegrationTests {
|
||||
|
||||
private static final Resource CONTEXT =
|
||||
qualifiedResource(RegexpMethodPointcutAdvisorIntegrationTests.class, "context.xml");
|
||||
qualifiedResource(RegexpMethodPointcutAdvisorIntegrationTests.class, "context.xml");
|
||||
|
||||
|
||||
@Test
|
||||
public void testSinglePattern() throws Throwable {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
@ -25,7 +25,6 @@ import org.springframework.aop.framework.ProxyFactory;
|
|||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.tests.aop.interceptor.SerializableNopInterceptor;
|
||||
import org.springframework.tests.sample.beans.Person;
|
||||
import org.springframework.tests.sample.beans.SerializablePerson;
|
||||
|
@ -41,31 +40,31 @@ import static org.springframework.tests.TestResourceUtils.*;
|
|||
*/
|
||||
public class HotSwappableTargetSourceTests {
|
||||
|
||||
private static final Resource CONTEXT = qualifiedResource(HotSwappableTargetSourceTests.class, "context.xml");
|
||||
|
||||
/** Initial count value set in bean factory XML */
|
||||
private static final int INITIAL_COUNT = 10;
|
||||
|
||||
private DefaultListableBeanFactory beanFactory;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setup() {
|
||||
this.beanFactory = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(CONTEXT);
|
||||
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
|
||||
qualifiedResource(HotSwappableTargetSourceTests.class, "context.xml"));
|
||||
}
|
||||
|
||||
/**
|
||||
* We must simulate container shutdown, which should clear threads.
|
||||
*/
|
||||
@After
|
||||
public void tearDown() {
|
||||
public void close() {
|
||||
// Will call pool.close()
|
||||
this.beanFactory.destroySingletons();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check it works like a normal invoker
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testBasicFunctionality() {
|
||||
|
@ -106,18 +105,13 @@ public class HotSwappableTargetSourceTests {
|
|||
assertEquals(target1.getCount(), proxied.getCount());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param invalid
|
||||
* @return the message
|
||||
*/
|
||||
private IllegalArgumentException testRejectsSwapToInvalidValue(Object invalid) {
|
||||
@Test
|
||||
public void testRejectsSwapToNull() {
|
||||
HotSwappableTargetSource swapper = (HotSwappableTargetSource) beanFactory.getBean("swapper");
|
||||
IllegalArgumentException aopex = null;
|
||||
try {
|
||||
swapper.swap(invalid);
|
||||
fail("Shouldn't be able to swap to invalid value [" + invalid + "]");
|
||||
swapper.swap(null);
|
||||
fail("Shouldn't be able to swap to invalid value");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// Ok
|
||||
|
@ -126,19 +120,9 @@ public class HotSwappableTargetSourceTests {
|
|||
|
||||
// It shouldn't be corrupted, it should still work
|
||||
testBasicFunctionality();
|
||||
return aopex;
|
||||
assertTrue(aopex.getMessage().contains("null"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRejectsSwapToNull() {
|
||||
IllegalArgumentException ex = testRejectsSwapToInvalidValue(null);
|
||||
assertTrue(ex.getMessage().contains("null"));
|
||||
}
|
||||
|
||||
// TODO test reject swap to wrong interface or class?
|
||||
// how to decide what's valid?
|
||||
|
||||
|
||||
@Test
|
||||
public void testSerialization() throws Exception {
|
||||
SerializablePerson sp1 = new SerializablePerson();
|
||||
|
@ -165,4 +149,5 @@ public class HotSwappableTargetSourceTests {
|
|||
assertEquals(sp1.getName(), p.getName());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
@ -19,11 +19,8 @@ package org.springframework.aop.target;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.tests.sample.beans.SideEffectBean;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
@ -35,19 +32,20 @@ import static org.springframework.tests.TestResourceUtils.*;
|
|||
*/
|
||||
public class PrototypeTargetSourceTests {
|
||||
|
||||
private static final Resource CONTEXT = qualifiedResource(PrototypeTargetSourceTests.class, "context.xml");
|
||||
|
||||
/** Initial count value set in bean factory XML */
|
||||
private static final int INITIAL_COUNT = 10;
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
private DefaultListableBeanFactory beanFactory;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setup() {
|
||||
this.beanFactory = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.beanFactory).loadBeanDefinitions(CONTEXT);
|
||||
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
|
||||
qualifiedResource(PrototypeTargetSourceTests.class, "context.xml"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test that multiple invocations of the prototype bean will result
|
||||
* in no change to visible state, as a new instance is used.
|
||||
|
@ -66,5 +64,4 @@ public class PrototypeTargetSourceTests {
|
|||
assertEquals(INITIAL_COUNT, prototype.getCount());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
@ -21,7 +21,6 @@ import org.junit.Test;
|
|||
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.SideEffectBean;
|
||||
|
||||
|
@ -34,26 +33,27 @@ import static org.springframework.tests.TestResourceUtils.*;
|
|||
*/
|
||||
public class ThreadLocalTargetSourceTests {
|
||||
|
||||
private static final Resource CONTEXT = qualifiedResource(ThreadLocalTargetSourceTests.class, "context.xml");
|
||||
|
||||
/** Initial count value set in bean factory XML */
|
||||
private static final int INITIAL_COUNT = 10;
|
||||
|
||||
private DefaultListableBeanFactory beanFactory;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setup() {
|
||||
this.beanFactory = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(CONTEXT);
|
||||
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
|
||||
qualifiedResource(ThreadLocalTargetSourceTests.class, "context.xml"));
|
||||
}
|
||||
|
||||
/**
|
||||
* We must simulate container shutdown, which should clear threads.
|
||||
*/
|
||||
protected void tearDown() {
|
||||
protected void close() {
|
||||
this.beanFactory.destroySingletons();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check we can use two different ThreadLocalTargetSources
|
||||
* managing objects of different types without them interfering
|
||||
|
@ -141,7 +141,7 @@ public class ThreadLocalTargetSourceTests {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test for SPR-1442. Destroyed target should re-associated with thread and not throw NPE
|
||||
* Test for SPR-1442. Destroyed target should re-associated with thread and not throw NPE.
|
||||
*/
|
||||
@Test
|
||||
public void testReuseDestroyedTarget() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
@ -50,10 +50,8 @@ import static org.springframework.tests.TestResourceUtils.*;
|
|||
*/
|
||||
public class ConcurrentBeanFactoryTests {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ConcurrentBeanFactoryTests.class);
|
||||
private static final Resource CONTEXT = qualifiedResource(ConcurrentBeanFactoryTests.class, "context.xml");
|
||||
|
||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd");
|
||||
|
||||
private static final Date DATE_1, DATE_2;
|
||||
|
||||
static {
|
||||
|
@ -66,27 +64,32 @@ public class ConcurrentBeanFactoryTests {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ConcurrentBeanFactoryTests.class);
|
||||
|
||||
private BeanFactory factory;
|
||||
|
||||
private final Set<TestRun> set = Collections.synchronizedSet(new HashSet<TestRun>());
|
||||
private final Set<TestRun> set = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
private Throwable ex;
|
||||
|
||||
private Throwable ex = null;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setup() throws Exception {
|
||||
Assume.group(TestGroup.PERFORMANCE);
|
||||
|
||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(CONTEXT);
|
||||
factory.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
|
||||
@Override
|
||||
public void registerCustomEditors(PropertyEditorRegistry registry) {
|
||||
registry.registerCustomEditor(Date.class, new CustomDateEditor((DateFormat) DATE_FORMAT.clone(), false));
|
||||
}
|
||||
});
|
||||
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(
|
||||
qualifiedResource(ConcurrentBeanFactoryTests.class, "context.xml"));
|
||||
|
||||
factory.addPropertyEditorRegistrar(
|
||||
registry -> registry.registerCustomEditor(Date.class,
|
||||
new CustomDateEditor((DateFormat) DATE_FORMAT.clone(), false)));
|
||||
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSingleThread() {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
@ -21,10 +21,8 @@ import org.junit.Test;
|
|||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.config.DependencyDescriptor;
|
||||
import org.springframework.beans.factory.support.AutowireCandidateResolver;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReader;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.tests.TestResourceUtils.*;
|
||||
|
@ -38,13 +36,12 @@ import static org.springframework.tests.TestResourceUtils.*;
|
|||
*/
|
||||
public class CustomAutowireConfigurerTests {
|
||||
|
||||
private static final Resource CONTEXT = qualifiedResource(CustomAutowireConfigurerTests.class, "context.xml");
|
||||
|
||||
@Test
|
||||
public void testCustomResolver() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
BeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
|
||||
reader.loadBeanDefinitions(CONTEXT);
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
qualifiedResource(CustomAutowireConfigurerTests.class, "context.xml"));
|
||||
|
||||
CustomAutowireConfigurer cac = new CustomAutowireConfigurer();
|
||||
CustomResolver customResolver = new CustomResolver();
|
||||
bf.setAutowireCandidateResolver(customResolver);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
@ -22,7 +22,6 @@ import org.junit.Test;
|
|||
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
@ -37,9 +36,6 @@ import static org.springframework.tests.TestResourceUtils.*;
|
|||
*/
|
||||
public class FieldRetrievingFactoryBeanTests {
|
||||
|
||||
private static final Resource CONTEXT =
|
||||
qualifiedResource(FieldRetrievingFactoryBeanTests.class, "context.xml");
|
||||
|
||||
@Test
|
||||
public void testStaticField() throws Exception {
|
||||
FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean();
|
||||
|
@ -127,7 +123,9 @@ public class FieldRetrievingFactoryBeanTests {
|
|||
@Test
|
||||
public void testBeanNameSyntaxWithBeanFactory() throws Exception {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
qualifiedResource(FieldRetrievingFactoryBeanTests.class, "context.xml"));
|
||||
|
||||
TestBean testBean = (TestBean) bf.getBean("testBean");
|
||||
assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), testBean.getSomeIntegerArray()[0]);
|
||||
assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), testBean.getSomeIntegerArray()[1]);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
@ -27,7 +27,6 @@ import org.springframework.beans.factory.BeanFactory;
|
|||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.SerializationTestUtils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
@ -42,25 +41,25 @@ import static org.springframework.tests.TestResourceUtils.*;
|
|||
*/
|
||||
public class ObjectFactoryCreatingFactoryBeanTests {
|
||||
|
||||
private static final Resource CONTEXT =
|
||||
qualifiedResource(ObjectFactoryCreatingFactoryBeanTests.class, "context.xml");
|
||||
|
||||
private DefaultListableBeanFactory beanFactory;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
public void setup() {
|
||||
this.beanFactory = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(CONTEXT);
|
||||
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
|
||||
qualifiedResource(ObjectFactoryCreatingFactoryBeanTests.class, "context.xml"));
|
||||
this.beanFactory.setSerializationId("test");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
public void close() {
|
||||
this.beanFactory.setSerializationId(null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFactoryOperation() throws Exception {
|
||||
public void testFactoryOperation() {
|
||||
FactoryTestBean testBean = beanFactory.getBean("factoryTestBean", FactoryTestBean.class);
|
||||
ObjectFactory<?> objectFactory = testBean.getObjectFactory();
|
||||
|
||||
|
@ -82,7 +81,7 @@ public class ObjectFactoryCreatingFactoryBeanTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testProviderOperation() throws Exception {
|
||||
public void testProviderOperation() {
|
||||
ProviderTestBean testBean = beanFactory.getBean("providerTestBean", ProviderTestBean.class);
|
||||
Provider<?> provider = testBean.getProvider();
|
||||
|
||||
|
@ -152,7 +151,7 @@ public class ObjectFactoryCreatingFactoryBeanTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testEnsureOFBFBReportsThatItActuallyCreatesObjectFactoryInstances() throws Exception {
|
||||
public void testEnsureOFBFBReportsThatItActuallyCreatesObjectFactoryInstances() {
|
||||
assertEquals("Must be reporting that it creates ObjectFactory instances (as per class contract).",
|
||||
ObjectFactory.class, new ObjectFactoryCreatingFactoryBean().getObjectType());
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
@ -25,7 +25,6 @@ import org.junit.Test;
|
|||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
@ -40,12 +39,11 @@ import static org.springframework.tests.TestResourceUtils.*;
|
|||
*/
|
||||
public class SimpleScopeTests {
|
||||
|
||||
private static final Resource CONTEXT = qualifiedResource(SimpleScopeTests.class, "context.xml");
|
||||
|
||||
private DefaultListableBeanFactory beanFactory;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
public void setup() {
|
||||
beanFactory = new DefaultListableBeanFactory();
|
||||
Scope scope = new NoOpScope() {
|
||||
private int index;
|
||||
|
@ -69,10 +67,11 @@ public class SimpleScopeTests {
|
|||
assertEquals("myScope", scopeNames[0]);
|
||||
assertSame(scope, beanFactory.getRegisteredScope("myScope"));
|
||||
|
||||
XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(beanFactory);
|
||||
xbdr.loadBeanDefinitions(CONTEXT);
|
||||
new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(
|
||||
qualifiedResource(SimpleScopeTests.class, "context.xml"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCanGetScopedObject() {
|
||||
TestBean tb1 = (TestBean) beanFactory.getBean("usesScope");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
@ -24,7 +24,6 @@ import org.junit.Test;
|
|||
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
@ -37,8 +36,6 @@ import static org.springframework.tests.TestResourceUtils.*;
|
|||
*/
|
||||
public class CustomProblemReporterTests {
|
||||
|
||||
private static final Resource CONTEXT = qualifiedResource(CustomProblemReporterTests.class, "context.xml");
|
||||
|
||||
private CollatingProblemReporter problemReporter;
|
||||
|
||||
private DefaultListableBeanFactory beanFactory;
|
||||
|
@ -47,16 +44,17 @@ public class CustomProblemReporterTests {
|
|||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
public void setup() {
|
||||
this.problemReporter = new CollatingProblemReporter();
|
||||
this.beanFactory = new DefaultListableBeanFactory();
|
||||
this.reader = new XmlBeanDefinitionReader(this.beanFactory);
|
||||
this.reader.setProblemReporter(this.problemReporter);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testErrorsAreCollated() {
|
||||
this.reader.loadBeanDefinitions(CONTEXT);
|
||||
this.reader.loadBeanDefinitions(qualifiedResource(CustomProblemReporterTests.class, "context.xml"));
|
||||
assertEquals("Incorrect number of errors collated", 4, this.problemReporter.getErrors().length);
|
||||
|
||||
TestBean bean = (TestBean) this.beanFactory.getBean("validBean");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
@ -119,7 +119,7 @@ public abstract class Jackson2CodecSupport {
|
|||
|
||||
@Nullable
|
||||
protected MethodParameter getParameter(ResolvableType type) {
|
||||
return type.getSource() instanceof MethodParameter ? (MethodParameter) type.getSource() : null;
|
||||
return (type.getSource() instanceof MethodParameter ? (MethodParameter) type.getSource() : null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
@ -39,11 +39,10 @@ import org.springframework.web.context.ServletContextAware;
|
|||
/**
|
||||
* Subclass of {@link GenericApplicationContext}, suitable for web environments.
|
||||
*
|
||||
* <p>Implements the
|
||||
* {@link org.springframework.web.context.ConfigurableWebApplicationContext},
|
||||
* but is not intended for declarative setup in {@code web.xml}. Instead,
|
||||
* it is designed for programmatic setup, for example for building nested contexts or
|
||||
* for use within Spring 3.1 {@link org.springframework.web.WebApplicationInitializer org.springframework.web.WebApplicationInitializers}.
|
||||
* <p>Implements {@link org.springframework.web.context.ConfigurableWebApplicationContext},
|
||||
* but is not intended for declarative setup in {@code web.xml}. Instead, it is designed
|
||||
* for programmatic setup, for example for building nested contexts or for use within
|
||||
* {@link org.springframework.web.WebApplicationInitializer WebApplicationInitializers}.
|
||||
*
|
||||
* <p><b>If you intend to implement a WebApplicationContext that reads bean definitions
|
||||
* from configuration files, consider deriving from AbstractRefreshableWebApplicationContext,
|
||||
|
|
|
@ -42,18 +42,13 @@ import org.springframework.http.MediaType;
|
|||
import org.springframework.http.codec.Pojo;
|
||||
import org.springframework.util.MimeType;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static java.util.Arrays.*;
|
||||
import static java.util.Collections.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.core.ResolvableType.forClass;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8;
|
||||
import static org.springframework.http.MediaType.APPLICATION_STREAM_JSON;
|
||||
import static org.springframework.http.MediaType.APPLICATION_XML;
|
||||
import static org.springframework.http.codec.json.Jackson2JsonDecoder.JSON_VIEW_HINT;
|
||||
import static org.springframework.http.codec.json.JacksonViewBean.MyJacksonView1;
|
||||
import static org.springframework.http.codec.json.JacksonViewBean.MyJacksonView3;
|
||||
import static org.springframework.core.ResolvableType.*;
|
||||
import static org.springframework.http.MediaType.*;
|
||||
import static org.springframework.http.codec.json.Jackson2JsonDecoder.*;
|
||||
import static org.springframework.http.codec.json.JacksonViewBean.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Jackson2JsonDecoder}.
|
||||
|
@ -67,10 +62,12 @@ public class Jackson2JsonDecoderTests extends AbstractDecoderTestCase<Jackson2Js
|
|||
|
||||
private Pojo pojo2 = new Pojo("f2", "b2");
|
||||
|
||||
|
||||
public Jackson2JsonDecoderTests() {
|
||||
super(new Jackson2JsonDecoder());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void canDecode() {
|
||||
|
@ -83,7 +80,7 @@ public class Jackson2JsonDecoderTests extends AbstractDecoderTestCase<Jackson2Js
|
|||
assertFalse(decoder.canDecode(forClass(Pojo.class), APPLICATION_XML));
|
||||
}
|
||||
|
||||
@Test // SPR-15866
|
||||
@Test // SPR-15866
|
||||
public void canDecodeWithProvidedMimeType() {
|
||||
MimeType textJavascript = new MimeType("text", "javascript", StandardCharsets.UTF_8);
|
||||
Jackson2JsonDecoder decoder = new Jackson2JsonDecoder(new ObjectMapper(), textJavascript);
|
||||
|
@ -212,7 +209,6 @@ public class Jackson2JsonDecoderTests extends AbstractDecoderTestCase<Jackson2Js
|
|||
}
|
||||
|
||||
|
||||
|
||||
private static class BeanWithNoDefaultConstructor {
|
||||
|
||||
private final String property1;
|
||||
|
@ -231,12 +227,14 @@ public class Jackson2JsonDecoderTests extends AbstractDecoderTestCase<Jackson2Js
|
|||
public String getProperty2() {
|
||||
return this.property2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@JsonDeserialize(using = Deserializer.class)
|
||||
public static class TestObject {
|
||||
|
||||
private int test;
|
||||
|
||||
public int getTest() {
|
||||
return this.test;
|
||||
}
|
||||
|
@ -245,6 +243,7 @@ public class Jackson2JsonDecoderTests extends AbstractDecoderTestCase<Jackson2Js
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Deserializer extends StdDeserializer<TestObject> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
@ -254,8 +253,7 @@ public class Jackson2JsonDecoderTests extends AbstractDecoderTestCase<Jackson2Js
|
|||
}
|
||||
|
||||
@Override
|
||||
public TestObject deserialize(JsonParser p,
|
||||
DeserializationContext ctxt) throws IOException {
|
||||
public TestObject deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
JsonNode node = p.readValueAsTree();
|
||||
TestObject result = new TestObject();
|
||||
result.setTest(node.get("test").asInt());
|
||||
|
|
Loading…
Reference in New Issue