You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2012/06/21 19:28:19 UTC
[7/9] Refactor all the tapestry-ioc Spock specifications into the
ioc.specs package Convert some package-private classes and constructors to
public
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/ServiceProxySpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/ServiceProxySpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/ServiceProxySpec.groovy
deleted file mode 100644
index 9222792..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/ServiceProxySpec.groovy
+++ /dev/null
@@ -1,96 +0,0 @@
-package org.apache.tapestry5.ioc
-
-class ServiceProxySpec extends AbstractRegistrySpecification {
-
- def "shutdown deactivaties proxies"() {
- buildRegistry FredModule, BarneyModule
-
- def fred = getService "Fred", Runnable
-
- fred.run()
-
- shutdown()
-
- when:
-
- fred.run()
-
- then:
-
- RuntimeException ex = thrown()
-
- ex.message.contains "Proxy for service Fred is no longer active because the IOC Registry has been shut down."
-
- fred.toString() == "<Proxy for Fred(java.lang.Runnable)>"
-
- cleanup:
-
- registry = null
- }
-
- def "show that services defined without a implementation are instantiated immediately"() {
- buildRegistry NonProxiedServiceModule
-
- when:
-
- def holder = getService StringHolder
-
- then:
-
- holder instanceof StringHolderImpl // and not some proxy
- }
-
- def "service builder methods with a class (not interface) return type are not proxied, but are cached"() {
-
- buildRegistry ConcreteServiceBuilderModule
-
- when:
-
- def h1 = getService StringHolder
-
- then: "not proxied"
-
- h1 instanceof StringHolderImpl
-
- when:
-
- def h2 = getService StringHolder
-
- then: "cached"
-
- h2.is h1
- }
-
- def "verify that a proxy for an autobuilt object lazily instantiates the implementation"() {
-
- buildRegistry()
-
- expect:
- IntegrationTestFixture.countingGreeterInstantiationCount == 0
-
- when: "obtaining the proxy"
-
- def g = proxy Greeter, CountingGreeterImpl
-
- then: "the implementation is not yet instantiated"
-
- IntegrationTestFixture.countingGreeterInstantiationCount == 0
-
- when: "invoking toString() on the proxy"
-
- assert g.toString() == "<Autoreload proxy org.apache.tapestry5.ioc.CountingGreeterImpl(org.apache.tapestry5.ioc.Greeter)>"
-
- then: "the implementation is not yet instantiated"
-
- IntegrationTestFixture.countingGreeterInstantiationCount == 0
-
- when: "invoking other methods on the proxy"
-
- assert g.greeting == "Hello"
-
- then: "the implementation is now instantiated"
-
- IntegrationTestFixture.countingGreeterInstantiationCount == 1
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ContributionDefImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ContributionDefImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ContributionDefImplSpec.groovy
deleted file mode 100644
index 84aee7c..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ContributionDefImplSpec.groovy
+++ /dev/null
@@ -1,208 +0,0 @@
-package org.apache.tapestry5.ioc.internal
-
-import org.apache.tapestry5.ioc.annotations.InjectService
-import org.slf4j.Logger
-import spock.lang.Shared
-import spock.lang.Specification
-
-import java.lang.reflect.Method
-import javax.inject.Named
-
-import org.apache.tapestry5.ioc.*
-
-class ModuleFixture {
-
- void contributeUnordered(Configuration configuration) {
- configuration.add(ContributionDefImplSpec.toContribute);
- }
-
- void contributeUnorderedInjectedService(Configuration<UpcaseService> configuration,
- @InjectService("Zap")
- UpcaseService service) {
- configuration.add(service);
- }
-
- void contributeUnorderedParameterNamedService(Configuration<UpcaseService> configuration,
- @Named("Zap")
- UpcaseService service) {
- configuration.add(service);
- }
-
- void contributeUnorderedWrongParameter(MappedConfiguration configuration) {
- throw new IllegalStateException("Unreachable.")
- }
-
- void contributeOrderedParameterInjectedService(OrderedConfiguration<UpcaseService> configuration,
- @InjectService("Zap")
- UpcaseService service)
- {
- configuration.add("fred", service);
- }
-
- void contributeMappedParameterInjectedService(MappedConfiguration<String, UpcaseService> configuration,
- @InjectService("Zap")
- UpcaseService service)
- {
- configuration.add("upcase", service);
- }
-}
-
-
-class ContributionDefImplSpec extends Specification {
-
- static Object toContribute
-
- @Shared
- OperationTracker tracker = new QuietOperationTracker()
-
- ServiceResources resources = Mock()
- Logger logger = Mock()
-
- @Shared
- ModuleBuilderSource source = new ModuleBuilderSource() {
-
- @Override
- Object getModuleBuilder() {
- return new ModuleFixture()
- }
- }
-
- private Method findMethod(name) {
- return ModuleFixture.methods.find { it.name == name }
- }
-
- def createContributionDef(methodName) {
- return new ContributionDefImpl("Foo", findMethod(methodName), false, null, null, null)
- }
-
- def "contribute to an unordered collection"() {
-
- Configuration configuration = Mock()
-
- toContribute = new Object()
-
- def cd = createContributionDef "contributeUnordered"
-
- when:
-
- cd.contribute(source, resources, configuration)
-
- then:
-
- 1 * resources.logger >> logger
- _ * resources.serviceId >> "Foo"
- 1 * configuration.add(toContribute)
- _ * resources.tracker >> tracker
-
- 0 * _
- }
-
- def "unordered configuration injects and contributes a service via @InjectService"() {
-
- Configuration configuration = Mock()
- UpcaseService service = Mock()
-
- def cd = createContributionDef "contributeUnorderedInjectedService"
-
- when:
-
- cd.contribute(source, resources, configuration)
-
- then:
-
- 1 * resources.getService("Zap", UpcaseService) >> service
-
- 1 * resources.logger >> logger
- _ * resources.serviceId >> "Foo"
- 1 * configuration.add(service)
- _ * resources.tracker >> tracker
-
- 0 * _
- }
-
- def "unordered configuration injects and contributes a service via @Named"() {
- Configuration configuration = Mock()
- UpcaseService service = Mock()
-
- def cd = createContributionDef "contributeUnorderedParameterNamedService"
-
- when:
-
- cd.contribute(source, resources, configuration)
-
- then:
-
- 1 * resources.getService("Zap", UpcaseService) >> service
-
- 1 * resources.logger >> logger
- _ * resources.serviceId >> "Foo"
- 1 * configuration.add(service)
- _ * resources.tracker >> tracker
-
- }
-
- def "contribution method configuration parameter must be correct type"() {
- Configuration configuration = Mock()
-
- def cd = createContributionDef "contributeUnorderedWrongParameter"
-
- when:
-
- cd.contribute(source, resources, configuration)
-
- then:
-
- _ * resources.logger >> logger
- _ * resources.serviceId >> "Foo"
- _ * resources.tracker >> tracker
-
- RuntimeException e = thrown()
-
- e.message.contains "Service 'Foo' is configured using org.apache.tapestry5.ioc.Configuration, not org.apache.tapestry5.ioc.MappedConfiguration."
- }
-
- def "ordered configuration injects and contributes a service via @InjectService"() {
-
- OrderedConfiguration configuration= Mock()
- UpcaseService service = Mock()
-
- def cd = createContributionDef "contributeOrderedParameterInjectedService"
-
- when:
-
- cd.contribute(source, resources, configuration)
-
- then:
-
- 1 * configuration.add("fred", service)
-
- _ * resources.getService("Zap", UpcaseService) >> service
-
- _ * resources.logger >> logger
- _ * resources.serviceId >> "Foo"
- _ * resources.tracker >> tracker
- }
-
- def "mapped configuration injects and contributes a service via @InjectService"() {
- MappedConfiguration configuration= Mock()
- UpcaseService service = Mock()
-
- def cd = createContributionDef "contributeMappedParameterInjectedService"
-
- when:
-
- cd.contribute(source, resources, configuration)
-
- then:
-
- 1 * configuration.add("upcase", service)
-
- _ * resources.getService("Zap", UpcaseService) >> service
-
- _ * resources.logger >> logger
- _ * resources.serviceId >> "Foo"
- _ * resources.tracker >> tracker
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/DefaultModuleDefImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/DefaultModuleDefImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/DefaultModuleDefImplSpec.groovy
deleted file mode 100644
index c79ad3a..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/DefaultModuleDefImplSpec.groovy
+++ /dev/null
@@ -1,449 +0,0 @@
-package org.apache.tapestry5.ioc.internal
-
-import org.apache.tapestry5.internal.plastic.PlasticClassLoader
-import org.apache.tapestry5.internal.plastic.PlasticInternalUtils
-import org.apache.tapestry5.internal.plastic.asm.ClassWriter
-import org.apache.tapestry5.ioc.def.ServiceDef3
-import org.apache.tapestry5.ioc.internal.services.PlasticProxyFactoryImpl
-import org.apache.tapestry5.ioc.services.PlasticProxyFactory
-import org.slf4j.Logger
-import spock.lang.Shared
-import spock.lang.Specification
-import spock.lang.Unroll
-import org.apache.tapestry5.ioc.*
-
-import static org.apache.tapestry5.internal.plastic.asm.Opcodes.*
-
-class DefaultModuleDefImplSpec extends Specification {
-
- @Shared
- PlasticProxyFactory proxyFactory = new PlasticProxyFactoryImpl(Thread.currentThread().contextClassLoader, null)
-
- @Shared
- OperationTracker tracker = new QuietOperationTracker()
-
- Logger logger = Mock()
-
- def "toString() of module lists services in the module"() {
- when:
-
- def md = module SimpleModule
-
- then:
-
- md.toString() == "ModuleDef[$SimpleModule.name Barney, Fred, Wilma]"
- }
-
- def "serviceIds contains all service ids"() {
- def md = module SimpleModule
-
- expect:
-
- md.serviceIds == ["Fred", "Barney", "Wilma"] as Set
- }
-
- def "ServiceDef obtainable by service id"() {
- def md = module SimpleModule
-
- when:
-
- def sd = md.getServiceDef "fred"
-
- then:
-
- sd.serviceId == "Fred"
- sd.serviceInterface == FieService
- sd.toString().contains "${SimpleModule.name}.buildFred()"
- sd.serviceScope == ScopeConstants.DEFAULT
- !sd.eagerLoad
- sd.markers.empty
-
- when:
-
- sd = md.getServiceDef("Wilma")
-
- then:
-
- sd.eagerLoad
- }
-
- def "ModuleDef exposes decorator methods as DecoratorDefs"() {
- def md = module SimpleModule
-
- when:
-
- def decos = md.decoratorDefs
-
- then:
-
- decos.size() == 1
-
- def deco = decos.find()
-
- deco.decoratorId == "Logging"
- deco.toString().contains "${SimpleModule.name}.decorateLogging(Class, Object)"
- }
-
- def "@ServiceId annotation on service builder method overrides naming convention"() {
- when:
-
- def md = module ServiceIdViaAnnotationModule
-
- then:
-
- md.getServiceDef("FooService") != null
- }
-
- def "@ServiceId on implementation class overrides default id from ServiceBinder.bind() default"() {
- when:
-
- def md = module ServiceIdViaAnnotationModule
-
- then:
-
- md.getServiceDef("BarneyService") != null
- }
-
- def "@Named annotation on service builder method overrides naming convention"() {
- when:
-
- def md = module NamedServiceModule
-
- then:
-
- md.getServiceDef("BazService") != null
- }
-
- def "@Named annotation on service implementation class overrides ServiceBinder.bind() default"() {
- when:
-
- def md = module NamedServiceModule
-
- then:
-
- md.getServiceDef("QuuxService") != null
- }
-
- def "naming convention for a service builder method named build() is derived from the return type"() {
- when:
-
- def md = module DefaultServiceIdModule
-
- then:
-
- md.getServiceDef("FieService") != null
- }
-
- def "conflicting service ids result in an exception"() {
- when:
-
- module ServiceIdConflictMethodModule
-
- then:
-
- RuntimeException ex = thrown()
-
- ex.message.contains "Service Fred (defined by ${ServiceIdConflictMethodModule.name}.buildFred()"
- ex.message.contains "conflicts with previously defined service defined by ${ServiceIdConflictMethodModule.name}.buildFred(Object)"
- }
-
- def "a service builder method may not return void"() {
- when:
-
- module VoidBuilderMethodModule
-
- then:
-
- RuntimeException ex = thrown()
-
- ex.message.contains "${VoidBuilderMethodModule.name}.buildNull()"
- ex.message.contains "but the return type (void) is not acceptable"
- }
-
- def "a service builder method may not return an array"() {
- when:
-
- module BuilderMethodModule
-
- then:
-
- RuntimeException ex = thrown()
-
- ex.message.contains "${BuilderMethodModule.name}.buildStringArray()"
- ex.message.contains "but the return type (java.lang.String[])"
- }
-
- @Unroll
- def "A decorator method #desc"() {
- when:
-
- module moduleClass
-
- then:
-
- RuntimeException e = thrown()
-
- e.message.contains expectedText
-
- where:
-
- moduleClass | expectedText | desc
- PrimitiveDecoratorMethodModule | "decoratePrimitive" | "may not return a primitive type"
- ArrayDecoratorMethodModule | "decorateArray" | "may not return an array"
- }
-
- @Unroll
- def "#desc"() {
- when:
-
- def md = module moduleClass
-
- then:
-
- def defs = md.contributionDefs
-
- defs.size() == 1
-
- def cd = defs.find()
-
- cd.serviceId == serviceId
-
- cd.toString().contains "${moduleClass.name}.$methodSignature"
-
- where:
-
- moduleClass | serviceId | methodSignature | desc
- SimpleModule | "Barney" | "contributeBarney(Configuration)" | "contribution without annotation to configuration"
- OrderedConfigurationModule | "Ordered" | "contributeOrdered(OrderedConfiguration)" | "contribution to ordered configuration"
- MappedConfigurationModule | "Mapped" | "contributeMapped(MappedConfiguration)" | "contribution to mapped configuration"
- }
-
- @Unroll
- def "service contribution method that #desc throws an exception"() {
-
- when:
-
- module moduleClass
-
- then:
-
- RuntimeException e = thrown()
-
- e.message.contains message
-
- where:
-
- moduleClass | message | desc
-
- NoUsableContributionParameterModule | "does not contain a parameter of type Configuration, OrderedConfiguration or MappedConfiguration" | "does not include configuration parameter"
- TooManyContributionParametersModule | "contains more than one parameter of type Configuration, OrderedConfiguration, or MappedConfiguration" | "includes more than one configuration parameter"
- }
-
- def "using defaults for ServiceBinder.bind()"() {
-
- when:
-
- def md = module AutobuildModule
- ServiceDef3 sd = md.getServiceDef "stringholder"
-
- then:
-
- sd.serviceInterface == StringHolder
- sd.serviceId == "StringHolder"
- sd.serviceScope == ScopeConstants.DEFAULT
- !sd.isEagerLoad()
- sd.markers.empty
- !sd.preventDecoration
- }
-
- def "overriding defaults for ServiceBinder.bind()"() {
-
- when:
-
- def md = module ComplexAutobuildModule
- ServiceDef3 sd = md.getServiceDef "sh"
-
- then:
-
- sd.serviceInterface == StringHolder
- sd.serviceId == "SH"
- sd.serviceScope == "magic"
- sd.eagerLoad
- sd.preventDecoration
- }
-
- def "implementation class for ServiceBinder.bind() must have a public constructor"() {
- when:
-
- module UninstantiableAutobuildServiceModule
-
- then:
-
- RuntimeException e = thrown()
-
- e.message.contains "Class org.apache.tapestry5.ioc.internal.RunnableServiceImpl (implementation of service 'Runnable') does not contain any public constructors."
- }
-
- def "the bind() method of a module class must be a static method"() {
- when:
-
- module NonStaticBindMethodModule
-
- then:
-
- RuntimeException e = thrown()
-
- e.message.contains "Method org.apache.tapestry5.ioc.internal.NonStaticBindMethodModule.bind(ServiceBinder)"
- e.message.contains "appears to be a service binder method, but is an instance method, not a static method"
- }
-
- def "when autobuilding a service implementation, the constructor with the most parameters is chosen"() {
- ServiceBuilderResources resources = Mock()
-
- when:
-
- def md = module MutlipleAutobuildServiceConstructorsModule
-
- def sd = md.getServiceDef "stringholder"
-
- then:
-
- sd != null
-
- 0 * _
-
- when:
-
- def oc = sd.createServiceCreator(resources)
- def holder = oc.createObject()
-
- holder.value = "foo"
-
- then:
-
- holder instanceof StringHolder
- holder.value == "FOO"
-
- _ * resources.serviceId >> "StringHolder"
- _ * resources.logger >> logger
- _ * resources.serviceInterface >> StringHolder
- 1 * resources.getService("ToUpperCaseStringHolder", StringHolder) >> new ToUpperCaseStringHolder()
- _ * resources.tracker >> tracker
-
- 1 * logger.debug(_) >> { args ->
- assert args[0].contains(
- "Invoking constructor org.apache.tapestry5.ioc.internal.MultipleConstructorsAutobuildService(StringHolder)")
- }
-
- 0 * _
- }
-
- def "an exception inside a bind() method bubbles up"() {
- when:
-
- module ExceptionInBindMethod
-
- then:
-
- RuntimeException e = thrown()
-
- e.message.contains "Error invoking service binder method org.apache.tapestry5.ioc.internal.ExceptionInBindMethod.bind(ServiceBinder)"
- e.message.contains "at ExceptionInBindMethod.java"
- e.message.contains "Really, how often is this going to happen?"
- }
-
- def "@EagerLoad annotation on service implementation class is reflected in the ServiceDef"() {
- when:
-
- def md = module EagerLoadViaAnnotationModule
- def sd = md.getServiceDef "runnable"
-
- then:
-
- sd.eagerLoad
- }
-
- private DefaultModuleDefImpl module(moduleClass) {
- new DefaultModuleDefImpl(moduleClass, logger, proxyFactory)
- }
-
- def "marker annotations on the service builder method are available in the ServiceDef"() {
-
- when:
-
- def md = module MarkerModule
- def sd = md.getServiceDef "greeter"
-
- then:
-
- sd.markers == [BlueMarker] as Set
- }
-
- def "marker annotations specified via ServiceBinder is available in the ServiceDef"() {
- when:
-
- def md = module MarkerModule
- def sd = md.getServiceDef "redgreeter"
-
- then:
-
- sd.markers == [RedMarker] as Set
- }
-
- def "marker annotation on the implementation class is available in the ServiceDef"() {
- when:
-
- def md = module MarkerModule
- def sd = md.getServiceDef "SecondRedGreeter"
-
- then:
-
- sd.markers == [RedMarker] as Set
- }
-
- def "marker annotation from ServiceBinder and implementation class are merged"() {
- when:
-
- def md = module MarkerModule
- def sd = md.getServiceDef "SurprisinglyBlueGreeter"
-
- then:
-
- sd.markers == [RedMarker, BlueMarker] as Set
- }
-
- def "public synthetic methods on module class are ignored"() {
- def moduleClass = createSyntheticModuleClass()
-
- when:
-
- def md = module moduleClass
-
- then:
-
- md.serviceIds.size() == 1
- }
-
- private createSyntheticModuleClass() {
-
- def cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES)
-
- cw.visit(V1_5, ACC_PUBLIC, "EnhancedSyntheticMethodModule", null,
- PlasticInternalUtils.toInternalName(SyntheticMethodModule.name), null);
-
- def mv = cw.visitMethod ACC_PUBLIC | ACC_STATIC | ACC_SYNTHETIC, "synth", "()V", null, null
- mv.visitCode()
- mv.visitInsn RETURN
- mv.visitEnd()
-
- cw.visitEnd()
-
- def bytecode = cw.toByteArray()
-
- ClassLoader loader = Thread.currentThread().contextClassLoader
-
- PlasticClassLoader plasticLoader = new PlasticClassLoader(loader, new NoopClassLoaderDelegate())
-
- return plasticLoader.defineClassWithBytecode("EnhancedSyntheticMethodModule", bytecode)
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/GlobPatternMatcherSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/GlobPatternMatcherSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/GlobPatternMatcherSpec.groovy
deleted file mode 100644
index d2d368a..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/GlobPatternMatcherSpec.groovy
+++ /dev/null
@@ -1,63 +0,0 @@
-package org.apache.tapestry5.ioc.internal
-
-import spock.lang.Specification
-import spock.lang.Unroll
-
-
-@Unroll
-class GlobPatternMatcherSpec extends Specification {
-
- def "input '#input' matches pattern '#pattern'"() {
-
- def matcher = new GlobPatternMatcher(pattern)
-
- expect:
-
- matcher.matches(input)
-
- where:
-
- input | pattern
- "fred" | "fred"
- "fred" | "FRED"
- "fred" | "*"
- "" | "*"
- "fred.Barney" | "*Barney"
- "fred.Barney" | "*BARNEY"
- "fred.Barney" | "fred*"
- "fred.Barney" | "FRED*"
- "fredBarney" | "*dB*"
- "fredBarney" | "*DB*"
- "fred.Barney" | "*Barney*"
- "fred.Barney" | "*fred*"
- "fred.Barney" | "*FRED*"
- "MyEntityDAO" | ".*dao"
- "FredDAO" | "(fred|barney)dao"
- }
-
- def "input '#input' does not match pattern '#pattern'"() {
-
- def matcher = new GlobPatternMatcher(pattern)
-
- expect:
-
- ! matcher.matches(input)
-
- where:
-
- input | pattern
- "xfred" | "fred"
- "fredx" | "fred"
- "fred" | "xfred"
- "fred" | "fredx"
- "fred.Barneyx" | "*Barney"
- "fred.Barney" | "*Barneyx"
- "fred.Barney" | "*xBarney"
- "xfred.Barney" | "fred*"
- "fred.Barney" | "fredx*"
- "fred.Barney" | "xfred*"
- "fred.Barney" | "*flint*"
- "MyEntityDAL" | ".*dao"
- "WilmaDAO" | "(fred|barney)dao"
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/LazyAdvisorImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/LazyAdvisorImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/LazyAdvisorImplSpec.groovy
deleted file mode 100644
index d68d845..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/LazyAdvisorImplSpec.groovy
+++ /dev/null
@@ -1,141 +0,0 @@
-package org.apache.tapestry5.ioc.internal
-
-import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
-import org.apache.tapestry5.ioc.Greeter
-import org.apache.tapestry5.ioc.annotations.NotLazy
-import org.apache.tapestry5.ioc.services.AspectDecorator
-import org.apache.tapestry5.ioc.services.LazyAdvisor
-
-import java.sql.SQLException
-
-public interface LazyService {
-
- void notLazyBecauseVoid();
-
- String notLazyBecauseOfReturnValue();
-
- /**
- * The only lazy method.
- */
- Greeter createGreeter() throws RuntimeException;
-
- Greeter safeCreateCreator();
-
- @NotLazy
- Greeter notLazyFromAnnotationGreeter();
-
- Greeter notLazyCreateGreeter() throws SQLException;
-}
-
-class LazyAdvisorImplSpec extends AbstractSharedRegistrySpecification {
-
- def LazyService advise(LazyService base) {
- def decorator = getService AspectDecorator
- def advisor = getService LazyAdvisor
-
- def builder = decorator.createBuilder LazyService, base, "<LazyService Proxy>"
-
-
- advisor.addLazyMethodInvocationAdvice builder
-
- builder.build()
- }
-
- LazyService service = Mock()
- LazyService advised = advise service
-
- def "void methods are not lazy"() {
-
- when:
-
- advised.notLazyBecauseVoid()
-
- then:
-
- service.notLazyBecauseVoid()
- }
-
- def "methods with a non-interface return type are not lazy"() {
-
- when:
-
- assert advised.notLazyBecauseOfReturnValue() == "so true"
-
- then:
-
- 1 * service.notLazyBecauseOfReturnValue() >> "so true"
- }
-
- def "returned thunks cache the return value"() {
-
- Greeter greeter = Mock()
-
- when:
-
- def thunk = advised.createGreeter()
-
- then:
-
- 0 * _
-
- when:
-
- assert thunk.greeting == "Lazy!"
-
- then:
-
- 1 * service.createGreeter() >> greeter
- 1 * greeter.greeting >> "Lazy!"
- 0 * _
-
- when:
-
- assert thunk.greeting == "Still Lazy!"
-
- then: "the greeter instance is cached"
-
- 1 * greeter.greeting >> "Still Lazy!"
- 0 * _
- }
-
- def "a checked exception will prevent laziness"() {
-
- Greeter greeter = Mock()
-
- when:
-
- assert advised.notLazyCreateGreeter().is(greeter)
-
- then:
-
- 1 * service.notLazyCreateGreeter() >> greeter
- 0 * _
- }
-
- def "the @NotLazy annotation prevents laziness"() {
-
- Greeter greeter = Mock()
-
- when:
-
- assert advised.notLazyFromAnnotationGreeter().is(greeter)
-
- then:
-
- 1 * service.notLazyFromAnnotationGreeter() >> greeter
- 0 * _
- }
-
- def "thunk class is cached"() {
-
- when:
-
- def g1 = advised.createGreeter()
- def g2 = advised.safeCreateCreator()
-
- then:
-
- g1.class == g2.class
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/LoggingDecoratorImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/LoggingDecoratorImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/LoggingDecoratorImplSpec.groovy
deleted file mode 100644
index 2d77d9a..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/LoggingDecoratorImplSpec.groovy
+++ /dev/null
@@ -1,172 +0,0 @@
-package org.apache.tapestry5.ioc.internal
-
-import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
-import org.apache.tapestry5.ioc.services.LoggingDecorator
-import org.slf4j.Logger
-import org.xml.sax.SAXParseException
-
-interface AdderService {
-
- long add(long operand1, long operand2);
-}
-
-interface ExceptionService {
-
- void parse() throws SAXParseException;
-}
-
-class LoggingDecoratorImplSpec extends AbstractSharedRegistrySpecification {
-
- LoggingDecorator decorator = getService LoggingDecorator
-
- Logger logger = Mock()
-
- def "logging of void method"() {
-
- _ * logger.debugEnabled >> true
-
- Runnable delegate = Mock()
-
- Runnable interceptor = decorator.build(Runnable, delegate, "foo.Bar", logger)
-
- when:
-
- interceptor.run()
-
- then:
-
- 1 * logger.debug("[ENTER] run()")
-
- then:
-
- 1 * delegate.run()
-
- then:
-
- 1 * logger.debug("[ EXIT] run")
-
- interceptor.toString() == "<Logging interceptor for foo.Bar(java.lang.Runnable)>"
- }
-
- def "runtime exception inside method is logged"() {
- _ * logger.debugEnabled >> true
-
- Runnable delegate = Mock()
-
- Runnable interceptor = decorator.build(Runnable, delegate, "foo.Bar", logger)
-
- def t = new RuntimeException("From delegate.")
-
- when:
-
- interceptor.run()
-
- then:
-
- 1 * logger.debug("[ENTER] run()")
-
- then:
-
- 1 * delegate.run() >> {
- throw t
- }
-
- then:
-
- 1 * logger.debug("[ FAIL] run -- ${RuntimeException.name}", t)
-
- then:
-
- RuntimeException e = thrown()
-
- e.is t
- }
-
- def "method throws checked exception"() {
- Throwable t = new SAXParseException("From delegate.", null)
- _ * logger.debugEnabled >> true
- ExceptionService delegate = Mock()
-
- ExceptionService service = decorator.build(ExceptionService, delegate, "MyService", logger)
-
- when:
-
- service.parse()
-
- then:
-
- Throwable actual = thrown()
-
- actual.is(t)
-
- 1 * logger.debug("[ENTER] parse()")
-
- 1 * delegate.parse() >> { throw t }
-
- 1 * logger.debug("[ FAIL] parse -- ${SAXParseException.name}", t)
- }
-
- def "handling of object parameter and return type"() {
- _ * logger.debugEnabled >> true
-
- UpcaseService delegate = Mock()
-
- UpcaseService service = decorator.build(UpcaseService, delegate, "MyService", logger)
-
- when:
-
- assert service.upcase("barney") == "BARNEY"
-
- then:
-
- 1 * logger.debug('[ENTER] upcase("barney")')
-
- 1 * delegate.upcase(_) >> { args -> args[0].toUpperCase() }
-
- 1 * logger.debug('[ EXIT] upcase ["BARNEY"]')
- }
-
- def "handling of primitive parameter and return type"() {
- _ * logger.debugEnabled >> true
-
- AdderService delegate = Mock()
-
- AdderService service = decorator.build(AdderService, delegate, "Adder", logger)
-
- when:
-
- assert service.add(6, 13) == 19
-
- then:
-
- 1 * logger.debug("[ENTER] add(6, 13)")
-
- 1 * delegate.add(_, _) >> { args -> args[0] + args[1] }
-
- 1 * logger.debug("[ EXIT] add [19]")
- }
-
- def "toString() method of service interface is delegated"() {
- _ * logger.debugEnabled >> true
-
- // Spock's Mocking doesn't seem to be as savvy as Tapestry's about letting toString()
- // delegate through, so we can't implement ToStringService as a Mock
-
- ToStringService delegate = new ToStringService() {
-
- String toString() { "FROM DELEGATE" }
- }
-
- ToStringService service = decorator.build(ToStringService, delegate, "ToString", logger)
-
- when:
-
- assert service.toString() == "FROM DELEGATE"
-
- then:
-
- 1 * logger.debug("[ENTER] toString()")
- 1 * logger.debug('[ EXIT] toString ["FROM DELEGATE"]')
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/LoggingSourceImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/LoggingSourceImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/LoggingSourceImplSpec.groovy
deleted file mode 100644
index 3601124..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/LoggingSourceImplSpec.groovy
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.apache.tapestry5.ioc.internal
-
-import org.apache.tapestry5.ioc.LoggerSource
-import org.slf4j.LoggerFactory
-import spock.lang.Specification
-
-class LoggingSourceImplSpec extends Specification {
-
- LoggerSource loggerSource = new LoggerSourceImpl()
-
- def "get logger by class"() {
- Class clazz = getClass()
-
- expect:
-
- loggerSource.getLogger(clazz).is(LoggerFactory.getLogger(clazz))
- }
-
- def "get logger by name"() {
- String name = "foo.Bar"
-
- expect:
-
- loggerSource.getLogger(name).is(LoggerFactory.getLogger(name))
-
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ModuleImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ModuleImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ModuleImplSpec.groovy
deleted file mode 100644
index 169eafe..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ModuleImplSpec.groovy
+++ /dev/null
@@ -1,280 +0,0 @@
-package org.apache.tapestry5.ioc.internal
-
-import org.apache.tapestry5.ioc.AdvisorDef2
-import org.apache.tapestry5.ioc.BlueMarker
-import org.apache.tapestry5.ioc.RedMarker
-import org.apache.tapestry5.ioc.services.PlasticProxyFactory
-import org.slf4j.Logger
-import spock.lang.Specification
-import org.apache.tapestry5.ioc.def.*
-
-class ModuleImplSpec extends Specification {
-
- Logger logger = Mock()
- InternalRegistry registry = Mock()
- PlasticProxyFactory proxyFactory = Mock()
- ServiceActivityTracker tracker = Mock()
-
- def "findServiceIdsForInterface() test"() {
-
- ModuleDef md = new DefaultModuleDefImpl(ModuleImplTestModule, logger, proxyFactory)
-
- when:
-
- Module module = new ModuleImpl(registry, tracker, md, proxyFactory, logger)
-
- def serviceIds = module.findServiceIdsForInterface(FieService)
-
- then:
-
- serviceIds.size() == 2
- serviceIds.containsAll(["Fie", "OtherFie"])
- }
-
- def "findMatchingDecoratorDefs() with exact DecoratorDef match"() {
- ServiceDef sd = Mock()
- DecoratorDef2 def1 = Mock()
- DecoratorDef def2 = Mock()
- ModuleDef md = Mock()
-
- def decoratorDefs = [def1, def2] as Set
-
- when:
-
- Module module = new ModuleImpl(registry, tracker, md, proxyFactory, logger)
-
- then:
-
- 1 * md.serviceIds >> Collections.EMPTY_SET
-
- when:
-
- def matches = module.findMatchingDecoratorDefs(sd)
-
- then:
-
- matches.size() == 1
- matches.contains def2
-
- 1 * md.decoratorDefs >> decoratorDefs
-
- 1 * sd.serviceInterface >> Runnable
-
- 1 * def1.matches(sd) >> false
-
- // Maybe not a complete match, so does it match by type & markers?
- 1 * def1.serviceInterface >> ToStringService
-
- // An exact match
- 1 * def2.matches(sd) >> true
-
- 0 * _
- }
-
- def "findDecoratorDefs() with matching service but non-matching marker annotations"() {
- ServiceDef sd = Mock()
- DecoratorDef2 def1 = Mock()
- DecoratorDef def2 = Mock()
- ModuleDef md = Mock()
-
- def decoratorDefs = [def1, def2] as Set
- def def1markers = [BlueMarker] as Set
- def sdmarkers = [RedMarker] as Set
- def registrymarkers = [RedMarker, BlueMarker] as Set
-
- when:
-
- Module module = new ModuleImpl(registry, tracker, md, proxyFactory, logger)
-
- then:
-
- 1 * md.serviceIds >> Collections.EMPTY_SET
-
- when:
-
- def matches = module.findMatchingDecoratorDefs(sd)
-
- then:
-
- matches.size() == 1
- matches.contains def2
-
- 1 * md.decoratorDefs >> decoratorDefs
-
- 1 * def1.matches(sd) >> false
- 1 * def1.serviceInterface >> Object
- _ * sd.serviceInterface >> Runnable
- 1 * def1.markers >> def1markers
- 1 * sd.markers >> sdmarkers
-
- 1 * def2.matches(sd) >> true
-
- 1 * registry.markerAnnotations >> registrymarkers
-
- 0 * _
- }
-
- def "findMatchingServiceAdvisors() where the advise is for a different interface than the service"() {
- AdvisorDef2 def1 = Mock()
- AdvisorDef2 def2 = Mock()
- ModuleDef2 md = Mock()
- ServiceDef sd = Mock()
-
- def advisors = [def1, def2] as Set
-
- when:
-
- Module module = new ModuleImpl(registry, tracker, md, proxyFactory, logger)
-
- then:
-
- 1 * md.serviceIds >> Collections.EMPTY_SET
-
- when:
-
- def matches = module.findMatchingServiceAdvisors(sd)
-
- then:
-
- matches.size() == 1
- matches.contains def2
-
- 1 * md.advisorDefs >> advisors
-
- 1 * def1.matches(sd) >> false
- 1 * def1.serviceInterface >> ToStringService
-
- 1 * sd.serviceInterface >> Runnable
-
- 1 * def2.matches(sd) >> true
-
- 0 * _
- }
-
- def "findMatchingServiceAdvisors() where the advice is for a matching service type but non-matching marker annotations"() {
- AdvisorDef2 def1 = Mock()
- AdvisorDef2 def2 = Mock()
- ModuleDef2 md = Mock()
- ServiceDef sd = Mock()
-
- def advisors = [def1, def2] as Set
- def def1markers = [BlueMarker] as Set
- def registrymarkers = [BlueMarker, RedMarker] as Set
- def servicemarkers = [RedMarker] as Set
-
- when:
-
- Module module = new ModuleImpl(registry, tracker, md, proxyFactory, logger)
-
- then:
-
- 1 * md.serviceIds >> Collections.EMPTY_SET
-
- when:
-
- def matches = module.findMatchingServiceAdvisors(sd)
-
- then:
-
- matches.size() == 1
- matches.contains def2
-
- 1 * registry.markerAnnotations >> registrymarkers
-
- 1 * md.advisorDefs >> advisors
-
- 1 * def1.matches(sd) >> false
- 1 * def1.serviceInterface >> Object
-
- 1 * sd.serviceInterface >> Runnable
- 1 * sd.markers >> servicemarkers
-
- 1 * def1.markers >> def1markers
-
- 1 * def2.matches(sd) >> true
-
- 0 * _
- }
-
- def "findMatchingServiceAdvisors() match on type and marker annotations"()
- {
- AdvisorDef2 ad = Mock()
- ModuleDef2 md = Mock()
- ServiceDef sd = Mock()
-
- def advisors = [ad] as Set
- def admarkers = [RedMarker] as Set
- def registrymarkers = [BlueMarker, RedMarker] as Set
- def servicemarkers = [RedMarker] as Set
-
- when:
-
- Module module = new ModuleImpl(registry, tracker, md, proxyFactory, logger)
-
- then:
-
- 1 * md.serviceIds >> Collections.EMPTY_SET
-
- when:
-
- def matches = module.findMatchingServiceAdvisors(sd)
-
- then:
-
- matches.size() == 1
- matches.contains ad
-
- 1 * registry.markerAnnotations >> registrymarkers
-
- 1 * md.advisorDefs >> advisors
-
- 1 * ad.matches(sd) >> false
- 1 * ad.serviceInterface >> Object
-
- 1 * sd.serviceInterface >> Runnable
- 1 * sd.markers >> servicemarkers
-
- 1 * ad.markers >> admarkers
-
- 0 * _
- }
-
-
- def "findMatchingServiceAdvisors() where there are no marker annotations at all"() {
- AdvisorDef2 ad = Mock()
- ModuleDef2 md = Mock()
- ServiceDef sd = Mock()
-
- def advisors = [ad] as Set
-
- when:
-
- Module module = new ModuleImpl(registry, tracker, md, proxyFactory, logger)
-
- then:
-
- 1 * md.serviceIds >> Collections.EMPTY_SET
-
- when:
-
- def matches = module.findMatchingServiceAdvisors(sd)
-
- then:
-
- matches.size() == 0
-
- 1 * registry.markerAnnotations >> Collections.EMPTY_SET
-
- 1 * md.advisorDefs >> advisors
-
- 1 * ad.matches(sd) >> false
- 1 * ad.serviceInterface >> Object
-
- 1 * sd.serviceInterface >> Runnable
-
- 1 * ad.markers >> Collections.EMPTY_SET
-
- 0 * _
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/RecursiveServiceCreationCheckWrapperSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/RecursiveServiceCreationCheckWrapperSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/RecursiveServiceCreationCheckWrapperSpec.groovy
deleted file mode 100644
index 703d50e..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/RecursiveServiceCreationCheckWrapperSpec.groovy
+++ /dev/null
@@ -1,80 +0,0 @@
-package org.apache.tapestry5.ioc.internal
-
-import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
-import org.apache.tapestry5.ioc.ObjectCreator
-import org.apache.tapestry5.ioc.def.ServiceDef
-import org.slf4j.Logger
-
-class RecursiveServiceCreationCheckWrapperSpec extends AbstractSharedRegistrySpecification {
-
- static DESCRIPTION = "{SOURCE DESCRIPTION}"
-
- Logger logger = Mock()
- ObjectCreatorSource source = Mock()
- ObjectCreator delegate = Mock()
- Object service = Mock()
-
- ServiceDef sd = new ServiceDefImpl(Runnable, null, "Bar", null, "singleton", false, false, source)
-
- def "ensure that the creator is called only once"() {
-
- when:
-
- ObjectCreator wrapper = new RecursiveServiceCreationCheckWrapper(sd, delegate, logger)
-
- def actual = wrapper.createObject()
-
- then:
-
- actual == service
-
- 1 * delegate.createObject() >> service
-
- when:
-
- wrapper.createObject()
-
- then:
-
- IllegalStateException e = thrown()
-
- e.message.contains "Construction of service 'Bar' has failed due to recursion"
- e.message.contains DESCRIPTION
-
- 1 * source.description >> DESCRIPTION
- }
-
- def "construction exceptions are logged properly"() {
-
- def t = new RuntimeException("Just cranky.")
-
- when:
-
- ObjectCreator wrapper = new RecursiveServiceCreationCheckWrapper(sd, delegate, logger)
-
- wrapper.createObject()
-
- then:
-
- RuntimeException e = thrown()
-
- e.is(t)
-
- 1 * delegate.createObject() >> { throw t }
-
- 1 * logger.error("Construction of service Bar failed: ${t.message}", t)
-
-
- when: "a subsequent call"
-
- def actual = wrapper.createObject()
-
- then: "the delegate is reinvoked (succesfully, this time)"
-
- actual.is(service)
-
- 1 * delegate.createObject() >> service
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvokerSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvokerSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvokerSpec.groovy
deleted file mode 100644
index 5226b87..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvokerSpec.groovy
+++ /dev/null
@@ -1,195 +0,0 @@
-package org.apache.tapestry5.ioc.internal
-
-import org.slf4j.Logger
-import org.apache.tapestry5.ioc.*
-
-class ServiceBuilderMethodInvokerSpec extends AbstractSharedRegistrySpecification {
-
- static String DESCRIPTION = "{CREATOR DESCRIPTION}"
- static String SERVICE_ID = "Fie"
-
- Logger logger = Mock()
- FieService implementation = Mock()
- OperationTracker tracker = new QuietOperationTracker()
- ServiceBuilderResources resources = Mock()
- ServiceBuilderMethodFixture fixture = new ServiceBuilderMethodFixture();
-
- def setup() {
-
- fixture.fie = implementation
-
- _ * resources.tracker >> tracker
- _ * resources.moduleBuilder >> fixture
- _ * resources.serviceId >> SERVICE_ID
- _ * resources.serviceInterface >> FieService
- _ * resources.logger >> logger
- }
-
- def "invoke a service builder method with no arguments"() {
-
- when:
-
- ObjectCreator oc = createObjectCreator "build_noargs"
-
- def actual = oc.createObject()
-
- then:
-
- actual.is implementation
- }
-
- def ServiceBuilderMethodInvoker createObjectCreator(methodName) {
- new ServiceBuilderMethodInvoker(resources, DESCRIPTION,
- findMethod(fixture, methodName))
- }
-
- def invoke(methodName) {
- createObjectCreator(methodName).createObject()
- }
-
- def "invoke a method with injected parameters"() {
-
- fixture.expectedServiceInterface = FieService
- fixture.expectedServiceResources = resources
- fixture.expectedLogger = logger
-
- when:
-
- def actual = invoke "build_args"
-
- then:
-
- actual.is implementation
- }
-
- def "@Inject annotation bypasses service resources when resolving value to inject"() {
-
- fixture.expectedString = "Injected"
-
- when:
-
- def actual = invoke "build_with_forced_injection"
-
- then:
-
- actual.is implementation
-
- 1 * resources.getObject(String, _ as AnnotationProvider) >> "Injected"
- }
-
- def "@InjectService on method parameter"() {
-
- FoeService foe = Mock()
-
- fixture.expectedFoe = foe
-
- when:
-
- def actual = invoke "build_injected"
-
- then:
-
- actual.is implementation
-
- 1 * resources.getService("Foe", FoeService) >> foe
- }
-
- def "@Named annotation on method parameter"() {
-
- FoeService foe = Mock()
-
- fixture.expectedFoe = foe
-
- when:
-
- def actual = invoke "build_named_injected"
-
- then:
-
- actual.is implementation
-
- 1 * resources.getService("Foe", FoeService) >> foe
- }
-
- def "injection of ordered configuration as List"() {
-
- List<Runnable> configuration = Mock()
-
- fixture.expectedConfiguration = configuration
-
- when:
-
- def actual = invoke "buildWithOrderedConfiguration"
-
- then:
-
- actual.is implementation
-
- 1 * resources.getOrderedConfiguration(Runnable) >> configuration
- }
-
- def "injection of unordered collection (as Collection)"() {
-
- Collection<Runnable> configuration = Mock()
-
- fixture.expectedConfiguration = configuration
-
- when:
-
- def actual = invoke "buildWithUnorderedConfiguration"
-
- then:
-
- actual.is implementation
-
- 1 * resources.getUnorderedConfiguration(Runnable) >> configuration
- }
-
- def "builder method returns null"() {
-
- fixture.fie = null
-
- when:
-
- createObjectCreator("buildWithUnorderedConfiguration").createObject()
-
- then:
-
- RuntimeException e = thrown()
-
- e.message == "Builder method ${DESCRIPTION} (for service 'Fie') returned null."
- }
-
- def "builder method failure"() {
-
- when:
-
- createObjectCreator("build_fail").createObject()
-
- then:
-
- RuntimeException e= thrown()
-
- e.message.contains "build_fail()"
- e.message.contains "Method failed."
-
- e.cause.message == "Method failed."
- }
-
- def "automatically injected dependency (without an annotation)"() {
-
- FoeService foe = Mock()
-
- fixture.expectedFoe = foe
-
- when:
-
- def actual = invoke "build_auto"
-
- then:
-
- actual.is implementation
-
- 1 * resources.getObject(FoeService, _ as AnnotationProvider) >> foe
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ServiceCreatorGenericsSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ServiceCreatorGenericsSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ServiceCreatorGenericsSpec.groovy
deleted file mode 100644
index 6084e30..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ServiceCreatorGenericsSpec.groovy
+++ /dev/null
@@ -1,79 +0,0 @@
-package org.apache.tapestry5.ioc.internal
-
-import spock.lang.Specification
-
-import java.lang.reflect.Method
-
-import static org.apache.tapestry5.ioc.internal.AbstractServiceCreator.findParameterizedTypeFromGenericType
-
-class ServiceCreatorGenericsSpec extends Specification {
-
- Method findMethod(name) {
- Method method = ServiceBuilderMethodFixture.methods.find { it.name == name}
-
- assert method != null
-
- return method
- }
-
- def methodMissing(String name, args) {
- AbstractServiceCreator."$name"(* args)
- }
-
- def "parameterized type of generic method parameter is extracted"() {
-
- when:
-
- def method = findMethod "methodWithParameterizedList"
-
- then:
-
- method.parameterTypes[0] == List
-
- def type = method.genericParameterTypes[0]
-
- type.toString() == "java.util.List<java.lang.Runnable>"
-
- findParameterizedTypeFromGenericType(type) == Runnable
- }
-
- def "parameterized type of a non-generic parameter is Object"() {
-
- when:
-
- def method = findMethod "methodWithList"
-
- then:
-
- method.parameterTypes[0] == List
-
- def type = method.genericParameterTypes[0]
-
- type.toString() == "interface java.util.List"
- findParameterizedTypeFromGenericType(type) == Object
- }
-
- def "getting parameterized type for a non-support type is a failure"() {
-
- when:
-
- def method = findMethod "methodWithWildcardList"
-
- then:
-
- method.parameterTypes[0] == List
-
- def type = method.genericParameterTypes[0]
-
- when:
-
- findParameterizedTypeFromGenericType(type)
-
- then:
-
- IllegalArgumentException e = thrown()
-
- e.message == IOCMessages.genericTypeNotSupported(type)
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapperSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapperSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapperSpec.groovy
deleted file mode 100644
index fdc1363..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapperSpec.groovy
+++ /dev/null
@@ -1,78 +0,0 @@
-package org.apache.tapestry5.ioc.internal
-
-import org.apache.tapestry5.ioc.Configuration
-import org.apache.tapestry5.ioc.ObjectLocator
-import spock.lang.Specification
-
-class ValidatingConfigurationWrapperSpec extends Specification {
-
- TypeCoercerProxy tc = Mock()
- ObjectLocator locator = Mock()
-
- def collection = []
-
- def "valid contribution"() {
- Runnable value = Mock()
-
- Configuration config = new ValidatingConfigurationWrapper(Runnable, null, tc, collection, "Baz")
-
- when:
-
- config.add(value)
-
- then:
-
- tc.coerce(value, Runnable) >> value
-
- collection == [value]
- }
-
- def "contributed value may be coerced"() {
- Runnable value = Mock()
- Runnable coerced = Mock()
-
- Configuration config = new ValidatingConfigurationWrapper(Runnable, null, tc, collection, "Baz")
-
- when:
-
- config.add(value)
-
- then:
-
- tc.coerce(value, Runnable) >> coerced
-
- collection == [coerced]
- }
-
- def "an instance of a class may be contributed"() {
- HashMap contributed = new HashMap()
- Map coerced = Mock()
-
- Configuration config = new ValidatingConfigurationWrapper(Map, locator, tc, collection, "Baz")
-
- when:
-
- config.addInstance(HashMap)
-
- then:
-
- locator.autobuild(HashMap) >> contributed
- tc.coerce(contributed, Map) >> coerced
-
- collection == [coerced]
- }
-
- def "null may not be contributed"() {
- Configuration config = new ValidatingConfigurationWrapper(Runnable, null, tc, collection, "Baz")
-
- when:
-
- config.add(null)
-
- then:
-
- NullPointerException e = thrown()
-
- e.message == "Service contribution (to service 'Baz') was null."
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ValidatingMappedConfigurationWrapperSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ValidatingMappedConfigurationWrapperSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ValidatingMappedConfigurationWrapperSpec.groovy
deleted file mode 100644
index 5fec1ff..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ValidatingMappedConfigurationWrapperSpec.groovy
+++ /dev/null
@@ -1,152 +0,0 @@
-package org.apache.tapestry5.ioc.internal
-
-import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
-import org.apache.tapestry5.ioc.MappedConfiguration
-import org.apache.tapestry5.ioc.ObjectLocator
-import org.apache.tapestry5.ioc.def.ContributionDef
-import org.apache.tapestry5.ioc.services.PlasticProxyFactory
-
-import java.sql.SQLException
-
-class ValidatingMappedConfigurationWrapperSpec extends AbstractSharedRegistrySpecification {
-
- static String SERVICE_ID = "Baz"
-
- ObjectLocator locator = Mock()
- TypeCoercerProxy tc = Mock()
- Map keyToContribution = [:]
- Map map = [:]
-
- def "contribute a property key and value"() {
- ContributionDef cd = Mock()
- def keyToContribution = [:]
- ObjectLocator locator = Mock()
- def map = [:]
- TypeCoercerProxy tc = Mock()
- Runnable value = Mock()
-
- MappedConfiguration config = new ValidatingMappedConfigurationWrapper(Runnable, locator, tc, map, null, SERVICE_ID, cd, Class, keyToContribution)
-
- when:
-
- config.add(Integer, value)
-
- then:
-
- tc.coerce(value, Runnable) >> value
-
- map[Integer].is(value)
- keyToContribution[Integer].is(cd)
- }
-
- def "an added value may be coerced to the correct type"() {
-
- ContributionDef cd = Mock()
- def value = "coerce-me"
- Runnable coerced = Mock()
-
- MappedConfiguration config = new ValidatingMappedConfigurationWrapper(Runnable, locator, tc, map, null, SERVICE_ID, cd, Class, keyToContribution)
-
- when:
-
- config.add(Integer, value)
-
- then:
-
- tc.coerce(value, Runnable) >> coerced
-
- map[Integer].is(coerced)
- keyToContribution[Integer].is(cd)
- }
-
- def ContributionDef newContributionDef(methodName) {
-
- def proxyFactory = getService PlasticProxyFactory
-
- return new ContributionDefImpl(SERVICE_ID, findMethod(methodName), false, proxyFactory, null, null);
- }
-
- def findMethod(name) {
- return this.class.methods.find() { it.name == name }
- }
-
-
- public void contributionPlaceholder1() {
-
- }
-
- public void contributionPlaceholder2() {
-
- }
-
- def "may not contribute a duplicate key"() {
- ContributionDef def1 = newContributionDef "contributionPlaceholder1"
- ContributionDef def2 = newContributionDef "contributionPlaceholder2"
-
- keyToContribution[Integer] = def1
-
- MappedConfiguration config = new ValidatingMappedConfigurationWrapper(Runnable, locator, tc, map, null, SERVICE_ID, def2, Class, keyToContribution)
-
- when:
-
- config.add(Integer, "does-not-matter")
-
- then:
-
- IllegalArgumentException e = thrown()
-
- e.message.contains "Service contribution (to service 'Baz') conflicts with existing contribution"
-
- keyToContribution[Integer].is(def1)
- map.isEmpty()
- }
-
- def "the contributed key may not be null"() {
- ContributionDef cd = newContributionDef "contributionPlaceholder1"
-
- MappedConfiguration config = new ValidatingMappedConfigurationWrapper(Runnable, locator, tc, map, null, SERVICE_ID, cd, Class, keyToContribution)
-
- when:
-
- config.add(null, "does-not-matter")
-
- then:
-
- NullPointerException e = thrown()
-
- e.message == "Key for service contribution (to service '$SERVICE_ID') was null."
- }
-
- def "adding a key of the wrong type is an exception"() {
- ContributionDef cd = newContributionDef "contributionPlaceholder1"
-
- MappedConfiguration config = new ValidatingMappedConfigurationWrapper(Runnable, locator, tc, map, null, SERVICE_ID, cd, Class, keyToContribution)
-
- when:
-
- config.add("java.util.List", "does-not-matter")
-
- then:
-
- IllegalArgumentException e = thrown()
-
- e.message == "Key for service contribution (to service 'Baz') was an instance of java.lang.String, but the expected key type was java.lang.Class."
- }
-
- def "contributing a null value is an exception"() {
- ContributionDef cd = newContributionDef "contributionPlaceholder1"
-
- MappedConfiguration config = new ValidatingMappedConfigurationWrapper(Runnable, locator, tc, map, null, SERVICE_ID, cd, Class, keyToContribution)
-
- when:
-
- config.add(SQLException, null)
-
- then:
-
- NullPointerException e = thrown()
-
- e.message == "Service contribution (to service 'Baz') was null."
- map.isEmpty()
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperSpec.groovy
deleted file mode 100644
index 0e7fc43..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperSpec.groovy
+++ /dev/null
@@ -1,80 +0,0 @@
-package org.apache.tapestry5.ioc.internal
-
-import org.apache.tapestry5.ioc.ObjectLocator
-import org.apache.tapestry5.ioc.OrderedConfiguration
-import org.apache.tapestry5.ioc.internal.util.Orderer
-import org.slf4j.Logger
-import spock.lang.Specification
-
-class ValidatingOrderedConfigurationWrapperSpec extends Specification {
-
- def "contribution of a coerceable instance"() {
- Runnable contribution = Mock()
- Runnable coerced = Mock()
- Runnable pre = Mock()
- Runnable post = Mock()
- Logger logger = Mock()
- TypeCoercerProxy tc = Mock()
-
- def orderer = new Orderer(logger)
-
- orderer.add "pre", pre
- orderer.add "post", post
-
- OrderedConfiguration config = new ValidatingOrderedConfigurationWrapper(Runnable, null, tc, orderer, null, null)
-
- when:
-
- config.add("id", contribution, "after:pre", "before:post")
-
- then:
-
- 1 * tc.coerce(contribution, Runnable) >> coerced
-
- orderer.ordered == [pre, coerced, post]
- }
-
- def "contribution of a valid type"() {
- Map instance = new HashMap()
- Map pre = Mock()
- Map post = Mock()
- ObjectLocator locator = Mock()
- TypeCoercerProxy tc = Mock()
- Logger logger = Mock()
-
- def orderer = new Orderer(logger)
-
- orderer.add "pre", pre
- orderer.add "post", post
-
- OrderedConfiguration config = new ValidatingOrderedConfigurationWrapper(Map, locator, tc, orderer, null, null)
-
- when:
-
- config.addInstance("id", HashMap, "after:pre", "before:post")
-
- then:
-
- 1 * locator.autobuild(HashMap) >> instance
- 1 * tc.coerce(instance, Map) >> instance
-
- orderer.ordered == [pre, instance, post]
- }
-
- def "null objected passed through"() {
- Logger logger = Mock()
-
- Orderer orderer = new Orderer(logger)
- OrderedConfiguration config = new ValidatingOrderedConfigurationWrapper(Runnable, null, null, orderer, null, null)
-
- when:
-
- config.add("id", null)
-
- then:
-
- orderer.ordered.empty
-
-
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/AspectInterceptorBuilderImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/AspectInterceptorBuilderImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/AspectInterceptorBuilderImplSpec.groovy
deleted file mode 100644
index 9722cea..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/AspectInterceptorBuilderImplSpec.groovy
+++ /dev/null
@@ -1,152 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import org.apache.commons.lang.StringUtils
-import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
-import org.apache.tapestry5.ioc.services.AspectDecorator
-import org.apache.tapestry5.plastic.MethodAdvice
-import org.apache.tapestry5.plastic.MethodInvocation
-import spock.lang.Shared
-
-
-interface Subject {
-
- void advised();
-
- void notAdvised();
-}
-
-interface ArraysSubject {
-
- String[] operation(String[] inputs);
-}
-
-class AspectInterceptorBuilderImplSpec extends AbstractSharedRegistrySpecification {
-
- @Shared
- private AspectDecorator decorator
-
- def setupSpec() {
- decorator = getService AspectDecorator
- }
-
- def "ensure that non-advised methods are not passed through the MethodAdvice object"() {
- Subject delegate = Mock()
- MethodAdvice advice = Mock()
-
- def builder = decorator.createBuilder Subject, delegate, "<Subject>"
-
- builder.adviseMethod Subject.getMethod("advised"), advice
-
- Subject interceptor = builder.build()
-
- when:
-
- interceptor.advised()
-
- then:
-
- 1 * advice.advise(_) >> { MethodInvocation mi ->
- assert mi.method.name == "advised"
- mi.proceed()
- }
- 1 * delegate.advised()
- 0 * _
-
- when:
-
- interceptor.notAdvised()
-
- then:
-
- 1 * delegate.notAdvised()
- 0 * _
- }
-
- def "failure when advising a method that is not in the service interface"() {
- Subject delegate = Mock()
- MethodAdvice advice = Mock()
-
- def builder = decorator.createBuilder Subject, delegate, "<Subject>"
-
- when:
-
- builder.adviseMethod Runnable.getMethod("run"), advice
-
- then:
-
- IllegalArgumentException e = thrown()
-
- e.message == "Method public abstract void java.lang.Runnable.run() is not defined for interface interface org.apache.tapestry5.ioc.internal.services.Subject."
- }
-
- def "multiple advice for single method is processed in order"() {
- TextTransformer delegate = Mock()
- MethodAdvice stripFirstLetter = Mock()
- MethodAdvice reverse = Mock()
-
- def builder = decorator.createBuilder TextTransformer, delegate, "<TextTransformer>"
-
- def method = TextTransformer.getMethod "transform", String
-
- builder.adviseMethod method, stripFirstLetter
- builder.adviseMethod method, reverse
-
- TextTransformer advised = builder.build()
-
- when:
-
- def result = advised.transform "Tapestry"
-
- then:
-
- result == "[yrtsepa]"
-
- 1 * stripFirstLetter.advise(_) >> { MethodInvocation mi ->
- assert mi.getParameter(0) == "Tapestry"
- mi.setParameter 0, mi.getParameter(0).substring(1)
- mi.proceed()
- }
-
- 1 * reverse.advise(_) >> { MethodInvocation mi ->
- assert mi.getParameter(0) == "apestry"
- mi.setParameter 0, StringUtils.reverse(mi.getParameter(0))
- mi.proceed()
- }
-
- 1 * delegate.transform(_) >> { it }
- }
-
- def "arrays are allowed as method parameters and return values"() {
- ArraysSubject delegate = Mock()
- MethodAdvice advice = Mock()
-
- def builder = decorator.createBuilder ArraysSubject, delegate, "unused"
- builder.adviseAllMethods advice
-
- ArraysSubject advised = builder.build()
-
- when:
-
- def result = advised.operation(["Fred", "Barney"] as String[])
-
- then:
-
- 1 * advice.advise(_) >> { MethodInvocation it ->
- String[] inputs = it.getParameter(0)
-
- it.setParameter 0, inputs.collect({it.toUpperCase() }) as String[]
-
- it.proceed()
-
- def index = 0
-
- it.setReturnValue it.getReturnValue().collect({ value -> "${index++}:$value" }) as String[]
- }
-
- 1 * delegate.operation(_) >> { it[0] }
-
- result.class == ([] as String[]).class
- result.asType(List) == ["0:FRED", "1:BARNEY"]
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/BridgeBuilderSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/BridgeBuilderSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/BridgeBuilderSpec.groovy
deleted file mode 100644
index a62299e..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/BridgeBuilderSpec.groovy
+++ /dev/null
@@ -1,169 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
-import org.apache.tapestry5.ioc.services.PlasticProxyFactory
-import org.slf4j.Logger
-import spock.lang.Shared
-
-class BridgeBuilderSpec extends AbstractSharedRegistrySpecification {
-
- @Shared
- PlasticProxyFactory proxyFactory;
-
- def setupSpec() {
- proxyFactory = getService PlasticProxyFactory
- }
-
- def "toString() of proxy is as expected"() {
- Logger logger = Mock()
- StandardFilter sf = Mock()
- StandardService ss = Mock()
-
- BridgeBuilder builder = new BridgeBuilder(logger, StandardService, StandardFilter, proxyFactory)
-
- when:
-
- def bridge = builder.instantiateBridge(ss, sf)
-
- then:
-
- bridge.toString() == "<PipelineBridge from org.apache.tapestry5.ioc.internal.services.StandardService to org.apache.tapestry5.ioc.internal.services.StandardFilter>"
- }
-
- def "standard service and interface"() {
- Logger logger = Mock()
- StandardFilter sf = Mock()
- StandardService ss = Mock()
-
- BridgeBuilder builder = new BridgeBuilder(logger, StandardService, StandardFilter, proxyFactory)
- def bridge = builder.instantiateBridge(ss, sf)
-
- when:
-
- assert bridge.run(5) == 18
-
- // 18 = 3 * (5 + 1)
- // so the filter runs first, and passes 6 to the service
- // seems there's an issue in Spock with chaining mocks this way
-
- then:
-
- 1 * sf.run(_, _) >> { i, service -> service.run(i + 1) }
-
- 1 * ss.run(_) >> { i -> 3 * i }
-
- 0 * _
- }
-
- def "when toString() is part of service interface, it is forwarded through the filter"() {
- Logger logger = Mock()
-
- ToStringService service = new ToStringService() {
-
- String toString() { "Service" }
- }
-
- ToStringFilter filter = new ToStringFilter() {
-
- String toString(ToStringService s) {
- s.toString().toUpperCase()
- }
- }
-
- BridgeBuilder builder = new BridgeBuilder(logger, ToStringService, ToStringFilter, proxyFactory)
-
- when:
-
- ToStringService bridge = builder.instantiateBridge(service, filter)
-
- then:
-
- bridge.toString() == "SERVICE"
- }
-
- def "unmatched service interface method is logged and exception thrown"() {
- Logger logger = Mock()
- ExtraServiceMethod next = Mock()
- Serializable filter = Mock()
-
- BridgeBuilder builder = new BridgeBuilder(logger, ExtraServiceMethod, Serializable, proxyFactory)
-
- when:
-
- ExtraServiceMethod esm = builder.instantiateBridge(next, filter)
-
- then:
-
- 1 * logger.error("Method void extraServiceMethod() has no match in filter interface java.io.Serializable.")
-
- when:
-
- esm.extraServiceMethod()
-
- then:
-
- RuntimeException e = thrown()
-
- e.message == "Method void extraServiceMethod() has no match in filter interface java.io.Serializable."
- }
-
- def "extra methods in filter interface are logged and ignored"() {
- Logger logger = Mock()
- Serializable next = Mock()
- ExtraFilterMethod filter = Mock()
-
- BridgeBuilder builder = new BridgeBuilder(logger, Serializable, ExtraFilterMethod, proxyFactory)
-
- when:
-
- assert builder.instantiateBridge(next, filter) != null
-
- then:
-
- 1 * logger.error("Method void extraFilterMethod() of filter interface org.apache.tapestry5.ioc.internal.services.ExtraFilterMethod does not have a matching method in java.io.Serializable.")
-
- 0 * _
- }
-
- def "the service parameter may be a middle parameter of the filter method"() {
- Logger logger = Mock()
-
- MiddleFilter mf = new MiddleFilter() {
-
- @Override
- void execute(int count, char ch, MiddleService service, StringBuilder buffer) {
- service.execute(count, ch, buffer)
-
- buffer.append(' ')
-
- service.execute(count + 1, Character.toUpperCase(ch), buffer)
- }
- }
-
- MiddleService ms = new MiddleService() {
-
- @Override
- void execute(int count, char ch, StringBuilder buffer) {
- count.times() { buffer.append ch }
- }
- }
-
- BridgeBuilder builder = new BridgeBuilder(logger, MiddleService, MiddleFilter, proxyFactory)
-
-
- MiddleService bridge = builder.instantiateBridge(ms, mf)
-
- StringBuilder buffer = new StringBuilder("CODE: ")
-
- when:
-
-
- bridge.execute(3, 'a' as char, buffer)
-
- then:
-
- buffer.toString() == "CODE: aaa AAAA"
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ChainBuilderImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ChainBuilderImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ChainBuilderImplSpec.groovy
deleted file mode 100644
index 9c41bda..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ChainBuilderImplSpec.groovy
+++ /dev/null
@@ -1,122 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
-import org.apache.tapestry5.ioc.services.ChainBuilder
-
-interface ChainCommand {
-
- void run();
-
- int workInt(int input);
-
- boolean workBoolean(boolean input);
-
- double workDouble(double input);
-
- String workString(String input);
-}
-
-class ChainBuilderImplSpec extends AbstractSharedRegistrySpecification {
-
- ChainCommand c1 = Mock()
- ChainCommand c2 = Mock()
-
- ChainCommand chain = getService(ChainBuilder).build(ChainCommand, [c1, c2])
-
- def "chaining of simple void method with no parameters"() {
- when:
-
- chain.run()
-
- then:
-
- 1 * c1.run()
-
- then:
-
- 1 * c2.run()
- 0 * _
- }
-
- def "chaining of method with int parameter and return type"() {
-
- when:
-
- assert chain.workInt(7) == 99
-
- then:
-
- 1 * c1.workInt(7) >> 0
-
- then:
-
- 1 * c2.workInt(7) >> 99
- 0 * _
- }
-
- def "verify that an int method that returns a non-zero value short-circuits the chain"() {
- when:
-
- assert chain.workInt(7) == 88
-
- then:
-
- 1 * c1.workInt(7) >> 88
- 0 * _
- }
-
- def "verify boolean parameters, return type, and short circuiting"() {
-
- when:
-
- assert chain.workBoolean(true) == true
-
- then:
-
- 1 * c1.workBoolean(true) >> false
-
- then:
-
- 1 * c2.workBoolean(true) >> true
- 0 * _
- }
-
- def "verify string method parameter, return type, and short circuiting"() {
- when:
-
- assert chain.workString("fred") == "flintstone"
-
- then:
-
- 1 * c1.workString("fred") >> null
-
- then:
-
- 1 * c2.workString("fred") >> "flintstone"
- 0 * _
- }
-
- def "verify double method parameter, return type, and short circuiting"() {
-
- when:
-
- assert chain.workDouble(1.2d) == 3.14d
-
- then:
-
- 1 * c1.workDouble(1.2d) >> 0d
-
- then:
-
- 1 * c2.workDouble(1.2d) >> 3.14d
- 0 * _
- }
-
- def "chain instance has reasonable toString()"() {
- expect:
-
- chain.toString() == "<Command chain of org.apache.tapestry5.ioc.internal.services.ChainCommand>"
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ClassNameLocatorImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ClassNameLocatorImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ClassNameLocatorImplSpec.groovy
deleted file mode 100644
index 7744ae4..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ClassNameLocatorImplSpec.groovy
+++ /dev/null
@@ -1,74 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import org.apache.tapestry5.ioc.services.ClassNameLocator
-import spock.lang.Specification
-
-class ClassNameLocatorImplSpec extends Specification {
-
- ClassNameLocator locator = new ClassNameLocatorImpl(new ClasspathURLConverterImpl());
-
- def assertInList(classNames, packageName, String... expectedNames) {
-
- expectedNames.each { name ->
- String qualifiedName = "${packageName}.${name}"
-
- assert classNames.contains(qualifiedName), "[$qualifiedName] not present in ${classNames.join(', ')}."
- }
- }
-
- def assertNotInList(classNames, packageName, String... expectedNames) {
-
- expectedNames.each { name ->
- String qualifiedName = "${packageName}.${name}"
-
- assert !classNames.contains(qualifiedName), "[$qualifiedName] should not be present in ${classNames.join(', ')}."
- }
- }
-
- def "locate classes inside a JAR file on the classpath"() {
-
- expect:
-
- assertInList locator.locateClassNames("javax.inject"),
- "javax.inject",
- "Inject", "Named", "Singleton"
- }
-
- def "can locate classes inside a subpackage, inside a classpath JAR file"() {
-
- expect:
-
- assertInList locator.locateClassNames("org.slf4j"),
- "org.slf4j",
- "spi.MDCAdapter"
- }
-
- def "can locate classes in local folder, but exclude inner classes"() {
-
- def packageName = "org.apache.tapestry5.ioc.services"
-
- when:
-
- def names = locator.locateClassNames packageName
-
- then:
-
- assertInList names, packageName, "SymbolSource", "TapestryIOCModule"
-
- assertNotInList names, packageName, 'TapestryIOCMOdules$1'
- }
-
- def "can locate classes in subpackage of local folders"() {
- def packageName = "org.apache.tapestry5"
-
- when:
-
- def names = locator.locateClassNames packageName
-
- then:
-
- assertInList names, packageName, "ioc.Orderable", "ioc.services.ChainBuilder"
- assertNotInList names, packageName, 'services.TapestryIOCModule$1'
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ClasspathResourceSymbolProviderSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ClasspathResourceSymbolProviderSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ClasspathResourceSymbolProviderSpec.groovy
deleted file mode 100644
index ffdab5c..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ClasspathResourceSymbolProviderSpec.groovy
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import spock.lang.Shared
-import spock.lang.Specification
-
-class ClasspathResourceSymbolProviderSpec extends Specification {
-
- static final String PATH = "org/apache/tapestry5/ioc/internal/services/foo.properties"
-
- @Shared
- def provider = new ClasspathResourceSymbolProvider(PATH)
-
- def "access properties"() {
-
- expect:
- provider.valueForSymbol("homer") == "simpson"
- provider.valueForSymbol("monty") == "burns"
- }
-
- def "keys are case insensitive"() {
- expect:
- provider.valueForSymbol("HOMER") == "simpson"
- }
-
- def "non-existent keys should return null"() {
- expect:
- provider.valueForSymbol("marge") == null
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/DefaultImplementationBuilderImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/DefaultImplementationBuilderImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/DefaultImplementationBuilderImplSpec.groovy
deleted file mode 100644
index 3e7d8b5..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/DefaultImplementationBuilderImplSpec.groovy
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
-import org.apache.tapestry5.ioc.services.DefaultImplementationBuilder
-
-
-class DefaultImplementationBuilderImplSpec extends AbstractSharedRegistrySpecification {
-
- DefaultImplementationBuilder builder = getService(DefaultImplementationBuilder)
-
- def "default simple interface does nothing"() {
- Runnable r = builder.createDefaultImplementation(Runnable)
-
- when:
-
- r.run()
-
- then:
-
- assert r.toString() == "<NoOp java.lang.Runnable>"
- }
-
- def "when toString() is part of interface, the default returns null"() {
- ToString ts = builder.createDefaultImplementation(ToString)
-
- expect:
-
- ts.toString() == null
- }
-
- def "built instances are cached (by type)"() {
- Runnable r1 = builder.createDefaultImplementation(Runnable)
- Runnable r2 = builder.createDefaultImplementation(Runnable)
-
- expect:
-
- r1.is r2
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImplSpec.groovy
deleted file mode 100644
index 5970946..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImplSpec.groovy
+++ /dev/null
@@ -1,215 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
-import org.apache.tapestry5.ioc.Location
-import org.apache.tapestry5.ioc.internal.util.TapestryException
-import org.apache.tapestry5.ioc.services.ExceptionAnalyzer
-
-class WriteOnlyPropertyException extends Exception {
-
- private String code;
-
- public String getCode() {
- return code;
- }
-
- public void setFaultCode(int code) {
- this.code = String.format("%04d", code);
- }
-}
-
-class SelfCausedException extends RuntimeException {
-
- SelfCausedException(String message) {
- super(message);
- }
-
- public Throwable getCause() {
- return this;
- }
-}
-
-class ExceptionAnalyzerImplSpec extends AbstractSharedRegistrySpecification {
-
- ExceptionAnalyzer analyzer = getService(ExceptionAnalyzer)
-
- def "analysis of a simple exception"() {
- when:
- def ea = analyzer.analyze(t)
-
- then:
-
- ea.exceptionInfos.size() == 1
-
- def ei = ea.exceptionInfos[0]
-
- ei.className == RuntimeException.name
- ei.message == message
-
- ei.propertyNames.empty
- !ei.stackTrace.empty
-
- where:
-
- message = "Hey! We've Got No Tomatoes"
- t = new RuntimeException(message)
- }
-
- def "access to properties of exception"() {
- Location l = Mock()
- def t = new TapestryException("Message", l, null)
-
- when:
- def ea = analyzer.analyze(t)
-
- then:
-
- ea.exceptionInfos.size() == 1
-
- def ei = ea.exceptionInfos[0]
-
- ei.propertyNames == ["location"]
- ei.getProperty("location").is(l)
- }
-
- def "access to nested exceptions"() {
- when:
-
- def ea = analyzer.analyze(outer)
-
- then:
-
- ea.exceptionInfos.size() == 2
-
- def ei = ea.exceptionInfos[0]
-
- ei.message == "Outer"
- ei.stackTrace.empty
-
- when:
-
- ei = ea.exceptionInfos[1]
-
- then:
-
- ei.message == "Inner"
- !ei.stackTrace.empty
-
- where:
-
- inner = new RuntimeException("Inner")
- outer = new RuntimeException("Outer", inner)
- }
-
- def "middle exception that adds no value is removed"() {
- when:
-
- def ea = analyzer.analyze(outer)
-
- then:
-
- ea.exceptionInfos.size() == 2
-
- def ei = ea.exceptionInfos[0]
-
- ei.message == "Outer: Middle"
- ei.stackTrace.empty
-
- when:
-
- ei = ea.exceptionInfos[1]
-
- then:
-
- ei.message == "Inner"
-
- !ei.stackTrace.empty
-
- where:
-
- inner = new RuntimeException("Inner");
- middle = new RuntimeException("Middle", inner);
- outer = new RuntimeException("Outer: Middle", middle);
- }
-
- def "a middle exception that adds extra information is retained"() {
- Location l = Mock()
- def inner = new RuntimeException("Inner");
- def middle = new TapestryException("Middle", l, inner);
- def outer = new RuntimeException("Outer: Middle", middle);
-
- when:
-
- def ea = analyzer.analyze(outer)
-
- then:
-
- ea.exceptionInfos.size() == 3
-
- def ei = ea.exceptionInfos[0]
-
- ei.message == "Outer: Middle"
- ei.stackTrace.empty
-
- when:
-
- ei = ea.exceptionInfos[1]
-
- then:
-
- ei.message == "Middle"
- ei.getProperty("location").is(l)
- ei.stackTrace.empty
-
- when:
-
- ei = ea.exceptionInfos[2]
-
- then:
-
- ei.message == "Inner"
- !ei.stackTrace.empty
- }
-
- def "write only properties are omitted"() {
- WriteOnlyPropertyException ex = new WriteOnlyPropertyException();
-
- ex.setFaultCode(99);
-
- when:
-
- def ea = analyzer.analyze(ex);
-
- then:
-
- def ei = ea.exceptionInfos[0]
-
- ei.propertyNames.contains("code")
- !ei.propertyNames.contains("faultCode")
- ei.getProperty("code") == "0099"
- }
-
- def "an exception that is its own cause does not cause an endless loop"() {
- when:
-
- def ea = analyzer.analyze(t)
-
- then:
-
- ea.exceptionInfos.size() == 1
-
- def ei = ea.exceptionInfos[0]
-
- ei.className == SelfCausedException.name
- ei.message == message
-
- !ei.propertyNames.contains("cause")
-
- !ei.stackTrace.empty
-
- where:
-
- message = "Who you lookin at?"
- t = new SelfCausedException(message)
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ExceptionTrackerImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ExceptionTrackerImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ExceptionTrackerImplSpec.groovy
deleted file mode 100644
index b86bd21..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ExceptionTrackerImplSpec.groovy
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import spock.lang.Specification
-
-
-class ExceptionTrackerImplSpec extends Specification {
-
- def "exceptions are tracked"() {
-
- def t1 = new RuntimeException()
- def t2 = new RuntimeException()
-
- when: "with a new tracker"
-
- def et = new ExceptionTrackerImpl()
-
- then: "never logged exceptions return false"
-
- !et.exceptionLogged(t1)
- !et.exceptionLogged(t2)
-
- then: "subsequently, the same exceptions return true"
-
- et.exceptionLogged(t1)
- et.exceptionLogged(t2)
-
- then: "and again"
-
- et.exceptionLogged(t1)
- et.exceptionLogged(t2)
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/FilterMethodAnalyzerSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/FilterMethodAnalyzerSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/FilterMethodAnalyzerSpec.groovy
deleted file mode 100644
index 5f5f9ef..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/FilterMethodAnalyzerSpec.groovy
+++ /dev/null
@@ -1,33 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import spock.lang.Specification
-import spock.lang.Unroll
-
-class FilterMethodAnalyzerSpec extends Specification {
-
- private MethodSignature find(clazz, name) {
- new MethodSignature(clazz.methods.find { it.name == name })
- }
-
- @Unroll
- def "position of delegate parameter for #methodName should be #position"() {
- def analyzer = new FilterMethodAnalyzer(SampleService)
-
- def mainMethod = find SampleService, methodName
- def filterMethod = find SampleFilter, methodName
-
- expect:
-
- analyzer.findServiceInterfacePosition(mainMethod, filterMethod) == position
-
- where:
-
- methodName | position
- "simpleMatch" | 0
- "mismatchParameterCount" | -1
- "mismatchReturnType" | -1
- "missingServiceInterface" | -1
- "complexMatch" | 2
-
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorSpec.groovy
deleted file mode 100644
index c1e9628..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorSpec.groovy
+++ /dev/null
@@ -1,52 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import org.apache.tapestry5.ioc.ObjectCreator
-import org.apache.tapestry5.ioc.internal.ServiceActivityTracker
-import org.apache.tapestry5.ioc.services.Status
-import spock.lang.Specification
-
-class JustInTimeObjectCreatorSpec extends Specification {
-
- static final String SERVICE_ID = "FooBar";
-
- def "can not create object after shutdown"() {
-
- ObjectCreator creator = Mock()
-
- def jit = new JustInTimeObjectCreator(null, creator, SERVICE_ID)
-
- // Simulate the invocation from the Registry when it shuts down.
- jit.run()
-
- when:
-
- jit.createObject()
-
- then:
-
- RuntimeException e = thrown()
-
- e.message.contains "Proxy for service FooBar is no longer active because the IOC Registry has been shut down."
- }
-
- def "lazily instantiates the object via its delegate creator"() {
-
- ObjectCreator creator = Mock()
- Object service = new Object()
- ServiceActivityTracker tracker = Mock()
-
- def jit = new JustInTimeObjectCreator(tracker, creator, SERVICE_ID)
-
- when:
-
- jit.eagerLoadService()
-
- then:
-
- 1 * creator.createObject() >> service
- 1 * tracker.setStatus(SERVICE_ID, Status.REAL)
- 0 * _
-
- jit.createObject().is service
- }
-}