Package org.hibernate.test.cfg

Source Code of org.hibernate.test.cfg.ConfigurationSerializationTest$Serial

/*
* Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
* third-party contributors as indicated by either @author tags or express
* copyright attribution statements applied by the authors.  All
* third-party contributions are distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program 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 distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA  02110-1301  USA\
*/
package org.hibernate.test.cfg;

import javax.persistence.Entity;
import javax.persistence.Id;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.hibernate.testing.junit.UnitTestCase;
import org.hibernate.cfg.Configuration;
import org.hibernate.util.SerializationHelper;
import org.hibernate.SessionFactory;

/**
* Copied over mostly from ConfigurationPerformanceTest
*
* @author Steve Ebersole
* @author Max Andersen
*/
public class ConfigurationSerializationTest extends UnitTestCase {
  public ConfigurationSerializationTest(String string) {
    super( string );
  }

  public static Test suite() {
    return new TestSuite( ConfigurationSerializationTest.class );
  }

  private static final String[] FILES = new String[] {
      "legacy/ABC.hbm.xml",
      "legacy/ABCExtends.hbm.xml",
      "legacy/Baz.hbm.xml",
      "legacy/Blobber.hbm.xml",
      "legacy/Broken.hbm.xml",
      "legacy/Category.hbm.xml",
      "legacy/Circular.hbm.xml",
      "legacy/Commento.hbm.xml",
      "legacy/ComponentNotNullMaster.hbm.xml",
      "legacy/Componentizable.hbm.xml",
      "legacy/Container.hbm.xml",
      "legacy/Custom.hbm.xml",
      "legacy/CustomSQL.hbm.xml",
      "legacy/Eye.hbm.xml",
      "legacy/Fee.hbm.xml",
      "legacy/Fo.hbm.xml",
      "legacy/FooBar.hbm.xml",
      "legacy/Fum.hbm.xml",
      "legacy/Fumm.hbm.xml",
      "legacy/Glarch.hbm.xml",
      "legacy/Holder.hbm.xml",
      "legacy/IJ2.hbm.xml",
      "legacy/Immutable.hbm.xml",
      "legacy/Location.hbm.xml",
      "legacy/Many.hbm.xml",
      "legacy/Map.hbm.xml",
      "legacy/Marelo.hbm.xml",
      "legacy/MasterDetail.hbm.xml",
      "legacy/Middle.hbm.xml",
      "legacy/Multi.hbm.xml",
      "legacy/MultiExtends.hbm.xml",
      "legacy/Nameable.hbm.xml",
      "legacy/One.hbm.xml",
      "legacy/ParentChild.hbm.xml",
      "legacy/Qux.hbm.xml",
      "legacy/Simple.hbm.xml",
      "legacy/SingleSeveral.hbm.xml",
      "legacy/Stuff.hbm.xml",
      "legacy/UpDown.hbm.xml",
      "legacy/Vetoer.hbm.xml",
      "legacy/WZ.hbm.xml",
      "cfg/orm-serializable.xml"
  };

  public void testConfiguraionSerializability() {
    Configuration cfg = new Configuration();
    for ( String file : FILES ) {
      cfg.addResource( "org/hibernate/test/" + file );
    }

    cfg.addAnnotatedClass( Serial.class );

    byte[] bytes = SerializationHelper.serialize( cfg );
    cfg = ( Configuration ) SerializationHelper.deserialize( bytes );

    // try to build SF
    SessionFactory factory = cfg.buildSessionFactory();
    factory.close();
  }

  @Entity
  public static class Serial {
    private String id;
    private String value;

    @Id
    public String getId() {
      return id;
    }

    public void setId(String id) {
      this.id = id;
    }
  }
}
TOP

Related Classes of org.hibernate.test.cfg.ConfigurationSerializationTest$Serial

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.