Search in sources :

Example 1 with EftarFileReader

use of org.opengrok.indexer.web.EftarFileReader in project OpenGrok by OpenGrok.

the class SystemControllerTest method testDtagsEftarReload.

@Test
public void testDtagsEftarReload() throws IOException {
    // The output file will be located in a directory under data root so create it first.
    Path dataRoot = Files.createTempDirectory("api_dtags_test");
    env.setDataRoot(dataRoot.toString());
    Paths.get(dataRoot.toString(), "index").toFile().mkdir();
    // Create path descriptions string.
    StringBuilder sb = new StringBuilder();
    PathDescription[] descriptions = { new PathDescription("/path1", "foo foo"), new PathDescription("/path2", "bar bar") };
    // Reload the contents via API call.
    Response r = target("system").path("pathdesc").request().post(Entity.json(descriptions));
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), r.getStatus());
    // Check
    Path eftarPath = env.getDtagsEftarPath();
    assertTrue(eftarPath.toFile().exists());
    try (EftarFileReader er = new EftarFileReader(eftarPath.toString())) {
        for (PathDescription description : descriptions) {
            assertEquals(description.getDescription(), er.get(description.getPath()));
        }
    }
    // Cleanup
    IOUtils.removeRecursive(dataRoot);
}
Also used : Path(java.nio.file.Path) Response(jakarta.ws.rs.core.Response) PathDescription(org.opengrok.indexer.web.PathDescription) EftarFileReader(org.opengrok.indexer.web.EftarFileReader) Test(org.junit.jupiter.api.Test)

Example 2 with EftarFileReader

use of org.opengrok.indexer.web.EftarFileReader in project OpenGrok by OpenGrok.

the class DirectoryListingTest method directoryListingWithEftarException.

@Test
public void directoryListingWithEftarException() throws IOException, HistoryException {
    EftarFileReader mockReader = mock(EftarFileReader.class);
    when(mockReader.getNode(anyString())).thenThrow(IOException.class);
    DirectoryListing instance = new DirectoryListing(mockReader);
    File file = new File(directory, "foo");
    StringWriter mockWriter = spy(StringWriter.class);
    instance.extraListTo("ctx", directory, mockWriter, directory.getPath(), Collections.singletonList(new DirectoryEntry(file)));
    verify(mockWriter, atLeast(20)).write(anyString());
}
Also used : StringWriter(java.io.StringWriter) DirectoryEntry(org.opengrok.indexer.search.DirectoryEntry) File(java.io.File) EftarFileReader(org.opengrok.indexer.web.EftarFileReader) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 EftarFileReader (org.opengrok.indexer.web.EftarFileReader)2 Response (jakarta.ws.rs.core.Response)1 File (java.io.File)1 StringWriter (java.io.StringWriter)1 Path (java.nio.file.Path)1 DirectoryEntry (org.opengrok.indexer.search.DirectoryEntry)1 PathDescription (org.opengrok.indexer.web.PathDescription)1