use of org.alfresco.util.schemacomp.model.PrimaryKey in project alfresco-repository by Alfresco.
the class SchemaCompTestingUtils method pk.
public static PrimaryKey pk(String name, String... columnNames) {
assertTrue("No columns specified", columnNames.length > 0);
// Create a list of column orders, ordered the same as the supplied column names
// i.e. 1, 2, 3... N
List<Integer> columnOrders = new ArrayList<Integer>(columnNames.length);
for (int i = 1; i <= columnNames.length; i++) {
columnOrders.add(i);
}
PrimaryKey pk = new PrimaryKey(null, name, Arrays.asList(columnNames), columnOrders);
return pk;
}
use of org.alfresco.util.schemacomp.model.PrimaryKey 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.PrimaryKey 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.PrimaryKey in project alfresco-repository by Alfresco.
the class DbObjectXMLTransformerTest method transformSchemaWithColumnOrderCheck.
@Test
public void transformSchemaWithColumnOrderCheck() throws IOException {
Collection<Column> columns = columns("one VARCHAR2(100)", "two NUMBER(10)");
PrimaryKey pk = new PrimaryKey(null, "pk_for_my_table", Arrays.asList("id"), Arrays.asList(1));
Collection<ForeignKey> fks = fkeys(fk("fk_one", "lc", "tt", "tc"), fk("fk_two", "lc", "tt", "tc"));
Collection<Index> indexes = indexes("index_one col1 col2", "index_two col3 col4");
Table tableOne = new Table(null, "table_one", columns, pk, fks, indexes);
Table tableTwo = new Table(null, "table_two", columns, pk, fks, indexes);
Schema schema = new Schema("my_schema", "alf_", 132, true);
schema.add(tableOne);
schema.add(tableTwo);
schema.add(new Sequence(null, "sequence_one"));
schema.add(new Sequence(null, "sequence_two"));
schema.add(new Sequence(null, "sequence_three"));
schema.setValidators(new ArrayList<DbValidator>());
transformer.output(schema);
BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
dumpOutput();
assertHasPreamble(reader);
assertEquals("<schema " + "xmlns=\"http://www.alfresco.org/repo/db-schema\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xsi:schemaLocation=\"http://www.alfresco.org/repo/db-schema db-schema.xsd\" " + "name=\"my_schema\" dbprefix=\"alf_\" version=\"132\" tablecolumnorder=\"true\">", reader.readLine());
assertEquals(" <objects>", reader.readLine());
skipUntilEnd(" {table}", reader);
skipUntilEnd(" {table}", reader);
skipUntilEnd(" {sequence}", reader, true);
skipUntilEnd(" {sequence}", reader, true);
skipUntilEnd(" {sequence}", reader, true);
assertEquals(" </objects>", reader.readLine());
assertEquals("</schema>", reader.readLine());
}
use of org.alfresco.util.schemacomp.model.PrimaryKey in project alfresco-repository by Alfresco.
the class DbObjectXMLTransformerTest method transformPrimaryKey.
@Test
public void transformPrimaryKey() throws IOException {
PrimaryKey pk = new PrimaryKey(null, "pk_name", Arrays.asList("a_column", "b_column"), Arrays.asList(2, 1));
transformer.output(pk);
BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
dumpOutput();
assertHasPreamble(reader);
assertEquals("<primarykey name=\"pk_name\">", reader.readLine());
assertEquals(" <columnnames>", reader.readLine());
assertEquals(" <columnname order=\"2\">a_column</columnname>", reader.readLine());
assertEquals(" <columnname order=\"1\">b_column</columnname>", reader.readLine());
assertEquals(" </columnnames>", reader.readLine());
assertEquals("</primarykey>", reader.readLine());
}
Aggregations