use of org.alfresco.util.schemacomp.model.Table in project alfresco-repository by Alfresco.
the class PostgreSQLDialectExportTester method doExportTest.
@Override
protected void doExportTest() throws Exception {
Schema schema = getSchema();
Table exampleTable = null;
Table otherTable = null;
Sequence exampleSeq = null;
for (DbObject dbo : schema) {
if (dbo.getName().equals("export_test_example")) {
exampleTable = (Table) dbo;
}
if (dbo.getName().equals("export_test_other")) {
otherTable = (Table) dbo;
}
if (dbo.getName().equals("export_test_example_seq")) {
exampleSeq = (Sequence) dbo;
}
}
checkExampleTable(schema, exampleTable);
checkOtherTable(schema, otherTable);
checkExampleSequence(schema, exampleSeq);
}
use of org.alfresco.util.schemacomp.model.Table in project alfresco-repository by Alfresco.
the class ValidatingVisitorTest method setUp.
@Before
public void setUp() throws Exception {
refTable = new Table("reference_table");
refIndex = new Index(refTable, "index_name", Arrays.asList("a", "b", "c"));
ctx = new DiffContext(new MySQLInnoDBDialect(), refSchema, targetSchema);
visitor = new ValidatingVisitor(ctx);
validators = new ArrayList<DbValidator>();
validators.add(Mockito.mock(DbValidator.class));
validators.add(Mockito.mock(DbValidator.class));
refIndex.setValidators(validators);
targetTable = new Table("target_table");
targetIndex1 = new Index(targetTable, "index_name", Arrays.asList("a", "b", "c"));
targetIndex2 = new Index(targetTable, "another_index", Arrays.asList("a", "b", "c"));
targetIndex3 = new Index(targetTable, "index_name", Arrays.asList("e", "f"));
comparisonUtils = Mockito.mock(ComparisonUtils.class);
visitor.setComparisonUtils(comparisonUtils);
}
use of org.alfresco.util.schemacomp.model.Table in project alfresco-repository by Alfresco.
the class XMLToSchemaTest method canReadSchemaXML.
@Test
public void canReadSchemaXML() {
xmlToSchema.parse();
Schema schema = xmlToSchema.getSchema();
assertNotNull("A null Schema object was returned", schema);
assertNull("Schema isn't meant to have a parent", schema.getParent());
assertEquals("alfresco", schema.getName());
assertEquals("myprefix_", schema.getDbPrefix());
assertEquals(325, schema.getVersion());
Iterator<DbObject> objects = schema.iterator();
Table table = (Table) objects.next();
assertSame("Wrong or no parent set on table", schema, table.getParent());
assertEquals("node", table.getName());
assertEquals(3, table.getColumns().size());
assertSame("Wrong or no parent set", table, table.getColumns().get(0).getParent());
assertEquals("id", table.getColumns().get(0).getName());
assertEquals("NUMBER(10)", table.getColumns().get(0).getType());
assertEquals(false, table.getColumns().get(0).isNullable());
assertEquals(1, table.getColumns().get(0).getOrder());
assertEquals(true, table.getColumns().get(0).isAutoIncrement());
assertSame("Wrong or no parent set", table, table.getColumns().get(1).getParent());
assertEquals("nodeRef", table.getColumns().get(1).getName());
assertEquals("VARCHAR2(200)", table.getColumns().get(1).getType());
assertEquals(false, table.getColumns().get(1).isNullable());
assertEquals(3, table.getColumns().get(1).getOrder());
assertEquals(false, table.getColumns().get(1).isAutoIncrement());
assertSame("Wrong or no parent set", table, table.getColumns().get(2).getParent());
assertEquals("name", table.getColumns().get(2).getName());
assertEquals("VARCHAR2(150)", table.getColumns().get(2).getType());
assertEquals(true, table.getColumns().get(2).isNullable());
assertEquals(2, table.getColumns().get(2).getOrder());
assertEquals(false, table.getColumns().get(2).isAutoIncrement());
assertSame("Wrong or no parent set", table, table.getPrimaryKey().getParent());
assertEquals("pk_node", table.getPrimaryKey().getName());
assertEquals(1, table.getPrimaryKey().getColumnNames().size());
assertEquals("id", table.getPrimaryKey().getColumnNames().get(0));
assertEquals(1, table.getPrimaryKey().getColumnOrders().get(0).intValue());
assertEquals(1, table.getForeignKeys().size());
assertSame("Wrong or no parent set", table, table.getForeignKeys().get(0).getParent());
assertEquals("fk_node_noderef", table.getForeignKeys().get(0).getName());
assertEquals("nodeRef", table.getForeignKeys().get(0).getLocalColumn());
assertEquals("node", table.getForeignKeys().get(0).getTargetTable());
assertEquals("nodeRef", table.getForeignKeys().get(0).getTargetColumn());
assertEquals(1, table.getIndexes().size());
Index index = table.getIndexes().get(0);
assertSame("Wrong or no parent set on index", table, index.getParent());
assertEquals("idx_node_by_id", index.getName());
assertEquals(true, index.isUnique());
assertEquals(2, index.getColumnNames().size());
assertEquals("id", index.getColumnNames().get(0));
assertEquals("nodeRef", index.getColumnNames().get(1));
assertEquals(1, index.getValidators().size());
DbValidator validator = index.getValidators().get(0);
assertEquals(NameValidator.class, validator.getClass());
assertEquals(1, validator.getPropertyNames().size());
assertEquals("idx_.+", validator.getProperty("pattern"));
Sequence seq = (Sequence) objects.next();
assertSame("Wrong or no parent set", schema, seq.getParent());
assertEquals("node_seq", seq.getName());
seq = (Sequence) objects.next();
assertSame("Wrong or no parent set", schema, seq.getParent());
assertEquals("person_seq", seq.getName());
seq = (Sequence) objects.next();
assertSame("Wrong or no parent set", schema, seq.getParent());
assertEquals("content_seq", seq.getName());
assertFalse("Should be no more DB objects", objects.hasNext());
}
use of org.alfresco.util.schemacomp.model.Table in project alfresco-repository by Alfresco.
the class SchemaComparatorTest method pkOrderingComparedCorrectly.
@Test
public void pkOrderingComparedCorrectly() {
reference = new Schema("schema", "alf_", 590, true);
target = new Schema("schema", "alf_", 590, true);
// Reference schema's database objects.
reference.add(new Table(reference, "table_name", columns("id NUMBER(10)", "nodeRef VARCHAR2(200)", "name VARCHAR2(150)"), new PrimaryKey(null, "my_pk_name", Arrays.asList("id", "nodeRef"), Arrays.asList(1, 2)), fkeys(), indexes()));
// Target schema's database objects - note different order of PK columns.
target.add(new Table(target, "table_name", columns("id NUMBER(10)", "nodeRef VARCHAR2(200)", "name VARCHAR2(150)"), new PrimaryKey(null, "my_pk_name", Arrays.asList("id", "nodeRef"), Arrays.asList(2, 1)), fkeys(), indexes()));
comparator = new SchemaComparator(reference, target, dialect);
comparator.validateAndCompare();
// See stdout for diagnostics dump...
dumpDiffs(comparator.getComparisonResults(), false);
dumpValidation(comparator.getComparisonResults());
Results results = comparator.getComparisonResults();
Iterator<Result> it = results.iterator();
Difference diff = (Difference) it.next();
assertEquals(Where.IN_BOTH_BUT_DIFFERENCE, diff.getWhere());
assertEquals("schema.table_name.my_pk_name.columnOrders[0]", diff.getLeft().getPath());
assertEquals("schema.table_name.my_pk_name.columnOrders[0]", diff.getRight().getPath());
assertEquals("columnOrders[0]", diff.getLeft().getPropertyName());
assertEquals(1, diff.getLeft().getPropertyValue());
assertEquals("columnOrders[0]", diff.getRight().getPropertyName());
assertEquals(2, diff.getRight().getPropertyValue());
diff = (Difference) it.next();
assertEquals(Where.IN_BOTH_BUT_DIFFERENCE, diff.getWhere());
assertEquals("schema.table_name.my_pk_name.columnOrders[1]", diff.getLeft().getPath());
assertEquals("schema.table_name.my_pk_name.columnOrders[1]", diff.getRight().getPath());
assertEquals("columnOrders[1]", diff.getLeft().getPropertyName());
assertEquals(2, diff.getLeft().getPropertyValue());
assertEquals("columnOrders[1]", diff.getRight().getPropertyName());
assertEquals(1, diff.getRight().getPropertyValue());
assertFalse("There should be no more differences", it.hasNext());
}
use of org.alfresco.util.schemacomp.model.Table in project alfresco-repository by Alfresco.
the class SchemaComparatorTest method canPerformDiff.
@Test
public void canPerformDiff() {
// Reference schema's database objects.
reference.add(new Table(reference, "tbl_no_diff", columns("id NUMBER(10)", "nodeRef VARCHAR2(200)", "name VARCHAR2(150)"), pk("pk_tbl_no_diff", "id"), fkeys(fk("fk_tbl_no_diff", "nodeRef", "node", "nodeRef")), indexes("idx_node id nodeRef")));
reference.add(table("table_in_reference"));
reference.add(new Table(reference, "tbl_has_diff_pk", columns("id NUMBER(10)", "nodeRef VARCHAR2(200)"), pk("pk_is_diff", "id"), fkeys(), indexes("idx_one id nodeRef", "idx_two id")));
// Target schema's database objects.
target.add(new Table(target, "tbl_no_diff", columns("id NUMBER(10)", "nodeRef VARCHAR2(200)", "name VARCHAR2(150)"), pk("pk_tbl_no_diff", "id"), fkeys(fk("fk_tbl_no_diff", "nodeRef", "node", "nodeRef")), indexes("idx_node id nodeRef")));
target.add(new Table(target, "tbl_has_diff_pk", columns("id NUMBER(10)", "nodeRef VARCHAR2(200)"), pk("pk_is_diff", "nodeRef"), fkeys(), indexes("idx_one id nodeRef", "idx_two [unique] id")));
target.add(table("table_in_target"));
comparator = new SchemaComparator(reference, target, dialect);
comparator.validateAndCompare();
// See stdout for diagnostics dump...
dumpDiffs(comparator.getComparisonResults(), false);
dumpValidation(comparator.getComparisonResults());
Results results = comparator.getComparisonResults();
Iterator<Result> it = results.iterator();
// Table table_in_reference only appears in the reference schema
Difference diff = (Difference) it.next();
assertEquals(Where.ONLY_IN_REFERENCE, diff.getWhere());
assertEquals("schema.table_in_reference", diff.getLeft().getPath());
assertEquals(null, diff.getRight());
assertEquals(null, diff.getLeft().getPropertyName());
assertEquals(null, diff.getLeft().getPropertyValue());
// Table tbl_has_diff_pk has PK of "id" in reference and "nodeRef" in target
diff = (Difference) it.next();
assertEquals(Where.IN_BOTH_BUT_DIFFERENCE, diff.getWhere());
assertEquals("schema.tbl_has_diff_pk.pk_is_diff.columnNames[0]", diff.getLeft().getPath());
assertEquals("schema.tbl_has_diff_pk.pk_is_diff.columnNames[0]", diff.getRight().getPath());
assertEquals("columnNames[0]", diff.getLeft().getPropertyName());
assertEquals("id", diff.getLeft().getPropertyValue());
assertEquals("columnNames[0]", diff.getRight().getPropertyName());
assertEquals("nodeRef", diff.getRight().getPropertyValue());
// idx_two is unique in the righ_schema but not in the reference
diff = (Difference) it.next();
assertEquals("schema.tbl_has_diff_pk.idx_two.unique", diff.getLeft().getPath());
assertEquals("schema.tbl_has_diff_pk.idx_two.unique", diff.getRight().getPath());
assertEquals("unique", diff.getLeft().getPropertyName());
assertEquals(false, diff.getLeft().getPropertyValue());
assertEquals("unique", diff.getRight().getPropertyName());
assertEquals(true, diff.getRight().getPropertyValue());
// Table table_in_target does not exist in the reference schema
diff = (Difference) it.next();
assertEquals(Where.ONLY_IN_TARGET, diff.getWhere());
assertEquals("schema.table_in_target", diff.getRight().getPath());
assertEquals(null, diff.getLeft());
assertEquals(null, diff.getRight().getPropertyName());
assertEquals(null, diff.getRight().getPropertyValue());
assertFalse("There should be no more differences", it.hasNext());
}
Aggregations