river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter_firmst...@apache.org
Subject svn commit: r1450679 - in /river/jtsk/skunk/qa_refactor/trunk/test/src: org/apache/river/api/io/ org/apache/river/api/io/DistributedObjectOutputStreamTest.java tests/support/DistributedObject.java
Date Wed, 27 Feb 2013 08:48:15 GMT
Author: peter_firmstone
Date: Wed Feb 27 08:48:14 2013
New Revision: 1450679

URL: http://svn.apache.org/r1450679
Log:
Distributed object serialization test.

Added:
    river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/
    river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/DistributedObjectOutputStreamTest.java
    river/jtsk/skunk/qa_refactor/trunk/test/src/tests/support/DistributedObject.java

Added: river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/DistributedObjectOutputStreamTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/DistributedObjectOutputStreamTest.java?rev=1450679&view=auto
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/DistributedObjectOutputStreamTest.java
(added)
+++ river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/DistributedObjectOutputStreamTest.java
Wed Feb 27 08:48:14 2013
@@ -0,0 +1,63 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.river.api.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import tests.support.DistributedObject;
+
+/**
+ *
+ * @author peter
+ */
+public class DistributedObjectOutputStreamTest {
+    
+    public DistributedObjectOutputStreamTest() {
+    }
+
+    /**
+     * Test of create method, of class DistributedObjectOutputStream.
+     */
+    @Test
+    public void testCreate() throws Exception {
+        System.out.println("create");
+        DistributedObject expResult = new DistributedObject("Testing");
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        ObjectOutputStream outst = DistributedObjectOutputStream.create(out);
+        outst.writeObject(expResult);
+        ObjectInputStream in = new DistributedObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
+        Object result = in.readObject();
+        assertEquals(expResult.toString(), result.toString());
+        out = new ByteArrayOutputStream();
+        outst = DistributedObjectOutputStream.create(out);
+        expResult = new DistributedObject("Testing", 1);
+        outst.writeObject(expResult);
+        in = new DistributedObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
+        result = in.readObject();
+        assertEquals(expResult.toString(), result.toString());
+        expResult = new DistributedObject("Testing", 2);
+        outst.writeObject(expResult);
+        in = new DistributedObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
+        result = in.readObject();
+        assertEquals(expResult.toString(), result.toString());
+    }
+}

Added: river/jtsk/skunk/qa_refactor/trunk/test/src/tests/support/DistributedObject.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/test/src/tests/support/DistributedObject.java?rev=1450679&view=auto
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/test/src/tests/support/DistributedObject.java (added)
+++ river/jtsk/skunk/qa_refactor/trunk/test/src/tests/support/DistributedObject.java Wed Feb
27 08:48:14 2013
@@ -0,0 +1,93 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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 tests.support;
+
+import java.io.Serializable;
+import org.apache.river.api.io.Distributed;
+import org.apache.river.api.io.SerialFactory;
+
+/**
+ *
+ * @author peter
+ */
+public class DistributedObject implements Distributed {
+    
+    public static DistributedObject create(String str){
+        return new DistributedObject(str);
+    }
+    
+    private final String testString;
+    /* 0 - constructor
+     * 1 - static factory method
+     * 2 - builder
+     */
+    private final int method;
+    
+    public DistributedObject(String str){
+        testString = str;
+        method = 0;
+    }
+    
+    public DistributedObject(String str, int method){
+        testString = str;
+        this.method = method;
+    }
+
+    @Override
+    public SerialFactory substitute() {
+        Class[] signature = new Class[1];
+        Object[] parameters = new Object[1];
+        parameters[0] = testString;
+        if (method == 0){
+            signature[0] = String.class;
+            return new SerialFactory(this.getClass(), null, signature, parameters );
+        }
+        if (method == 1){
+            signature[0] = String.class;
+            return new SerialFactory(this.getClass(), "create", signature, parameters);
+        }
+        if (method == 2){
+            Builder builder = new Builder().setString(testString);
+            return new SerialFactory(builder, "build", null, null);
+        }
+        return null;
+    }
+    
+    public String toString(){
+        return testString;
+    }
+    
+    public static class Builder implements Serializable {
+        private static final long serialVersionUID = 1L;
+        
+        private String str;
+        
+        public Builder(){
+            
+        }
+        
+        public Builder setString(String str){
+            this.str = str;
+            return this;
+        }
+        
+        public DistributedObject build(){
+            return new DistributedObject(str);
+        }
+    }
+    
+}



Mime
View raw message