FilePersister implements Persister { @Override public TestResult loadTestResult(PersistMetadata metadata) { File file = checkFileAvailable(getTestResultFile(metadata)); LOG.debug("[Load TestResult] ({})", file); LOG.trace("[Load TestResult] ({})", metadata); try { TestResult testResult = JSONUtils.readValue(file, TestResult.class); LOG.trace("[Load TestResult] => {}", testResult); List<ScreenshotResult> results = new ArrayList<ScreenshotResult>(testResult.getScreenshotResults().size()); for (ScreenshotResult r : testResult.getScreenshotResults()) { PersistMetadata m = new PersistMetadata(metadata.getExpectedId(), metadata.getClassName(), r.getTestMethod(), r.getScreenshotId(), new PtlCapabilities(r.getCapabilities())); List<TargetResult> targetResults = fillScreenshotImageProperty(r.getTargetResults(), m); results.add(new ScreenshotResult(r.getScreenshotId(), r.getResult(), r.getExpectedId(), targetResults, r.getTestClass(), r.getTestMethod(), r.getCapabilities(), null)); } return new TestResult(testResult.getResultId(), testResult.getResult(), results); } catch (JSONException e) { LOG.debug("Failed to load TestResult.", e); throw e; } catch (Exception e) { LOG.debug("Failed to fill TestResult object.", e); throw e; } } FilePersister();  FilePersister(FilePersisterConfig config); @Override void saveDiffImage(PersistMetadata metadata, BufferedImage image); @Override BufferedImage loadDiffImage(PersistMetadata metadata); @Override void saveScreenshot(PersistMetadata metadata, BufferedImage image); @Override InputStream getImageStream(PersistMetadata metadata); @Override BufferedImage loadScreenshot(PersistMetadata metadata); @Override void saveTargetResults(PersistMetadata metadata, List<TargetResult> results); @Override List<TargetResult> loadTargetResults(final PersistMetadata metadata); @Override void saveTestResult(PersistMetadata metadata, TestResult result); @Override TestResult loadTestResult(PersistMetadata metadata); @Override void saveExpectedIds(Map<String, Map<String, String>> expectedIds); @Override Map<String, Map<String, String>> loadExpectedIds(); File getResultDirectoryFile(); File getExpectedIdsFile(); File getTestResultFile(PersistMetadata metadata); File getTargetResultsFile(PersistMetadata metadata); File getScreenshotImageFile(PersistMetadata metadata); File getDiffImageFile(PersistMetadata metadata); String getExpectedIdsFileName(); String getTestResultFileName(); String getTargetResultsFileName(PersistMetadata metadata); String getScreenshotImageFileName(PersistMetadata metadata); String getDiffImageFileName(PersistMetadata metadata); static final String DEFAULT_EXPECTED_IDS_FILE_NAME; static final String DEFAULT_TEST_RESULT_FILE_NAME; }
@Test public void testLoadTestResult() throws Exception { File file = new File(BASE_DIRECTORY + "/test1/testClass/result.json"); file.getParentFile().mkdirs(); FileUtils.copyURLToFile(getClass().getResource("FilePersister_TestResult.json"), file); PersistMetadata metadata = new PersistMetadata("test1", "testClass"); TestResult actual = persister.loadTestResult(metadata); TestResult expected = JSONUtils.readValue(getClass().getResourceAsStream("FilePersister_TestResult.json"), TestResult.class); Field imageField = TargetResult.class.getDeclaredField("image"); imageField.setAccessible(true); for (ScreenshotResult sr : expected.getScreenshotResults()) { ScreenshotImage image = new PersistedScreenshotImage(persister, new PersistMetadata(expected.getResultId(), sr.getTestClass(), sr.getTestMethod(), sr.getScreenshotId(), new IndexDomSelector( SelectorType.TAG_NAME, "body", 0), null, new PtlCapabilities(sr.getCapabilities()))); imageField.set(sr.getTargetResults().get(0), image); } assertThat(actual, is(expected)); }
@Test public void testLoadTestResult_not_found() throws Exception { expectedException.expect(ResourceUnavailableException.class); PersistMetadata metadata = new PersistMetadata("test1", "testClass"); persister.loadTestResult(metadata); }