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 junit.framework.Assert; 024import junit.framework.TestCase; 025import org.jdtaus.core.container.Dependencies; 026import org.jdtaus.core.container.Dependency; 027import org.jdtaus.core.container.Implementation; 028import org.jdtaus.core.container.Implementations; 029import org.jdtaus.core.container.Module; 030import org.jdtaus.core.container.Modules; 031import org.jdtaus.core.container.Properties; 032import org.jdtaus.core.container.Property; 033import org.jdtaus.core.container.Specification; 034import org.jdtaus.core.container.Specifications; 035 036/** 037 * Unit tests for the container model. 038 * 039 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 040 * @version $JDTAUS: ModelTest.java 8709 2012-10-02 21:07:40Z schulte $ 041 */ 042public class ModelTest extends TestCase 043{ 044 //--ModelTest--------------------------------------------------------------- 045 046 /** 047 * Creates a linked test model. 048 * 049 * @return a linked test model. 050 */ 051 public static final Modules getTestModel() 052 { 053 final Specification spec = new Specification(); 054 final Specifications specs = new Specifications(); 055 final Implementation impl = new Implementation(); 056 final Implementations impls = new Implementations(); 057 final Dependency dep = new Dependency(); 058 final Dependencies deps = new Dependencies(); 059 final Property prop = new Property(); 060 final Properties props = new Properties(); 061 final Module mod = new Module(); 062 final Modules mods = new Modules(); 063 064 spec.setIdentifier( Specification.class.getName() ); 065 impl.setIdentifier( Implementation.class.getName() ); 066 impl.setName( Implementation.class.getName() ); 067 dep.setName( Dependency.class.getName() ); 068 prop.setName( Property.class.getName() ); 069 prop.setType( String.class ); 070 mod.setName( Module.class.getName() ); 071 072 specs.setSpecifications( new Specification[] { spec } ); 073 impls.setImplementations( new Implementation[] { impl } ); 074 deps.setDependencies( new Dependency[] { dep } ); 075 props.setProperties( new Property[] { prop } ); 076 mods.setModules( new Module[] { mod } ); 077 078 spec.setImplementations( impls ); 079 impl.setDependencies( deps ); 080 impl.setImplementedSpecifications( specs ); 081 impl.setProperties( props ); 082 dep.setImplementation( impl ); 083 dep.setProperties( props ); 084 dep.setSpecification( spec ); 085 mod.setImplementations( impls ); 086 mod.setProperties( props ); 087 mod.setSpecifications( specs ); 088 089 return mods; 090 } 091 092 //---------------------------------------------------------------ModelTest-- 093 //--Tests------------------------------------------------------------------- 094 095 /** 096 * Tests the {@code equals(Object)}, {@code hashCode()}, {@code toString()} 097 * and {@code clone()} methods of all model objects. 098 */ 099 public void testObject() throws Exception 100 { 101 final Modules mods = ModelTest.getTestModel(); 102 103 Assert.assertEquals( mods, mods ); 104 Assert.assertEquals( mods.hashCode(), mods.hashCode() ); 105 System.out.println( mods ); 106 mods.clone(); 107 108 final Specifications specs = mods.getSpecifications(); 109 110 Assert.assertEquals( specs, specs ); 111 Assert.assertEquals( specs.hashCode(), specs.hashCode() ); 112 System.out.println( specs ); 113 specs.clone(); 114 115 final Implementations impls = mods.getImplementations(); 116 117 Assert.assertEquals( impls, impls ); 118 Assert.assertEquals( impls.hashCode(), impls.hashCode() ); 119 System.out.println( impls ); 120 impls.clone(); 121 } 122 123 //-------------------------------------------------------------------Tests-- 124}