moving .scripting.* unit tests from .testsuite -> .context
This commit is contained in:
parent
31f5961dce
commit
3e8c013df3
|
@ -29,6 +29,7 @@
|
|||
<classpathentry kind="var" path="IVY_CACHE/org.aspectj/com.springsource.org.aspectj.weaver/1.6.2.RELEASE/com.springsource.org.aspectj.weaver-1.6.2.RELEASE.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/edu.emory.mathcs.backport/com.springsource.edu.emory.mathcs.backport/3.0.0/com.springsource.edu.emory.mathcs.backport-3.0.0.jar" sourcepath="/IVY_CACHE/edu.emory.mathcs.backport/com.springsource.edu.emory.mathcs.backport/3.0.0/com.springsource.edu.emory.mathcs.backport-sources-3.0.0.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/org.easymock/com.springsource.org.easymock/2.3.0/com.springsource.org.easymock-2.3.0.jar" sourcepath="/IVY_CACHE/org.easymock/com.springsource.org.easymock/2.3.0/com.springsource.org.easymock-sources-2.3.0.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/org.antlr/com.springsource.antlr/2.7.6/com.springsource.antlr-2.7.6.jar" sourcepath="/IVY_CACHE/org.antlr/com.springsource.antlr/2.7.6/com.springsource.antlr-sources-2.7.6.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.expression"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -39,6 +39,7 @@
|
|||
<dependency org="javax.persistence" name="com.springsource.javax.persistence" rev="1.0.0" conf="provided, jpa->compile"/>
|
||||
<dependency org="javax.xml.ws" name="com.springsource.javax.xml.ws" rev="2.1.1" conf="provided, ws->compile"/>
|
||||
<dependency org="net.sourceforge.cglib" name="com.springsource.net.sf.cglib" rev="2.1.3" conf="optional, bytecode-proxy->compile"/>
|
||||
<dependency org="org.antlr" name="com.springsource.antlr" rev="2.7.6" conf="test->compile"/>
|
||||
<dependency org="org.aopalliance" name="com.springsource.org.aopalliance" rev="1.0.0" conf="compile->compile"/>
|
||||
<dependency org="org.apache.commons" name="com.springsource.org.apache.commons.logging" rev="1.1.1" conf="compile->compile"/>
|
||||
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="1.5.4" conf="optional, aspectj->compile"/>
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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.aop.framework;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.aop.MethodBeforeAdvice;
|
||||
|
||||
/**
|
||||
* Simple before advice example that we can use for counting checks.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public class CountingBeforeAdvice extends MethodCounter implements MethodBeforeAdvice {
|
||||
|
||||
public void before(Method m, Object[] args, Object target) throws Throwable {
|
||||
count(m);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright 2002-2007 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.aop.framework;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Useful abstract superclass for counting advices etc.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public class MethodCounter implements Serializable {
|
||||
|
||||
/** Method name --> count, does not understand overloading */
|
||||
private HashMap map = new HashMap();
|
||||
|
||||
private int allCount;
|
||||
|
||||
protected void count(Method m) {
|
||||
count(m.getName());
|
||||
}
|
||||
|
||||
protected void count(String methodName) {
|
||||
Integer i = (Integer) map.get(methodName);
|
||||
i = (i != null) ? new Integer(i.intValue() + 1) : new Integer(1);
|
||||
map.put(methodName, i);
|
||||
++allCount;
|
||||
}
|
||||
|
||||
public int getCalls(String methodName) {
|
||||
Integer i = (Integer) map.get(methodName);
|
||||
return (i != null ? i.intValue() : 0);
|
||||
}
|
||||
|
||||
public int getCalls() {
|
||||
return allCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* A bit simplistic: just wants the same class.
|
||||
* Doesn't worry about counts.
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object other) {
|
||||
return (other != null && other.getClass() == this.getClass());
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return getClass().hashCode();
|
||||
}
|
||||
|
||||
}
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.scripting.groovy;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
@ -24,6 +26,7 @@ import groovy.lang.DelegatingMetaClass;
|
|||
import groovy.lang.GroovyObject;
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.aop.target.dynamic.Refreshable;
|
||||
|
@ -42,7 +45,6 @@ import org.springframework.scripting.Messenger;
|
|||
import org.springframework.scripting.ScriptCompilationException;
|
||||
import org.springframework.scripting.ScriptSource;
|
||||
import org.springframework.scripting.support.ScriptFactoryPostProcessor;
|
||||
import org.springframework.test.AssertThrows;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
|
@ -50,9 +52,11 @@ import org.springframework.test.AssertThrows;
|
|||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @author Mark Fisher
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class GroovyScriptFactoryTests extends TestCase {
|
||||
public class GroovyScriptFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testStaticScript() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContext.xml", getClass());
|
||||
|
||||
|
@ -81,6 +85,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticPrototypeScript() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContext.xml", getClass());
|
||||
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
|
||||
|
@ -99,6 +104,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
assertEquals("Byebye World!", messenger2.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticScriptWithInstance() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContext.xml", getClass());
|
||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerInstance"));
|
||||
|
@ -112,6 +118,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticScriptWithInlineDefinedInstance() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContext.xml", getClass());
|
||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerInstanceInline"));
|
||||
|
@ -125,6 +132,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonStaticScript() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyRefreshableContext.xml", getClass());
|
||||
Messenger messenger = (Messenger) ctx.getBean("messenger");
|
||||
|
@ -142,6 +150,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
assertEquals("Incorrect refresh count", 2, refreshable.getRefreshCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonStaticPrototypeScript() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyRefreshableContext.xml", getClass());
|
||||
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
|
||||
|
@ -165,6 +174,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
assertEquals("Incorrect refresh count", 2, refreshable.getRefreshCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScriptCompilationException() throws Exception {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("org/springframework/scripting/groovy/groovyBrokenContext.xml");
|
||||
|
@ -175,6 +185,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScriptedClassThatDoesNotHaveANoArgCtor() throws Exception {
|
||||
MockControl mock = MockControl.createControl(ScriptSource.class);
|
||||
ScriptSource script = (ScriptSource) mock.getMock();
|
||||
|
@ -195,6 +206,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
mock.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScriptedClassThatHasNoPublicNoArgCtor() throws Exception {
|
||||
MockControl mock = MockControl.createControl(ScriptSource.class);
|
||||
ScriptSource script = (ScriptSource) mock.getMock();
|
||||
|
@ -215,6 +227,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
mock.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithTwoClassesDefinedInTheOneGroovyFile_CorrectClassFirst() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("twoClassesCorrectOneFirst.xml", getClass());
|
||||
Messenger messenger = (Messenger) ctx.getBean("messenger");
|
||||
|
@ -225,6 +238,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
GroovyObject goo = (GroovyObject) messenger;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithTwoClassesDefinedInTheOneGroovyFile_WrongClassFirst() throws Exception {
|
||||
try {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("twoClassesWrongOneFirst.xml", getClass());
|
||||
|
@ -236,6 +250,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCtorWithNullScriptSourceLocator() throws Exception {
|
||||
try {
|
||||
new GroovyScriptFactory(null);
|
||||
|
@ -245,6 +260,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCtorWithEmptyScriptSourceLocator() throws Exception {
|
||||
try {
|
||||
new GroovyScriptFactory("");
|
||||
|
@ -254,6 +270,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCtorWithWhitespacedScriptSourceLocator() throws Exception {
|
||||
try {
|
||||
new GroovyScriptFactory("\n ");
|
||||
|
@ -263,6 +280,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithInlineScriptWithLeadingWhitespace() throws Exception {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("lwspBadGroovyContext.xml", getClass());
|
||||
|
@ -273,6 +291,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetScriptedObjectDoesNotChokeOnNullInterfacesBeingPassedIn() throws Exception {
|
||||
MockControl mock = MockControl.createControl(ScriptSource.class);
|
||||
ScriptSource scriptSource = (ScriptSource) mock.getMock();
|
||||
|
@ -288,6 +307,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
mock.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetScriptedObjectDoesChokeOnNullScriptSourceBeingPassedIn() throws Exception {
|
||||
GroovyScriptFactory factory = new GroovyScriptFactory("a script source locator (doesn't matter here)");
|
||||
try {
|
||||
|
@ -298,6 +318,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResourceScriptFromTag() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd.xml", getClass());
|
||||
Messenger messenger = (Messenger) ctx.getBean("messenger");
|
||||
|
@ -313,6 +334,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
assertEquals(-200, countingAspect.getCalls());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeScriptFromTag() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd.xml", getClass());
|
||||
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
|
||||
|
@ -328,6 +350,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
assertEquals("Byebye World!", messenger2.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineScriptFromTag() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd.xml", getClass());
|
||||
Calculator calculator = (Calculator) ctx.getBean("calculator");
|
||||
|
@ -335,6 +358,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
assertFalse(calculator instanceof Refreshable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefreshableFromTag() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd.xml", getClass());
|
||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("refreshableMessenger"));
|
||||
|
@ -351,6 +375,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnonymousScriptDetected() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd.xml", getClass());
|
||||
Map beans = ctx.getBeansOfType(Messenger.class);
|
||||
|
@ -361,6 +386,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
* Tests the SPR-2098 bug whereby no more than 1 property element could be
|
||||
* passed to a scripted bean :(
|
||||
*/
|
||||
@Test
|
||||
public void testCanPassInMoreThanOneProperty() {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-multiple-properties.xml", getClass());
|
||||
TestBean tb = (TestBean) ctx.getBean("testBean");
|
||||
|
@ -385,28 +411,30 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMetaClassWithBeans() {
|
||||
testMetaClass("org/springframework/scripting/groovy/calculators.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMetaClassWithXsd() {
|
||||
testMetaClass("org/springframework/scripting/groovy/calculators-with-xsd.xml");
|
||||
}
|
||||
|
||||
private void testMetaClass(final String xmlFile) {
|
||||
// expect the exception we threw in the custom metaclass to show it got invoked
|
||||
AssertThrows at = new AssertThrows(IllegalStateException.class) {
|
||||
public void test() throws Exception {
|
||||
ApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(xmlFile);
|
||||
Calculator calc = (Calculator) ctx.getBean("delegatingCalculator");
|
||||
calc.add(1, 2);
|
||||
}
|
||||
};
|
||||
at.runTest();
|
||||
assertEquals("Gotcha", at.getActualException().getMessage());
|
||||
try {
|
||||
ApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(xmlFile);
|
||||
Calculator calc = (Calculator) ctx.getBean("delegatingCalculator");
|
||||
calc.add(1, 2);
|
||||
fail("expected IllegalStateException");
|
||||
} catch (IllegalStateException ex) {
|
||||
assertEquals("Gotcha", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFactoryBean() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("groovyContext.xml", getClass());
|
||||
Object factory = context.getBean("&factory");
|
||||
|
@ -416,6 +444,7 @@ public class GroovyScriptFactoryTests extends TestCase {
|
|||
assertEquals("test", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefreshableFactoryBean() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("groovyContext.xml", getClass());
|
||||
Object factory = context.getBean("&refreshableFactory");
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue