Skip to content

Commit b2f411e

Browse files
committed
Fix test when resource could not be loaded from jar
1 parent 1a2bb6b commit b2f411e

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

opengrok-web/src/test/java/org/opengrok/web/api/v1/controller/ProjectsControllerTest.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,18 @@
4242
import org.opengrok.indexer.history.RepositoryInfo;
4343
import org.opengrok.indexer.index.IndexDatabase;
4444
import org.opengrok.indexer.index.Indexer;
45+
import org.opengrok.indexer.util.IOUtils;
4546
import org.opengrok.indexer.util.TestRepository;
4647

4748
import javax.ws.rs.client.Entity;
4849
import javax.ws.rs.core.Application;
4950
import javax.ws.rs.core.GenericType;
5051
import java.io.File;
52+
import java.io.IOException;
53+
import java.nio.file.CopyOption;
54+
import java.nio.file.Files;
55+
import java.nio.file.Path;
56+
import java.nio.file.StandardCopyOption;
5157
import java.util.ArrayList;
5258
import java.util.Arrays;
5359
import java.util.Collections;
@@ -337,7 +343,7 @@ private void delete(final String project) {
337343
}
338344

339345
@Test
340-
public void testIndexed() {
346+
public void testIndexed() throws IOException {
341347
String projectName = "mercurial";
342348

343349
// When a project is added, it should be marked as not indexed.
@@ -357,9 +363,15 @@ public void testIndexed() {
357363

358364
// Add some changes to the repository.
359365
File mercurialRoot = new File(repository.getSourceRoot() + File.separator + "mercurial");
360-
MercurialRepositoryTest.runHgCommand(mercurialRoot,
361-
"import", HistoryGuru.getInstance().getClass().
362-
getResource("/history/hg-export-subdir.txt").getPath());
366+
367+
// copy file from jar to a temp file
368+
Path temp = Files.createTempFile("opengrok", "temp");
369+
Files.copy(HistoryGuru.getInstance().getClass().getResourceAsStream("/history/hg-export-subdir.txt"),
370+
temp, StandardCopyOption.REPLACE_EXISTING);
371+
372+
MercurialRepositoryTest.runHgCommand(mercurialRoot, "import", temp.toString());
373+
374+
temp.toFile().delete();
363375

364376
// Test that the project's indexed flag becomes true only after
365377
// the message is applied.

0 commit comments

Comments
 (0)