integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java
public static void createNewYamlFile(
      String inputYamlFile, String generatedYamlFile, String oldString, String newString)
      throws Exception {
    LoggerHelper.getLocal().log(Level.INFO, "Creating new  " + generatedYamlFile);

    Files.copy(
        new File(inputYamlFile).toPath(),
        Paths.get(generatedYamlFile),
        StandardCopyOption.REPLACE_EXISTING);

    // read each line in input domain file and replace with intended changed property
    BufferedReader reader = new BufferedReader(new FileReader(generatedYamlFile));
    String line = "";
    StringBuffer changedLines = new StringBuffer();
    boolean isLineChanged = false;
    while ((line = reader.readLine()) != null) {
      if (line.contains(oldString)) {
        String changedLine = line.replace(line.substring(line.indexOf(oldString)), newString);
        changedLines.append(changedLine).append("\n");
        isLineChanged = true;
      }

      if (!isLineChanged) {
        changedLines.append(line).append("\n");
      }
      isLineChanged = false;
    }
    reader.close();
    // writing to the file
    Files.write(Paths.get(generatedYamlFile), changedLines.toString().getBytes());
    LoggerHelper.getLocal().log(Level.INFO, "Done - generate the new yaml file ");
  }
/**
   * create yaml file with changed property.
   *
   * @param inputYamlFile     input
   * @param generatedYamlFile generated
   * @param oldString         old
   * @param newString         new
   * @throws Exception exception
   */
create yaml file with changed property.
create yaml file with changed property .
public static void createNewYamlFile(
      String inputYamlFile, String generatedYamlFile, String oldString, String newString)
      throws Exception {
    LoggerHelper.getLocal().log(Level.INFO, "Creating new  " + generatedYamlFile);
    Files.copy(
        new File(inputYamlFile).toPath(),
        Paths.get(generatedYamlFile),
        StandardCopyOption.REPLACE_EXISTING);
    BufferedReader reader = new BufferedReader(new FileReader(generatedYamlFile));
    String line = "";
    StringBuffer changedLines = new StringBuffer();
    boolean isLineChanged = false;
    while ((line = reader.readLine()) != null) {
      if (line.contains(oldString)) {
        String changedLine = line.replace(line.substring(line.indexOf(oldString)), newString);
        changedLines.append(changedLine).append("\n");
        isLineChanged = true;
      }
      if (!isLineChanged) {
        changedLines.append(line).append("\n");
      }
      isLineChanged = false;
    }
    reader.close();
    Files.write(Paths.get(generatedYamlFile), changedLines.toString().getBytes());
    LoggerHelper.getLocal().log(Level.INFO, "Done - generate the new yaml file ");
  }
public static void createNewYamlFile ( String inputYamlFile , String generatedYamlFile , String oldString , String newString ) throws Exception { LoggerHelper . getLocal ( ) . log ( Level . INFO , "Creating new  " + generatedYamlFile ) ; Files . copy ( new File ( inputYamlFile ) . toPath ( ) , Paths . get ( generatedYamlFile ) , StandardCopyOption . REPLACE_EXISTING ) ; BufferedReader reader = new BufferedReader ( new FileReader ( generatedYamlFile ) ) ; String line = "" ; StringBuffer changedLines = new StringBuffer ( ) ; boolean isLineChanged = false ; while ( ( line = reader . readLine ( ) ) != null ) { if ( line . contains ( oldString ) ) { String changedLine = line . replace ( line . substring ( line . indexOf ( oldString ) ) , newString ) ; changedLines . append ( changedLine ) . append ( "\n" ) ; isLineChanged = true ; } if ( ! isLineChanged ) { changedLines . append ( line ) . append ( "\n" ) ; } isLineChanged = false ; } reader . close ( ) ; Files . write ( Paths . get ( generatedYamlFile ) , changedLines . toString ( ) . getBytes ( ) ) ; LoggerHelper . getLocal ( ) . log ( Level . INFO , "Done - generate the new yaml file " ) ; }
create yaml file with changed property.
create yaml file with changed property .
// read each line in input domain file and replace with intended changed property // writing to the file