ConfigFileHelper { public void clearTablesAndSaveToFile() { final ProjectMutator<? extends Project> projectMutator = Project.deepCopy(DocumentTranscoder.load( currentlyOpenFile.toPath(), this::fromJson ) ).mutator(); projectMutator.setSpeedmentVersion(infoComponent.getEditionAndVersionString()); final Project project = projectMutator.document(); LOGGER.info("clearing tables"); project.dbmses().forEach(dbms -> { LOGGER.info("dbms: " + dbms.getName()); dbms.schemas().forEach(schema -> { LOGGER.info("schema: " + schema.getName()); if (schema.getData().containsKey("tables")) { LOGGER.info("Removing " + schema.tables().count()); schema.getData().remove("tables"); } else { LOGGER.info("No tables to remove"); } }); }); if (currentlyOpenFile.isFile()) { if (currentlyOpenFile.exists() && !currentlyOpenFile.delete()) { userInterfaceComponent.log(OutputUtil.warning("Unable to delete " + currentlyOpenFile)); } DocumentTranscoder.save(project, currentlyOpenFile.toPath(), Json::toJson); } else { throw new SpeedmentToolException(currentlyOpenFile.toPath() + " is not a file"); } } ConfigFileHelper(
        final DocumentPropertyComponent documentPropertyComponent,
        final DbmsHandlerComponent dbmsHandlerComponent,
        final PasswordComponent passwordComponent,
        final TranslatorManager translatorManager,
        final ProjectComponent projectComponent,
        final InfoComponent infoComponent,
        @Config(name = METADATA_LOCATION, value = DEFAULT_CONFIG_LOCATION) final File currentlyOpenFile
    ); @ExecuteBefore(State.INITIALIZED) void setInjector(Injector injector); @ExecuteBefore(State.INITIALIZED) void setUserInterfaceComponent(UserInterfaceComponent userInterfaceComponent); boolean isFileOpen(); File getCurrentlyOpenFile(); void setCurrentlyOpenFile(File currentlyOpenFile); void loadFromDatabaseAndSaveToFile(); boolean loadFromDatabase(DbmsProperty dbms, String schemaName); void loadConfigFile(File file, ReuseStage reuse); void saveConfigFile(); void saveCurrentlyOpenConfigFile(); void generateSources(); void clearTablesAndSaveToFile(); void saveProjectToCurrentlyOpenFile(ProjectProperty project); static final String DEFAULT_CONFIG_LOCATION; }
@Test @Disabled void clearTablesAndSaveToFile() throws Exception { try { when(mockedCurrentlyOpenFile.toPath()).thenReturn(new File("src/test/resources/testIn.json").toPath(), new File("target/testOut.json").toPath()); helper.clearTablesAndSaveToFile(); verifyOutputFile("target/testOut.json"); } catch (SpeedmentConfigException e) { System.out.println("WARNING: Test skipped in gradle"); } }
@Test @Disabled void clearTablesAndSaveToFileNoTables() throws Exception { try { when(mockedCurrentlyOpenFile.toPath()).thenReturn(new File("src/test/resources/testInNoTables.json").toPath(), new File("target/testOutNoTables.json").toPath()); helper.clearTablesAndSaveToFile(); verifyOutputFile("target/testOutNoTables.json"); } catch (SpeedmentConfigException e) { System.out.println("WARNING: Test skipped in gradle"); } }