Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Development/DBWS/ParseDDLDS/Testing/VisitMethods"

(Test suite)
(Tests)
Line 11: Line 11:
 
== Tests  ==
 
== Tests  ==
  
The purpose of the following tests is to ensure that all visit methods in a given chain are called. The tests verify that all data set in the model can be retrieved successfully.  Each test suite has an associated <code>visitor</code>, whose purpose is to build a string representation of the data contained in the given Type instance.  For example:
+
The purpose of the following test suites is to ensure that all visit methods in a given chain are called. The tests verify that all data set in the model can be retrieved successfully.  Each test suite has an associated <code>visitor</code>, whose purpose is to build a string representation of the data contained in the given Type instance.  For example:
  
 
=== Test suite ===
 
=== Test suite ===

Revision as of 12:10, 12 August 2011


Parsing DDL for Metadata: Visit Method Testing

Tests

The purpose of the following test suites is to ensure that all visit methods in a given chain are called. The tests verify that all data set in the model can be retrieved successfully. Each test suite has an associated visitor, whose purpose is to build a string representation of the data contained in the given Type instance. For example:

Test suite

public class TableTypeTestSuite {
    protected static String TABLE =
            "TABLE EMP_SCHEMA.EMPLOYEE (\n" +
                    "\tID\tVARCHAR\n" +
                    "\tNAME\tVARCHAR2 (NOT NULL)\n" +
                    "\tDEPT\tNUMERIC\n" +
                    "\tPRIMARY KEY (ID)\n" +
                ")";
 
    @Test
    public void testTableType() {
        // setup TableType
        TableType table = new TableType("EMPLOYEE");
        table.setSchema("EMP_SCHEMA");
 
        FieldType col = new FieldType("ID");
        col.setDataType(new VarCharType());
        col.setPk();
        table.addCompositeType(col);
        col = new FieldType("NAME");
        col.setDataType(new VarChar2Type());
        col.setNotNull();
        table.addCompositeType(col);
        col = new FieldType("DEPT");
        col.setDataType(new NumericType());
        table.addCompositeType(col);
 
        // visit
        TableTypeVisitor visitor = new TableTypeVisitor();
        table.accept(visitor);
        assertEquals("TableTypeVisitor test failed:\n", visitor.toString(), TABLE);
    }
}

Visitor

public class TableTypeVisitor extends BaseDatabaseTypeVisitor {
    public String tableName;
    public String schema;
    public List<String> columnData = new ArrayList<String>();
    public List<String> pkColumns = new ArrayList<String>();
 
    public void beginVisit(TableType databaseType) {
        tableName = databaseType.getTableName();
        schema = databaseType.getSchema();
    }
 
    public void beginVisit(FieldType databaseType) {
        if (databaseType.notNull()) {
            columnData.add(databaseType.getFieldName() + "\t" + databaseType.getTypeName() + " (NOT NULL)");
        } else {
            columnData.add(databaseType.getFieldName() + "\t" + databaseType.getTypeName());
        }
        if (databaseType.pk()) {
            pkColumns.add(databaseType.getFieldName());
        }
    }
 
    public String toString() {
        StringBuilder sb = new StringBuilder("TABLE ");
        if (schema != null) {
            sb.append(schema);
            sb.append(".");
        }
        sb.append(tableName);
        sb.append(" (\n");
        for (String col : columnData) {
            sb.append("\t");
            sb.append(col);
            sb.append("\n");
        }
        if (pkColumns.size() > 0) {
            sb.append("\t");
            sb.append("PRIMARY KEY (");
            for (int i = 0; i < pkColumns.size();) {
                sb.append(pkColumns.get(i));
                if (++i < pkColumns.size()) {
                    sb.append(',');
                }
            }
            sb.append(")\n");
        }
        sb.append(")");
        return sb.toString();
    }
}

The tests reside in the org.eclipse.persistence.tools.oracleddl.test.metadata.visit package.


Test Suite Types Covered Implemented
FunctionTypeTestSuite FunctionType, DatabaseType, ProcedureType, ArgumentType, ArgumentTypeDirection   Yes
IntervalTypeTestSuite IntervalDayToSecond, IntervalYearToMonth   Yes
PrecisionTypeTestSuite DecimalType, DoubleType, FloatType, NumericType, RealType    Yes
ProcedureTypeTestSuite ProcedureType, ArgumentType, ArgumentTypeDirection, DatabaseType   Yes
SizedTypeTestSuite BinaryType, BlobType, CharType, ClobType, LongRawType, LongType, NCharType, NClobType, NVarChar2Type, RawType, URowIdType, VarChar2Type, VarCharType   Yes
TableTypeTestSuite TableType, FieldType, DatabaseType   Yes

Back to the top