Moved tests from testsuite to context and context support

This commit is contained in:
Arjen Poutsma
2008-10-30 16:24:14 +00:00
parent a1545e3f06
commit 100a80e112
11 changed files with 104 additions and 11 deletions

View File

@@ -172,6 +172,17 @@
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$IVY_CACHE$/org.easymock/com.springsource.org.easymock/2.3.0/com.springsource.org.easymock-2.3.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$IVY_CACHE$/org.easymock/com.springsource.org.easymock/2.3.0/com.springsource.org.easymock-sources-2.3.0.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntryProperties />
</component>
<component name="copyright">

View File

@@ -52,6 +52,7 @@
<!-- test dependencies -->
<dependency org="org.apache.log4j" name="com.springsource.org.apache.log4j" rev="1.2.15" conf="test->runtime"/>
<dependency org="org.junit" name="com.springsource.org.junit" rev="4.4.0" conf="test->runtime" />
<dependency org="org.easymock" name="com.springsource.org.easymock" rev="2.3.0" conf="test->compile"/>
</dependencies>
</ivy-module>

View File

@@ -1,16 +1,90 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.parent</artifactId>
<version>3.0-M1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.context</artifactId>
<packaging>jar</packaging>
<name>Spring Core Abstractions and Utilities</name>
<version>3.0.0.M1</version>
<name>Spring Framework: Context</name>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.agent</artifactId>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<groupId>javax.ejb</groupId>
<artifactId>com.springsource.javax.ejb</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>com.springsource.javax.jms</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>com.springsource.javax.persistence</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.sourceforge.cglib</groupId>
<artifactId>com.springsource.net.sf.cglib</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>com.springsource.org.aspectj.weaver</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.aopalliance</groupId>
<artifactId>com.springsource.org.aopalliance</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>com.springsource.org.jruby</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>com.springsource.org.codehaus.groovy</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.beanshell</groupId>
<artifactId>com.springsource.bsh</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>edu.emory.mathcs.backport</groupId>
<artifactId>com.springsource.edu.emory.mathcs.backport</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.oracle.oc4j</groupId>
<artifactId>com.springsource.oracle.classloader</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.sun.enterprise</groupId>
<artifactId>com.springsource.com.sun.enterprise.loader</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2002-2005 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.access;
import junit.framework.TestCase;
import org.easymock.MockControl;
import org.springframework.context.ConfigurableApplicationContext;
/**
* Unit test for ContextBeanFactoryReference
*
* @author Colin Sampaleanu
*/
public class ContextBeanFactoryReferenceTests extends TestCase {
public void testAllOperations() {
MockControl control = MockControl.createControl(ConfigurableApplicationContext.class);
ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) control.getMock();
ctx.close();
control.replay();
ContextBeanFactoryReference bfr = new ContextBeanFactoryReference(ctx);
assertNotNull(bfr.getFactory());
bfr.release();
try {
bfr.getFactory();
}
catch (IllegalStateException e) {
// expected
}
control.verify();
}
}

View File

