@Test public void testInjectCustomJavaScriptFilesOverridingNewer() throws Exception { Path configOrig = Paths.get(this.getClass().getResource("mock-files/inject_top.txt").toURI()); Path config = Paths.get(configOrig.getParent().toString() + File.separator + "inject_top_temp.txt"); Path targetOrig = Paths.get(this.getClass().getResource("mock-old-js/inject.js").toURI()); Path target = Paths.get(targetOrig.getParent().toString() + File.separator + "inject_temp.js"); FileUtils.copyFile(configOrig.toFile(), config.toFile()); FileUtils.copyFile(targetOrig.toFile(), target.toFile()); Files.setLastModifiedTime(target, FileTime.fromMillis(DateTime.now().minusYears(10).getMillis())); Path source = Paths.get(SahiProxy.class.getResource("inject_source.js").toURI()); when(props.getSahiJSInjectConfigFile()).thenReturn(config); when(props.getSahiJSInjectTargetFile()).thenReturn(target); when(props.getSahiJSInjectSourceFile()).thenReturn(source); assertFalse(FileUtils.readFileToString(config.toFile()).contains(SahiProxy.SAKULI_INJECT_SCRIPT_TAG)); assertContains(FileUtils.readFileToString(target.toFile()), " testling.injectCustomJavaScriptFiles(); assertTrue(FileUtils.readFileToString(config.toFile()).contains(SahiProxy.SAKULI_INJECT_SCRIPT_TAG)); assertContains(FileUtils.readFileToString(target.toFile()), "Sahi.prototype.originalEx = Sahi.prototype.ex;"); assertContains(FileUtils.readFileToString(target.toFile()), "Sahi.prototype.ex = function (isStep) {"); }
protected void injectCustomJavaScriptFiles() throws IOException { File injectFile = props.getSahiJSInjectConfigFile().toFile(); String injectFileString = FileUtils.readFileToString(injectFile, Charsets.UTF_8); if (!injectFileString.contains(SAKULI_INJECT_SCRIPT_TAG)) { injectFileString = StringUtils.replace(injectFileString, SAHI_INJECT_END, SAKULI_INJECT_SCRIPT_TAG + "\r\n" + SAHI_INJECT_END); FileUtils.writeStringToFile(injectFile, injectFileString, Charsets.UTF_8); logger.info("added '{}' to Sahi inject config file '{}'", SAKULI_INJECT_SCRIPT_TAG, props.getSahiJSInjectConfigFile().toString()); } Path source = props.getSahiJSInjectSourceFile(); Path target = props.getSahiJSInjectTargetFile(); if (isNewer(source, target)) { FileUtils.copyFile(source.toFile(), target.toFile(), false); logger.info("copied file '{}' to target '{}'", source.toString(), target.toString()); } }
SahiProxy { protected void injectCustomJavaScriptFiles() throws IOException { File injectFile = props.getSahiJSInjectConfigFile().toFile(); String injectFileString = FileUtils.readFileToString(injectFile, Charsets.UTF_8); if (!injectFileString.contains(SAKULI_INJECT_SCRIPT_TAG)) { injectFileString = StringUtils.replace(injectFileString, SAHI_INJECT_END, SAKULI_INJECT_SCRIPT_TAG + "\r\n" + SAHI_INJECT_END); FileUtils.writeStringToFile(injectFile, injectFileString, Charsets.UTF_8); logger.info("added '{}' to Sahi inject config file '{}'", SAKULI_INJECT_SCRIPT_TAG, props.getSahiJSInjectConfigFile().toString()); } Path source = props.getSahiJSInjectSourceFile(); Path target = props.getSahiJSInjectTargetFile(); if (isNewer(source, target)) { FileUtils.copyFile(source.toFile(), target.toFile(), false); logger.info("copied file '{}' to target '{}'", source.toString(), target.toString()); } } }
SahiProxy { protected void injectCustomJavaScriptFiles() throws IOException { File injectFile = props.getSahiJSInjectConfigFile().toFile(); String injectFileString = FileUtils.readFileToString(injectFile, Charsets.UTF_8); if (!injectFileString.contains(SAKULI_INJECT_SCRIPT_TAG)) { injectFileString = StringUtils.replace(injectFileString, SAHI_INJECT_END, SAKULI_INJECT_SCRIPT_TAG + "\r\n" + SAHI_INJECT_END); FileUtils.writeStringToFile(injectFile, injectFileString, Charsets.UTF_8); logger.info("added '{}' to Sahi inject config file '{}'", SAKULI_INJECT_SCRIPT_TAG, props.getSahiJSInjectConfigFile().toString()); } Path source = props.getSahiJSInjectSourceFile(); Path target = props.getSahiJSInjectTargetFile(); if (isNewer(source, target)) { FileUtils.copyFile(source.toFile(), target.toFile(), false); logger.info("copied file '{}' to target '{}'", source.toString(), target.toString()); } }  }
SahiProxy { protected void injectCustomJavaScriptFiles() throws IOException { File injectFile = props.getSahiJSInjectConfigFile().toFile(); String injectFileString = FileUtils.readFileToString(injectFile, Charsets.UTF_8); if (!injectFileString.contains(SAKULI_INJECT_SCRIPT_TAG)) { injectFileString = StringUtils.replace(injectFileString, SAHI_INJECT_END, SAKULI_INJECT_SCRIPT_TAG + "\r\n" + SAHI_INJECT_END); FileUtils.writeStringToFile(injectFile, injectFileString, Charsets.UTF_8); logger.info("added '{}' to Sahi inject config file '{}'", SAKULI_INJECT_SCRIPT_TAG, props.getSahiJSInjectConfigFile().toString()); } Path source = props.getSahiJSInjectSourceFile(); Path target = props.getSahiJSInjectTargetFile(); if (isNewer(source, target)) { FileUtils.copyFile(source.toFile(), target.toFile(), false); logger.info("copied file '{}' to target '{}'", source.toString(), target.toString()); } }  void startProxy(); void startProxy(boolean asyncron); void shutdown(); }
SahiProxy { protected void injectCustomJavaScriptFiles() throws IOException { File injectFile = props.getSahiJSInjectConfigFile().toFile(); String injectFileString = FileUtils.readFileToString(injectFile, Charsets.UTF_8); if (!injectFileString.contains(SAKULI_INJECT_SCRIPT_TAG)) { injectFileString = StringUtils.replace(injectFileString, SAHI_INJECT_END, SAKULI_INJECT_SCRIPT_TAG + "\r\n" + SAHI_INJECT_END); FileUtils.writeStringToFile(injectFile, injectFileString, Charsets.UTF_8); logger.info("added '{}' to Sahi inject config file '{}'", SAKULI_INJECT_SCRIPT_TAG, props.getSahiJSInjectConfigFile().toString()); } Path source = props.getSahiJSInjectSourceFile(); Path target = props.getSahiJSInjectTargetFile(); if (isNewer(source, target)) { FileUtils.copyFile(source.toFile(), target.toFile(), false); logger.info("copied file '{}' to target '{}'", source.toString(), target.toString()); } }  void startProxy(); void startProxy(boolean asyncron); void shutdown(); static final String SAHI_INJECT_END; static final String SAKULI_INJECT_SCRIPT_TAG; }