/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.serial.data.tests;
import junit.framework.TestCase;
import org.jboss.serial.data.TestWithBigDecimal;
import org.jboss.serial.io.JBossObjectOutputStream;
import org.jboss.serial.io.JBossObjectInputStream;
import java.io.*;
import java.math.BigDecimal;
/**
* $Id: BigDecimalTestCase.java,v 1.4 2006/04/18 18:42:38 csuconic Exp $
*
* @author <a href="mailto:clebert.suconic@jboss.com">Clebert Suconic</a>
*/
public class BigDecimalTestCase extends TestCase {
public void testJBossSerialization() throws Exception
{
for (int i=0;i<1000;i++)
{
TestWithBigDecimal obj = TestWithBigDecimal.createTestInstance();
ByteArrayOutputStream byteout = new ByteArrayOutputStream();
JBossObjectOutputStream out = new JBossObjectOutputStream (byteout);
out.writeObject(obj);
out.flush();
JBossObjectInputStream inp = new JBossObjectInputStream (new ByteArrayInputStream(byteout.toByteArray()));
TestWithBigDecimal obj2 = (TestWithBigDecimal)inp.readObject();
assertTrue(obj!=obj2);
assertEquals(obj,obj2);
BigDecimal result = obj2.getValue().add(obj2.getValue2());
System.out.println("result = " + result);
}
}
public void testJavaSerialization() throws Exception
{
TestWithBigDecimal obj = TestWithBigDecimal.createTestInstance();
ByteArrayOutputStream byteout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream (byteout);
out.writeObject(obj);
out.flush();
ObjectInputStream inp = new ObjectInputStream (new ByteArrayInputStream(byteout.toByteArray()));
TestWithBigDecimal obj2 = (TestWithBigDecimal)inp.readObject();
assertTrue(obj!=obj2);
assertEquals(obj,obj2);
BigDecimal result = obj2.getValue().add(obj2.getValue2());
System.out.println("result = " + result);
}
public void testBigDecimalOnSerialization() throws Exception
{
TestWithBigDecimal obj = TestWithBigDecimal.createTestInstance();
BigDecimal decimal1_1 = obj.getValue();
BigDecimal decimal1_2 = obj.getValue2();
ByteArrayOutputStream byteout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream (byteout);
out.writeObject(decimal1_1);
out.writeObject(decimal1_2);
out.flush();
ObjectInputStream inp = new ObjectInputStream (new ByteArrayInputStream(byteout.toByteArray()));
BigDecimal decimal2_1 = (BigDecimal)inp.readObject();
BigDecimal decimal2_2 = (BigDecimal)inp.readObject();
BigDecimal result2 = decimal2_1.add(decimal2_2);
System.out.println("Result = " + result2);
}
}