@Override public Function<String, String> convertDbObjectName() { return Functions.getStringPassThru(); }
@Override public Function<String, String> convertDbObjectName() { return Functions.getStringPassThru(); }
@Before public void setup() { when(tableChangeType.getName()).thenReturn(ChangeType.TABLE_STR); when(platform.getChangeType(ChangeType.TABLE_STR)).thenReturn(tableChangeType); when(platform.convertDbObjectName()).thenReturn(Functions.getStringPassThru()); }
private void conversionTest(String testName, String platformName) { final File outputFolder = new File("./target/revengTest/" + testName); FileUtils.deleteQuietly(outputFolder); final ReladomoSchemaConverter reladomoSchemaConverter = new ReladomoSchemaConverter(); final ChangeType tableChangeType = mock(ChangeType.class); when(tableChangeType.getName()).thenReturn(ChangeType.TABLE_STR); when(tableChangeType.getDirectoryName()).thenReturn("table"); DbPlatform platform = mock(DbPlatform.class); when(platform.getName()).thenReturn(platformName); when(platform.getChangeType(ChangeType.TABLE_STR)).thenReturn(tableChangeType); when(platform.getObjectExclusionPredicateBuilder()).thenReturn(new ObjectTypeAndNamePredicateBuilder(ObjectTypeAndNamePredicateBuilder.FilterType.EXCLUDE)); when(platform.convertDbObjectName()).thenReturn(Functions.getStringPassThru()); reladomoSchemaConverter.convertDdlsToDaFormat(platform, new File("./src/test/resources/reveng/input/" + testName), outputFolder, "yourSchema", true, null); DirectoryAssert.assertDirectoriesEqual(new File("./src/test/resources/reveng/expected/" + testName), new File(outputFolder, "final")); } }
@Test public void testCycleValidationWithIncrementalChanges() { this.enricher = new GraphEnricherImpl(Functions.getStringPassThru()); SortableDependencyGroup sch1Obj1C1 = newChange(schema1, type1, "obj1", "c1", 0, null); SortableDependencyGroup sch1Obj1C2 = newChange(schema1, type1, "obj1", "c2", 1, Sets.immutable.<String>with("obj2")); SortableDependencyGroup sch1Obj1C3 = newChange(schema1, type1, "obj1", "c3", 2, null); SortableDependencyGroup sch1Obj2C1 = newChange(schema1, type1, "obj2", "c1", 0, null); SortableDependencyGroup sch1Obj2C2 = newChange(schema1, type1, "obj2", "c2", 1, null); SortableDependencyGroup sch1Obj2C3 = newChange(schema1, type1, "obj2", "c3", 2, Sets.immutable.<String>with("obj1.c3")); SortableDependencyGroup sch1Obj3 = newChange(schema1, type1, "obj3", Sets.immutable.with("obj1")); try { enricher.createDependencyGraph(Lists.mutable.with( sch1Obj1C1, sch1Obj1C2, sch1Obj1C3, sch1Obj2C1, sch1Obj2C2, sch1Obj2C3, sch1Obj3), false); fail("Expecting an exception here due to a cycle exception, but a cycle exception was not found"); } catch (IllegalArgumentException exc) { exc.printStackTrace(); assertThat(exc.getMessage(), containsString("Found cycles")); } }
@Test public void testCycleValidation() { this.enricher = new GraphEnricherImpl(Functions.getStringPassThru()); SortableDependencyGroup cyc1Obj1 = newChange(schema1, type1, "cyc1Obj1", Sets.immutable.with(schema2 + ".cyc1Obj3")); SortableDependencyGroup cyc1Obj2 = newChange(schema1, type2, "cyc1Obj2", Sets.immutable.with("cyc1Obj1")); SortableDependencyGroup cyc1Obj3 = newChange(schema2, type1, "cyc1Obj3", Sets.immutable.with(schema1 + ".cyc1Obj2", schema2 + ".cyc1Obj4", schema2 + ".notcyc1ObjB")); SortableDependencyGroup cyc1Obj4 = newChange(schema2, type1, "cyc1Obj4", Sets.immutable.with(schema2 + ".cyc1Obj5")); SortableDependencyGroup cyc1Obj5 = newChange(schema2, type1, "cyc1Obj5", Sets.immutable.with(schema2 + ".cyc1Obj3")); SortableDependencyGroup notcyc1ObjA = newChange(schema2, type1, "notcyc1ObjA", Sets.immutable.with(schema2 + ".cyc1Obj3")); // inbound edge to cycle, but not in it SortableDependencyGroup notcyc1ObjB = newChange(schema2, type1, "notcyc1ObjB", Sets.immutable.<String>with()); // outbound edge from cycle, but not in it SortableDependencyGroup cyc2Obj1 = newChange(schema2, type1, "cyc2Obj1", Sets.immutable.with(schema2 + ".cyc2Obj2")); SortableDependencyGroup cyc2Obj2 = newChange(schema2, type1, "cyc2Obj2", Sets.immutable.with(schema2 + ".cyc2Obj3")); SortableDependencyGroup cyc2Obj3 = newChange(schema2, type1, "cyc2Obj3", Sets.immutable.with(schema2 + ".cyc2Obj1")); SortableDependencyGroup loneObj1 = newChange(schema2, type1, "loneObj1", Sets.immutable.<String>with()); try { enricher.createDependencyGraph(Lists.mutable.with( cyc1Obj1, cyc1Obj2, cyc1Obj3, cyc1Obj4, cyc1Obj5, notcyc1ObjA, notcyc1ObjB, cyc2Obj1, cyc2Obj2, cyc2Obj3, loneObj1), false); fail("Expecting an exception here due to a cycle exception, but a cycle exception was not found"); } catch (IllegalArgumentException exc) { exc.printStackTrace(); assertThat(exc.getMessage(), containsString("Found cycles")); } }
/** * The test data in this class is all written w/ case-sensitivy as the default. * If we pass caseInsensitive == true, then we enable that mode in the graph enricher and tweak the object names * a bit so that we can verify that the resolution works either way. */ private void testSchemaObjectDependencies(boolean caseInsensitive) { this.enricher = new GraphEnricherImpl(caseInsensitive ? StringFunctions.toUpperCase() : Functions.getStringPassThru()); SortableDependencyGroup sch1Obj1 = newChange(schema1, type1, "obj1", Sets.immutable.with("obj3", schema2 + ".obj2")); SortableDependencyGroup sch1Obj2 = newChange(schema1, type2, "obj2", Sets.immutable.<String>with()); // change the case of the object name to ensure others can still point to it SortableDependencyGroup sch1Obj3 = newChange(schema1, type1, caseInsensitive ? "obj3".toUpperCase() : "obj3", Sets.immutable.with("obj2")); // change the case of the dependency name to ensure that it can point to others SortableDependencyGroup sch2Obj1 = newChange(schema2, type1, "obj1", Sets.immutable.with(caseInsensitive ? "obj2".toUpperCase() : "obj2")); SortableDependencyGroup sch2Obj2 = newChange(schema2, type2, "obj2", Sets.immutable.with(schema1 + ".obj3")); DirectedGraph<SortableDependencyGroup, DefaultEdge> sortGraph = enricher.createDependencyGraph(Lists.mutable.with( sch1Obj1, sch1Obj2, sch1Obj3, sch2Obj1, sch2Obj2), false); validateChange(sortGraph, sch1Obj1, Sets.immutable.with(sch1Obj3, sch2Obj2), Sets.immutable.<SortableDependencyGroup>with()); validateChange(sortGraph, sch1Obj2, Sets.immutable.<SortableDependencyGroup>with(), Sets.immutable.with(sch1Obj3)); validateChange(sortGraph, sch1Obj3, Sets.immutable.with(sch1Obj2), Sets.immutable.with(sch1Obj1, sch2Obj2)); validateChange(sortGraph, sch2Obj1, Sets.immutable.with(sch2Obj2), Sets.immutable.<SortableDependencyGroup>with()); validateChange(sortGraph, sch2Obj2, Sets.immutable.with(sch1Obj3), Sets.immutable.with(sch1Obj1, sch2Obj1)); }
private void testSchemaObjectChangeDependencies(boolean caseInsensitive, boolean rollback) { this.enricher = new GraphEnricherImpl(caseInsensitive ? StringFunctions.toUpperCase() : Functions.getStringPassThru());