Search in sources :

Example 1 with Index

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

the class TypeNameOnlyValidatorTest method validateOnlyColumnsTest.

@Test
public void validateOnlyColumnsTest() {
    try {
        validator.validate(null, new Index(null, null, new ArrayList<String>()), ctx);
        fail("TypeNameOnlyValidator should validate only Column");
    } catch (AlfrescoRuntimeException e) {
    // should validate only Column
    }
}
Also used : ArrayList(java.util.ArrayList) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) Index(org.alfresco.util.schemacomp.model.Index) Test(org.junit.Test)

Example 2 with Index

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

the class SchemaCompTestingUtils method indexes.

/**
 * Create collection of indexes using strings of format "name column1 [column2 ... columnN]"
 */
public static Collection<Index> indexes(String... indexDefs) {
    Index[] indexes = new Index[indexDefs.length];
    for (int i = 0; i < indexDefs.length; i++) {
        String[] parts = indexDefs[i].split(" ");
        String name = parts[0];
        boolean unique = false;
        int columnsStart = 1;
        if (parts[1].equals("[unique]")) {
            unique = true;
            columnsStart++;
        }
        String[] columns = (String[]) ArrayUtils.subarray(parts, columnsStart, parts.length);
        indexes[i] = new Index(null, name, Arrays.asList(columns));
        indexes[i].setUnique(unique);
    }
    return Arrays.asList(indexes);
}
Also used : Index(org.alfresco.util.schemacomp.model.Index)

Example 3 with Index

use of org.alfresco.util.schemacomp.model.Index 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);
}
Also used : MySQLInnoDBDialect(org.alfresco.repo.domain.dialect.MySQLInnoDBDialect) Table(org.alfresco.util.schemacomp.model.Table) Index(org.alfresco.util.schemacomp.model.Index) DbValidator(org.alfresco.util.schemacomp.validator.DbValidator) Before(org.junit.Before)

Example 4 with Index

use of org.alfresco.util.schemacomp.model.Index 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 5 with Index

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

the class DbObjectXMLTransformerTest method transformIndex.

@Test
public void transformIndex() throws IOException {
    Index index = new Index(null, "index_name", Arrays.asList("first", "second"));
    transformer.output(index);
    BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
    dumpOutput();
    assertHasPreamble(reader);
    assertEquals("<index name=\"index_name\" unique=\"false\">", reader.readLine());
    assertEquals("  <columnnames>", reader.readLine());
    assertEquals("    <columnname>first</columnname>", reader.readLine());
    assertEquals("    <columnname>second</columnname>", reader.readLine());
    assertEquals("  </columnnames>", reader.readLine());
    assertEquals("</index>", reader.readLine());
}
Also used : BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) Index(org.alfresco.util.schemacomp.model.Index) Test(org.junit.Test)

Aggregations

Index (org.alfresco.util.schemacomp.model.Index)20 Column (org.alfresco.util.schemacomp.model.Column)11 ForeignKey (org.alfresco.util.schemacomp.model.ForeignKey)10 PrimaryKey (org.alfresco.util.schemacomp.model.PrimaryKey)10 Table (org.alfresco.util.schemacomp.model.Table)10 Test (org.junit.Test)10 DbValidator (org.alfresco.util.schemacomp.validator.DbValidator)8 Schema (org.alfresco.util.schemacomp.model.Schema)6 Sequence (org.alfresco.util.schemacomp.model.Sequence)6 BufferedReader (java.io.BufferedReader)5 StringReader (java.io.StringReader)5 ArrayList (java.util.ArrayList)3 DbObject (org.alfresco.util.schemacomp.model.DbObject)3 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 NameValidator (org.alfresco.util.schemacomp.validator.NameValidator)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 MySQLInnoDBDialect (org.alfresco.repo.domain.dialect.MySQLInnoDBDialect)1 DbProperty (org.alfresco.util.schemacomp.DbProperty)1 ValidationResult (org.alfresco.util.schemacomp.ValidationResult)1