summaryrefslogtreecommitdiffstats
path: root/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/TestData/StandardFactory.java
blob: eee92ee36610cfc93e05fe50fdc27250f14ab2a0 (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
package test.sdo21.tests.TestData;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import test.sdo21.framework.DataObjectFactory;
import commonj.sdo.DataObject;
import commonj.sdo.helper.HelperContext;

/**
 * Abstract base class for creating tests data of an specific nature.
 * Concrete specializations of this class may create the metadata by various means,
 * e.g. the SDO Dynamic API or XSD to SDO conversion,  or some other implementation
 * specific means, e.g. generation of static classes.
 * 
 * All derived classes must create equivalent metatdata by whatever means is chosen.
 *
 */
public abstract class StandardFactory implements TestDataFactory {
  
  public static final String TEST_NAMESPACE = "http://www.example.com/api_test";
  public static final String API_TYPE = "APITest";
  public final static String SEQ_TYPE = "Sequenced";
  public final static String EXT_TYPE = "Extended";
  public static final String ABSTRACT_TYPE = "Abstract";

  /**
   * this factory currently simple makes the assumption that the variant string is the
   * name of a type for which an empty instance is required
   */
  public DataObject createTestData(HelperContext scope, String variantString) throws Exception {
    return scope.getDataFactory().create(TEST_NAMESPACE, variantString);
  }
  
  /**
   * populateFields uses set<Type> to set each of the fields in the
   * DataObject. It is used to ensure a known set of expected values that are
   * not other than the default values for the various fields.
   * 
   * @param testDO
   * @param helperContext
   * @throws ExpectedConditionError
   */
  public void populateFields(DataObject testDO, HelperContext scope) throws Exception {
      testDO.setString("stringVal", "String 1");
      testDO.setBoolean("booleanVal", true);
      testDO.setBoolean("booleanVal2", false);
      testDO.setByte("byteVal", (byte)-127);
      testDO.setString("stringVal2", "Second string!");
      testDO.setBigDecimal("decimalVal", new BigDecimal(-3.00003));
      testDO.setBigDecimal("decimalVal2", new BigDecimal(18883.999999));
      testDO.setInt("intVal", (int)33333);
      testDO.setFloat("floatVal", (float)0.88881);
      testDO.setDouble("doubleVal", (double)119.13813);
      testDO.setDate("dateVal", new Date(System.currentTimeMillis()));
      testDO.setShort("shortVal", (short)-800);
      testDO.setLong("longVal", (long)88881113);
      testDO.setBytes("bytesVal", new byte[] {120, 80, -40});
      testDO.setBigInteger("integerVal", new BigInteger("88819313"));
      testDO.setChar("charVal", '*');
      testDO.setDataObject("sequencedElem", createTestData(scope, SEQ_TYPE));
      testDO.setDataObject("extendedElem", createTestData(scope, EXT_TYPE));
      testDO.setDataObject("contain", createTestData(scope, API_TYPE));
      List containMany = new ArrayList();
      containMany.add(createTestData(scope, API_TYPE));
      testDO.setList("containMany", containMany);
  }

}