Java Code Examples for com.intuit.karate.FileUtils#copy()

The following examples show how to use com.intuit.karate.FileUtils#copy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GatlingJobServer.java    From karate with MIT License 6 votes vote down vote up
@Override
public synchronized void handleUpload(File upload, String executorId, String chunkId) {
    String karateLog = upload.getPath() + File.separator + "karate.log";
    File karateLogFile = new File(karateLog);
    if (karateLogFile.exists()) {
        karateLogFile.renameTo(new File(karateLog + ".txt"));
    }
    String gatlingReportDir = "target" + File.separator + "reports" + File.separator;
    File[] dirs = upload.listFiles();
    for (File dir : dirs) {
        if (dir.isDirectory()) {
            File file = getFirstFileWithExtension(dir, "log");
            if (file != null) {
                FileUtils.copy(file, new File(gatlingReportDir + "simulation_" + chunkId + ".log"));
            }
        }
    }
    completed.add(executorId);
}
 
Example 2
Source File: DockerTarget.java    From karate with MIT License 6 votes vote down vote up
@Override
public Map<String, Object> stop(Logger logger) {
    Command.execLine(null, "docker stop " + containerId);
    if (!karateChrome) { // no video
        Command.execLine(null, "docker rm " + containerId);
        return Collections.EMPTY_MAP;
    }        
    String shortName = containerId.contains("_") ? containerId : StringUtils.truncate(containerId, 12, false);
    String dirName = "karate-chrome_" + shortName;
    String resultsDir = Command.getBuildDir() + File.separator + dirName;
    Command.execLine(null, "docker cp " + containerId + ":/tmp " + resultsDir);
    Command.execLine(null, "docker rm " + containerId);
    String video = resultsDir + File.separator + "karate.mp4";
    File file = new File(video);
    if (!file.exists()) {
        logger.warn("video file missing: {}", file);
        return Collections.EMPTY_MAP;
    }
    File copy = new File(Command.getBuildDir() + File.separator 
            + "cucumber-html-reports" + File.separator + dirName + ".mp4");
    FileUtils.copy(file, copy);
    return Collections.singletonMap("video", copy.getName());
}
 
Example 3
Source File: ScenarioJobServer.java    From karate with MIT License 5 votes vote down vote up
@Override
public void handleUpload(File upload, String executorId, String chunkId) {
    File jsonFile = getFirstFileWithExtension(upload, "json");
    if (jsonFile == null) {
        return;
    }
    String json = FileUtils.toString(jsonFile);
    File videoFile = getFirstFileWithExtension(upload, "mp4");
    List<Map<String, Object>> list = JsonUtils.toJsonDoc(json).read("$[0].elements");
    synchronized (CHUNK_RESULTS) {
        ChunkResult cr = CHUNK_RESULTS.remove(chunkId);
        LOGGER.info("chunk complete: {}, remaining: {}", chunkId, CHUNK_RESULTS.keySet());
        if (cr == null) {
            LOGGER.error("could not find chunk: {}", chunkId);
            return;
        }
        ScenarioResult sr = new ScenarioResult(cr.scenario, list, true);
        sr.setStartTime(cr.getStartTime());
        sr.setEndTime(System.currentTimeMillis());
        sr.setThreadName(executorId);
        cr.setResult(sr);
        if (videoFile != null) {
            File dest = new File(FileUtils.getBuildDir()
                    + File.separator + "cucumber-html-reports" + File.separator + chunkId + ".mp4");
            FileUtils.copy(videoFile, dest);
            sr.appendEmbed(Embed.forVideoFile(dest.getName()));
        }
        if (cr.parent.isComplete()) {
            LOGGER.info("feature complete, calling onComplete(): {}", cr.parent);
            cr.parent.onComplete();
        }
    }
}
 
Example 4
Source File: NettyUtils.java    From karate with MIT License 5 votes vote down vote up
public static void createSelfSignedCertificate(File cert, File key) {
    try {
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        FileUtils.copy(ssc.certificate(), cert);
        FileUtils.copy(ssc.privateKey(), key);
    } catch (Exception e) {
        throw new RuntimeException();
    }
}