001/*
002 *  jDTAUS Core API
003 *  Copyright (C) 2005 Christian Schulte
004 *  <cs@schulte.it>
005 *
006 *  This library is free software; you can redistribute it and/or
007 *  modify it under the terms of the GNU Lesser General Public
008 *  License as published by the Free Software Foundation; either
009 *  version 2.1 of the License, or any later version.
010 *
011 *  This library is distributed in the hope that it will be useful,
012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 *  Lesser General Public License for more details.
015 *
016 *  You should have received a copy of the GNU Lesser General Public
017 *  License along with this library; if not, write to the Free Software
018 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
019 *
020 */
021package org.jdtaus.core.container.test;
022
023import java.io.ObjectInputStream;
024import junit.framework.Assert;
025import junit.framework.TestCase;
026import org.jdtaus.core.container.Dependencies;
027import org.jdtaus.core.container.Implementation;
028import org.jdtaus.core.container.Properties;
029import org.jdtaus.core.container.Specifications;
030
031/**
032 * jUnit tests for {@code Implementation} implementations.
033 *
034 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
035 * @version $JDTAUS: ImplementationTest.java 8641 2012-09-27 06:45:17Z schulte $
036 */
037public class ImplementationTest extends TestCase
038{
039    //--ImplementationTest------------------------------------------------------
040
041    public void testObject() throws Exception
042    {
043        final Implementation i1 = new Implementation();
044        final Implementation i2 = new Implementation();
045
046        Assert.assertEquals( i1, i2 );
047        Assert.assertEquals( i1.hashCode(), i2.hashCode() );
048
049        System.out.println( i1.toString() );
050        System.out.println( i2.toString() );
051
052        i1.setDependencies( new Dependencies() );
053        i1.setImplementedSpecifications( new Specifications() );
054        i1.setParent( new Implementation() );
055        i1.setProperties( new Properties() );
056
057        i2.setDependencies( new Dependencies() );
058        i2.setImplementedSpecifications( new Specifications() );
059        i2.setParent( new Implementation() );
060        i2.setProperties( new Properties() );
061
062        Assert.assertEquals( i1, i2 );
063        Assert.assertEquals( i1.hashCode(), i2.hashCode() );
064
065        System.out.println( i1.toString() );
066        System.out.println( i2.toString() );
067
068        final Implementation clone1 = (Implementation) i1.clone();
069        final Implementation clone2 = (Implementation) i2.clone();
070
071        Assert.assertEquals( clone1, clone2 );
072        Assert.assertEquals( clone1.hashCode(), clone2.hashCode() );
073
074        System.out.println( clone1.toString() );
075        System.out.println( clone2.toString() );
076    }
077
078    public void testBackwardCompatibility_1_0() throws Exception
079    {
080        final ObjectInputStream in = new ObjectInputStream( this.getClass().
081            getResourceAsStream( "Implementation.ser" ) );
082
083        final Implementation current = new Implementation();
084        final Implementation serialized = (Implementation) in.readObject();
085
086        Assert.assertEquals( current, serialized );
087        Assert.assertEquals( current.hashCode(), serialized.hashCode() );
088    }
089
090    //------------------------------------------------------ImplementationTest--
091}