Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/Development/DBWS/ParseDDLDS/Testing/VisitMethods"
< EclipseLink | Development | DBWS | ParseDDLDS | Testing
(→Tests) |
(→Tests) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 9: | Line 9: | ||
= Parsing DDL for Metadata: Visit Method Testing = | = Parsing DDL for Metadata: Visit Method Testing = | ||
− | + | == Tests == | |
− | The purpose of the following | + | 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 <code>xxxType</code> instance. For example: |
− | The tests reside in the org.eclipse.persistence.tools.oracleddl.test.metadata.visit package. | + | === Test suite === |
+ | <source lang="java"> | ||
+ | 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); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | === Visitor === | ||
+ | <source lang="java"> | ||
+ | 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(); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | The tests reside in the <code>org.eclipse.persistence.tools.oracleddl.test.metadata.visit</code> package. | ||
<br> | <br> | ||
Line 19: | Line 110: | ||
{| width="200" border="1" cellpadding="1" cellspacing="1" | {| width="200" border="1" cellpadding="1" cellspacing="1" | ||
|- | |- | ||
− | | Test | + | | Test Suite |
− | | | + | | Types Covered |
| Implemented | | Implemented | ||
|- | |- | ||
| FunctionTypeTestSuite | | FunctionTypeTestSuite | ||
| FunctionType, DatabaseType, ProcedureType, ArgumentType, ArgumentTypeDirection | | FunctionType, DatabaseType, ProcedureType, ArgumentType, ArgumentTypeDirection | ||
− | | Yes | + | | Yes |
|- | |- | ||
| IntervalTypeTestSuite | | IntervalTypeTestSuite | ||
− | | IntervalDayToSecond, | + | | IntervalDayToSecond, IntervalYearToMonth |
− | | Yes | + | | Yes |
|- | |- | ||
| PrecisionTypeTestSuite | | PrecisionTypeTestSuite | ||
| DecimalType, DoubleType, FloatType, NumericType, RealType | | DecimalType, DoubleType, FloatType, NumericType, RealType | ||
− | | Yes | + | | Yes |
|- | |- | ||
| ProcedureTypeTestSuite | | ProcedureTypeTestSuite | ||
| ProcedureType, ArgumentType, ArgumentTypeDirection, DatabaseType | | ProcedureType, ArgumentType, ArgumentTypeDirection, DatabaseType | ||
− | | Yes | + | | Yes |
|- | |- | ||
| SizedTypeTestSuite | | SizedTypeTestSuite | ||
| BinaryType, BlobType, CharType, ClobType, LongRawType, LongType, NCharType, NClobType, NVarChar2Type, RawType, URowIdType, VarChar2Type, VarCharType | | BinaryType, BlobType, CharType, ClobType, LongRawType, LongType, NCharType, NClobType, NVarChar2Type, RawType, URowIdType, VarChar2Type, VarCharType | ||
− | | Yes | + | | Yes |
|- | |- | ||
| TableTypeTestSuite | | TableTypeTestSuite | ||
| TableType, FieldType, DatabaseType | | TableType, FieldType, DatabaseType | ||
− | | Yes | + | | Yes |
|} | |} |
Latest revision as of 12:57, 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 xxxType
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 |