@Test public void testAddedPK() { Schema s1 = makeBaseSchema(); Table t1 = s1.getTable("t1"); PrimaryKeyConstraint constraint = new PrimaryKeyConstraint(t1, t1.getColumn("a")); s1.setPrimaryKeyConstraint(constraint); Schema s2 = makeBaseSchema(); assertEquals( "The changed constraint when adding a PK should be the PK", constraint, ChangedConstraintFinder.getDifferentConstraint(s1, s2)); }
private TestCaseResult executeInserts( Data data, TestCaseResult normalTestResult, Map<Integer, TestCaseResult> failedMutants, TestCase testCase) { for (Table table : schema.getTablesInOrder()) { if (data.getTables().contains(table)) { List<Integer> applicableMutants = changedTableMap.get(table.getIdentifier().get()); applicableMutants = applicableMutants == null ? new ArrayList<Integer>() : applicableMutants; for (Row row : data.getRows(table)) { String insert = sqlWriter.writeInsertStatement(row); // Only insert if we haven't failed yet if (normalTestResult == null) { Integer normalResult = databaseInteractor.executeUpdate(insert); if (normalResult != 1) { normalTestResult = new TestCaseResult( new InsertStatementException("Failed, result was: " + normalResult, insert)); } } // Setup for parallel execution executor = Executors.newFixedThreadPool(4); for (Integer mutantId : applicableMutants) { // Only insert if we haven't failed yet if (!failedMutants.containsKey(mutantId)) { MutantInsertsTask task = new MutantInsertsTask(insert, mutantId, failedMutants, testCase); executor.submit(task); } } executor.shutdown(); try { executor.awaitTermination(1, TimeUnit.DAYS); } catch (InterruptedException ex) { throw new RuntimeException(ex); } // If a mutant isn't applicable, then it should 'inherit' the normal result for (int i = 0; i < mutants.size(); i++) { if (!applicableMutants.contains(i) && normalTestResult != null) { resultMap.get(i).add(testCase, normalTestResult); failedMutants.put(i, normalTestResult); } } } } } return normalTestResult; }
@Test public void testIdenticalSchemasWithUnique() { Schema s1 = makeBaseSchema(); Table s1t1 = s1.getTable("t1"); UniqueConstraint s1constraint = new UniqueConstraint(s1t1, s1t1.getColumn("a")); s1.addUniqueConstraint(s1constraint); Schema s2 = makeBaseSchema(); Table s2t1 = s2.getTable("t1"); UniqueConstraint s2constraint = new UniqueConstraint(s2t1, s2t1.getColumn("a")); s2.addUniqueConstraint(s2constraint); assertNull( "The changed constraint between identical schemas should be " + "null", ChangedConstraintFinder.getDifferentConstraint(s1, s2)); }
/** * Prepends each mutant with the relevant mutation number * * @param mutants */ private static void renameMutants(List<Mutant<Schema>> mutants) { for (int i = 0; i < mutants.size(); i++) { Schema mutantSchema = mutants.get(i).getMutatedArtefact(); for (Table table : mutantSchema.getTablesInOrder()) { table.setName("mutant_" + (i + 1) + "_" + table.getName()); } for (Constraint constraint : mutantSchema.getConstraints()) { if (constraint.hasIdentifier() && constraint.getIdentifier().get() != null) { String name = constraint.getIdentifier().get(); constraint.setName("mutant_" + (i + 1) + "_" + name); } } } }
@Test public void testPKMismatch() { Schema s1 = makeBaseSchema(); Table s1t1 = s1.getTable("t1"); PrimaryKeyConstraint s1constraint = new PrimaryKeyConstraint(s1t1, s1t1.getColumn("a"), s1t1.getColumn("b")); s1.setPrimaryKeyConstraint(s1constraint); Schema s2 = makeBaseSchema(); Table s2t1 = s2.getTable("t1"); PrimaryKeyConstraint s2constraint = new PrimaryKeyConstraint(s2t1, s2t1.getColumn("a")); s2.setPrimaryKeyConstraint(s2constraint); assertEquals( "The changed constraint with mismatched PKs should be the PK", s2constraint, ChangedConstraintFinder.getDifferentConstraint(s1, s2)); }
private Schema makeBaseSchema() { Schema s = new Schema("schema"); Table t1 = s.createTable("t1"); t1.addColumn(new Column("a", new IntDataType())); t1.addColumn(new Column("b", new IntDataType())); t1.addColumn(new Column("c", new IntDataType())); Table t2 = s.createTable("t2"); t2.addColumn(new Column("d", new IntDataType())); t2.addColumn(new Column("e", new IntDataType())); t2.addColumn(new Column("f", new IntDataType())); Table t3 = s.createTable("t3"); t3.addColumn(new Column("g", new IntDataType())); t3.addColumn(new Column("h", new IntDataType())); t3.addColumn(new Column("i", new IntDataType())); return s; }
public NistDML181() { super("NistDML181"); Table tableLongNamedPeople = this.createTable("LONG_NAMED_PEOPLE"); tableLongNamedPeople.createColumn("FIRSTNAME", new VarCharDataType(373)); tableLongNamedPeople.createColumn("LASTNAME", new VarCharDataType(373)); tableLongNamedPeople.createColumn("AGE", new IntDataType()); this.createPrimaryKeyConstraint( tableLongNamedPeople, tableLongNamedPeople.getColumn("FIRSTNAME"), tableLongNamedPeople.getColumn("LASTNAME")); Table tableOrders = this.createTable("ORDERS"); tableOrders.createColumn("FIRSTNAME", new VarCharDataType(373)); tableOrders.createColumn("LASTNAME", new VarCharDataType(373)); tableOrders.createColumn("TITLE", new VarCharDataType(80)); tableOrders.createColumn("COST", new NumericDataType(5, 2)); this.createForeignKeyConstraint( tableOrders, Arrays.asList(tableOrders.getColumn("FIRSTNAME"), tableOrders.getColumn("LASTNAME")), tableLongNamedPeople, Arrays.asList( tableLongNamedPeople.getColumn("FIRSTNAME"), tableLongNamedPeople.getColumn("LASTNAME"))); }
public ArtistTerm() { super("ArtistTerm"); Table tableArtists = this.createTable("artists"); tableArtists.createColumn("artist_id", new TextDataType()); this.createPrimaryKeyConstraint(tableArtists, tableArtists.getColumn("artist_id")); Table tableMbtags = this.createTable("mbtags"); tableMbtags.createColumn("mbtag", new TextDataType()); this.createPrimaryKeyConstraint(tableMbtags, tableMbtags.getColumn("mbtag")); Table tableTerms = this.createTable("terms"); tableTerms.createColumn("term", new TextDataType()); this.createPrimaryKeyConstraint(tableTerms, tableTerms.getColumn("term")); Table tableArtistMbtag = this.createTable("artist_mbtag"); tableArtistMbtag.createColumn("artist_id", new TextDataType()); tableArtistMbtag.createColumn("mbtag", new TextDataType()); this.createForeignKeyConstraint( tableArtistMbtag, tableArtistMbtag.getColumn("artist_id"), tableArtists, tableArtists.getColumn("artist_id")); this.createForeignKeyConstraint( tableArtistMbtag, tableArtistMbtag.getColumn("mbtag"), tableMbtags, tableMbtags.getColumn("mbtag")); Table tableArtistTerm = this.createTable("artist_term"); tableArtistTerm.createColumn("artist_id", new TextDataType()); tableArtistTerm.createColumn("term", new TextDataType()); this.createForeignKeyConstraint( tableArtistTerm, tableArtistTerm.getColumn("artist_id"), tableArtists, tableArtists.getColumn("artist_id")); this.createForeignKeyConstraint( tableArtistTerm, tableArtistTerm.getColumn("term"), tableTerms, tableTerms.getColumn("term")); }