Search in sources :

Example 1 with DbObject

use of org.alfresco.util.schemacomp.model.DbObject 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);
}
Also used : Table(org.alfresco.util.schemacomp.model.Table) DbObject(org.alfresco.util.schemacomp.model.DbObject) Schema(org.alfresco.util.schemacomp.model.Schema) Sequence(org.alfresco.util.schemacomp.model.Sequence)

Example 2 with DbObject

use of org.alfresco.util.schemacomp.model.DbObject 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());
}
Also used : Table(org.alfresco.util.schemacomp.model.Table) DbObject(org.alfresco.util.schemacomp.model.DbObject) Schema(org.alfresco.util.schemacomp.model.Schema) Index(org.alfresco.util.schemacomp.model.Index) Sequence(org.alfresco.util.schemacomp.model.Sequence) DbValidator(org.alfresco.util.schemacomp.validator.DbValidator) Test(org.junit.Test)

Example 3 with DbObject

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

the class DefaultComparisonUtilsTest method orderingFaultsWhenReferenceCollectionLonger.

@Test
public void orderingFaultsWhenReferenceCollectionLonger() {
    Collection<Object> reference = new ArrayList<Object>();
    Collections.<Object>addAll(reference, "a", "z", "x", "1", "2");
    DbObject refDbObj = new DbObjectWithCollection("reference", reference);
    DbProperty refCollProp = new DbProperty(refDbObj, "collection");
    Collection<Object> target = new ArrayList<Object>();
    Collections.<Object>addAll(target, "a", "Q", "x");
    DbObject targetDbObj = new DbObjectWithCollection("target", target);
    DbProperty targetCollProp = new DbProperty(targetDbObj, "collection");
    comparisonUtils.compareSimpleOrderedLists(refCollProp, targetCollProp, ctx);
    verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, dbPropForValue(refDbObj, "collection[0]", "a"), dbPropForValue(targetDbObj, "collection[0]", "a"));
    verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, dbPropForValue(refDbObj, "collection[1]", "z"), dbPropForValue(targetDbObj, "collection[1]", "Q"));
    verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, dbPropForValue(refDbObj, "collection[2]", "x"), dbPropForValue(targetDbObj, "collection[2]", "x"));
    verify(differences).add(Where.ONLY_IN_REFERENCE, dbPropForValue(refDbObj, "collection[3]", "1"), null);
    verify(differences).add(Where.ONLY_IN_REFERENCE, dbPropForValue(refDbObj, "collection[4]", "2"), null);
}
Also used : DbObject(org.alfresco.util.schemacomp.model.DbObject) AbstractDbObject(org.alfresco.util.schemacomp.model.AbstractDbObject) ArrayList(java.util.ArrayList) DbObject(org.alfresco.util.schemacomp.model.DbObject) AbstractDbObject(org.alfresco.util.schemacomp.model.AbstractDbObject) Test(org.junit.Test)

Example 4 with DbObject

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

the class DefaultComparisonUtilsTest method orderingFaultsWhenTargetCollectionLonger.

@Test
public void orderingFaultsWhenTargetCollectionLonger() {
    Collection<Object> reference = new ArrayList<Object>();
    Collections.<Object>addAll(reference, "a", "z", "x");
    DbObject refDbObj = new DbObjectWithCollection("reference", reference);
    DbProperty refCollProp = new DbProperty(refDbObj, "collection");
    Collection<Object> target = new ArrayList<Object>();
    Collections.<Object>addAll(target, "a", "Q", "x", "1", "2");
    DbObject targetDbObj = new DbObjectWithCollection("target", target);
    DbProperty targetCollProp = new DbProperty(targetDbObj, "collection");
    comparisonUtils.compareSimpleOrderedLists(refCollProp, targetCollProp, ctx);
    verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, dbPropForValue(refDbObj, "collection[0]", "a"), dbPropForValue(targetDbObj, "collection[0]", "a"));
    verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, dbPropForValue(refDbObj, "collection[1]", "z"), dbPropForValue(targetDbObj, "collection[1]", "Q"));
    verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, dbPropForValue(refDbObj, "collection[2]", "x"), dbPropForValue(targetDbObj, "collection[2]", "x"));
    verify(differences).add(Where.ONLY_IN_TARGET, null, dbPropForValue(targetDbObj, "collection[3]", "1"));
    verify(differences).add(Where.ONLY_IN_TARGET, null, dbPropForValue(targetDbObj, "collection[4]", "2"));
}
Also used : DbObject(org.alfresco.util.schemacomp.model.DbObject) AbstractDbObject(org.alfresco.util.schemacomp.model.AbstractDbObject) ArrayList(java.util.ArrayList) DbObject(org.alfresco.util.schemacomp.model.DbObject) AbstractDbObject(org.alfresco.util.schemacomp.model.AbstractDbObject) Test(org.junit.Test)

