View Javadoc

1   /*
2    *  jDTAUS Core API
3    *  Copyright (C) 2005 Christian Schulte
4    *  <cs@schulte.it>
5    *
6    *  This library is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public
8    *  License as published by the Free Software Foundation; either
9    *  version 2.1 of the License, or any later version.
10   *
11   *  This library is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this library; if not, write to the Free Software
18   *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19   *
20   */
21  package org.jdtaus.core.container.test;
22  
23  import junit.framework.Assert;
24  import junit.framework.TestCase;
25  import org.jdtaus.core.container.Dependencies;
26  import org.jdtaus.core.container.Dependency;
27  import org.jdtaus.core.container.Implementation;
28  import org.jdtaus.core.container.Implementations;
29  import org.jdtaus.core.container.Module;
30  import org.jdtaus.core.container.Modules;
31  import org.jdtaus.core.container.Properties;
32  import org.jdtaus.core.container.Property;
33  import org.jdtaus.core.container.Specification;
34  import org.jdtaus.core.container.Specifications;
35  
36  /**
37   * Unit tests for the container model.
38   *
39   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
40   * @version $JDTAUS: ModelTest.java 8709 2012-10-02 21:07:40Z schulte $
41   */
42  public class ModelTest extends TestCase
43  {
44      //--ModelTest---------------------------------------------------------------
45  
46      /**
47       * Creates a linked test model.
48       *
49       * @return a linked test model.
50       */
51      public static final Modules getTestModel()
52      {
53          final Specification spec = new Specification();
54          final Specifications specs = new Specifications();
55          final Implementation impl = new Implementation();
56          final Implementations impls = new Implementations();
57          final Dependency dep = new Dependency();
58          final Dependencies deps = new Dependencies();
59          final Property prop = new Property();
60          final Properties props = new Properties();
61          final Module mod = new Module();
62          final Modules mods = new Modules();
63  
64          spec.setIdentifier( Specification.class.getName() );
65          impl.setIdentifier( Implementation.class.getName() );
66          impl.setName( Implementation.class.getName() );
67          dep.setName( Dependency.class.getName() );
68          prop.setName( Property.class.getName() );
69          prop.setType( String.class );
70          mod.setName( Module.class.getName() );
71  
72          specs.setSpecifications( new Specification[] { spec } );
73          impls.setImplementations( new Implementation[] { impl } );
74          deps.setDependencies( new Dependency[] { dep } );
75          props.setProperties( new Property[] { prop } );
76          mods.setModules( new Module[] { mod } );
77  
78          spec.setImplementations( impls );
79          impl.setDependencies( deps );
80          impl.setImplementedSpecifications( specs );
81          impl.setProperties( props );
82          dep.setImplementation( impl );
83          dep.setProperties( props );
84          dep.setSpecification( spec );
85          mod.setImplementations( impls );
86          mod.setProperties( props );
87          mod.setSpecifications( specs );
88  
89          return mods;
90      }
91  
92      //---------------------------------------------------------------ModelTest--
93      //--Tests-------------------------------------------------------------------
94  
95      /**
96       * Tests the {@code equals(Object)}, {@code hashCode()}, {@code toString()}
97       * and {@code clone()} methods of all model objects.
98       */
99      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 }