Skip to content

Commit

Permalink
add negative test case
Browse files Browse the repository at this point in the history
  • Loading branch information
vladak committed Dec 11, 2023
1 parent 7c3f797 commit d53dba1
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
import org.opengrok.indexer.configuration.RuntimeEnvironment;
import org.opengrok.indexer.history.HistoryGuru;
import org.opengrok.indexer.history.RepositoryFactory;
import org.opengrok.indexer.index.IndexDatabase;
import org.opengrok.indexer.index.Indexer;
import org.opengrok.indexer.util.TestRepository;
import org.opengrok.web.api.v1.RestApp;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -53,6 +55,8 @@
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

class FileControllerTest extends OGKJerseyTest {

Expand Down Expand Up @@ -151,4 +155,24 @@ void testFileDefinitions() {
() -> assertFalse(defs.stream().map(Definitions.Tag::getLineStart).anyMatch(e -> e <= 0)),
() -> assertFalse(defs.stream().map(Definitions.Tag::getLineEnd).anyMatch(e -> e <= 0)));
}

/**
* Negative test case for file definitions API endpoint for a file that exists under the source root,
* however does not have matching document in the respective index database.
*/
@Test
void testFileDefinitionsNull() throws Exception {
final String path = "git/extra.file";
Path createdPath = Files.createFile(Path.of(env.getSourceRootPath(), path));
// Assumes that the API endpoint indeed calls IndexDatabase#getDefinitions()
assertNull(IndexDatabase.getDefinitions(createdPath.toFile()));
GenericType<List<Definitions.Tag>> type = new GenericType<>() {
};
List<Definitions.Tag> defs = target("file")
.path("defs")
.queryParam("path", path)
.request()
.get(type);
assertTrue(defs.isEmpty());
}
}

0 comments on commit d53dba1

Please sign in to comment.