org.brocalc.domain.SerializationTest.java Source code

Java tutorial

Introduction

Here is the source code for org.brocalc.domain.SerializationTest.java

Source

/*******************************************************************************
 * Copyright (c) 2013 51zero Ltd.
 *
 * This file is part of the Brokerage Calculation Library (brocalc).
 *
 * brocalc 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 3 of the License, or (at your
 * option) any later version.
 *
 * brocalc is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even he 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 brocalc.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

package org.brocalc.domain;

import org.apache.commons.lang.SerializationUtils;
import org.brocalc.domain.Broker;
import org.junit.Test;

import org.brocalc.calculator.BrokerageSchedule;
import org.brocalc.calculator.BrokerageScheduleFactory;

public class SerializationTest {

    private static final String EXAMPLE_SCHEDULE = "Active on and after 02-Mar-2012 \n" + "PLN,CZK,HUF,EUR\n"
            + "1 - 3 days - 5 USD per million USD transacted\n"
            + "4 days and over - 6 USD per million USD transacted \n" + "\n"
            + "Active between 01-Jan-2012 and 01-Mar-2012\n" + "PLN,CZK,HUF,EUR \n"
            + "6 USD per million USD transacted\n" + "\n" + "Active on and before 31-Dec-2011\n"
            + "PLN,CZK,HUF,EUR\n" + "7 USD per million USD transacted\n";

    @Test
    public void brokerageScheduleShouldSerialize() {
        Broker broker = new Broker("TestBroker");

        BrokerageScheduleFactory brokerageScheduleFactory = new BrokerageScheduleFactory();
        BrokerageSchedule brokerageSchedule = brokerageScheduleFactory.createBrokerageSchedule(broker,
                EXAMPLE_SCHEDULE);

        byte[] serializedForm = SerializationUtils.serialize(brokerageSchedule);
        brokerageSchedule = (BrokerageSchedule) SerializationUtils.deserialize(serializedForm);
    }

}