Skip to content

Commit

Permalink
Fix test fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
datazuul committed Nov 9, 2018
1 parent 4ade373 commit 2785037
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
import de.digitalcollections.model.impl.identifiable.resource.FileResourceImpl;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -166,14 +168,14 @@ public void findValidKeys() throws Exception {
resolvers.add(mockMultiPatternsFileNameResolver);

DirectoryStream<Path> mockDirectoryStream = mock(DirectoryStream.class);
Path[] mockFiles = { Paths.get("/opt/news/news_12345678.md"), Paths.get("/opt/news/news_23456789.md"),
Paths.get("README.md"), Paths.get("/opt/news/news_123.md")};
Path[] mockFiles = {Paths.get("/opt/news/news_12345678.md"), Paths.get("/opt/news/news_23456789.md"),
Paths.get("README.md"), Paths.get("/opt/news/news_123.md")};
when(mockDirectoryStream.spliterator()).then(invocation -> Arrays.spliterator(mockFiles));
resourceRepository.overrideDirectoryStream(mockDirectoryStream);

resourceRepository.setResourcePersistenceHandlers(resolvers);
Set<String> keys = resourceRepository.findKeys("news_(\\d{8})", RESOLVED);
assertThat(keys).containsExactly("news_12345678","news_23456789");
assertThat(keys).containsExactly("news_12345678", "news_23456789");
}

@Test
Expand All @@ -193,14 +195,14 @@ public void findValidKeysForExtendedPattern() throws Exception {
resolvers.add(mockMultiPatternsFileNameResolver);

DirectoryStream<Path> mockDirectoryStream = mock(DirectoryStream.class);
Path[] mockFiles = { Paths.get("/opt/news/news_12345678.md"), Paths.get("/opt/news/news_23456789.md"),
Paths.get("README.md"), Paths.get("/opt/news/news_123.md")};
Path[] mockFiles = {Paths.get("/opt/news/news_12345678.md"), Paths.get("/opt/news/news_23456789.md"),
Paths.get("README.md"), Paths.get("/opt/news/news_123.md")};
when(mockDirectoryStream.spliterator()).then(invocation -> Arrays.spliterator(mockFiles));
resourceRepository.overrideDirectoryStream(mockDirectoryStream);

resourceRepository.setResourcePersistenceHandlers(resolvers);
Set<String> keys = resourceRepository.findKeys("news_(\\d{6})(\\d{2})", RESOLVED);
assertThat(keys).containsExactly("news_12345678","news_23456789");
assertThat(keys).containsExactly("news_12345678", "news_23456789");
}

@Test(expected = ResourceIOException.class)
Expand Down Expand Up @@ -228,9 +230,15 @@ public void assertZeroByteFile() throws ResourceIOException, URISyntaxException
}

@Test
public void assertExistingFile() throws ResourceIOException, URISyntaxException {
public void assertExistingFile() throws ResourceIOException, URISyntaxException, IOException {
String newResourceFilename = "test_file.txt";
File newCreatedResource = folder.newFile(newResourceFilename);
String data = "Test data";
final Path filePath = newCreatedResource.toPath();
Files.write(filePath, data.getBytes());

FileResource existingResource = new FileResourceImpl();
existingResource.setUri(new URI("file:/var/log/wtmp"));
existingResource.setUri(new URI("file:" + filePath.toString()));
existingResource.setMimeType(MimeType.MIME_WILDCARD);
resourceRepository.assertReadability(existingResource);
}
Expand Down

0 comments on commit 2785037

Please sign in to comment.