summaryrefslogtreecommitdiffstats
path: root/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/api/DataFactory/DataFactoryConsistencyBase.java
blob: cc32e6a0cb41d6a19163bf3e58a146a6218bdb07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 *  
 *  $Rev: 537762 $  $Date: 2007-05-14 10:38:19 +0100 (Mon, 14 May 2007) $
 */
package test.sdo21.tests.api.DataFactory;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import test.sdo21.tests.TestData.StandardFactory;
import test.sdo21.tests.api.CTSConsistencyBase;
import test.sdo21.tests.util.CTSUtil;

import commonj.sdo.DataObject;
import commonj.sdo.Type;

public abstract class  DataFactoryConsistencyBase extends CTSConsistencyBase {

  
  @Before
  public void setUp () throws Exception {
    super.setUp();
  }
  
  @After
  public void tearDown() throws Exception {
    super.tearDown();
  }
  
  /**
   * Verify the proper operation of DataFactory.create(Type).
   */
  @Test
  public void testDataFactoryCreateByType() {
      Type type = testDO.getType();

      DataObject typeDO = getScope().getDataFactory().create(type);

      assertNotNull("DataFactory.create(Type) did not return a DataObject as expected", typeDO);

      assertTrue("DataFactory.create(Type) did not return a DataObject of the expected Type.", CTSUtil.areEqualTypes(typeDO.getType(), type));
  }

  /**
   * Verify the proper operation of DataFactory.create(URI, Name).
   */
  @Test
  public void testDataFactoryCreateByURI() {
      Type type = testDO.getType();

      DataObject uriDO = getScope().getDataFactory().create(type.getURI(), type.getName());

      assertNotNull("DataFactory.create(URI, Name) did not return a DataObject as expected.", uriDO);

      assertTrue("DataFactory.create(URI, Name) did not return a DataObject of the expected Type.",
                 CTSUtil.areEqualTypes(uriDO.getType(), type));
  }

  /**
   * Verify the proper operation of DataFactory.create(Class).
   */
  @Test
  public void testDataFactoryCreateByClass() {
      Type type = testDO.getType();

      if (type.getInstanceClass() != null) {
          DataObject classDO = getScope().getDataFactory().create(type.getInstanceClass());

          assertNotNull("DataFactory.create(Class) did not return a DataObject as expected.", classDO);

          assertTrue("DataFactory.create(Class) did not return a DataObject of the expected Type.",
                     CTSUtil.areEqualTypes(classDO.getType(), type));
      }
  }

  /**
   * Verify that DataFactory.create with DataType results in
   * IllegalArgumentException
   */
  @Test
  public void testDataFactoryCreateDataTypeException() {
      try {
          Type dataType = getScope().getTypeHelper().getType("commonj.sdo", "Int");
          assertTrue("Could not test DataFactory.create(dataType) because dataType.isDataType = false", dataType
              .isDataType());
          getScope().getDataFactory().create(dataType);
          fail("DataFactory.create(dataType) did not throw an Exception.");
      } catch (IllegalArgumentException e) {
          // Do nothing
      } catch (Exception e) {
          fail("DataFactory.create(dataType) did not throw the expected IllegalArgumentException Exception.");
      }
  }

  /**
   * Verify that DataFactory.create with Abstract Type results in
   * IllegalArgumentException.
   */
  @Test
  public void testDataFactoryCreateAbstractException() {
      try {
          Type abstractType =
              getScope().getTypeHelper().getType(StandardFactory.TEST_NAMESPACE, "Abstract");

          assertTrue("Could not test DataFactory.create(abstractType) because abstractType.isAbstract = false",
                     abstractType.isAbstract());
          getScope().getDataFactory().create(abstractType);
          fail("DataFactory.create(abstractType) did not throw an Exception.");

      } catch (IllegalArgumentException e) {
          // Do nothing
      } catch (Exception e) {
          fail("DataFactory.create(abstractType) did not throw the expected IllegalArgumentException Exception.");
      }
  }
  
  
}