tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject [3/3] git commit: Convert TestNG to Spock
Date Fri, 22 Jun 2012 21:30:16 GMT
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/180766cd
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/180766cd
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/180766cd

Branch: refs/heads/master
Commit: 180766cdbd949605abf4a6ab844cfc04f8ef130d
Parents: 79b2040
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Fri Jun 22 14:00:04 2012 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Fri Jun 22 14:00:04 2012 -0700

----------------------------------------------------------------------
 .../internal/ServiceProxySerializationTest.java    |   96 ---------------
 .../services/ServiceProxySerializationSpec.groovy  |   73 +++++++++++
 2 files changed, 73 insertions(+), 96 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/180766cd/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ServiceProxySerializationTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ServiceProxySerializationTest.java
b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ServiceProxySerializationTest.java
deleted file mode 100644
index a10aa01..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ServiceProxySerializationTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright 2007 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;
-
-import org.apache.tapestry5.ioc.Registry;
-import org.apache.tapestry5.ioc.services.TypeCoercer;
-import org.apache.tapestry5.ioc.test.IOCTestCase;
-import org.testng.annotations.Test;
-
-import java.io.*;
-
-public class ServiceProxySerializationTest extends IOCTestCase
-{
-    @Test
-    public void serialization_deserialization() throws Exception
-    {
-        Registry r = buildRegistry();
-
-        TypeCoercer proxy = r.getService(TypeCoercer.class);
-
-        byte[] serialized = serialize(proxy);
-
-        TypeCoercer proxy2 = deserialize(TypeCoercer.class, serialized);
-
-        assertSame(proxy2, proxy, "De-serialized proxy is same object if Registry unchanged.");
-
-        r.shutdown();
-
-        r = buildRegistry();
-
-        TypeCoercer proxy3 = deserialize(TypeCoercer.class, serialized);
-
-        assertNotNull(proxy3);
-        assertNotSame(proxy3, proxy, "New proxy should be different, as it is from a different
Registry.");
-
-        r.shutdown();
-    }
-
-    @Test
-    public void deserialize_with_no_registry() throws Exception
-    {
-        Registry r = buildRegistry();
-
-        TypeCoercer proxy = r.getService(TypeCoercer.class);
-
-        byte[] serialized = serialize(proxy);
-
-        r.shutdown();
-
-        try
-        {
-            deserialize(TypeCoercer.class, serialized);
-            unreachable();
-        }
-        catch (Exception ex)
-        {
-            assertMessageContains(ex,
-                                  "Service token for service 'TypeCoercer' can not be converted
back into a proxy because no proxy provider has been registered");
-        }
-    }
-
-    private byte[] serialize(Object object) throws IOException
-    {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        ObjectOutputStream oos = new ObjectOutputStream(baos);
-
-        oos.writeObject(object);
-
-        oos.close();
-
-        return baos.toByteArray();
-    }
-
-    private <T> T deserialize(Class<T> type, byte[] serialized) throws IOException,
ClassNotFoundException
-    {
-        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(serialized));
-
-        Object raw = ois.readObject();
-
-        ois.close();
-
-        return type.cast(raw);
-    }
-}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/180766cd/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ServiceProxySerializationSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ServiceProxySerializationSpec.groovy
b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ServiceProxySerializationSpec.groovy
new file mode 100644
index 0000000..a68ae6e
--- /dev/null
+++ b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ServiceProxySerializationSpec.groovy
@@ -0,0 +1,73 @@
+package org.apache.tapestry5.ioc.internal.services
+
+import ioc.specs.AbstractRegistrySpecification
+import org.apache.tapestry5.ioc.services.TypeCoercer
+
+
+class ServiceProxySerializationSpec extends AbstractRegistrySpecification {
+
+  def "test serialization and deserialization of a service"() {
+    buildRegistry()
+
+    TypeCoercer proxy1 = getService TypeCoercer
+
+    def serialized = serialize proxy1
+
+    when:
+
+    TypeCoercer proxy2 = deserialize serialized
+
+    then:
+
+    proxy1.is(proxy2)
+
+    when:
+
+    shutdown()
+    buildRegistry()
+
+    TypeCoercer proxy3 = deserialize serialized
+
+    then:
+
+    !proxy1.is(proxy3)
+  }
+
+  def "deserialize with no registry identifies the service which can not be de-serialized"()
{
+    buildRegistry()
+
+    TypeCoercer proxy1 = getService TypeCoercer
+
+    def serialized = serialize proxy1
+
+
+    when:
+
+    shutdown()
+
+    registry = null
+
+    deserialize(serialized)
+
+    then:
+
+    Exception e = thrown()
+
+    e.message.contains "Service token for service 'TypeCoercer' can not be converted back
into a proxy because no proxy provider has been registered"
+  }
+
+  def serialize(object) {
+    def baos = new ByteArrayOutputStream()
+
+    baos.withObjectOutputStream {
+      it << object
+      it.close()
+    }
+
+    return baos.toByteArray()
+  }
+
+  def deserialize(bytes) {
+    return new ByteArrayInputStream(bytes).newObjectInputStream().readObject()
+  }
+}


Mime
View raw message