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 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); } }