Search in sources :

Example 1 with Column

use of org.alfresco.util.schemacomp.model.Column in project alfresco-repository by Alfresco.

the class SchemaCompTestingUtils method columns.

public static Collection<Column> columns(boolean compareColOrder, String... colDefs) {
    assertTrue("Tables must have columns", colDefs.length > 0);
    Column[] columns = new Column[colDefs.length];
    for (int i = 0; i < colDefs.length; i++) {
        String[] parts = colDefs[i].split(" ");
        columns[i] = new Column(null, parts[0], parts[1], false);
        columns[i].setOrder(i + 1);
        columns[i].setCompareOrder(compareColOrder);
    }
    return Arrays.asList(columns);
}
Also used : Column(org.alfresco.util.schemacomp.model.Column)

Example 2 with Column

use of org.alfresco.util.schemacomp.model.Column in project alfresco-repository by Alfresco.

the class DbObjectXMLTransformerTest method transformColumn.

@Test
public void transformColumn() throws IOException {
    Column column = new Column(null, "last_name", "VARCHAR2(100)", true);
    column.setAutoIncrement(true);
    column.setOrder(2);
    transformer.output(column);
    BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
    dumpOutput();
    assertHasPreamble(reader);
    assertEquals("<column name=\"last_name\" order=\"2\">", reader.readLine());
    assertEquals("  <type>VARCHAR2(100)</type>", reader.readLine());
    assertEquals("  <nullable>true</nullable>", reader.readLine());
    assertEquals("  <autoincrement>true</autoincrement>", reader.readLine());
    assertEquals("</column>", reader.readLine());
}
Also used : Column(org.alfresco.util.schemacomp.model.Column) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 3 with Column

use of org.alfresco.util.schemacomp.model.Column 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());
}
Also used : Table(org.alfresco.util.schemacomp.model.Table) Schema(org.alfresco.util.schemacomp.model.Schema) PrimaryKey(org.alfresco.util.schemacomp.model.PrimaryKey) Index(org.alfresco.util.schemacomp.model.Index) Sequence(org.alfresco.util.schemacomp.model.Sequence) ForeignKey(org.alfresco.util.schemacomp.model.ForeignKey) Column(org.alfresco.util.schemacomp.model.Column) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) DbValidator(org.alfresco.util.schemacomp.validator.DbValidator) Test(org.junit.Test)

Example 4 with Column

use of org.alfresco.util.schemacomp.model.Column in project alfresco-repository by Alfresco.

the class DifferenceTest method describe.

@Test
public void describe() {
    DbProperty refDbProp = mock(DbProperty.class);
    when(refDbProp.getPath()).thenReturn("alfresco.some_table.some_column.name");
    when(refDbProp.getDbObject()).thenReturn(new Column("some_column"));
    when(refDbProp.getPropertyValue()).thenReturn("node_ref");
    DbProperty targetDbProp = mock(DbProperty.class);
    when(targetDbProp.getPath()).thenReturn("alfresco.some_table.some_column.name");
    when(targetDbProp.getDbObject()).thenReturn(new Column("some_column"));
    when(targetDbProp.getPropertyValue()).thenReturn("nood_ref");
    Difference diff = new Difference(Where.IN_BOTH_BUT_DIFFERENCE, refDbProp, targetDbProp);
    assertEquals("Difference: expected column alfresco.some_table.some_column.name=\"node_ref\"" + ", but was alfresco.some_table.some_column.name=\"nood_ref\"", diff.describe());
}
Also used : Column(org.alfresco.util.schemacomp.model.Column) Test(org.junit.Test)

Example 5 with Column

use of org.alfresco.util.schemacomp.model.Column in project alfresco-repository by Alfresco.

the class DifferenceTest method describeTargetOnly.

@Test
public void describeTargetOnly() {
    DbProperty targetDbProp = mock(DbProperty.class);
    when(targetDbProp.getPath()).thenReturn("alfresco.some_table.some_column");
    when(targetDbProp.getDbObject()).thenReturn(new Column("some_column"));
    Difference diff = new Difference(Where.ONLY_IN_TARGET, null, targetDbProp);
    assertEquals("Difference: unexpected column found in database with path: alfresco.some_table.some_column", diff.describe());
}
Also used : Column(org.alfresco.util.schemacomp.model.Column) Test(org.junit.Test)

Aggregations

Column (org.alfresco.util.schemacomp.model.Column)19 Index (org.alfresco.util.schemacomp.model.Index)11 PrimaryKey (org.alfresco.util.schemacomp.model.PrimaryKey)11 ForeignKey (org.alfresco.util.schemacomp.model.ForeignKey)10 Test (org.junit.Test)8 Table (org.alfresco.util.schemacomp.model.Table)7 BufferedReader (java.io.BufferedReader)5 StringReader (java.io.StringReader)5 Sequence (org.alfresco.util.schemacomp.model.Sequence)5 DbValidator (org.alfresco.util.schemacomp.validator.DbValidator)5 Schema (org.alfresco.util.schemacomp.model.Schema)4 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 DbProperty (org.alfresco.util.schemacomp.DbProperty)1 ValidationResult (org.alfresco.util.schemacomp.ValidationResult)1 DbObject (org.alfresco.util.schemacomp.model.DbObject)1 NameValidator (org.alfresco.util.schemacomp.validator.NameValidator)1