use of org.alfresco.util.schemacomp.model.Schema 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.Schema 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.Schema 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.Schema in project alfresco-repository by Alfresco.
the class SchemaComparatorTest method columnOrderingIgnoredWhenDisabled.
@Test
public void columnOrderingIgnoredWhenDisabled() {
reference = new Schema("schema", "alf_", 590, false);
target = new Schema("schema", "alf_", 590, false);
// Reference schema's database objects.
reference.add(new Table(reference, "table_name", columns(false, "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 column order
target.add(new Table(target, "table_name", columns(false, "id NUMBER(10)", "name VARCHAR2(150)", "nodeRef VARCHAR2(200)"), new PrimaryKey(null, "my_pk_name", Arrays.asList("id", "nodeRef"), Arrays.asList(1, 2)), 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();
// There are no logical differences
assertEquals(0, results.size());
}
use of org.alfresco.util.schemacomp.model.Schema in project alfresco-repository by Alfresco.
the class SchemaComparatorTest method setup.
@Before
public void setup() {
reference = new Schema("schema", "alf_", 590, true);
target = new Schema("schema", "alf_", 590, true);
dialect = new MySQLInnoDBDialect();
}
Aggregations