@Override @Nonnull public Optional<Resource> getContent() throws IOException { final Path absolutePath = normalizedPath(getAbsolutePath()); return Files.exists(absolutePath) ? Optional.of(new FileSystemResource(absolutePath.toFile())) : Optional.empty(); }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ public static void assertSameContents2 (final @Nonnull Path expectedPath, final @Nonnull Path actualPath) throws IOException { FileComparisonUtils.assertSameContents(toFileBMT46(normalizedPath(expectedPath.toAbsolutePath())), toFileBMT46(normalizedPath(actualPath.toAbsolutePath()))); } }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ @Nonnull public static File toFileBMT46 (final @Nonnull Path path) throws IOException { File file = path.toFile(); if (probeBMT46(path)) { file = File.createTempFile("bmt46-", "." + extensionOf(path)); file.deleteOnExit(); log.warn("Workaround for BMT-46: copying {} to temporary file: {}", path, file); Files.copy(path, file.toPath(), StandardCopyOption.REPLACE_EXISTING); } return file; }
/******************************************************************************************************************* * * Tries to fix a path for character normalization issues (see BMT-46). The idea is to first normalize the encoding * to the native form. If it doesn't work, a broken path is replaced to avoid further errors (of course, the * resource won't be available when requested). * It doesn't try to call normalizedPath() because it's expensive. * * @param binding the binding * @return the path * ******************************************************************************************************************/ @Nonnull protected static Path toPath (final @Nonnull Binding binding) { try // FIXME: see BMT-46 - try all posibile normalizations { return Paths.get(normalizedToNativeForm(toString(binding).get())); } catch (InvalidPathException e) { // FIXME: perhaps we could try a similar trick to normalizedPath() - the problem being the fact that it // currently accepts a Path, but we can't convert to a Path. It should be rewritten to work with a String // in input. log.error("Invalid path {}", e.toString()); return Paths.get("broken SEE BMT-46"); } }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ public static void assertSameContents (final @Nonnull Path expectedPath, final @Nonnull Path actualPath) throws IOException { FileComparisonUtils.assertSameContents(toFileBMT46(expectedPath), toFileBMT46(actualPath)); // FileComparisonUtils.assertSameContents(Files.readAllLines(expectedPath), Files.readAllLines(actualPath)); }
found = Objects.equals(normalizedToNativeForm(element.toString()), normalizedToNativeForm(childName.toString()));
@Override @Nonnegative public long getSize() throws IOException { return Files.size(normalizedPath(getAbsolutePath())); }
final Path normalizedPath = normalizedPath(path.toAbsolutePath()); log.debug("path: {}", normalizedPath); file = toFileBMT46(normalizedPath);
/******************************************************************************************************************* * * Queries the catalog for the whole data in various ways and dumps the results to check the consistency. * ******************************************************************************************************************/ @Test(dataProvider = "testSetNamesProvider") public void must_properly_query_the_whole_catalog_in_various_ways (final @Nonnull String testSetName, final @CheckForNull String otherTestSetName, final @Nonnull Id source, final @Nonnull Id fallbackSource) throws Exception { // given final Repository repository = context.getBean(Repository.class); if (otherTestSetName != null) { loadRepository(repository, PATH_TEST_SETS.resolve(otherTestSetName + ".n3")); } loadRepository(repository, PATH_TEST_SETS.resolve(testSetName + ".n3")); final RepositoryMediaCatalog underTest = context.getBean(RepositoryMediaCatalog.class); underTest.setSource(source); underTest.setFallback(fallbackSource); final Path expectedResult = PATH_EXPECTED_TEST_RESULTS.resolve(testSetName + "-dump.txt"); final Path actualResult = PATH_TEST_RESULTS.resolve(testSetName + "-dump.txt"); // when queryAndDump(underTest, actualResult); // then assertSameContents(normalizedPath(expectedResult).toFile(), normalizedPath(actualResult).toFile()); }
@Override public void received (final @Nonnull ActionInvocation actionInvocation, final @Nonnull DIDLContent didl) { try { log.info("received() - {}", actionInvocation); final String fileName = String.format("%s/%s/%s/%s-%03d.txt", clientDeviceName, testSetName, sequenceName, sequenceName, n.getAndIncrement()); final Path expectedFile = EXPECTED_PATH.resolve(fileName); final Path actualFile = ACTUAL_PATH.resolve(fileName); Files.createDirectories(actualFile.getParent()); final String header = String.format("%s(%s)", actionInvocation.getAction().getName(), actionInvocation.getInputMap()); final DIDLParser parser = new DIDLParser(); final String baseUrl = resourceServer.absoluteUrl(""); final String result = xmlPrettyPrinted(parser.generate(didl)).replaceAll(baseUrl, "http://<server>/"); final String queries = String.format("QUERY COUNT: %d", RepositoryTrackFinder.getQueryCount()); Files.write(actualFile, (header + "\n" + result + "\n" + queries).getBytes(UTF_8)); assertSameContents(normalizedPath(expectedFile), normalizedPath(actualFile)); } catch (Throwable e) { log.error("", e); error.set(e); } latch.countDown(); }