You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ro...@apache.org on 2007/04/09 23:50:07 UTC
svn commit: r526930 [2/2] - in /webservices/axis2/trunk/java/modules/kernel:
src/org/apache/axis2/util/ObjectStateUtils.java
test/org/apache/axis2/engine/ObjectSaveTest.java
Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/ObjectSaveTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/ObjectSaveTest.java?view=diff&rev=526930&r1=526929&r2=526930
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/ObjectSaveTest.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/ObjectSaveTest.java Mon Apr 9 14:50:06 2007
@@ -17,9 +17,11 @@
package org.apache.axis2.engine;
import junit.framework.TestCase;
+
import org.apache.axis2.util.MetaDataEntry;
import org.apache.axis2.util.ObjectStateUtils;
+import javax.xml.namespace.QName;
import java.io.Externalizable;
import java.io.File;
import java.io.FileInputStream;
@@ -29,63 +31,70 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
-public class ObjectSaveTest extends TestCase {
+public class ObjectSaveTest extends TestCase
+{
private String testArg = null;
// simple constructor needed for nested class Externalizable interface
- public ObjectSaveTest() {
+ public ObjectSaveTest()
+ {
}
- public ObjectSaveTest(String arg0) {
+ public ObjectSaveTest(String arg0)
+ {
super(arg0);
testArg = new String(arg0);
}
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception
+ {
//org.apache.log4j.BasicConfigurator.configure();
}
- public void testObjectSerializable() throws Exception {
- File theFile = null;
- String theFilename = null;
- boolean saved = false;
- boolean restored = false;
- boolean done = false;
+ public void testObjectSerializable() throws Exception
+ {
+ File theFile = null;
+ String theFilename = null;
+ boolean saved = false;
+ boolean restored = false;
+ boolean done = false;
System.out.println("ObjectSaveTest:testObjectSerializable(): BEGIN ---------------");
// ---------------------------------------------------------
// setup an object to use
// ---------------------------------------------------------
- MetaDataEntry obj = new MetaDataEntry("object_1", "object_1");
+ MetaDataEntry obj = new MetaDataEntry("object_1","object_1");
// ---------------------------------------------------------
// setup a temporary file to use
// ---------------------------------------------------------
- try {
- theFile = File.createTempFile("objectTest", null);
+ try
+ {
+ theFile = File.createTempFile("objectTest",null);
theFilename = theFile.getName();
- System.out.println(
- "ObjectSaveTest:testObjectSerializable(): temp file = [" + theFilename + "]");
+ System.out.println("ObjectSaveTest:testObjectSerializable(): temp file = ["+theFilename+"]");
}
- catch (Exception ex) {
- System.out.println(
- "ObjectSaveTest:testObjectSerializable(): error creating temp file = [" +
- ex.getMessage() + "]");
+ catch (Exception ex)
+ {
+ System.out.println("ObjectSaveTest:testObjectSerializable(): error creating temp file = ["+ex.getMessage()+"]");
theFile = null;
}
- if (theFile != null) {
+ if (theFile != null)
+ {
// ---------------------------------------------------------
// save to the temporary file
// ---------------------------------------------------------
- try {
+ try
+ {
// setup an output stream to a physical file
FileOutputStream outStream = new FileOutputStream(theFile);
@@ -105,17 +114,14 @@
outStream.close();
saved = true;
- System.out.println(
- "ObjectSaveTest:testObjectSerializable(): ....save operation completed.....");
+ System.out.println("ObjectSaveTest:testObjectSerializable(): ....save operation completed.....");
long filesize = theFile.length();
- System.out.println(
- "ObjectSaveTest:testObjectSerializable(): file size after save [" +
- filesize + "] temp file = [" + theFilename + "]");
- }
- catch (Exception ex2) {
- System.out.println("ObjectSaveTest:testObjectSerializable(): error during save [" +
- ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
+ System.out.println("ObjectSaveTest:testObjectSerializable(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
+ }
+ catch (Exception ex2)
+ {
+ System.out.println("ObjectSaveTest:testObjectSerializable(): error during save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
ex2.printStackTrace();
}
@@ -124,7 +130,8 @@
// ---------------------------------------------------------
// restore from the temporary file
// ---------------------------------------------------------
- try {
+ try
+ {
// setup an input stream to the file
FileInputStream inStream = new FileInputStream(theFile);
@@ -135,20 +142,17 @@
// try to restore the options
System.out.println("ObjectSaveTest:testObjectSerializable(): restoring .....");
restored = false;
- MetaDataEntry restored_obj = (MetaDataEntry) ObjectStateUtils
- .readObject(inObjStream, "testObject:serializable");
+ MetaDataEntry restored_obj = (MetaDataEntry) ObjectStateUtils.readObject(inObjStream, "testObject:serializable");
inObjStream.close();
inStream.close();
restored = true;
- System.out.println(
- "ObjectSaveTest:testObjectSerializable(): ....restored operation completed.....");
+ System.out.println("ObjectSaveTest:testObjectSerializable(): ....restored operation completed.....");
}
- catch (Exception ex2) {
- System.out.println(
- "ObjectSaveTest:testObjectSerializable(): error during restore [" +
- ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
+ catch (Exception ex2)
+ {
+ System.out.println("ObjectSaveTest:testObjectSerializable(): error during restore ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
ex2.printStackTrace();
}
@@ -157,11 +161,14 @@
// if the save/restore of the object succeeded,
// then don't keep the temporary file around
boolean removeTmpFile = saved && restored;
- if (removeTmpFile) {
- try {
+ if (removeTmpFile)
+ {
+ try
+ {
theFile.delete();
}
- catch (Exception e) {
+ catch (Exception e)
+ {
// just absorb it
}
}
@@ -177,84 +184,87 @@
}
- public void testObjectNotSerializable() throws Exception {
- File theFile = null;
- String theFilename = null;
- boolean saved = false;
- boolean restored = false;
- boolean expected_exception = false;
- boolean done = false;
+ public void testObjectNotSerializable() throws Exception
+ {
+ File theFile = null;
+ String theFilename = null;
+ boolean saved = false;
+ boolean restored = false;
+ boolean expected_exception = false;
+ boolean done = false;
System.out.println("ObjectSaveTest:testObjectNotSerializable(): BEGIN ---------------");
// ---------------------------------------------------------
// setup an object to use
// ---------------------------------------------------------
- NotSerializableObject obj = new NotSerializableObject("nso_1");
+ NotSerializableObject obj = new NotSerializableObject("nso_1");
+
// ---------------------------------------------------------
// setup a temporary file to use
// ---------------------------------------------------------
- try {
- theFile = File.createTempFile("objectTest", null);
+ try
+ {
+ theFile = File.createTempFile("objectTest",null);
theFilename = theFile.getName();
- System.out.println("ObjectSaveTest:testObjectNotSerializable(): temp file = [" +
- theFilename + "]");
+ System.out.println("ObjectSaveTest:testObjectNotSerializable(): temp file = ["+theFilename+"]");
}
- catch (Exception ex) {
- System.out.println(
- "ObjectSaveTest:testObjectNotSerializable(): error creating temp file = [" +
- ex.getMessage() + "]");
+ catch (Exception ex)
+ {
+ System.out.println("ObjectSaveTest:testObjectNotSerializable(): error creating temp file = ["+ex.getMessage()+"]");
theFile = null;
}
- if (theFile != null) {
+ if (theFile != null)
+ {
// ---------------------------------------------------------
// save to the temporary file
// ---------------------------------------------------------
- try {
+ FileOutputStream outStream = null;
+ ObjectOutputStream outObjStream = null;
+ try
+ {
// setup an output stream to a physical file
- FileOutputStream outStream = new FileOutputStream(theFile);
+ outStream = new FileOutputStream(theFile);
// attach a stream capable of writing objects to the
// stream connected to the file
- ObjectOutputStream outObjStream = new ObjectOutputStream(outStream);
+ outObjStream = new ObjectOutputStream(outStream);
// try to save
System.out.println("ObjectSaveTest:testObjectNotSerializable(): saving .....");
saved = false;
ObjectStateUtils.writeObject(outObjStream, obj, "testObject:NotSerializable");
- // close out the streams
- outObjStream.flush();
- outObjStream.close();
- outStream.flush();
- outStream.close();
-
saved = true;
- System.out.println(
- "ObjectSaveTest:testObjectNotSerializable(): ....save operation completed.....");
+ System.out.println("ObjectSaveTest:testObjectNotSerializable(): ....save operation completed.....");
long filesize = theFile.length();
- System.out.println(
- "ObjectSaveTest:testObjectNotSerializable(): file size after save [" +
- filesize + "] temp file = [" + theFilename + "]");
+ System.out.println("ObjectSaveTest:testObjectNotSerializable(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
}
- catch (Exception ex2) {
+ catch (Exception ex2)
+ {
// expect an error here
// ObjectStateUtils catches the NotSerializableException and logs it
- if (ex2 instanceof NotSerializableException) {
+ if (ex2 instanceof NotSerializableException)
+ {
expected_exception = true;
- } else {
- System.out.println("ObjectSaveTest:testObjectNotSerializable(): save [" +
- ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
+ }
+ else
+ {
+ System.out.println("ObjectSaveTest:testObjectNotSerializable(): save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
}
}
+ // close out the streams
+ if(outObjStream != null) outObjStream.close();
+ if(outStream != null) outStream.close();
// ---------------------------------------------------------
// restore from the temporary file
// ---------------------------------------------------------
- try {
+ try
+ {
// setup an input stream to the file
FileInputStream inStream = new FileInputStream(theFile);
@@ -265,20 +275,17 @@
// try to restore the options
System.out.println("ObjectSaveTest:testObjectSerializable(): restoring .....");
restored = false;
- Object restored_obj =
- ObjectStateUtils.readObject(inObjStream, "testObject:NotSerializable");
+ Object restored_obj = ObjectStateUtils.readObject(inObjStream, "testObject:NotSerializable");
inObjStream.close();
inStream.close();
restored = true;
- System.out.println(
- "ObjectSaveTest:testObjectNotSerializable(): ....restored operation completed.....");
+ System.out.println("ObjectSaveTest:testObjectNotSerializable(): ....restored operation completed.....");
}
- catch (Exception ex) {
- System.out.println(
- "ObjectSaveTest:testObjectNotSerializable(): error during restore [" +
- ex.getClass().getName() + " : " + ex.getMessage() + "]");
+ catch (Exception ex)
+ {
+ System.out.println("ObjectSaveTest:testObjectNotSerializable(): error during restore ["+ex.getClass().getName()+" : "+ex.getMessage()+"]");
ex.printStackTrace();
}
@@ -287,11 +294,14 @@
// if the save/restore of the object succeeded,
// then don't keep the temporary file around
boolean removeTmpFile = saved && restored;
- if (removeTmpFile) {
- try {
+ if (removeTmpFile)
+ {
+ try
+ {
theFile.delete();
}
- catch (Exception e) {
+ catch (Exception e)
+ {
// just absorb it
}
}
@@ -303,13 +313,14 @@
}
- public void testArrayList() throws Exception {
- File theFile = null;
- String theFilename = null;
- boolean saved = false;
- boolean restored = false;
- boolean done = false;
- boolean comparesOK = false;
+ public void testArrayList() throws Exception
+ {
+ File theFile = null;
+ String theFilename = null;
+ boolean saved = false;
+ boolean restored = false;
+ boolean done = false;
+ boolean comparesOK = false;
System.out.println("ObjectSaveTest:testArrayList(): BEGIN ---------------");
@@ -333,22 +344,25 @@
// ---------------------------------------------------------
// setup a temporary file to use
// ---------------------------------------------------------
- try {
- theFile = File.createTempFile("arraylistTest", null);
+ try
+ {
+ theFile = File.createTempFile("arraylistTest",null);
theFilename = theFile.getName();
- System.out.println("ObjectSaveTest:testArrayList(): temp file = [" + theFilename + "]");
+ System.out.println("ObjectSaveTest:testArrayList(): temp file = ["+theFilename+"]");
}
- catch (Exception ex) {
- System.out.println("ObjectSaveTest:testArrayList(): error creating temp file = [" +
- ex.getMessage() + "]");
+ catch (Exception ex)
+ {
+ System.out.println("ObjectSaveTest:testArrayList(): error creating temp file = ["+ex.getMessage()+"]");
theFile = null;
}
- if (theFile != null) {
+ if (theFile != null)
+ {
// ---------------------------------------------------------
// save to the temporary file
// ---------------------------------------------------------
- try {
+ try
+ {
// setup an output stream to a physical file
FileOutputStream outStream = new FileOutputStream(theFile);
@@ -368,16 +382,14 @@
outStream.close();
saved = true;
- System.out.println(
- "ObjectSaveTest:testArrayList(): ....save operation completed.....");
+ System.out.println("ObjectSaveTest:testArrayList(): ....save operation completed.....");
long filesize = theFile.length();
- System.out.println("ObjectSaveTest:testArrayList(): file size after save [" +
- filesize + "] temp file = [" + theFilename + "]");
+ System.out.println("ObjectSaveTest:testArrayList(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
}
- catch (Exception ex2) {
- System.out.println("ObjectSaveTest:testArrayList(): error during save [" +
- ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
+ catch (Exception ex2)
+ {
+ System.out.println("ObjectSaveTest:testArrayList(): error during save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
ex2.printStackTrace();
}
@@ -388,7 +400,8 @@
// ---------------------------------------------------------
ArrayList restored_obj = null;
- try {
+ try
+ {
// setup an input stream to the file
FileInputStream inStream = new FileInputStream(theFile);
@@ -404,33 +417,37 @@
inStream.close();
restored = true;
- System.out.println(
- "ObjectSaveTest:testArrayList(): ....restored operation completed.....");
+ System.out.println("ObjectSaveTest:testArrayList(): ....restored operation completed.....");
}
- catch (Exception ex2) {
- System.out.println("ObjectSaveTest:testArrayList(): error during restore [" +
- ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
+ catch (Exception ex2)
+ {
+ System.out.println("ObjectSaveTest:testArrayList(): error during restore ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
ex2.printStackTrace();
}
// if the save/restore of the object succeeded,
// then don't keep the temporary file around
boolean removeTmpFile = saved && restored;
- if (removeTmpFile) {
- try {
+ if (removeTmpFile)
+ {
+ try
+ {
theFile.delete();
}
- catch (Exception e) {
+ catch (Exception e)
+ {
// just absorb it
}
}
assertTrue(restored);
- if (restored_obj != null) {
+ if (restored_obj != null)
+ {
int restored_size = restored_obj.size();
- if (restored_size == (initial_size - 1)) {
+ if (restored_size == (initial_size-1))
+ {
comparesOK = true;
}
}
@@ -438,7 +455,7 @@
// TODO: check for exact entries
assertTrue(comparesOK);
-
+
// indicate that the temp file was created ok
done = true;
}
@@ -450,13 +467,14 @@
}
- public void testHashMap() throws Exception {
- File theFile = null;
- String theFilename = null;
- boolean saved = false;
- boolean restored = false;
- boolean done = false;
- boolean comparesOK = false;
+ public void testHashMap() throws Exception
+ {
+ File theFile = null;
+ String theFilename = null;
+ boolean saved = false;
+ boolean restored = false;
+ boolean done = false;
+ boolean comparesOK = false;
System.out.println("ObjectSaveTest:testHashMap(): BEGIN ---------------");
@@ -474,7 +492,7 @@
obj.put(new String("key8"), new Integer(5));
obj.put(new String("key9"), new Integer(6));
obj.put(new NotSerializableObject("TestForHashMapKey"), new Integer(7));
- obj.put(new String("key10"), new Integer(8));
+ obj.put(new String("key10"),new Integer(8));
int initial_size = obj.size();
@@ -482,22 +500,25 @@
// ---------------------------------------------------------
// setup a temporary file to use
// ---------------------------------------------------------
- try {
- theFile = File.createTempFile("hashmapTest", null);
+ try
+ {
+ theFile = File.createTempFile("hashmapTest",null);
theFilename = theFile.getName();
- System.out.println("ObjectSaveTest:testHashMap(): temp file = [" + theFilename + "]");
+ System.out.println("ObjectSaveTest:testHashMap(): temp file = ["+theFilename+"]");
}
- catch (Exception ex) {
- System.out.println("ObjectSaveTest:testHashMap(): error creating temp file = [" +
- ex.getMessage() + "]");
+ catch (Exception ex)
+ {
+ System.out.println("ObjectSaveTest:testHashMap(): error creating temp file = ["+ex.getMessage()+"]");
theFile = null;
}
- if (theFile != null) {
+ if (theFile != null)
+ {
// ---------------------------------------------------------
// save to the temporary file
// ---------------------------------------------------------
- try {
+ try
+ {
// setup an output stream to a physical file
FileOutputStream outStream = new FileOutputStream(theFile);
@@ -517,16 +538,14 @@
outStream.close();
saved = true;
- System.out
- .println("ObjectSaveTest:testHashMap(): ....save operation completed.....");
+ System.out.println("ObjectSaveTest:testHashMap(): ....save operation completed.....");
long filesize = theFile.length();
- System.out.println("ObjectSaveTest:testHashMap(): file size after save [" +
- filesize + "] temp file = [" + theFilename + "]");
+ System.out.println("ObjectSaveTest:testHashMap(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
}
- catch (Exception ex2) {
- System.out.println("ObjectSaveTest:testHashMap(): error during save [" +
- ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
+ catch (Exception ex2)
+ {
+ System.out.println("ObjectSaveTest:testHashMap(): error during save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
ex2.printStackTrace();
}
@@ -537,7 +556,8 @@
// ---------------------------------------------------------
HashMap restored_obj = null;
- try {
+ try
+ {
// setup an input stream to the file
FileInputStream inStream = new FileInputStream(theFile);
@@ -553,33 +573,37 @@
inStream.close();
restored = true;
- System.out.println(
- "ObjectSaveTest:testHashMap(): ....restored operation completed.....");
+ System.out.println("ObjectSaveTest:testHashMap(): ....restored operation completed.....");
}
- catch (Exception ex2) {
- System.out.println("ObjectSaveTest:testHashMap(): error during restore [" +
- ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
+ catch (Exception ex2)
+ {
+ System.out.println("ObjectSaveTest:testHashMap(): error during restore ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
ex2.printStackTrace();
}
// if the save/restore of the object succeeded,
// then don't keep the temporary file around
boolean removeTmpFile = saved && restored;
- if (removeTmpFile) {
- try {
+ if (removeTmpFile)
+ {
+ try
+ {
theFile.delete();
}
- catch (Exception e) {
+ catch (Exception e)
+ {
// just absorb it
}
}
assertTrue(restored);
- if (restored_obj != null) {
+ if (restored_obj != null)
+ {
int restored_size = restored_obj.size();
- if (restored_size == (initial_size - 3)) {
+ if (restored_size == (initial_size-3))
+ {
// there are entries in the map that are not serializable
comparesOK = true;
}
@@ -588,7 +612,7 @@
// TODO: check for exact entries
assertTrue(comparesOK);
-
+
// indicate that the temp file was created ok
done = true;
}
@@ -600,13 +624,14 @@
}
- public void testLinkedList() throws Exception {
- File theFile = null;
- String theFilename = null;
- boolean saved = false;
- boolean restored = false;
- boolean done = false;
- boolean comparesOK = false;
+ public void testLinkedList() throws Exception
+ {
+ File theFile = null;
+ String theFilename = null;
+ boolean saved = false;
+ boolean restored = false;
+ boolean done = false;
+ boolean comparesOK = false;
System.out.println("ObjectSaveTest:testLinkedList(): BEGIN ---------------");
@@ -630,23 +655,25 @@
// ---------------------------------------------------------
// setup a temporary file to use
// ---------------------------------------------------------
- try {
- theFile = File.createTempFile("linkedlistTest", null);
+ try
+ {
+ theFile = File.createTempFile("linkedlistTest",null);
theFilename = theFile.getName();
- System.out
- .println("ObjectSaveTest:testLinkedList(): temp file = [" + theFilename + "]");
+ System.out.println("ObjectSaveTest:testLinkedList(): temp file = ["+theFilename+"]");
}
- catch (Exception ex) {
- System.out.println("ObjectSaveTest:testLinkedList(): error creating temp file = [" +
- ex.getMessage() + "]");
+ catch (Exception ex)
+ {
+ System.out.println("ObjectSaveTest:testLinkedList(): error creating temp file = ["+ex.getMessage()+"]");
theFile = null;
}
- if (theFile != null) {
+ if (theFile != null)
+ {
// ---------------------------------------------------------
// save to the temporary file
// ---------------------------------------------------------
- try {
+ try
+ {
// setup an output stream to a physical file
FileOutputStream outStream = new FileOutputStream(theFile);
@@ -666,16 +693,14 @@
outStream.close();
saved = true;
- System.out.println(
- "ObjectSaveTest:testLinkedList(): ....save operation completed.....");
+ System.out.println("ObjectSaveTest:testLinkedList(): ....save operation completed.....");
long filesize = theFile.length();
- System.out.println("ObjectSaveTest:testLinkedList(): file size after save [" +
- filesize + "] temp file = [" + theFilename + "]");
+ System.out.println("ObjectSaveTest:testLinkedList(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
}
- catch (Exception ex2) {
- System.out.println("ObjectSaveTest:testLinkedList(): error during save [" +
- ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
+ catch (Exception ex2)
+ {
+ System.out.println("ObjectSaveTest:testLinkedList(): error during save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
ex2.printStackTrace();
}
@@ -686,7 +711,8 @@
// ---------------------------------------------------------
LinkedList restored_obj = null;
- try {
+ try
+ {
// setup an input stream to the file
FileInputStream inStream = new FileInputStream(theFile);
@@ -697,39 +723,42 @@
// try to restore the options
System.out.println("ObjectSaveTest:testLinkedList(): restoring .....");
restored = false;
- restored_obj =
- ObjectStateUtils.readLinkedList(inObjStream, "testObject:LinkedList");
+ restored_obj = ObjectStateUtils.readLinkedList(inObjStream, "testObject:LinkedList");
inObjStream.close();
inStream.close();
restored = true;
- System.out.println(
- "ObjectSaveTest:testLinkedList(): ....restored operation completed.....");
+ System.out.println("ObjectSaveTest:testLinkedList(): ....restored operation completed.....");
}
- catch (Exception ex2) {
- System.out.println("ObjectSaveTest:testLinkedList(): error during restore [" +
- ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
+ catch (Exception ex2)
+ {
+ System.out.println("ObjectSaveTest:testLinkedList(): error during restore ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
ex2.printStackTrace();
}
// if the save/restore of the object succeeded,
// then don't keep the temporary file around
boolean removeTmpFile = saved && restored;
- if (removeTmpFile) {
- try {
+ if (removeTmpFile)
+ {
+ try
+ {
theFile.delete();
}
- catch (Exception e) {
+ catch (Exception e)
+ {
// just absorb it
}
}
assertTrue(restored);
- if (restored_obj != null) {
+ if (restored_obj != null)
+ {
int restored_size = restored_obj.size();
- if (restored_size == (initial_size - 1)) {
+ if (restored_size == (initial_size-1))
+ {
comparesOK = true;
}
}
@@ -737,7 +766,7 @@
// TODO: check for exact entries
assertTrue(comparesOK);
-
+
// indicate that the temp file was created ok
done = true;
}
@@ -749,7 +778,10 @@
}
- public class NotSerializableObject implements Externalizable {
+
+
+ public class NotSerializableObject implements Externalizable
+ {
private String label = "TestObject";
private String ID = null;
@@ -757,29 +789,34 @@
private PrintStream ps = System.out;
// default constructor needed for Externalizable interface
- public NotSerializableObject() {
+ public NotSerializableObject()
+ {
}
- public NotSerializableObject(String identifier) {
+ public NotSerializableObject(String identifier)
+ {
ID = identifier;
ps = System.out;
}
-
- public void setID(String s) {
+
+ public void setID(String s)
+ {
ID = s;
}
- public String getID() {
+ public String getID()
+ {
return ID;
}
- public void writeExternal(java.io.ObjectOutput out) throws IOException {
+ public void writeExternal(java.io.ObjectOutput out) throws IOException
+ {
throw new NotSerializableException("Test Object is not serializable");
}
- public void readExternal(java.io.ObjectInput in)
- throws IOException, ClassNotFoundException {
+ public void readExternal(java.io.ObjectInput in) throws IOException, ClassNotFoundException
+ {
throw new IOException("Test object is not serializable");
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org
Re: svn commit: r526930 [2/2] - in /webservices/axis2/trunk/java/modules/kernel: src/org/apache/axis2/util/ObjectStateUtils.java test/org/apache/axis2/engine/ObjectSaveTest.java
Posted by Davanum Srinivas <da...@gmail.com>.
Ann,
Could you please avoid reformatting???
thanks,
dims
> On 4/9/07, robinsona@apache.org <ro...@apache.org> wrote:
> > Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/ObjectSaveTest.java
> > URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/ObjectSaveTest.java?view=diff&rev=526930&r1=526929&r2=526930
> > ==============================================================================
> > --- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/ObjectSaveTest.java (original)
> > +++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/ObjectSaveTest.java Mon Apr 9 14:50:06 2007
> > @@ -17,9 +17,11 @@
> > package org.apache.axis2.engine;
> >
> > import junit.framework.TestCase;
> > +
> > import org.apache.axis2.util.MetaDataEntry;
> > import org.apache.axis2.util.ObjectStateUtils;
> >
> > +import javax.xml.namespace.QName;
> > import java.io.Externalizable;
> > import java.io.File;
> > import java.io.FileInputStream;
> > @@ -29,63 +31,70 @@
> > import java.io.ObjectInputStream;
> > import java.io.ObjectOutputStream;
> > import java.io.PrintStream;
> > +import java.io.Serializable;
> > import java.util.ArrayList;
> > import java.util.HashMap;
> > import java.util.LinkedList;
> >
> > -public class ObjectSaveTest extends TestCase {
> > +public class ObjectSaveTest extends TestCase
> > +{
> > private String testArg = null;
> >
> > // simple constructor needed for nested class Externalizable interface
> > - public ObjectSaveTest() {
> > + public ObjectSaveTest()
> > + {
> > }
> >
> > - public ObjectSaveTest(String arg0) {
> > + public ObjectSaveTest(String arg0)
> > + {
> > super(arg0);
> > testArg = new String(arg0);
> > }
> >
> >
> > - protected void setUp() throws Exception {
> > + protected void setUp() throws Exception
> > + {
> > //org.apache.log4j.BasicConfigurator.configure();
> > }
> >
> >
> > - public void testObjectSerializable() throws Exception {
> > - File theFile = null;
> > - String theFilename = null;
> > - boolean saved = false;
> > - boolean restored = false;
> > - boolean done = false;
> > + public void testObjectSerializable() throws Exception
> > + {
> > + File theFile = null;
> > + String theFilename = null;
> > + boolean saved = false;
> > + boolean restored = false;
> > + boolean done = false;
> >
> > System.out.println("ObjectSaveTest:testObjectSerializable(): BEGIN ---------------");
> >
> > // ---------------------------------------------------------
> > // setup an object to use
> > // ---------------------------------------------------------
> > - MetaDataEntry obj = new MetaDataEntry("object_1", "object_1");
> > + MetaDataEntry obj = new MetaDataEntry("object_1","object_1");
> >
> > // ---------------------------------------------------------
> > // setup a temporary file to use
> > // ---------------------------------------------------------
> > - try {
> > - theFile = File.createTempFile("objectTest", null);
> > + try
> > + {
> > + theFile = File.createTempFile("objectTest",null);
> > theFilename = theFile.getName();
> > - System.out.println(
> > - "ObjectSaveTest:testObjectSerializable(): temp file = [" + theFilename + "]");
> > + System.out.println("ObjectSaveTest:testObjectSerializable(): temp file = ["+theFilename+"]");
> > }
> > - catch (Exception ex) {
> > - System.out.println(
> > - "ObjectSaveTest:testObjectSerializable(): error creating temp file = [" +
> > - ex.getMessage() + "]");
> > + catch (Exception ex)
> > + {
> > + System.out.println("ObjectSaveTest:testObjectSerializable(): error creating temp file = ["+ex.getMessage()+"]");
> > theFile = null;
> > }
> >
> > - if (theFile != null) {
> > + if (theFile != null)
> > + {
> > // ---------------------------------------------------------
> > // save to the temporary file
> > // ---------------------------------------------------------
> > - try {
> > + try
> > + {
> > // setup an output stream to a physical file
> > FileOutputStream outStream = new FileOutputStream(theFile);
> >
> > @@ -105,17 +114,14 @@
> > outStream.close();
> >
> > saved = true;
> > - System.out.println(
> > - "ObjectSaveTest:testObjectSerializable(): ....save operation completed.....");
> > + System.out.println("ObjectSaveTest:testObjectSerializable(): ....save operation completed.....");
> >
> > long filesize = theFile.length();
> > - System.out.println(
> > - "ObjectSaveTest:testObjectSerializable(): file size after save [" +
> > - filesize + "] temp file = [" + theFilename + "]");
> > - }
> > - catch (Exception ex2) {
> > - System.out.println("ObjectSaveTest:testObjectSerializable(): error during save [" +
> > - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> > + System.out.println("ObjectSaveTest:testObjectSerializable(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
> > + }
> > + catch (Exception ex2)
> > + {
> > + System.out.println("ObjectSaveTest:testObjectSerializable(): error during save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> > ex2.printStackTrace();
> > }
> >
> > @@ -124,7 +130,8 @@
> > // ---------------------------------------------------------
> > // restore from the temporary file
> > // ---------------------------------------------------------
> > - try {
> > + try
> > + {
> > // setup an input stream to the file
> > FileInputStream inStream = new FileInputStream(theFile);
> >
> > @@ -135,20 +142,17 @@
> > // try to restore the options
> > System.out.println("ObjectSaveTest:testObjectSerializable(): restoring .....");
> > restored = false;
> > - MetaDataEntry restored_obj = (MetaDataEntry) ObjectStateUtils
> > - .readObject(inObjStream, "testObject:serializable");
> > + MetaDataEntry restored_obj = (MetaDataEntry) ObjectStateUtils.readObject(inObjStream, "testObject:serializable");
> > inObjStream.close();
> > inStream.close();
> >
> > restored = true;
> > - System.out.println(
> > - "ObjectSaveTest:testObjectSerializable(): ....restored operation completed.....");
> > + System.out.println("ObjectSaveTest:testObjectSerializable(): ....restored operation completed.....");
> >
> > }
> > - catch (Exception ex2) {
> > - System.out.println(
> > - "ObjectSaveTest:testObjectSerializable(): error during restore [" +
> > - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> > + catch (Exception ex2)
> > + {
> > + System.out.println("ObjectSaveTest:testObjectSerializable(): error during restore ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> > ex2.printStackTrace();
> > }
> >
> > @@ -157,11 +161,14 @@
> > // if the save/restore of the object succeeded,
> > // then don't keep the temporary file around
> > boolean removeTmpFile = saved && restored;
> > - if (removeTmpFile) {
> > - try {
> > + if (removeTmpFile)
> > + {
> > + try
> > + {
> > theFile.delete();
> > }
> > - catch (Exception e) {
> > + catch (Exception e)
> > + {
> > // just absorb it
> > }
> > }
> > @@ -177,84 +184,87 @@
> > }
> >
> >
> > - public void testObjectNotSerializable() throws Exception {
> > - File theFile = null;
> > - String theFilename = null;
> > - boolean saved = false;
> > - boolean restored = false;
> > - boolean expected_exception = false;
> > - boolean done = false;
> > + public void testObjectNotSerializable() throws Exception
> > + {
> > + File theFile = null;
> > + String theFilename = null;
> > + boolean saved = false;
> > + boolean restored = false;
> > + boolean expected_exception = false;
> > + boolean done = false;
> >
> > System.out.println("ObjectSaveTest:testObjectNotSerializable(): BEGIN ---------------");
> >
> > // ---------------------------------------------------------
> > // setup an object to use
> > // ---------------------------------------------------------
> > - NotSerializableObject obj = new NotSerializableObject("nso_1");
> > + NotSerializableObject obj = new NotSerializableObject("nso_1");
> > +
> >
> > // ---------------------------------------------------------
> > // setup a temporary file to use
> > // ---------------------------------------------------------
> > - try {
> > - theFile = File.createTempFile("objectTest", null);
> > + try
> > + {
> > + theFile = File.createTempFile("objectTest",null);
> > theFilename = theFile.getName();
> > - System.out.println("ObjectSaveTest:testObjectNotSerializable(): temp file = [" +
> > - theFilename + "]");
> > + System.out.println("ObjectSaveTest:testObjectNotSerializable(): temp file = ["+theFilename+"]");
> > }
> > - catch (Exception ex) {
> > - System.out.println(
> > - "ObjectSaveTest:testObjectNotSerializable(): error creating temp file = [" +
> > - ex.getMessage() + "]");
> > + catch (Exception ex)
> > + {
> > + System.out.println("ObjectSaveTest:testObjectNotSerializable(): error creating temp file = ["+ex.getMessage()+"]");
> > theFile = null;
> > }
> >
> > - if (theFile != null) {
> > + if (theFile != null)
> > + {
> > // ---------------------------------------------------------
> > // save to the temporary file
> > // ---------------------------------------------------------
> > - try {
> > + FileOutputStream outStream = null;
> > + ObjectOutputStream outObjStream = null;
> > + try
> > + {
> > // setup an output stream to a physical file
> > - FileOutputStream outStream = new FileOutputStream(theFile);
> > + outStream = new FileOutputStream(theFile);
> >
> > // attach a stream capable of writing objects to the
> > // stream connected to the file
> > - ObjectOutputStream outObjStream = new ObjectOutputStream(outStream);
> > + outObjStream = new ObjectOutputStream(outStream);
> >
> > // try to save
> > System.out.println("ObjectSaveTest:testObjectNotSerializable(): saving .....");
> > saved = false;
> > ObjectStateUtils.writeObject(outObjStream, obj, "testObject:NotSerializable");
> >
> > - // close out the streams
> > - outObjStream.flush();
> > - outObjStream.close();
> > - outStream.flush();
> > - outStream.close();
> > -
> > saved = true;
> > - System.out.println(
> > - "ObjectSaveTest:testObjectNotSerializable(): ....save operation completed.....");
> > + System.out.println("ObjectSaveTest:testObjectNotSerializable(): ....save operation completed.....");
> >
> > long filesize = theFile.length();
> > - System.out.println(
> > - "ObjectSaveTest:testObjectNotSerializable(): file size after save [" +
> > - filesize + "] temp file = [" + theFilename + "]");
> > + System.out.println("ObjectSaveTest:testObjectNotSerializable(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
> > }
> > - catch (Exception ex2) {
> > + catch (Exception ex2)
> > + {
> > // expect an error here
> > // ObjectStateUtils catches the NotSerializableException and logs it
> > - if (ex2 instanceof NotSerializableException) {
> > + if (ex2 instanceof NotSerializableException)
> > + {
> > expected_exception = true;
> > - } else {
> > - System.out.println("ObjectSaveTest:testObjectNotSerializable(): save [" +
> > - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> > + }
> > + else
> > + {
> > + System.out.println("ObjectSaveTest:testObjectNotSerializable(): save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> > }
> > }
> > + // close out the streams
> > + if(outObjStream != null) outObjStream.close();
> > + if(outStream != null) outStream.close();
> >
> > // ---------------------------------------------------------
> > // restore from the temporary file
> > // ---------------------------------------------------------
> > - try {
> > + try
> > + {
> > // setup an input stream to the file
> > FileInputStream inStream = new FileInputStream(theFile);
> >
> > @@ -265,20 +275,17 @@
> > // try to restore the options
> > System.out.println("ObjectSaveTest:testObjectSerializable(): restoring .....");
> > restored = false;
> > - Object restored_obj =
> > - ObjectStateUtils.readObject(inObjStream, "testObject:NotSerializable");
> > + Object restored_obj = ObjectStateUtils.readObject(inObjStream, "testObject:NotSerializable");
> > inObjStream.close();
> > inStream.close();
> >
> > restored = true;
> > - System.out.println(
> > - "ObjectSaveTest:testObjectNotSerializable(): ....restored operation completed.....");
> > + System.out.println("ObjectSaveTest:testObjectNotSerializable(): ....restored operation completed.....");
> >
> > }
> > - catch (Exception ex) {
> > - System.out.println(
> > - "ObjectSaveTest:testObjectNotSerializable(): error during restore [" +
> > - ex.getClass().getName() + " : " + ex.getMessage() + "]");
> > + catch (Exception ex)
> > + {
> > + System.out.println("ObjectSaveTest:testObjectNotSerializable(): error during restore ["+ex.getClass().getName()+" : "+ex.getMessage()+"]");
> > ex.printStackTrace();
> > }
> >
> > @@ -287,11 +294,14 @@
> > // if the save/restore of the object succeeded,
> > // then don't keep the temporary file around
> > boolean removeTmpFile = saved && restored;
> > - if (removeTmpFile) {
> > - try {
> > + if (removeTmpFile)
> > + {
> > + try
> > + {
> > theFile.delete();
> > }
> > - catch (Exception e) {
> > + catch (Exception e)
> > + {
> > // just absorb it
> > }
> > }
> > @@ -303,13 +313,14 @@
> > }
> >
> >
> > - public void testArrayList() throws Exception {
> > - File theFile = null;
> > - String theFilename = null;
> > - boolean saved = false;
> > - boolean restored = false;
> > - boolean done = false;
> > - boolean comparesOK = false;
> > + public void testArrayList() throws Exception
> > + {
> > + File theFile = null;
> > + String theFilename = null;
> > + boolean saved = false;
> > + boolean restored = false;
> > + boolean done = false;
> > + boolean comparesOK = false;
> >
> > System.out.println("ObjectSaveTest:testArrayList(): BEGIN ---------------");
> >
> > @@ -333,22 +344,25 @@
> > // ---------------------------------------------------------
> > // setup a temporary file to use
> > // ---------------------------------------------------------
> > - try {
> > - theFile = File.createTempFile("arraylistTest", null);
> > + try
> > + {
> > + theFile = File.createTempFile("arraylistTest",null);
> > theFilename = theFile.getName();
> > - System.out.println("ObjectSaveTest:testArrayList(): temp file = [" + theFilename + "]");
> > + System.out.println("ObjectSaveTest:testArrayList(): temp file = ["+theFilename+"]");
> > }
> > - catch (Exception ex) {
> > - System.out.println("ObjectSaveTest:testArrayList(): error creating temp file = [" +
> > - ex.getMessage() + "]");
> > + catch (Exception ex)
> > + {
> > + System.out.println("ObjectSaveTest:testArrayList(): error creating temp file = ["+ex.getMessage()+"]");
> > theFile = null;
> > }
> >
> > - if (theFile != null) {
> > + if (theFile != null)
> > + {
> > // ---------------------------------------------------------
> > // save to the temporary file
> > // ---------------------------------------------------------
> > - try {
> > + try
> > + {
> > // setup an output stream to a physical file
> > FileOutputStream outStream = new FileOutputStream(theFile);
> >
> > @@ -368,16 +382,14 @@
> > outStream.close();
> >
> > saved = true;
> > - System.out.println(
> > - "ObjectSaveTest:testArrayList(): ....save operation completed.....");
> > + System.out.println("ObjectSaveTest:testArrayList(): ....save operation completed.....");
> >
> > long filesize = theFile.length();
> > - System.out.println("ObjectSaveTest:testArrayList(): file size after save [" +
> > - filesize + "] temp file = [" + theFilename + "]");
> > + System.out.println("ObjectSaveTest:testArrayList(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
> > }
> > - catch (Exception ex2) {
> > - System.out.println("ObjectSaveTest:testArrayList(): error during save [" +
> > - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> > + catch (Exception ex2)
> > + {
> > + System.out.println("ObjectSaveTest:testArrayList(): error during save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> > ex2.printStackTrace();
> > }
> >
> > @@ -388,7 +400,8 @@
> > // ---------------------------------------------------------
> > ArrayList restored_obj = null;
> >
> > - try {
> > + try
> > + {
> > // setup an input stream to the file
> > FileInputStream inStream = new FileInputStream(theFile);
> >
> > @@ -404,33 +417,37 @@
> > inStream.close();
> >
> > restored = true;
> > - System.out.println(
> > - "ObjectSaveTest:testArrayList(): ....restored operation completed.....");
> > + System.out.println("ObjectSaveTest:testArrayList(): ....restored operation completed.....");
> >
> > }
> > - catch (Exception ex2) {
> > - System.out.println("ObjectSaveTest:testArrayList(): error during restore [" +
> > - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> > + catch (Exception ex2)
> > + {
> > + System.out.println("ObjectSaveTest:testArrayList(): error during restore ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> > ex2.printStackTrace();
> > }
> >
> > // if the save/restore of the object succeeded,
> > // then don't keep the temporary file around
> > boolean removeTmpFile = saved && restored;
> > - if (removeTmpFile) {
> > - try {
> > + if (removeTmpFile)
> > + {
> > + try
> > + {
> > theFile.delete();
> > }
> > - catch (Exception e) {
> > + catch (Exception e)
> > + {
> > // just absorb it
> > }
> > }
> >
> > assertTrue(restored);
> >
> > - if (restored_obj != null) {
> > + if (restored_obj != null)
> > + {
> > int restored_size = restored_obj.size();
> > - if (restored_size == (initial_size - 1)) {
> > + if (restored_size == (initial_size-1))
> > + {
> > comparesOK = true;
> > }
> > }
> > @@ -438,7 +455,7 @@
> > // TODO: check for exact entries
> >
> > assertTrue(comparesOK);
> > -
> > +
> > // indicate that the temp file was created ok
> > done = true;
> > }
> > @@ -450,13 +467,14 @@
> > }
> >
> >
> > - public void testHashMap() throws Exception {
> > - File theFile = null;
> > - String theFilename = null;
> > - boolean saved = false;
> > - boolean restored = false;
> > - boolean done = false;
> > - boolean comparesOK = false;
> > + public void testHashMap() throws Exception
> > + {
> > + File theFile = null;
> > + String theFilename = null;
> > + boolean saved = false;
> > + boolean restored = false;
> > + boolean done = false;
> > + boolean comparesOK = false;
> >
> > System.out.println("ObjectSaveTest:testHashMap(): BEGIN ---------------");
> >
> > @@ -474,7 +492,7 @@
> > obj.put(new String("key8"), new Integer(5));
> > obj.put(new String("key9"), new Integer(6));
> > obj.put(new NotSerializableObject("TestForHashMapKey"), new Integer(7));
> > - obj.put(new String("key10"), new Integer(8));
> > + obj.put(new String("key10"),new Integer(8));
> >
> >
> > int initial_size = obj.size();
> > @@ -482,22 +500,25 @@
> > // ---------------------------------------------------------
> > // setup a temporary file to use
> > // ---------------------------------------------------------
> > - try {
> > - theFile = File.createTempFile("hashmapTest", null);
> > + try
> > + {
> > + theFile = File.createTempFile("hashmapTest",null);
> > theFilename = theFile.getName();
> > - System.out.println("ObjectSaveTest:testHashMap(): temp file = [" + theFilename + "]");
> > + System.out.println("ObjectSaveTest:testHashMap(): temp file = ["+theFilename+"]");
> > }
> > - catch (Exception ex) {
> > - System.out.println("ObjectSaveTest:testHashMap(): error creating temp file = [" +
> > - ex.getMessage() + "]");
> > + catch (Exception ex)
> > + {
> > + System.out.println("ObjectSaveTest:testHashMap(): error creating temp file = ["+ex.getMessage()+"]");
> > theFile = null;
> > }
> >
> > - if (theFile != null) {
> > + if (theFile != null)
> > + {
> > // ---------------------------------------------------------
> > // save to the temporary file
> > // ---------------------------------------------------------
> > - try {
> > + try
> > + {
> > // setup an output stream to a physical file
> > FileOutputStream outStream = new FileOutputStream(theFile);
> >
> > @@ -517,16 +538,14 @@
> > outStream.close();
> >
> > saved = true;
> > - System.out
> > - .println("ObjectSaveTest:testHashMap(): ....save operation completed.....");
> > + System.out.println("ObjectSaveTest:testHashMap(): ....save operation completed.....");
> >
> > long filesize = theFile.length();
> > - System.out.println("ObjectSaveTest:testHashMap(): file size after save [" +
> > - filesize + "] temp file = [" + theFilename + "]");
> > + System.out.println("ObjectSaveTest:testHashMap(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
> > }
> > - catch (Exception ex2) {
> > - System.out.println("ObjectSaveTest:testHashMap(): error during save [" +
> > - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> > + catch (Exception ex2)
> > + {
> > + System.out.println("ObjectSaveTest:testHashMap(): error during save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> > ex2.printStackTrace();
> > }
> >
> > @@ -537,7 +556,8 @@
> > // ---------------------------------------------------------
> > HashMap restored_obj = null;
> >
> > - try {
> > + try
> > + {
> > // setup an input stream to the file
> > FileInputStream inStream = new FileInputStream(theFile);
> >
> > @@ -553,33 +573,37 @@
> > inStream.close();
> >
> > restored = true;
> > - System.out.println(
> > - "ObjectSaveTest:testHashMap(): ....restored operation completed.....");
> > + System.out.println("ObjectSaveTest:testHashMap(): ....restored operation completed.....");
> >
> > }
> > - catch (Exception ex2) {
> > - System.out.println("ObjectSaveTest:testHashMap(): error during restore [" +
> > - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> > + catch (Exception ex2)
> > + {
> > + System.out.println("ObjectSaveTest:testHashMap(): error during restore ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> > ex2.printStackTrace();
> > }
> >
> > // if the save/restore of the object succeeded,
> > // then don't keep the temporary file around
> > boolean removeTmpFile = saved && restored;
> > - if (removeTmpFile) {
> > - try {
> > + if (removeTmpFile)
> > + {
> > + try
> > + {
> > theFile.delete();
> > }
> > - catch (Exception e) {
> > + catch (Exception e)
> > + {
> > // just absorb it
> > }
> > }
> >
> > assertTrue(restored);
> >
> > - if (restored_obj != null) {
> > + if (restored_obj != null)
> > + {
> > int restored_size = restored_obj.size();
> > - if (restored_size == (initial_size - 3)) {
> > + if (restored_size == (initial_size-3))
> > + {
> > // there are entries in the map that are not serializable
> > comparesOK = true;
> > }
> > @@ -588,7 +612,7 @@
> > // TODO: check for exact entries
> >
> > assertTrue(comparesOK);
> > -
> > +
> > // indicate that the temp file was created ok
> > done = true;
> > }
> > @@ -600,13 +624,14 @@
> > }
> >
> >
> > - public void testLinkedList() throws Exception {
> > - File theFile = null;
> > - String theFilename = null;
> > - boolean saved = false;
> > - boolean restored = false;
> > - boolean done = false;
> > - boolean comparesOK = false;
> > + public void testLinkedList() throws Exception
> > + {
> > + File theFile = null;
> > + String theFilename = null;
> > + boolean saved = false;
> > + boolean restored = false;
> > + boolean done = false;
> > + boolean comparesOK = false;
> >
> > System.out.println("ObjectSaveTest:testLinkedList(): BEGIN ---------------");
> >
> > @@ -630,23 +655,25 @@
> > // ---------------------------------------------------------
> > // setup a temporary file to use
> > // ---------------------------------------------------------
> > - try {
> > - theFile = File.createTempFile("linkedlistTest", null);
> > + try
> > + {
> > + theFile = File.createTempFile("linkedlistTest",null);
> > theFilename = theFile.getName();
> > - System.out
> > - .println("ObjectSaveTest:testLinkedList(): temp file = [" + theFilename + "]");
> > + System.out.println("ObjectSaveTest:testLinkedList(): temp file = ["+theFilename+"]");
> > }
> > - catch (Exception ex) {
> > - System.out.println("ObjectSaveTest:testLinkedList(): error creating temp file = [" +
> > - ex.getMessage() + "]");
> > + catch (Exception ex)
> > + {
> > + System.out.println("ObjectSaveTest:testLinkedList(): error creating temp file = ["+ex.getMessage()+"]");
> > theFile = null;
> > }
> >
> > - if (theFile != null) {
> > + if (theFile != null)
> > + {
> > // ---------------------------------------------------------
> > // save to the temporary file
> > // ---------------------------------------------------------
> > - try {
> > + try
> > + {
> > // setup an output stream to a physical file
> > FileOutputStream outStream = new FileOutputStream(theFile);
> >
> > @@ -666,16 +693,14 @@
> > outStream.close();
> >
> > saved = true;
> > - System.out.println(
> > - "ObjectSaveTest:testLinkedList(): ....save operation completed.....");
> > + System.out.println("ObjectSaveTest:testLinkedList(): ....save operation completed.....");
> >
> > long filesize = theFile.length();
> > - System.out.println("ObjectSaveTest:testLinkedList(): file size after save [" +
> > - filesize + "] temp file = [" + theFilename + "]");
> > + System.out.println("ObjectSaveTest:testLinkedList(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
> > }
> > - catch (Exception ex2) {
> > - System.out.println("ObjectSaveTest:testLinkedList(): error during save [" +
> > - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> > + catch (Exception ex2)
> > + {
> > + System.out.println("ObjectSaveTest:testLinkedList(): error during save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> > ex2.printStackTrace();
> > }
> >
> > @@ -686,7 +711,8 @@
> > // ---------------------------------------------------------
> > LinkedList restored_obj = null;
> >
> > - try {
> > + try
> > + {
> > // setup an input stream to the file
> > FileInputStream inStream = new FileInputStream(theFile);
> >
> > @@ -697,39 +723,42 @@
> > // try to restore the options
> > System.out.println("ObjectSaveTest:testLinkedList(): restoring .....");
> > restored = false;
> > - restored_obj =
> > - ObjectStateUtils.readLinkedList(inObjStream, "testObject:LinkedList");
> > + restored_obj = ObjectStateUtils.readLinkedList(inObjStream, "testObject:LinkedList");
> > inObjStream.close();
> > inStream.close();
> >
> > restored = true;
> > - System.out.println(
> > - "ObjectSaveTest:testLinkedList(): ....restored operation completed.....");
> > + System.out.println("ObjectSaveTest:testLinkedList(): ....restored operation completed.....");
> >
> > }
> > - catch (Exception ex2) {
> > - System.out.println("ObjectSaveTest:testLinkedList(): error during restore [" +
> > - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> > + catch (Exception ex2)
> > + {
> > + System.out.println("ObjectSaveTest:testLinkedList(): error during restore ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> > ex2.printStackTrace();
> > }
> >
> > // if the save/restore of the object succeeded,
> > // then don't keep the temporary file around
> > boolean removeTmpFile = saved && restored;
> > - if (removeTmpFile) {
> > - try {
> > + if (removeTmpFile)
> > + {
> > + try
> > + {
> > theFile.delete();
> > }
> > - catch (Exception e) {
> > + catch (Exception e)
> > + {
> > // just absorb it
> > }
> > }
> >
> > assertTrue(restored);
> >
> > - if (restored_obj != null) {
> > + if (restored_obj != null)
> > + {
> > int restored_size = restored_obj.size();
> > - if (restored_size == (initial_size - 1)) {
> > + if (restored_size == (initial_size-1))
> > + {
> > comparesOK = true;
> > }
> > }
> > @@ -737,7 +766,7 @@
> > // TODO: check for exact entries
> >
> > assertTrue(comparesOK);
> > -
> > +
> > // indicate that the temp file was created ok
> > done = true;
> > }
> > @@ -749,7 +778,10 @@
> > }
> >
> >
> > - public class NotSerializableObject implements Externalizable {
> > +
> > +
> > + public class NotSerializableObject implements Externalizable
> > + {
> > private String label = "TestObject";
> > private String ID = null;
> >
> > @@ -757,29 +789,34 @@
> > private PrintStream ps = System.out;
> >
> > // default constructor needed for Externalizable interface
> > - public NotSerializableObject() {
> > + public NotSerializableObject()
> > + {
> > }
> >
> > - public NotSerializableObject(String identifier) {
> > + public NotSerializableObject(String identifier)
> > + {
> > ID = identifier;
> > ps = System.out;
> > }
> > -
> > - public void setID(String s) {
> > +
> > + public void setID(String s)
> > + {
> > ID = s;
> > }
> >
> > - public String getID() {
> > + public String getID()
> > + {
> > return ID;
> > }
> >
> > - public void writeExternal(java.io.ObjectOutput out) throws IOException {
> > + public void writeExternal(java.io.ObjectOutput out) throws IOException
> > + {
> > throw new NotSerializableException("Test Object is not serializable");
> > }
> >
> >
> > - public void readExternal(java.io.ObjectInput in)
> > - throws IOException, ClassNotFoundException {
> > + public void readExternal(java.io.ObjectInput in) throws IOException, ClassNotFoundException
> > + {
> > throw new IOException("Test object is not serializable");
> > }
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
> > For additional commands, e-mail: axis-cvs-help@ws.apache.org
> >
> >
>
>
> --
> Davanum Srinivas :: http://wso2.org/ :: Oxygen for Web Services Developers
>
--
Davanum Srinivas :: http://wso2.org/ :: Oxygen for Web Services Developers
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org
Re: svn commit: r526930 [2/2] - in /webservices/axis2/trunk/java/modules/kernel: src/org/apache/axis2/util/ObjectStateUtils.java test/org/apache/axis2/engine/ObjectSaveTest.java
Posted by Davanum Srinivas <da...@gmail.com>.
Ann,
Could you please avoid reformatting???
thanks,
dims
On 4/9/07, robinsona@apache.org <ro...@apache.org> wrote:
> Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/ObjectSaveTest.java
> URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/ObjectSaveTest.java?view=diff&rev=526930&r1=526929&r2=526930
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/ObjectSaveTest.java (original)
> +++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/ObjectSaveTest.java Mon Apr 9 14:50:06 2007
> @@ -17,9 +17,11 @@
> package org.apache.axis2.engine;
>
> import junit.framework.TestCase;
> +
> import org.apache.axis2.util.MetaDataEntry;
> import org.apache.axis2.util.ObjectStateUtils;
>
> +import javax.xml.namespace.QName;
> import java.io.Externalizable;
> import java.io.File;
> import java.io.FileInputStream;
> @@ -29,63 +31,70 @@
> import java.io.ObjectInputStream;
> import java.io.ObjectOutputStream;
> import java.io.PrintStream;
> +import java.io.Serializable;
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.LinkedList;
>
> -public class ObjectSaveTest extends TestCase {
> +public class ObjectSaveTest extends TestCase
> +{
> private String testArg = null;
>
> // simple constructor needed for nested class Externalizable interface
> - public ObjectSaveTest() {
> + public ObjectSaveTest()
> + {
> }
>
> - public ObjectSaveTest(String arg0) {
> + public ObjectSaveTest(String arg0)
> + {
> super(arg0);
> testArg = new String(arg0);
> }
>
>
> - protected void setUp() throws Exception {
> + protected void setUp() throws Exception
> + {
> //org.apache.log4j.BasicConfigurator.configure();
> }
>
>
> - public void testObjectSerializable() throws Exception {
> - File theFile = null;
> - String theFilename = null;
> - boolean saved = false;
> - boolean restored = false;
> - boolean done = false;
> + public void testObjectSerializable() throws Exception
> + {
> + File theFile = null;
> + String theFilename = null;
> + boolean saved = false;
> + boolean restored = false;
> + boolean done = false;
>
> System.out.println("ObjectSaveTest:testObjectSerializable(): BEGIN ---------------");
>
> // ---------------------------------------------------------
> // setup an object to use
> // ---------------------------------------------------------
> - MetaDataEntry obj = new MetaDataEntry("object_1", "object_1");
> + MetaDataEntry obj = new MetaDataEntry("object_1","object_1");
>
> // ---------------------------------------------------------
> // setup a temporary file to use
> // ---------------------------------------------------------
> - try {
> - theFile = File.createTempFile("objectTest", null);
> + try
> + {
> + theFile = File.createTempFile("objectTest",null);
> theFilename = theFile.getName();
> - System.out.println(
> - "ObjectSaveTest:testObjectSerializable(): temp file = [" + theFilename + "]");
> + System.out.println("ObjectSaveTest:testObjectSerializable(): temp file = ["+theFilename+"]");
> }
> - catch (Exception ex) {
> - System.out.println(
> - "ObjectSaveTest:testObjectSerializable(): error creating temp file = [" +
> - ex.getMessage() + "]");
> + catch (Exception ex)
> + {
> + System.out.println("ObjectSaveTest:testObjectSerializable(): error creating temp file = ["+ex.getMessage()+"]");
> theFile = null;
> }
>
> - if (theFile != null) {
> + if (theFile != null)
> + {
> // ---------------------------------------------------------
> // save to the temporary file
> // ---------------------------------------------------------
> - try {
> + try
> + {
> // setup an output stream to a physical file
> FileOutputStream outStream = new FileOutputStream(theFile);
>
> @@ -105,17 +114,14 @@
> outStream.close();
>
> saved = true;
> - System.out.println(
> - "ObjectSaveTest:testObjectSerializable(): ....save operation completed.....");
> + System.out.println("ObjectSaveTest:testObjectSerializable(): ....save operation completed.....");
>
> long filesize = theFile.length();
> - System.out.println(
> - "ObjectSaveTest:testObjectSerializable(): file size after save [" +
> - filesize + "] temp file = [" + theFilename + "]");
> - }
> - catch (Exception ex2) {
> - System.out.println("ObjectSaveTest:testObjectSerializable(): error during save [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + System.out.println("ObjectSaveTest:testObjectSerializable(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
> + }
> + catch (Exception ex2)
> + {
> + System.out.println("ObjectSaveTest:testObjectSerializable(): error during save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> ex2.printStackTrace();
> }
>
> @@ -124,7 +130,8 @@
> // ---------------------------------------------------------
> // restore from the temporary file
> // ---------------------------------------------------------
> - try {
> + try
> + {
> // setup an input stream to the file
> FileInputStream inStream = new FileInputStream(theFile);
>
> @@ -135,20 +142,17 @@
> // try to restore the options
> System.out.println("ObjectSaveTest:testObjectSerializable(): restoring .....");
> restored = false;
> - MetaDataEntry restored_obj = (MetaDataEntry) ObjectStateUtils
> - .readObject(inObjStream, "testObject:serializable");
> + MetaDataEntry restored_obj = (MetaDataEntry) ObjectStateUtils.readObject(inObjStream, "testObject:serializable");
> inObjStream.close();
> inStream.close();
>
> restored = true;
> - System.out.println(
> - "ObjectSaveTest:testObjectSerializable(): ....restored operation completed.....");
> + System.out.println("ObjectSaveTest:testObjectSerializable(): ....restored operation completed.....");
>
> }
> - catch (Exception ex2) {
> - System.out.println(
> - "ObjectSaveTest:testObjectSerializable(): error during restore [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + catch (Exception ex2)
> + {
> + System.out.println("ObjectSaveTest:testObjectSerializable(): error during restore ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> ex2.printStackTrace();
> }
>
> @@ -157,11 +161,14 @@
> // if the save/restore of the object succeeded,
> // then don't keep the temporary file around
> boolean removeTmpFile = saved && restored;
> - if (removeTmpFile) {
> - try {
> + if (removeTmpFile)
> + {
> + try
> + {
> theFile.delete();
> }
> - catch (Exception e) {
> + catch (Exception e)
> + {
> // just absorb it
> }
> }
> @@ -177,84 +184,87 @@
> }
>
>
> - public void testObjectNotSerializable() throws Exception {
> - File theFile = null;
> - String theFilename = null;
> - boolean saved = false;
> - boolean restored = false;
> - boolean expected_exception = false;
> - boolean done = false;
> + public void testObjectNotSerializable() throws Exception
> + {
> + File theFile = null;
> + String theFilename = null;
> + boolean saved = false;
> + boolean restored = false;
> + boolean expected_exception = false;
> + boolean done = false;
>
> System.out.println("ObjectSaveTest:testObjectNotSerializable(): BEGIN ---------------");
>
> // ---------------------------------------------------------
> // setup an object to use
> // ---------------------------------------------------------
> - NotSerializableObject obj = new NotSerializableObject("nso_1");
> + NotSerializableObject obj = new NotSerializableObject("nso_1");
> +
>
> // ---------------------------------------------------------
> // setup a temporary file to use
> // ---------------------------------------------------------
> - try {
> - theFile = File.createTempFile("objectTest", null);
> + try
> + {
> + theFile = File.createTempFile("objectTest",null);
> theFilename = theFile.getName();
> - System.out.println("ObjectSaveTest:testObjectNotSerializable(): temp file = [" +
> - theFilename + "]");
> + System.out.println("ObjectSaveTest:testObjectNotSerializable(): temp file = ["+theFilename+"]");
> }
> - catch (Exception ex) {
> - System.out.println(
> - "ObjectSaveTest:testObjectNotSerializable(): error creating temp file = [" +
> - ex.getMessage() + "]");
> + catch (Exception ex)
> + {
> + System.out.println("ObjectSaveTest:testObjectNotSerializable(): error creating temp file = ["+ex.getMessage()+"]");
> theFile = null;
> }
>
> - if (theFile != null) {
> + if (theFile != null)
> + {
> // ---------------------------------------------------------
> // save to the temporary file
> // ---------------------------------------------------------
> - try {
> + FileOutputStream outStream = null;
> + ObjectOutputStream outObjStream = null;
> + try
> + {
> // setup an output stream to a physical file
> - FileOutputStream outStream = new FileOutputStream(theFile);
> + outStream = new FileOutputStream(theFile);
>
> // attach a stream capable of writing objects to the
> // stream connected to the file
> - ObjectOutputStream outObjStream = new ObjectOutputStream(outStream);
> + outObjStream = new ObjectOutputStream(outStream);
>
> // try to save
> System.out.println("ObjectSaveTest:testObjectNotSerializable(): saving .....");
> saved = false;
> ObjectStateUtils.writeObject(outObjStream, obj, "testObject:NotSerializable");
>
> - // close out the streams
> - outObjStream.flush();
> - outObjStream.close();
> - outStream.flush();
> - outStream.close();
> -
> saved = true;
> - System.out.println(
> - "ObjectSaveTest:testObjectNotSerializable(): ....save operation completed.....");
> + System.out.println("ObjectSaveTest:testObjectNotSerializable(): ....save operation completed.....");
>
> long filesize = theFile.length();
> - System.out.println(
> - "ObjectSaveTest:testObjectNotSerializable(): file size after save [" +
> - filesize + "] temp file = [" + theFilename + "]");
> + System.out.println("ObjectSaveTest:testObjectNotSerializable(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
> }
> - catch (Exception ex2) {
> + catch (Exception ex2)
> + {
> // expect an error here
> // ObjectStateUtils catches the NotSerializableException and logs it
> - if (ex2 instanceof NotSerializableException) {
> + if (ex2 instanceof NotSerializableException)
> + {
> expected_exception = true;
> - } else {
> - System.out.println("ObjectSaveTest:testObjectNotSerializable(): save [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + }
> + else
> + {
> + System.out.println("ObjectSaveTest:testObjectNotSerializable(): save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> }
> }
> + // close out the streams
> + if(outObjStream != null) outObjStream.close();
> + if(outStream != null) outStream.close();
>
> // ---------------------------------------------------------
> // restore from the temporary file
> // ---------------------------------------------------------
> - try {
> + try
> + {
> // setup an input stream to the file
> FileInputStream inStream = new FileInputStream(theFile);
>
> @@ -265,20 +275,17 @@
> // try to restore the options
> System.out.println("ObjectSaveTest:testObjectSerializable(): restoring .....");
> restored = false;
> - Object restored_obj =
> - ObjectStateUtils.readObject(inObjStream, "testObject:NotSerializable");
> + Object restored_obj = ObjectStateUtils.readObject(inObjStream, "testObject:NotSerializable");
> inObjStream.close();
> inStream.close();
>
> restored = true;
> - System.out.println(
> - "ObjectSaveTest:testObjectNotSerializable(): ....restored operation completed.....");
> + System.out.println("ObjectSaveTest:testObjectNotSerializable(): ....restored operation completed.....");
>
> }
> - catch (Exception ex) {
> - System.out.println(
> - "ObjectSaveTest:testObjectNotSerializable(): error during restore [" +
> - ex.getClass().getName() + " : " + ex.getMessage() + "]");
> + catch (Exception ex)
> + {
> + System.out.println("ObjectSaveTest:testObjectNotSerializable(): error during restore ["+ex.getClass().getName()+" : "+ex.getMessage()+"]");
> ex.printStackTrace();
> }
>
> @@ -287,11 +294,14 @@
> // if the save/restore of the object succeeded,
> // then don't keep the temporary file around
> boolean removeTmpFile = saved && restored;
> - if (removeTmpFile) {
> - try {
> + if (removeTmpFile)
> + {
> + try
> + {
> theFile.delete();
> }
> - catch (Exception e) {
> + catch (Exception e)
> + {
> // just absorb it
> }
> }
> @@ -303,13 +313,14 @@
> }
>
>
> - public void testArrayList() throws Exception {
> - File theFile = null;
> - String theFilename = null;
> - boolean saved = false;
> - boolean restored = false;
> - boolean done = false;
> - boolean comparesOK = false;
> + public void testArrayList() throws Exception
> + {
> + File theFile = null;
> + String theFilename = null;
> + boolean saved = false;
> + boolean restored = false;
> + boolean done = false;
> + boolean comparesOK = false;
>
> System.out.println("ObjectSaveTest:testArrayList(): BEGIN ---------------");
>
> @@ -333,22 +344,25 @@
> // ---------------------------------------------------------
> // setup a temporary file to use
> // ---------------------------------------------------------
> - try {
> - theFile = File.createTempFile("arraylistTest", null);
> + try
> + {
> + theFile = File.createTempFile("arraylistTest",null);
> theFilename = theFile.getName();
> - System.out.println("ObjectSaveTest:testArrayList(): temp file = [" + theFilename + "]");
> + System.out.println("ObjectSaveTest:testArrayList(): temp file = ["+theFilename+"]");
> }
> - catch (Exception ex) {
> - System.out.println("ObjectSaveTest:testArrayList(): error creating temp file = [" +
> - ex.getMessage() + "]");
> + catch (Exception ex)
> + {
> + System.out.println("ObjectSaveTest:testArrayList(): error creating temp file = ["+ex.getMessage()+"]");
> theFile = null;
> }
>
> - if (theFile != null) {
> + if (theFile != null)
> + {
> // ---------------------------------------------------------
> // save to the temporary file
> // ---------------------------------------------------------
> - try {
> + try
> + {
> // setup an output stream to a physical file
> FileOutputStream outStream = new FileOutputStream(theFile);
>
> @@ -368,16 +382,14 @@
> outStream.close();
>
> saved = true;
> - System.out.println(
> - "ObjectSaveTest:testArrayList(): ....save operation completed.....");
> + System.out.println("ObjectSaveTest:testArrayList(): ....save operation completed.....");
>
> long filesize = theFile.length();
> - System.out.println("ObjectSaveTest:testArrayList(): file size after save [" +
> - filesize + "] temp file = [" + theFilename + "]");
> + System.out.println("ObjectSaveTest:testArrayList(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
> }
> - catch (Exception ex2) {
> - System.out.println("ObjectSaveTest:testArrayList(): error during save [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + catch (Exception ex2)
> + {
> + System.out.println("ObjectSaveTest:testArrayList(): error during save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> ex2.printStackTrace();
> }
>
> @@ -388,7 +400,8 @@
> // ---------------------------------------------------------
> ArrayList restored_obj = null;
>
> - try {
> + try
> + {
> // setup an input stream to the file
> FileInputStream inStream = new FileInputStream(theFile);
>
> @@ -404,33 +417,37 @@
> inStream.close();
>
> restored = true;
> - System.out.println(
> - "ObjectSaveTest:testArrayList(): ....restored operation completed.....");
> + System.out.println("ObjectSaveTest:testArrayList(): ....restored operation completed.....");
>
> }
> - catch (Exception ex2) {
> - System.out.println("ObjectSaveTest:testArrayList(): error during restore [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + catch (Exception ex2)
> + {
> + System.out.println("ObjectSaveTest:testArrayList(): error during restore ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> ex2.printStackTrace();
> }
>
> // if the save/restore of the object succeeded,
> // then don't keep the temporary file around
> boolean removeTmpFile = saved && restored;
> - if (removeTmpFile) {
> - try {
> + if (removeTmpFile)
> + {
> + try
> + {
> theFile.delete();
> }
> - catch (Exception e) {
> + catch (Exception e)
> + {
> // just absorb it
> }
> }
>
> assertTrue(restored);
>
> - if (restored_obj != null) {
> + if (restored_obj != null)
> + {
> int restored_size = restored_obj.size();
> - if (restored_size == (initial_size - 1)) {
> + if (restored_size == (initial_size-1))
> + {
> comparesOK = true;
> }
> }
> @@ -438,7 +455,7 @@
> // TODO: check for exact entries
>
> assertTrue(comparesOK);
> -
> +
> // indicate that the temp file was created ok
> done = true;
> }
> @@ -450,13 +467,14 @@
> }
>
>
> - public void testHashMap() throws Exception {
> - File theFile = null;
> - String theFilename = null;
> - boolean saved = false;
> - boolean restored = false;
> - boolean done = false;
> - boolean comparesOK = false;
> + public void testHashMap() throws Exception
> + {
> + File theFile = null;
> + String theFilename = null;
> + boolean saved = false;
> + boolean restored = false;
> + boolean done = false;
> + boolean comparesOK = false;
>
> System.out.println("ObjectSaveTest:testHashMap(): BEGIN ---------------");
>
> @@ -474,7 +492,7 @@
> obj.put(new String("key8"), new Integer(5));
> obj.put(new String("key9"), new Integer(6));
> obj.put(new NotSerializableObject("TestForHashMapKey"), new Integer(7));
> - obj.put(new String("key10"), new Integer(8));
> + obj.put(new String("key10"),new Integer(8));
>
>
> int initial_size = obj.size();
> @@ -482,22 +500,25 @@
> // ---------------------------------------------------------
> // setup a temporary file to use
> // ---------------------------------------------------------
> - try {
> - theFile = File.createTempFile("hashmapTest", null);
> + try
> + {
> + theFile = File.createTempFile("hashmapTest",null);
> theFilename = theFile.getName();
> - System.out.println("ObjectSaveTest:testHashMap(): temp file = [" + theFilename + "]");
> + System.out.println("ObjectSaveTest:testHashMap(): temp file = ["+theFilename+"]");
> }
> - catch (Exception ex) {
> - System.out.println("ObjectSaveTest:testHashMap(): error creating temp file = [" +
> - ex.getMessage() + "]");
> + catch (Exception ex)
> + {
> + System.out.println("ObjectSaveTest:testHashMap(): error creating temp file = ["+ex.getMessage()+"]");
> theFile = null;
> }
>
> - if (theFile != null) {
> + if (theFile != null)
> + {
> // ---------------------------------------------------------
> // save to the temporary file
> // ---------------------------------------------------------
> - try {
> + try
> + {
> // setup an output stream to a physical file
> FileOutputStream outStream = new FileOutputStream(theFile);
>
> @@ -517,16 +538,14 @@
> outStream.close();
>
> saved = true;
> - System.out
> - .println("ObjectSaveTest:testHashMap(): ....save operation completed.....");
> + System.out.println("ObjectSaveTest:testHashMap(): ....save operation completed.....");
>
> long filesize = theFile.length();
> - System.out.println("ObjectSaveTest:testHashMap(): file size after save [" +
> - filesize + "] temp file = [" + theFilename + "]");
> + System.out.println("ObjectSaveTest:testHashMap(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
> }
> - catch (Exception ex2) {
> - System.out.println("ObjectSaveTest:testHashMap(): error during save [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + catch (Exception ex2)
> + {
> + System.out.println("ObjectSaveTest:testHashMap(): error during save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> ex2.printStackTrace();
> }
>
> @@ -537,7 +556,8 @@
> // ---------------------------------------------------------
> HashMap restored_obj = null;
>
> - try {
> + try
> + {
> // setup an input stream to the file
> FileInputStream inStream = new FileInputStream(theFile);
>
> @@ -553,33 +573,37 @@
> inStream.close();
>
> restored = true;
> - System.out.println(
> - "ObjectSaveTest:testHashMap(): ....restored operation completed.....");
> + System.out.println("ObjectSaveTest:testHashMap(): ....restored operation completed.....");
>
> }
> - catch (Exception ex2) {
> - System.out.println("ObjectSaveTest:testHashMap(): error during restore [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + catch (Exception ex2)
> + {
> + System.out.println("ObjectSaveTest:testHashMap(): error during restore ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> ex2.printStackTrace();
> }
>
> // if the save/restore of the object succeeded,
> // then don't keep the temporary file around
> boolean removeTmpFile = saved && restored;
> - if (removeTmpFile) {
> - try {
> + if (removeTmpFile)
> + {
> + try
> + {
> theFile.delete();
> }
> - catch (Exception e) {
> + catch (Exception e)
> + {
> // just absorb it
> }
> }
>
> assertTrue(restored);
>
> - if (restored_obj != null) {
> + if (restored_obj != null)
> + {
> int restored_size = restored_obj.size();
> - if (restored_size == (initial_size - 3)) {
> + if (restored_size == (initial_size-3))
> + {
> // there are entries in the map that are not serializable
> comparesOK = true;
> }
> @@ -588,7 +612,7 @@
> // TODO: check for exact entries
>
> assertTrue(comparesOK);
> -
> +
> // indicate that the temp file was created ok
> done = true;
> }
> @@ -600,13 +624,14 @@
> }
>
>
> - public void testLinkedList() throws Exception {
> - File theFile = null;
> - String theFilename = null;
> - boolean saved = false;
> - boolean restored = false;
> - boolean done = false;
> - boolean comparesOK = false;
> + public void testLinkedList() throws Exception
> + {
> + File theFile = null;
> + String theFilename = null;
> + boolean saved = false;
> + boolean restored = false;
> + boolean done = false;
> + boolean comparesOK = false;
>
> System.out.println("ObjectSaveTest:testLinkedList(): BEGIN ---------------");
>
> @@ -630,23 +655,25 @@
> // ---------------------------------------------------------
> // setup a temporary file to use
> // ---------------------------------------------------------
> - try {
> - theFile = File.createTempFile("linkedlistTest", null);
> + try
> + {
> + theFile = File.createTempFile("linkedlistTest",null);
> theFilename = theFile.getName();
> - System.out
> - .println("ObjectSaveTest:testLinkedList(): temp file = [" + theFilename + "]");
> + System.out.println("ObjectSaveTest:testLinkedList(): temp file = ["+theFilename+"]");
> }
> - catch (Exception ex) {
> - System.out.println("ObjectSaveTest:testLinkedList(): error creating temp file = [" +
> - ex.getMessage() + "]");
> + catch (Exception ex)
> + {
> + System.out.println("ObjectSaveTest:testLinkedList(): error creating temp file = ["+ex.getMessage()+"]");
> theFile = null;
> }
>
> - if (theFile != null) {
> + if (theFile != null)
> + {
> // ---------------------------------------------------------
> // save to the temporary file
> // ---------------------------------------------------------
> - try {
> + try
> + {
> // setup an output stream to a physical file
> FileOutputStream outStream = new FileOutputStream(theFile);
>
> @@ -666,16 +693,14 @@
> outStream.close();
>
> saved = true;
> - System.out.println(
> - "ObjectSaveTest:testLinkedList(): ....save operation completed.....");
> + System.out.println("ObjectSaveTest:testLinkedList(): ....save operation completed.....");
>
> long filesize = theFile.length();
> - System.out.println("ObjectSaveTest:testLinkedList(): file size after save [" +
> - filesize + "] temp file = [" + theFilename + "]");
> + System.out.println("ObjectSaveTest:testLinkedList(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
> }
> - catch (Exception ex2) {
> - System.out.println("ObjectSaveTest:testLinkedList(): error during save [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + catch (Exception ex2)
> + {
> + System.out.println("ObjectSaveTest:testLinkedList(): error during save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> ex2.printStackTrace();
> }
>
> @@ -686,7 +711,8 @@
> // ---------------------------------------------------------
> LinkedList restored_obj = null;
>
> - try {
> + try
> + {
> // setup an input stream to the file
> FileInputStream inStream = new FileInputStream(theFile);
>
> @@ -697,39 +723,42 @@
> // try to restore the options
> System.out.println("ObjectSaveTest:testLinkedList(): restoring .....");
> restored = false;
> - restored_obj =
> - ObjectStateUtils.readLinkedList(inObjStream, "testObject:LinkedList");
> + restored_obj = ObjectStateUtils.readLinkedList(inObjStream, "testObject:LinkedList");
> inObjStream.close();
> inStream.close();
>
> restored = true;
> - System.out.println(
> - "ObjectSaveTest:testLinkedList(): ....restored operation completed.....");
> + System.out.println("ObjectSaveTest:testLinkedList(): ....restored operation completed.....");
>
> }
> - catch (Exception ex2) {
> - System.out.println("ObjectSaveTest:testLinkedList(): error during restore [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + catch (Exception ex2)
> + {
> + System.out.println("ObjectSaveTest:testLinkedList(): error during restore ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> ex2.printStackTrace();
> }
>
> // if the save/restore of the object succeeded,
> // then don't keep the temporary file around
> boolean removeTmpFile = saved && restored;
> - if (removeTmpFile) {
> - try {
> + if (removeTmpFile)
> + {
> + try
> + {
> theFile.delete();
> }
> - catch (Exception e) {
> + catch (Exception e)
> + {
> // just absorb it
> }
> }
>
> assertTrue(restored);
>
> - if (restored_obj != null) {
> + if (restored_obj != null)
> + {
> int restored_size = restored_obj.size();
> - if (restored_size == (initial_size - 1)) {
> + if (restored_size == (initial_size-1))
> + {
> comparesOK = true;
> }
> }
> @@ -737,7 +766,7 @@
> // TODO: check for exact entries
>
> assertTrue(comparesOK);
> -
> +
> // indicate that the temp file was created ok
> done = true;
> }
> @@ -749,7 +778,10 @@
> }
>
>
> - public class NotSerializableObject implements Externalizable {
> +
> +
> + public class NotSerializableObject implements Externalizable
> + {
> private String label = "TestObject";
> private String ID = null;
>
> @@ -757,29 +789,34 @@
> private PrintStream ps = System.out;
>
> // default constructor needed for Externalizable interface
> - public NotSerializableObject() {
> + public NotSerializableObject()
> + {
> }
>
> - public NotSerializableObject(String identifier) {
> + public NotSerializableObject(String identifier)
> + {
> ID = identifier;
> ps = System.out;
> }
> -
> - public void setID(String s) {
> +
> + public void setID(String s)
> + {
> ID = s;
> }
>
> - public String getID() {
> + public String getID()
> + {
> return ID;
> }
>
> - public void writeExternal(java.io.ObjectOutput out) throws IOException {
> + public void writeExternal(java.io.ObjectOutput out) throws IOException
> + {
> throw new NotSerializableException("Test Object is not serializable");
> }
>
>
> - public void readExternal(java.io.ObjectInput in)
> - throws IOException, ClassNotFoundException {
> + public void readExternal(java.io.ObjectInput in) throws IOException, ClassNotFoundException
> + {
> throw new IOException("Test object is not serializable");
> }
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-cvs-help@ws.apache.org
>
>
--
Davanum Srinivas :: http://wso2.org/ :: Oxygen for Web Services Developers
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org
Re: svn commit: r526930 [2/2] - in /webservices/axis2/trunk/java/modules/kernel: src/org/apache/axis2/util/ObjectStateUtils.java test/org/apache/axis2/engine/ObjectSaveTest.java
Posted by Davanum Srinivas <da...@gmail.com>.
Ann,
Could you please avoid reformatting???
thanks,
dims
On 4/9/07, robinsona@apache.org <ro...@apache.org> wrote:
> Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/ObjectSaveTest.java
> URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/ObjectSaveTest.java?view=diff&rev=526930&r1=526929&r2=526930
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/ObjectSaveTest.java (original)
> +++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/ObjectSaveTest.java Mon Apr 9 14:50:06 2007
> @@ -17,9 +17,11 @@
> package org.apache.axis2.engine;
>
> import junit.framework.TestCase;
> +
> import org.apache.axis2.util.MetaDataEntry;
> import org.apache.axis2.util.ObjectStateUtils;
>
> +import javax.xml.namespace.QName;
> import java.io.Externalizable;
> import java.io.File;
> import java.io.FileInputStream;
> @@ -29,63 +31,70 @@
> import java.io.ObjectInputStream;
> import java.io.ObjectOutputStream;
> import java.io.PrintStream;
> +import java.io.Serializable;
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.LinkedList;
>
> -public class ObjectSaveTest extends TestCase {
> +public class ObjectSaveTest extends TestCase
> +{
> private String testArg = null;
>
> // simple constructor needed for nested class Externalizable interface
> - public ObjectSaveTest() {
> + public ObjectSaveTest()
> + {
> }
>
> - public ObjectSaveTest(String arg0) {
> + public ObjectSaveTest(String arg0)
> + {
> super(arg0);
> testArg = new String(arg0);
> }
>
>
> - protected void setUp() throws Exception {
> + protected void setUp() throws Exception
> + {
> //org.apache.log4j.BasicConfigurator.configure();
> }
>
>
> - public void testObjectSerializable() throws Exception {
> - File theFile = null;
> - String theFilename = null;
> - boolean saved = false;
> - boolean restored = false;
> - boolean done = false;
> + public void testObjectSerializable() throws Exception
> + {
> + File theFile = null;
> + String theFilename = null;
> + boolean saved = false;
> + boolean restored = false;
> + boolean done = false;
>
> System.out.println("ObjectSaveTest:testObjectSerializable(): BEGIN ---------------");
>
> // ---------------------------------------------------------
> // setup an object to use
> // ---------------------------------------------------------
> - MetaDataEntry obj = new MetaDataEntry("object_1", "object_1");
> + MetaDataEntry obj = new MetaDataEntry("object_1","object_1");
>
> // ---------------------------------------------------------
> // setup a temporary file to use
> // ---------------------------------------------------------
> - try {
> - theFile = File.createTempFile("objectTest", null);
> + try
> + {
> + theFile = File.createTempFile("objectTest",null);
> theFilename = theFile.getName();
> - System.out.println(
> - "ObjectSaveTest:testObjectSerializable(): temp file = [" + theFilename + "]");
> + System.out.println("ObjectSaveTest:testObjectSerializable(): temp file = ["+theFilename+"]");
> }
> - catch (Exception ex) {
> - System.out.println(
> - "ObjectSaveTest:testObjectSerializable(): error creating temp file = [" +
> - ex.getMessage() + "]");
> + catch (Exception ex)
> + {
> + System.out.println("ObjectSaveTest:testObjectSerializable(): error creating temp file = ["+ex.getMessage()+"]");
> theFile = null;
> }
>
> - if (theFile != null) {
> + if (theFile != null)
> + {
> // ---------------------------------------------------------
> // save to the temporary file
> // ---------------------------------------------------------
> - try {
> + try
> + {
> // setup an output stream to a physical file
> FileOutputStream outStream = new FileOutputStream(theFile);
>
> @@ -105,17 +114,14 @@
> outStream.close();
>
> saved = true;
> - System.out.println(
> - "ObjectSaveTest:testObjectSerializable(): ....save operation completed.....");
> + System.out.println("ObjectSaveTest:testObjectSerializable(): ....save operation completed.....");
>
> long filesize = theFile.length();
> - System.out.println(
> - "ObjectSaveTest:testObjectSerializable(): file size after save [" +
> - filesize + "] temp file = [" + theFilename + "]");
> - }
> - catch (Exception ex2) {
> - System.out.println("ObjectSaveTest:testObjectSerializable(): error during save [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + System.out.println("ObjectSaveTest:testObjectSerializable(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
> + }
> + catch (Exception ex2)
> + {
> + System.out.println("ObjectSaveTest:testObjectSerializable(): error during save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> ex2.printStackTrace();
> }
>
> @@ -124,7 +130,8 @@
> // ---------------------------------------------------------
> // restore from the temporary file
> // ---------------------------------------------------------
> - try {
> + try
> + {
> // setup an input stream to the file
> FileInputStream inStream = new FileInputStream(theFile);
>
> @@ -135,20 +142,17 @@
> // try to restore the options
> System.out.println("ObjectSaveTest:testObjectSerializable(): restoring .....");
> restored = false;
> - MetaDataEntry restored_obj = (MetaDataEntry) ObjectStateUtils
> - .readObject(inObjStream, "testObject:serializable");
> + MetaDataEntry restored_obj = (MetaDataEntry) ObjectStateUtils.readObject(inObjStream, "testObject:serializable");
> inObjStream.close();
> inStream.close();
>
> restored = true;
> - System.out.println(
> - "ObjectSaveTest:testObjectSerializable(): ....restored operation completed.....");
> + System.out.println("ObjectSaveTest:testObjectSerializable(): ....restored operation completed.....");
>
> }
> - catch (Exception ex2) {
> - System.out.println(
> - "ObjectSaveTest:testObjectSerializable(): error during restore [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + catch (Exception ex2)
> + {
> + System.out.println("ObjectSaveTest:testObjectSerializable(): error during restore ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> ex2.printStackTrace();
> }
>
> @@ -157,11 +161,14 @@
> // if the save/restore of the object succeeded,
> // then don't keep the temporary file around
> boolean removeTmpFile = saved && restored;
> - if (removeTmpFile) {
> - try {
> + if (removeTmpFile)
> + {
> + try
> + {
> theFile.delete();
> }
> - catch (Exception e) {
> + catch (Exception e)
> + {
> // just absorb it
> }
> }
> @@ -177,84 +184,87 @@
> }
>
>
> - public void testObjectNotSerializable() throws Exception {
> - File theFile = null;
> - String theFilename = null;
> - boolean saved = false;
> - boolean restored = false;
> - boolean expected_exception = false;
> - boolean done = false;
> + public void testObjectNotSerializable() throws Exception
> + {
> + File theFile = null;
> + String theFilename = null;
> + boolean saved = false;
> + boolean restored = false;
> + boolean expected_exception = false;
> + boolean done = false;
>
> System.out.println("ObjectSaveTest:testObjectNotSerializable(): BEGIN ---------------");
>
> // ---------------------------------------------------------
> // setup an object to use
> // ---------------------------------------------------------
> - NotSerializableObject obj = new NotSerializableObject("nso_1");
> + NotSerializableObject obj = new NotSerializableObject("nso_1");
> +
>
> // ---------------------------------------------------------
> // setup a temporary file to use
> // ---------------------------------------------------------
> - try {
> - theFile = File.createTempFile("objectTest", null);
> + try
> + {
> + theFile = File.createTempFile("objectTest",null);
> theFilename = theFile.getName();
> - System.out.println("ObjectSaveTest:testObjectNotSerializable(): temp file = [" +
> - theFilename + "]");
> + System.out.println("ObjectSaveTest:testObjectNotSerializable(): temp file = ["+theFilename+"]");
> }
> - catch (Exception ex) {
> - System.out.println(
> - "ObjectSaveTest:testObjectNotSerializable(): error creating temp file = [" +
> - ex.getMessage() + "]");
> + catch (Exception ex)
> + {
> + System.out.println("ObjectSaveTest:testObjectNotSerializable(): error creating temp file = ["+ex.getMessage()+"]");
> theFile = null;
> }
>
> - if (theFile != null) {
> + if (theFile != null)
> + {
> // ---------------------------------------------------------
> // save to the temporary file
> // ---------------------------------------------------------
> - try {
> + FileOutputStream outStream = null;
> + ObjectOutputStream outObjStream = null;
> + try
> + {
> // setup an output stream to a physical file
> - FileOutputStream outStream = new FileOutputStream(theFile);
> + outStream = new FileOutputStream(theFile);
>
> // attach a stream capable of writing objects to the
> // stream connected to the file
> - ObjectOutputStream outObjStream = new ObjectOutputStream(outStream);
> + outObjStream = new ObjectOutputStream(outStream);
>
> // try to save
> System.out.println("ObjectSaveTest:testObjectNotSerializable(): saving .....");
> saved = false;
> ObjectStateUtils.writeObject(outObjStream, obj, "testObject:NotSerializable");
>
> - // close out the streams
> - outObjStream.flush();
> - outObjStream.close();
> - outStream.flush();
> - outStream.close();
> -
> saved = true;
> - System.out.println(
> - "ObjectSaveTest:testObjectNotSerializable(): ....save operation completed.....");
> + System.out.println("ObjectSaveTest:testObjectNotSerializable(): ....save operation completed.....");
>
> long filesize = theFile.length();
> - System.out.println(
> - "ObjectSaveTest:testObjectNotSerializable(): file size after save [" +
> - filesize + "] temp file = [" + theFilename + "]");
> + System.out.println("ObjectSaveTest:testObjectNotSerializable(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
> }
> - catch (Exception ex2) {
> + catch (Exception ex2)
> + {
> // expect an error here
> // ObjectStateUtils catches the NotSerializableException and logs it
> - if (ex2 instanceof NotSerializableException) {
> + if (ex2 instanceof NotSerializableException)
> + {
> expected_exception = true;
> - } else {
> - System.out.println("ObjectSaveTest:testObjectNotSerializable(): save [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + }
> + else
> + {
> + System.out.println("ObjectSaveTest:testObjectNotSerializable(): save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> }
> }
> + // close out the streams
> + if(outObjStream != null) outObjStream.close();
> + if(outStream != null) outStream.close();
>
> // ---------------------------------------------------------
> // restore from the temporary file
> // ---------------------------------------------------------
> - try {
> + try
> + {
> // setup an input stream to the file
> FileInputStream inStream = new FileInputStream(theFile);
>
> @@ -265,20 +275,17 @@
> // try to restore the options
> System.out.println("ObjectSaveTest:testObjectSerializable(): restoring .....");
> restored = false;
> - Object restored_obj =
> - ObjectStateUtils.readObject(inObjStream, "testObject:NotSerializable");
> + Object restored_obj = ObjectStateUtils.readObject(inObjStream, "testObject:NotSerializable");
> inObjStream.close();
> inStream.close();
>
> restored = true;
> - System.out.println(
> - "ObjectSaveTest:testObjectNotSerializable(): ....restored operation completed.....");
> + System.out.println("ObjectSaveTest:testObjectNotSerializable(): ....restored operation completed.....");
>
> }
> - catch (Exception ex) {
> - System.out.println(
> - "ObjectSaveTest:testObjectNotSerializable(): error during restore [" +
> - ex.getClass().getName() + " : " + ex.getMessage() + "]");
> + catch (Exception ex)
> + {
> + System.out.println("ObjectSaveTest:testObjectNotSerializable(): error during restore ["+ex.getClass().getName()+" : "+ex.getMessage()+"]");
> ex.printStackTrace();
> }
>
> @@ -287,11 +294,14 @@
> // if the save/restore of the object succeeded,
> // then don't keep the temporary file around
> boolean removeTmpFile = saved && restored;
> - if (removeTmpFile) {
> - try {
> + if (removeTmpFile)
> + {
> + try
> + {
> theFile.delete();
> }
> - catch (Exception e) {
> + catch (Exception e)
> + {
> // just absorb it
> }
> }
> @@ -303,13 +313,14 @@
> }
>
>
> - public void testArrayList() throws Exception {
> - File theFile = null;
> - String theFilename = null;
> - boolean saved = false;
> - boolean restored = false;
> - boolean done = false;
> - boolean comparesOK = false;
> + public void testArrayList() throws Exception
> + {
> + File theFile = null;
> + String theFilename = null;
> + boolean saved = false;
> + boolean restored = false;
> + boolean done = false;
> + boolean comparesOK = false;
>
> System.out.println("ObjectSaveTest:testArrayList(): BEGIN ---------------");
>
> @@ -333,22 +344,25 @@
> // ---------------------------------------------------------
> // setup a temporary file to use
> // ---------------------------------------------------------
> - try {
> - theFile = File.createTempFile("arraylistTest", null);
> + try
> + {
> + theFile = File.createTempFile("arraylistTest",null);
> theFilename = theFile.getName();
> - System.out.println("ObjectSaveTest:testArrayList(): temp file = [" + theFilename + "]");
> + System.out.println("ObjectSaveTest:testArrayList(): temp file = ["+theFilename+"]");
> }
> - catch (Exception ex) {
> - System.out.println("ObjectSaveTest:testArrayList(): error creating temp file = [" +
> - ex.getMessage() + "]");
> + catch (Exception ex)
> + {
> + System.out.println("ObjectSaveTest:testArrayList(): error creating temp file = ["+ex.getMessage()+"]");
> theFile = null;
> }
>
> - if (theFile != null) {
> + if (theFile != null)
> + {
> // ---------------------------------------------------------
> // save to the temporary file
> // ---------------------------------------------------------
> - try {
> + try
> + {
> // setup an output stream to a physical file
> FileOutputStream outStream = new FileOutputStream(theFile);
>
> @@ -368,16 +382,14 @@
> outStream.close();
>
> saved = true;
> - System.out.println(
> - "ObjectSaveTest:testArrayList(): ....save operation completed.....");
> + System.out.println("ObjectSaveTest:testArrayList(): ....save operation completed.....");
>
> long filesize = theFile.length();
> - System.out.println("ObjectSaveTest:testArrayList(): file size after save [" +
> - filesize + "] temp file = [" + theFilename + "]");
> + System.out.println("ObjectSaveTest:testArrayList(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
> }
> - catch (Exception ex2) {
> - System.out.println("ObjectSaveTest:testArrayList(): error during save [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + catch (Exception ex2)
> + {
> + System.out.println("ObjectSaveTest:testArrayList(): error during save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> ex2.printStackTrace();
> }
>
> @@ -388,7 +400,8 @@
> // ---------------------------------------------------------
> ArrayList restored_obj = null;
>
> - try {
> + try
> + {
> // setup an input stream to the file
> FileInputStream inStream = new FileInputStream(theFile);
>
> @@ -404,33 +417,37 @@
> inStream.close();
>
> restored = true;
> - System.out.println(
> - "ObjectSaveTest:testArrayList(): ....restored operation completed.....");
> + System.out.println("ObjectSaveTest:testArrayList(): ....restored operation completed.....");
>
> }
> - catch (Exception ex2) {
> - System.out.println("ObjectSaveTest:testArrayList(): error during restore [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + catch (Exception ex2)
> + {
> + System.out.println("ObjectSaveTest:testArrayList(): error during restore ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> ex2.printStackTrace();
> }
>
> // if the save/restore of the object succeeded,
> // then don't keep the temporary file around
> boolean removeTmpFile = saved && restored;
> - if (removeTmpFile) {
> - try {
> + if (removeTmpFile)
> + {
> + try
> + {
> theFile.delete();
> }
> - catch (Exception e) {
> + catch (Exception e)
> + {
> // just absorb it
> }
> }
>
> assertTrue(restored);
>
> - if (restored_obj != null) {
> + if (restored_obj != null)
> + {
> int restored_size = restored_obj.size();
> - if (restored_size == (initial_size - 1)) {
> + if (restored_size == (initial_size-1))
> + {
> comparesOK = true;
> }
> }
> @@ -438,7 +455,7 @@
> // TODO: check for exact entries
>
> assertTrue(comparesOK);
> -
> +
> // indicate that the temp file was created ok
> done = true;
> }
> @@ -450,13 +467,14 @@
> }
>
>
> - public void testHashMap() throws Exception {
> - File theFile = null;
> - String theFilename = null;
> - boolean saved = false;
> - boolean restored = false;
> - boolean done = false;
> - boolean comparesOK = false;
> + public void testHashMap() throws Exception
> + {
> + File theFile = null;
> + String theFilename = null;
> + boolean saved = false;
> + boolean restored = false;
> + boolean done = false;
> + boolean comparesOK = false;
>
> System.out.println("ObjectSaveTest:testHashMap(): BEGIN ---------------");
>
> @@ -474,7 +492,7 @@
> obj.put(new String("key8"), new Integer(5));
> obj.put(new String("key9"), new Integer(6));
> obj.put(new NotSerializableObject("TestForHashMapKey"), new Integer(7));
> - obj.put(new String("key10"), new Integer(8));
> + obj.put(new String("key10"),new Integer(8));
>
>
> int initial_size = obj.size();
> @@ -482,22 +500,25 @@
> // ---------------------------------------------------------
> // setup a temporary file to use
> // ---------------------------------------------------------
> - try {
> - theFile = File.createTempFile("hashmapTest", null);
> + try
> + {
> + theFile = File.createTempFile("hashmapTest",null);
> theFilename = theFile.getName();
> - System.out.println("ObjectSaveTest:testHashMap(): temp file = [" + theFilename + "]");
> + System.out.println("ObjectSaveTest:testHashMap(): temp file = ["+theFilename+"]");
> }
> - catch (Exception ex) {
> - System.out.println("ObjectSaveTest:testHashMap(): error creating temp file = [" +
> - ex.getMessage() + "]");
> + catch (Exception ex)
> + {
> + System.out.println("ObjectSaveTest:testHashMap(): error creating temp file = ["+ex.getMessage()+"]");
> theFile = null;
> }
>
> - if (theFile != null) {
> + if (theFile != null)
> + {
> // ---------------------------------------------------------
> // save to the temporary file
> // ---------------------------------------------------------
> - try {
> + try
> + {
> // setup an output stream to a physical file
> FileOutputStream outStream = new FileOutputStream(theFile);
>
> @@ -517,16 +538,14 @@
> outStream.close();
>
> saved = true;
> - System.out
> - .println("ObjectSaveTest:testHashMap(): ....save operation completed.....");
> + System.out.println("ObjectSaveTest:testHashMap(): ....save operation completed.....");
>
> long filesize = theFile.length();
> - System.out.println("ObjectSaveTest:testHashMap(): file size after save [" +
> - filesize + "] temp file = [" + theFilename + "]");
> + System.out.println("ObjectSaveTest:testHashMap(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
> }
> - catch (Exception ex2) {
> - System.out.println("ObjectSaveTest:testHashMap(): error during save [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + catch (Exception ex2)
> + {
> + System.out.println("ObjectSaveTest:testHashMap(): error during save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> ex2.printStackTrace();
> }
>
> @@ -537,7 +556,8 @@
> // ---------------------------------------------------------
> HashMap restored_obj = null;
>
> - try {
> + try
> + {
> // setup an input stream to the file
> FileInputStream inStream = new FileInputStream(theFile);
>
> @@ -553,33 +573,37 @@
> inStream.close();
>
> restored = true;
> - System.out.println(
> - "ObjectSaveTest:testHashMap(): ....restored operation completed.....");
> + System.out.println("ObjectSaveTest:testHashMap(): ....restored operation completed.....");
>
> }
> - catch (Exception ex2) {
> - System.out.println("ObjectSaveTest:testHashMap(): error during restore [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + catch (Exception ex2)
> + {
> + System.out.println("ObjectSaveTest:testHashMap(): error during restore ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> ex2.printStackTrace();
> }
>
> // if the save/restore of the object succeeded,
> // then don't keep the temporary file around
> boolean removeTmpFile = saved && restored;
> - if (removeTmpFile) {
> - try {
> + if (removeTmpFile)
> + {
> + try
> + {
> theFile.delete();
> }
> - catch (Exception e) {
> + catch (Exception e)
> + {
> // just absorb it
> }
> }
>
> assertTrue(restored);
>
> - if (restored_obj != null) {
> + if (restored_obj != null)
> + {
> int restored_size = restored_obj.size();
> - if (restored_size == (initial_size - 3)) {
> + if (restored_size == (initial_size-3))
> + {
> // there are entries in the map that are not serializable
> comparesOK = true;
> }
> @@ -588,7 +612,7 @@
> // TODO: check for exact entries
>
> assertTrue(comparesOK);
> -
> +
> // indicate that the temp file was created ok
> done = true;
> }
> @@ -600,13 +624,14 @@
> }
>
>
> - public void testLinkedList() throws Exception {
> - File theFile = null;
> - String theFilename = null;
> - boolean saved = false;
> - boolean restored = false;
> - boolean done = false;
> - boolean comparesOK = false;
> + public void testLinkedList() throws Exception
> + {
> + File theFile = null;
> + String theFilename = null;
> + boolean saved = false;
> + boolean restored = false;
> + boolean done = false;
> + boolean comparesOK = false;
>
> System.out.println("ObjectSaveTest:testLinkedList(): BEGIN ---------------");
>
> @@ -630,23 +655,25 @@
> // ---------------------------------------------------------
> // setup a temporary file to use
> // ---------------------------------------------------------
> - try {
> - theFile = File.createTempFile("linkedlistTest", null);
> + try
> + {
> + theFile = File.createTempFile("linkedlistTest",null);
> theFilename = theFile.getName();
> - System.out
> - .println("ObjectSaveTest:testLinkedList(): temp file = [" + theFilename + "]");
> + System.out.println("ObjectSaveTest:testLinkedList(): temp file = ["+theFilename+"]");
> }
> - catch (Exception ex) {
> - System.out.println("ObjectSaveTest:testLinkedList(): error creating temp file = [" +
> - ex.getMessage() + "]");
> + catch (Exception ex)
> + {
> + System.out.println("ObjectSaveTest:testLinkedList(): error creating temp file = ["+ex.getMessage()+"]");
> theFile = null;
> }
>
> - if (theFile != null) {
> + if (theFile != null)
> + {
> // ---------------------------------------------------------
> // save to the temporary file
> // ---------------------------------------------------------
> - try {
> + try
> + {
> // setup an output stream to a physical file
> FileOutputStream outStream = new FileOutputStream(theFile);
>
> @@ -666,16 +693,14 @@
> outStream.close();
>
> saved = true;
> - System.out.println(
> - "ObjectSaveTest:testLinkedList(): ....save operation completed.....");
> + System.out.println("ObjectSaveTest:testLinkedList(): ....save operation completed.....");
>
> long filesize = theFile.length();
> - System.out.println("ObjectSaveTest:testLinkedList(): file size after save [" +
> - filesize + "] temp file = [" + theFilename + "]");
> + System.out.println("ObjectSaveTest:testLinkedList(): file size after save ["+filesize+"] temp file = ["+theFilename+"]");
> }
> - catch (Exception ex2) {
> - System.out.println("ObjectSaveTest:testLinkedList(): error during save [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + catch (Exception ex2)
> + {
> + System.out.println("ObjectSaveTest:testLinkedList(): error during save ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> ex2.printStackTrace();
> }
>
> @@ -686,7 +711,8 @@
> // ---------------------------------------------------------
> LinkedList restored_obj = null;
>
> - try {
> + try
> + {
> // setup an input stream to the file
> FileInputStream inStream = new FileInputStream(theFile);
>
> @@ -697,39 +723,42 @@
> // try to restore the options
> System.out.println("ObjectSaveTest:testLinkedList(): restoring .....");
> restored = false;
> - restored_obj =
> - ObjectStateUtils.readLinkedList(inObjStream, "testObject:LinkedList");
> + restored_obj = ObjectStateUtils.readLinkedList(inObjStream, "testObject:LinkedList");
> inObjStream.close();
> inStream.close();
>
> restored = true;
> - System.out.println(
> - "ObjectSaveTest:testLinkedList(): ....restored operation completed.....");
> + System.out.println("ObjectSaveTest:testLinkedList(): ....restored operation completed.....");
>
> }
> - catch (Exception ex2) {
> - System.out.println("ObjectSaveTest:testLinkedList(): error during restore [" +
> - ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
> + catch (Exception ex2)
> + {
> + System.out.println("ObjectSaveTest:testLinkedList(): error during restore ["+ex2.getClass().getName()+" : "+ex2.getMessage()+"]");
> ex2.printStackTrace();
> }
>
> // if the save/restore of the object succeeded,
> // then don't keep the temporary file around
> boolean removeTmpFile = saved && restored;
> - if (removeTmpFile) {
> - try {
> + if (removeTmpFile)
> + {
> + try
> + {
> theFile.delete();
> }
> - catch (Exception e) {
> + catch (Exception e)
> + {
> // just absorb it
> }
> }
>
> assertTrue(restored);
>
> - if (restored_obj != null) {
> + if (restored_obj != null)
> + {
> int restored_size = restored_obj.size();
> - if (restored_size == (initial_size - 1)) {
> + if (restored_size == (initial_size-1))
> + {
> comparesOK = true;
> }
> }
> @@ -737,7 +766,7 @@
> // TODO: check for exact entries
>
> assertTrue(comparesOK);
> -
> +
> // indicate that the temp file was created ok
> done = true;
> }
> @@ -749,7 +778,10 @@
> }
>
>
> - public class NotSerializableObject implements Externalizable {
> +
> +
> + public class NotSerializableObject implements Externalizable
> + {
> private String label = "TestObject";
> private String ID = null;
>
> @@ -757,29 +789,34 @@
> private PrintStream ps = System.out;
>
> // default constructor needed for Externalizable interface
> - public NotSerializableObject() {
> + public NotSerializableObject()
> + {
> }
>
> - public NotSerializableObject(String identifier) {
> + public NotSerializableObject(String identifier)
> + {
> ID = identifier;
> ps = System.out;
> }
> -
> - public void setID(String s) {
> +
> + public void setID(String s)
> + {
> ID = s;
> }
>
> - public String getID() {
> + public String getID()
> + {
> return ID;
> }
>
> - public void writeExternal(java.io.ObjectOutput out) throws IOException {
> + public void writeExternal(java.io.ObjectOutput out) throws IOException
> + {
> throw new NotSerializableException("Test Object is not serializable");
> }
>
>
> - public void readExternal(java.io.ObjectInput in)
> - throws IOException, ClassNotFoundException {
> + public void readExternal(java.io.ObjectInput in) throws IOException, ClassNotFoundException
> + {
> throw new IOException("Test object is not serializable");
> }
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-cvs-help@ws.apache.org
>
>
--
Davanum Srinivas :: http://wso2.org/ :: Oxygen for Web Services Developers
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org