Example 5 with DbObject

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

the class DefaultComparisonUtilsTest method compareSimpleCollections.

@Test
public void compareSimpleCollections() {
    Collection<Object> leftCollection = new ArrayList<Object>();
    leftCollection.add(123);
    leftCollection.add("both");
    Collection<Object> subCollectionLeft = new ArrayList<Object>();
    subCollectionLeft.add(3);
    subCollectionLeft.add("my string");
    subCollectionLeft.add(10);
    subCollectionLeft.add("another");
    leftCollection.add(subCollectionLeft);
    leftCollection.add(456);
    leftCollection.add("left only");
    DbObject leftDbObj = new DbObjectWithCollection("left", leftCollection);
    DbProperty leftCollProp = new DbProperty(leftDbObj, "collection");
    Collection<Object> rightCollection = new ArrayList<Object>();
    rightCollection.add(123);
    rightCollection.add(789);
    Collection<Object> subCollectionRight = new ArrayList<Object>(subCollectionLeft);
    rightCollection.add(subCollectionRight);
    rightCollection.add("right only");
    rightCollection.add("both");
    rightCollection.add("one more right only");
    DbObject rightDbObj = new DbObjectWithCollection("right", rightCollection);
    DbProperty rightCollProp = new DbProperty(rightDbObj, "collection");
    comparisonUtils.compareSimpleCollections(leftCollProp, rightCollProp, ctx);
    verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, dbPropForValue(leftDbObj, "collection[0]", 123), dbPropForValue(rightDbObj, "collection[0]", 123));
    verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, dbPropForValue(leftDbObj, "collection[1]", "both"), dbPropForValue(rightDbObj, "collection[4]", "both"));
    verify(differences).add(Where.IN_BOTH_NO_DIFFERENCE, dbPropForValue(leftDbObj, "collection[2]", subCollectionLeft), dbPropForValue(rightDbObj, "collection[2]", subCollectionRight));
    verify(differences).add(Where.ONLY_IN_REFERENCE, dbPropForValue(leftDbObj, "collection[3]", 456), dbPropForValue(rightDbObj, "collection", rightCollection));
    verify(differences).add(Where.ONLY_IN_REFERENCE, dbPropForValue(leftDbObj, "collection[4]", "left only"), dbPropForValue(rightDbObj, "collection", rightCollection));
    verify(differences).add(Where.ONLY_IN_TARGET, dbPropForValue(leftDbObj, "collection", leftCollection), dbPropForValue(rightDbObj, "collection[1]", 789));
    verify(differences).add(Where.ONLY_IN_TARGET, dbPropForValue(leftDbObj, "collection", leftCollection), dbPropForValue(rightDbObj, "collection[3]", "right only"));
    verify(differences).add(Where.ONLY_IN_TARGET, dbPropForValue(leftDbObj, "collection", leftCollection), dbPropForValue(rightDbObj, "collection[5]", "one more right only"));
}
Also used : DbObject(org.alfresco.util.schemacomp.model.DbObject) AbstractDbObject(org.alfresco.util.schemacomp.model.AbstractDbObject) ArrayList(java.util.ArrayList) DbObject(org.alfresco.util.schemacomp.model.DbObject) AbstractDbObject(org.alfresco.util.schemacomp.model.AbstractDbObject) Test(org.junit.Test)

Aggregations

DbObject (org.alfresco.util.schemacomp.model.DbObject)22 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)12 AbstractDbObject (org.alfresco.util.schemacomp.model.AbstractDbObject)12 DbValidator (org.alfresco.util.schemacomp.validator.DbValidator)9 Table (org.alfresco.util.schemacomp.model.Table)5 Schema (org.alfresco.util.schemacomp.model.Schema)4 Index (org.alfresco.util.schemacomp.model.Index)3 Sequence (org.alfresco.util.schemacomp.model.Sequence)3 PrimaryKey (org.alfresco.util.schemacomp.model.PrimaryKey)2 Collection (java.util.Collection)1 Where (org.alfresco.util.schemacomp.Difference.Where)1 Column (org.alfresco.util.schemacomp.model.Column)1 ForeignKey (org.alfresco.util.schemacomp.model.ForeignKey)1 NameValidator (org.alfresco.util.schemacomp.validator.NameValidator)1