|
|
|
@ -1,12 +1,28 @@ |
|
|
|
package org.springframework.scripting.groovy; |
|
|
|
/* |
|
|
|
|
|
|
|
* Copyright 2002-2013 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. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
package org.springframework.scripting.groovy; |
|
|
|
import static org.junit.Assert.fail; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.After; |
|
|
|
import org.junit.After; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.context.support.GenericXmlApplicationContext; |
|
|
|
import org.springframework.context.support.GenericXmlApplicationContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author Dave Syer |
|
|
|
* @author Dave Syer |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -14,18 +30,9 @@ public class GroovyAspectIntegrationTests { |
|
|
|
|
|
|
|
|
|
|
|
private GenericXmlApplicationContext context; |
|
|
|
private GenericXmlApplicationContext context; |
|
|
|
|
|
|
|
|
|
|
|
@After |
|
|
|
|
|
|
|
public void close() { |
|
|
|
|
|
|
|
if (context != null) { |
|
|
|
|
|
|
|
context.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testJavaBean() { |
|
|
|
public void testJavaBean() { |
|
|
|
|
|
|
|
|
|
|
|
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-java-context.xml"); |
|
|
|
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-java-context.xml"); |
|
|
|
|
|
|
|
|
|
|
|
TestService bean = context.getBean("javaBean", TestService.class); |
|
|
|
TestService bean = context.getBean("javaBean", TestService.class); |
|
|
|
LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class); |
|
|
|
LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class); |
|
|
|
|
|
|
|
|
|
|
|
@ -33,8 +40,9 @@ public class GroovyAspectIntegrationTests { |
|
|
|
try { |
|
|
|
try { |
|
|
|
bean.sayHello(); |
|
|
|
bean.sayHello(); |
|
|
|
fail("Expected exception"); |
|
|
|
fail("Expected exception"); |
|
|
|
} catch (RuntimeException e) { |
|
|
|
} |
|
|
|
assertEquals("TestServiceImpl", e.getMessage()); |
|
|
|
catch (RuntimeException ex) { |
|
|
|
|
|
|
|
assertEquals("TestServiceImpl", ex.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
assertEquals(1, logAdvice.getCountThrows()); |
|
|
|
assertEquals(1, logAdvice.getCountThrows()); |
|
|
|
|
|
|
|
|
|
|
|
@ -43,7 +51,6 @@ public class GroovyAspectIntegrationTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGroovyBeanInterface() { |
|
|
|
public void testGroovyBeanInterface() { |
|
|
|
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-groovy-interface-context.xml"); |
|
|
|
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-groovy-interface-context.xml"); |
|
|
|
|
|
|
|
|
|
|
|
TestService bean = context.getBean("groovyBean", TestService.class); |
|
|
|
TestService bean = context.getBean("groovyBean", TestService.class); |
|
|
|
LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class); |
|
|
|
LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class); |
|
|
|
|
|
|
|
|
|
|
|
@ -51,8 +58,9 @@ public class GroovyAspectIntegrationTests { |
|
|
|
try { |
|
|
|
try { |
|
|
|
bean.sayHello(); |
|
|
|
bean.sayHello(); |
|
|
|
fail("Expected exception"); |
|
|
|
fail("Expected exception"); |
|
|
|
} catch (RuntimeException e) { |
|
|
|
} |
|
|
|
assertEquals("GroovyServiceImpl", e.getMessage()); |
|
|
|
catch (RuntimeException ex) { |
|
|
|
|
|
|
|
assertEquals("GroovyServiceImpl", ex.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
assertEquals(1, logAdvice.getCountThrows()); |
|
|
|
assertEquals(1, logAdvice.getCountThrows()); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -60,9 +68,7 @@ public class GroovyAspectIntegrationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGroovyBeanDynamic() { |
|
|
|
public void testGroovyBeanDynamic() { |
|
|
|
|
|
|
|
|
|
|
|
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-groovy-dynamic-context.xml"); |
|
|
|
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-groovy-dynamic-context.xml"); |
|
|
|
|
|
|
|
|
|
|
|
TestService bean = context.getBean("groovyBean", TestService.class); |
|
|
|
TestService bean = context.getBean("groovyBean", TestService.class); |
|
|
|
LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class); |
|
|
|
LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class); |
|
|
|
|
|
|
|
|
|
|
|
@ -70,8 +76,9 @@ public class GroovyAspectIntegrationTests { |
|
|
|
try { |
|
|
|
try { |
|
|
|
bean.sayHello(); |
|
|
|
bean.sayHello(); |
|
|
|
fail("Expected exception"); |
|
|
|
fail("Expected exception"); |
|
|
|
} catch (RuntimeException e) { |
|
|
|
} |
|
|
|
assertEquals("GroovyServiceImpl", e.getMessage()); |
|
|
|
catch (RuntimeException ex) { |
|
|
|
|
|
|
|
assertEquals("GroovyServiceImpl", ex.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
// No proxy here because the pointcut only applies to the concrete class, not the interface
|
|
|
|
// No proxy here because the pointcut only applies to the concrete class, not the interface
|
|
|
|
assertEquals(0, logAdvice.getCountThrows()); |
|
|
|
assertEquals(0, logAdvice.getCountThrows()); |
|
|
|
@ -80,9 +87,7 @@ public class GroovyAspectIntegrationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGroovyBeanProxyTargetClass() { |
|
|
|
public void testGroovyBeanProxyTargetClass() { |
|
|
|
|
|
|
|
|
|
|
|
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-groovy-proxy-target-class-context.xml"); |
|
|
|
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-groovy-proxy-target-class-context.xml"); |
|
|
|
|
|
|
|
|
|
|
|
TestService bean = context.getBean("groovyBean", TestService.class); |
|
|
|
TestService bean = context.getBean("groovyBean", TestService.class); |
|
|
|
LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class); |
|
|
|
LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class); |
|
|
|
|
|
|
|
|
|
|
|
@ -90,11 +95,19 @@ public class GroovyAspectIntegrationTests { |
|
|
|
try { |
|
|
|
try { |
|
|
|
bean.sayHello(); |
|
|
|
bean.sayHello(); |
|
|
|
fail("Expected exception"); |
|
|
|
fail("Expected exception"); |
|
|
|
} catch (TestException e) { |
|
|
|
} |
|
|
|
assertEquals("GroovyServiceImpl", e.getMessage()); |
|
|
|
catch (TestException ex) { |
|
|
|
|
|
|
|
assertEquals("GroovyServiceImpl", ex.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
assertEquals(1, logAdvice.getCountBefore()); |
|
|
|
assertEquals(1, logAdvice.getCountBefore()); |
|
|
|
assertEquals(1, logAdvice.getCountThrows()); |
|
|
|
assertEquals(1, logAdvice.getCountThrows()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@After |
|
|
|
|
|
|
|
public void close() { |
|
|
|
|
|
|
|
if (context != null) { |
|
|
|
|
|
|
|
context.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|