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/12 23:37:22 UTC
[3/5] git commit: Convert TestNG to Spock
Convert TestNG to Spock
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/cb55d1c3
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/cb55d1c3
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/cb55d1c3
Branch: refs/heads/master
Commit: cb55d1c3ced4fb0803ac829b532a2b94d471c6cb
Parents: a663703
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Tue Jun 12 11:04:27 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Tue Jun 12 11:04:27 2012 -0700
----------------------------------------------------------------------
.../ioc/internal/services/RegistryStartup.java | 11 +-
.../ioc/internal/services/ServiceMessages.java | 5 -
.../internal/services/ServiceStrings.properties | 1 -
.../internal/services/RegistryStartupSpec.groovy | 95 ++++++++++
.../ioc/internal/services/RegistryStartupTest.java | 135 ---------------
5 files changed, 102 insertions(+), 145 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cb55d1c3/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/RegistryStartup.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/RegistryStartup.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/RegistryStartup.java
index a6b3d0c..35e3a34 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/RegistryStartup.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/RegistryStartup.java
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2012 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
package org.apache.tapestry5.ioc.internal.services;
import org.apache.tapestry5.ioc.Registry;
+import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.ioc.internal.util.OneShotLock;
import org.slf4j.Logger;
@@ -53,10 +54,12 @@ public class RegistryStartup implements Runnable
try
{
r.run();
- }
- catch (RuntimeException ex)
+ } catch (RuntimeException ex)
{
- logger.error(ServiceMessages.startupFailure(ex));
+ // startup-failure=An exception occurred during startup: %s
+
+ logger.error(String.format("An exception occurred during startup: %s",
+ InternalUtils.toMessage(ex)), ex);
}
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cb55d1c3/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ServiceMessages.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ServiceMessages.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ServiceMessages.java
index ad4c5b5..93899bf 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ServiceMessages.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ServiceMessages.java
@@ -90,9 +90,4 @@ public class ServiceMessages
{
return MESSAGES.format("service-build-failure", serviceId, cause);
}
-
- public static String startupFailure(Throwable cause)
- {
- return MESSAGES.format("startup-failure", cause);
- }
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cb55d1c3/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/services/ServiceStrings.properties
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/services/ServiceStrings.properties b/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/services/ServiceStrings.properties
index b16ae75..721a2d8 100644
--- a/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/services/ServiceStrings.properties
+++ b/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/services/ServiceStrings.properties
@@ -24,4 +24,3 @@ missing-symbol-close-brace-in-path=Input string '%s' is missing a symbol closing
failed-coercion=Coercion of %s to type %s (via %s) failed: %s
registry-shutdown=Proxy for service %s is no longer active because the IOC Registry has been shut down.
service-build-failure=Exception constructing service '%s': %s
-startup-failure=An exception occurred during startup: %s
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cb55d1c3/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/RegistryStartupSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/RegistryStartupSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/RegistryStartupSpec.groovy
new file mode 100644
index 0000000..bf171a1
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/RegistryStartupSpec.groovy
@@ -0,0 +1,95 @@
+package org.apache.tapestry5.ioc.internal.services
+
+import org.apache.tapestry5.ioc.RegistryBuilder
+import org.slf4j.Logger
+import spock.lang.Specification
+
+class RegistryStartupSpec extends Specification {
+
+
+ def "ensure that RegistryStartup service runs each of its contributed callbacks"() {
+ Runnable r1 = Mock()
+ Runnable r2 = Mock()
+ Logger logger = Mock()
+ def configuration = [r1, r2]
+
+ Runnable startup = new RegistryStartup(logger, configuration)
+
+ when:
+
+ startup.run()
+
+ then:
+
+ 1 * r1.run()
+
+ then:
+
+ 1 * r2.run()
+
+ then:
+
+ configuration.empty
+ }
+
+ def "callback failure is logged and execution continues"() {
+ Runnable r1 = Mock()
+ Runnable r2 = Mock()
+ Logger logger = Mock()
+ RuntimeException ex = new RuntimeException("Crunch!")
+
+ Runnable startup = new RegistryStartup(logger, [r1, r2])
+
+ when:
+
+ startup.run()
+
+ then:
+
+ 1 * r1.run() >> { throw ex }
+ 1 * logger.error("An exception occurred during startup: Crunch!", ex)
+ 1 * r2.run()
+ }
+
+ def "run may only be invoked once"() {
+ Logger logger = Mock()
+ Runnable startup = new RegistryStartup(logger, [])
+
+ startup.run()
+
+ when:
+
+ startup.run()
+
+ then:
+
+ IllegalStateException e= thrown()
+
+ e.message.contains "Method org.apache.tapestry5.ioc.internal.services.RegistryStartup.run"
+ e.message.contains "may no longer be invoked."
+ }
+
+ def "integration test"() {
+ when:
+
+ def registry = new RegistryBuilder().add(StartupModule).build()
+
+ then:
+
+ ! StartupModule.startupInvoked
+
+ when:
+
+ registry.performRegistryStartup()
+
+ then:
+
+ StartupModule.startupInvoked
+
+ cleanup:
+
+ registry.shutdown()
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cb55d1c3/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/RegistryStartupTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/RegistryStartupTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/RegistryStartupTest.java
deleted file mode 100644
index 96c0ef8..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/RegistryStartupTest.java
+++ /dev/null
@@ -1,135 +0,0 @@
-// Copyright 2007, 2008 The Apache Software Foundation
-//
-// 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.apache.tapestry5.ioc.internal.services;
-
-import org.apache.tapestry5.ioc.Registry;
-import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
-import org.apache.tapestry5.ioc.test.IOCTestCase;
-import org.slf4j.Logger;
-import org.testng.annotations.Test;
-
-import java.util.List;
-
-public class RegistryStartupTest extends IOCTestCase
-{
- /**
- * Runnable runs.
- */
- @Test
- public void success()
- {
- List<Runnable> configuration = CollectionFactory.newList();
-
- Runnable r1 = newMock(Runnable.class);
- Runnable r2 = newMock(Runnable.class);
-
- configuration.add(r1);
- configuration.add(r2);
-
- Logger logger = mockLogger();
-
- getMocksControl().checkOrder(true);
-
- r1.run();
- r2.run();
-
- replay();
-
- Runnable startup = new RegistryStartup(logger, configuration);
-
- startup.run();
-
- verify();
-
- // The configuration is cleared out at the end of the execution.
- assertTrue(configuration.isEmpty());
- }
-
- @Test
- public void failure_is_logged_but_execution_continues()
- {
- List<Runnable> configuration = CollectionFactory.newList();
- RuntimeException t = new RuntimeException("Runnable r1 has been a naughty boy.");
-
- Runnable r1 = newMock(Runnable.class);
- Runnable r2 = newMock(Runnable.class);
-
- configuration.add(r1);
- configuration.add(r2);
-
- Logger logger = mockLogger();
-
- getMocksControl().checkOrder(true);
-
- r1.run();
- setThrowable(t);
-
- logger.error(ServiceMessages.startupFailure(t));
-
- r2.run();
-
- replay();
-
- Runnable startup = new RegistryStartup(logger, configuration);
-
- startup.run();
-
- verify();
- }
-
- @Test
- public void run_may_only_be_called_once()
- {
- Logger logger = mockLogger();
- List<Runnable> configuration = CollectionFactory.newList();
-
- replay();
-
- Runnable startup = new RegistryStartup(logger, configuration);
-
- startup.run();
-
- try
- {
- startup.run();
- unreachable();
- }
- catch (IllegalStateException ex)
- {
- assertMessageContains(ex, "Method org.apache.tapestry5.ioc.internal.services.RegistryStartup.run(",
- "may no longer be invoked.");
-
- }
-
- verify();
- }
-
- @Test
- public void integration()
- {
- Registry r = buildRegistry(StartupModule.class);
-
- assertFalse(StartupModule.startupInvoked);
-
- r.performRegistryStartup();
-
- assertTrue(StartupModule.startupInvoked);
-
- // Ideally we'd have a way to show that the PerthreadManager was notified after
- // RegistryStartup did its thing, but ...
-
- r.shutdown();
- }
-}