FilePersister implements Persister { @Override public List<TargetResult> loadTargetResults(final PersistMetadata metadata) { File file = checkFileAvailable(getTargetResultsFile(metadata)); LOG.debug("[Load TargetResults] ({})", file); LOG.trace("[Load TargetResults] ({})", metadata); try { List<TargetResult> targetResults = JSONUtils.readValue(file, TARGET_RESULTS_REFERENCE); LOG.trace("[Load TargetResults] => {}", targetResults); return Collections.unmodifiableList(fillScreenshotImageProperty(targetResults, metadata)); } catch (JSONException e) { LOG.debug("Failed to load TargetResults.", e); throw e; } catch (Exception e) { LOG.debug("Failed to fill TargetResults 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 testLoadTargetResults() throws Exception { Map<String, Object> map = new HashMap<String, Object>(); map.put("platform", "WINDOWS"); map.put("browserName", "firefox"); map.put("version", "38"); final PtlCapabilities capabilities = new PtlCapabilities(map); final PersistMetadata metadata = new PersistMetadata("testId", "testClass", "testMethod", "scId", capabilities); List<TargetResult> jsonValue = JSONUtils.readValue( getClass().getResourceAsStream("FilePersister_TargetResults.json"), new TypeReference<List<TargetResult>>() { }); List<TargetResult> expected = new ArrayList<TargetResult>(Lists.transform(jsonValue, new Function<TargetResult, TargetResult>() { @Override public TargetResult apply(TargetResult r) { return new TargetResult(r.getResult(), r.getTarget(), r.getExcludes(), r.isMoveTarget(), r .getHiddenElementSelectors(), new PersistedScreenshotImage(persister, new PersistMetadata("testId", "testClass", "testMethod", "scId", new IndexDomSelector( SelectorType.TAG_NAME, "body", 0), null, capabilities)), r.getOptions()); } })); File file = new File(BASE_DIRECTORY + "/testId/testClass/testMethod_scId_WINDOWS_firefox_38.json"); file.getParentFile().mkdirs(); JSONUtils.writeValue(file, expected); List<TargetResult> results = persister.loadTargetResults(metadata); assertThat(results, is(expected)); }
@Test public void testLoadTargetResults_not_found() throws Exception { expectedException.expect(ResourceUnavailableException.class); Map<String, Object> map = new HashMap<String, Object>(); map.put("platform", "WINDOWS"); map.put("browserName", "firefox"); map.put("version", "38"); PtlCapabilities capabilities = new PtlCapabilities(map); PersistMetadata metadata = new PersistMetadata("testId", "testClass", "testMethod", "scId", capabilities); persister.loadTargetResults(metadata); }