@@ -0,0 +1,45 @@
/*
* Copyright 2002-2005 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.access;
import junit.framework.TestCase;
import org.springframework.beans.factory.access.BeanFactoryLocator;
/**
* @author Colin Sampaleanu
*/
public class DefaultLocatorFactoryTests extends TestCase {
/*
* Class to test for BeanFactoryLocator getInstance()
*/
public void testGetInstance() {
BeanFactoryLocator bf = DefaultLocatorFactory.getInstance();
BeanFactoryLocator bf2 = DefaultLocatorFactory.getInstance();
assertTrue(bf.equals(bf2));
}
/*
* Class to test for BeanFactoryLocator getInstance(String)
*/
public void testGetInstanceString() {
BeanFactoryLocator bf = DefaultLocatorFactory.getInstance("my-bean-refs.xml");
BeanFactoryLocator bf2 = DefaultLocatorFactory.getInstance("my-bean-refs.xml");
assertTrue(bf.equals(bf2));
}
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright 2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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.config;
import java.util.Date;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.config.PropertyOverrideConfigurer;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Arjen Poutsma
* @since 2.5.6
*/
public class ContextNamespaceHandlerTests {
private ApplicationContext applicationContext;
@Before
public void createAppContext() {
applicationContext = new ClassPathXmlApplicationContext("contextNamespaceHandlerTests.xml", getClass());
}
@Test
public void propertyPlaceholder() throws Exception {
Map beans = applicationContext.getBeansOfType(PropertyPlaceholderConfigurer.class);
assertFalse("No PropertyPlaceHolderConfigurer found", beans.isEmpty());
String s = (String) applicationContext.getBean("string");
assertEquals("No properties replaced", "bar", s);
}
@Test
public void propertyOverride() throws Exception {
Map beans = applicationContext.getBeansOfType(PropertyOverrideConfigurer.class);
assertFalse("No PropertyOverrideConfigurer found", beans.isEmpty());
Date date = (Date) applicationContext.getBean("date");
assertEquals("No properties overriden", 42, date.getMinutes());
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright 2002-2005 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.jndi;
import junit.framework.TestCase;
/**
* @author Rod Johnson
*/
public class JndiTemplateEditorTests extends TestCase {
public void testNullIsIllegalArgument() {
try {
new JndiTemplateEditor().setAsText(null);
fail("Null is illegal");
}
catch (IllegalArgumentException ex) {
// OK
}
}
public void testEmptyStringMeansNullEnvironment() {
JndiTemplateEditor je = new JndiTemplateEditor();
je.setAsText("");
JndiTemplate jt = (JndiTemplate) je.getValue();
assertTrue(jt.getEnvironment() == null);
}
public void testCustomEnvironment() {
JndiTemplateEditor je = new JndiTemplateEditor();
// These properties are meaningless for JNDI, but we don't worry about that:
// the underlying JNDI implementation will throw exceptions when the user tries
// to look anything up
je.setAsText("jndiInitialSomethingOrOther=org.springframework.myjndi.CompleteRubbish\nfoo=bar");
JndiTemplate jt = (JndiTemplate) je.getValue();
assertTrue(jt.getEnvironment().size() == 2);
assertTrue(jt.getEnvironment().getProperty("jndiInitialSomethingOrOther").equals("org.springframework.myjndi.CompleteRubbish"));
assertTrue(jt.getEnvironment().getProperty("foo").equals("bar"));
}
}

View File

@@ -0,0 +1,196 @@
/*
* Copyright 2002-2006 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.jndi;
import javax.naming.Context;
import javax.naming.NameNotFoundException;
import junit.framework.TestCase;
import org.easymock.MockControl;
/**
* @author Rod Johnson
* @author Juergen Hoeller
* @since 08.07.2003
*/
public class JndiTemplateTests extends TestCase {
public void testLookupSucceeds() throws Exception {
Object o = new Object();
String name = "foo";
MockControl mc = MockControl.createControl(Context.class);
final Context mock = (Context) mc.getMock();
mock.lookup(name);
mc.setReturnValue(o);
mock.close();
mc.setVoidCallable(1);
mc.replay();
JndiTemplate jt = new JndiTemplate() {
protected Context createInitialContext() {
return mock;
}
};
Object o2 = jt.lookup(name);
assertEquals(o, o2);
mc.verify();
}
public void testLookupFails() throws Exception {
NameNotFoundException ne = new NameNotFoundException();
String name = "foo";
MockControl mc = MockControl.createControl(Context.class);
final Context mock = (Context) mc.getMock();
mock.lookup(name);
mc.setThrowable(ne);
mock.close();
mc.setVoidCallable(1);
mc.replay();
JndiTemplate jt = new JndiTemplate() {
protected Context createInitialContext() {
return mock;
}
};
try {
jt.lookup(name);
fail("Should have thrown NamingException");
}
catch (NameNotFoundException ex) {
// Ok
}
mc.verify();
}
public void testLookupReturnsNull() throws Exception {
String name = "foo";
MockControl mc = MockControl.createControl(Context.class);
final Context mock = (Context) mc.getMock();
mock.lookup(name);
mc.setReturnValue(null);
mock.close();
mc.setVoidCallable(1);
mc.replay();
JndiTemplate jt = new JndiTemplate() {
protected Context createInitialContext() {
return mock;
}
};
try {
jt.lookup(name);
fail("Should have thrown NamingException");
}
catch (NameNotFoundException ex) {
// Ok
}
mc.verify();
}
public void testLookupFailsWithTypeMismatch() throws Exception {
Object o = new Object();
String name = "foo";
MockControl mc = MockControl.createControl(Context.class);
final Context mock = (Context) mc.getMock();
mock.lookup(name);
mc.setReturnValue(o);
mock.close();
mc.setVoidCallable(1);
mc.replay();
JndiTemplate jt = new JndiTemplate() {
protected Context createInitialContext() {
return mock;
}
};
try {
jt.lookup(name, String.class);
fail("Should have thrown TypeMismatchNamingException");
}
catch (TypeMismatchNamingException ex) {
// Ok
}
mc.verify();
}
public void testBind() throws Exception {
Object o = new Object();
String name = "foo";
MockControl mc = MockControl.createControl(Context.class);
final Context mock = (Context) mc.getMock();
mock.bind(name, o);
mc.setVoidCallable(1);
mock.close();
mc.setVoidCallable(1);
mc.replay();
JndiTemplate jt = new JndiTemplate() {
protected Context createInitialContext() {
return mock;
}
};
jt.bind(name, o);
mc.verify();
}
public void testRebind() throws Exception {
Object o = new Object();
String name = "foo";
MockControl mc = MockControl.createControl(Context.class);
final Context mock = (Context) mc.getMock();
mock.rebind(name, o);
mc.setVoidCallable(1);
mock.close();
mc.setVoidCallable(1);
mc.replay();
JndiTemplate jt = new JndiTemplate() {
protected Context createInitialContext() {
return mock;
}
};
jt.rebind(name, o);
mc.verify();
}
public void testUnbind() throws Exception {
String name = "something";
MockControl mc = MockControl.createControl(Context.class);
final Context mock = (Context) mc.getMock();
mock.unbind(name);
mc.setVoidCallable(1);
mock.close();
mc.setVoidCallable(1);
mc.replay();
JndiTemplate jt = new JndiTemplate() {
protected Context createInitialContext() {
return mock;
}
};
jt.unbind(name);
mc.verify();
}
}

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
<util:properties id="placeholderProps">
<prop key="foo">bar</prop>
</util:properties>
<context:property-placeholder properties-ref="placeholderProps"/>
<bean id="string" class="java.lang.String">
<constructor-arg value="${foo}"/>
</bean>
<util:properties id="overrideProps">
<prop key="date.minutes">42</prop>
</util:properties>
<context:property-override properties-ref="overrideProps"/>
<bean id="date" class="java.util.Date">
<property name="minutes" value="10"/>
</bean>
</beans>