/* * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * * Alfresco is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Alfresco is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Alfresco. If not, see . */ package org.alfresco.util.schemacomp; import static org.junit.Assert.assertTrue; import java.util.Arrays; import java.util.Collection; import java.util.List; import org.alfresco.util.schemacomp.Difference.Where; import org.alfresco.util.schemacomp.model.Column; import org.alfresco.util.schemacomp.model.ForeignKey; import org.alfresco.util.schemacomp.model.Index; import org.alfresco.util.schemacomp.model.PrimaryKey; import org.alfresco.util.schemacomp.model.Table; import org.apache.commons.lang.ArrayUtils; public class SchemaCompTestingUtils { public static void dumpValidation(List validationResults) { System.out.println("Validation Results (" + validationResults.size() + ")"); for (ValidationResult r : validationResults) { System.out.println(r); } } public static void dumpDiffs(Results differences, boolean showNonDifferences) { System.out.println("Differences (" + differences.size() + ")"); for (Difference d : differences) { if (d.getWhere() != Where.IN_BOTH_NO_DIFFERENCE || showNonDifferences) { System.out.println(d); } } } public static Table table(String name) { return new Table(null, name, columns("id NUMBER(10)"), pk("pk_" + name, "id"), fkeys(), indexes()); } public static Table table(String name, Collection columns, PrimaryKey primaryKey, Collection foreignKeys, Collection indexes) { return new Table(null, name, columns, primaryKey, foreignKeys, indexes); } public static Collection columns(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); } return Arrays.asList(columns); } public static PrimaryKey pk(String name, String... columnNames) { assertTrue("No columns specified", columnNames.length > 0); PrimaryKey pk = new PrimaryKey(null, name, Arrays.asList(columnNames)); return pk; } public static List fkeys(ForeignKey... fkeys) { return Arrays.asList(fkeys); } public static ForeignKey fk(String fkName, String localColumn, String targetTable, String targetColumn) { return new ForeignKey(null, fkName, localColumn, targetTable, targetColumn); } /** * Create collection of indexes using strings of format "name column1 [column2 ... columnN]" */ public static Collection 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]; String[] columns = (String[]) ArrayUtils.subarray(parts, 1, parts.length); indexes[i] = new Index(null, name, Arrays.asList(columns)); } return Arrays.asList(indexes); } }