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
}
}
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);
}
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);
}
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());
}
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());
}
Aggregations