Search in sources :

Example 1 with HistoryDTO

use of org.opengrok.web.api.v1.controller.HistoryController.HistoryDTO in project OpenGrok by OpenGrok.

the class HistoryControllerTest method testHistoryGet.

@Test
public void testHistoryGet() throws Exception {
    final String path = "git";
    int size = 5;
    int start = 2;
    Response response = target("history").queryParam("path", path).queryParam("max", size).queryParam("start", start).request().get();
    HistoryDTO history = response.readEntity(new GenericType<>() {
    });
    assertEquals(size, history.getEntries().size());
    assertEquals("Kryštof Tulinger <krystof.tulinger@oracle.com>", history.getEntries().get(0).getAuthor());
    History repoHistory = HistoryGuru.getInstance().getHistory(new File(repository.getSourceRoot(), path));
    assertEquals(history, getHistoryDTO(repoHistory.getHistoryEntries(size, start), repoHistory.getTags(), start, size, repoHistory.getHistoryEntries().size()));
}
Also used : Response(jakarta.ws.rs.core.Response) HistoryDTO(org.opengrok.web.api.v1.controller.HistoryController.HistoryDTO) HistoryController.getHistoryDTO(org.opengrok.web.api.v1.controller.HistoryController.getHistoryDTO) History(org.opengrok.indexer.history.History) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 2 with HistoryDTO

use of org.opengrok.web.api.v1.controller.HistoryController.HistoryDTO in project OpenGrok by OpenGrok.

the class HistoryControllerTest method testHistoryDTOEquals.

@Test
public void testHistoryDTOEquals() {
    HistoryEntry historyEntry = new HistoryEntry("1", new Date(1245446973L / 60 * 60 * 1000), "xyz", "foo", true);
    HistoryEntryDTO entry1 = new HistoryEntryDTO(historyEntry);
    historyEntry.setAuthor("abc");
    HistoryEntryDTO entry2 = new HistoryEntryDTO(historyEntry);
    assertEquals(entry1, entry1);
    assertNotEquals(entry1, entry2);
    HistoryDTO history1 = new HistoryDTO(Collections.singletonList(entry1), 0, 1, 1);
    HistoryDTO history2 = new HistoryDTO(Collections.singletonList(entry2), 0, 1, 1);
    assertEquals(history1, history1);
    assertNotEquals(history1, history2);
}
Also used : HistoryDTO(org.opengrok.web.api.v1.controller.HistoryController.HistoryDTO) HistoryController.getHistoryDTO(org.opengrok.web.api.v1.controller.HistoryController.getHistoryDTO) HistoryEntry(org.opengrok.indexer.history.HistoryEntry) Date(java.util.Date) HistoryEntryDTO(org.opengrok.web.api.v1.controller.HistoryController.HistoryEntryDTO) Test(org.junit.jupiter.api.Test)

Example 3 with HistoryDTO

use of org.opengrok.web.api.v1.controller.HistoryController.HistoryDTO in project OpenGrok by OpenGrok.

the class HistoryController method get.

@GET
@CorsEnable
@PathAuthorized
@Produces(MediaType.APPLICATION_JSON)
public HistoryDTO get(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("path") final String path, @QueryParam("withFiles") final boolean withFiles, @QueryParam("max") @DefaultValue(MAX_RESULTS + "") final int maxEntries, @QueryParam("start") @DefaultValue(0 + "") final int startIndex) throws HistoryException, IOException, NoPathParameterException {
    File file = toFile(path);
    History history = HistoryGuru.getInstance().getHistory(file, withFiles, true);
    if (history == null) {
        return null;
    }
    return getHistoryDTO(history.getHistoryEntries(maxEntries, startIndex), history.getTags(), startIndex, maxEntries, history.getHistoryEntries().size());
}
Also used : History(org.opengrok.indexer.history.History) FileUtil.toFile(org.opengrok.web.util.FileUtil.toFile) File(java.io.File) CorsEnable(org.opengrok.web.api.v1.filter.CorsEnable) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET) PathAuthorized(org.opengrok.web.api.v1.filter.PathAuthorized)

Aggregations

File (java.io.File)2 Test (org.junit.jupiter.api.Test)2 History (org.opengrok.indexer.history.History)2 HistoryDTO (org.opengrok.web.api.v1.controller.HistoryController.HistoryDTO)2 HistoryController.getHistoryDTO (org.opengrok.web.api.v1.controller.HistoryController.getHistoryDTO)2 GET (jakarta.ws.rs.GET)1 Produces (jakarta.ws.rs.Produces)1 Response (jakarta.ws.rs.core.Response)1 Date (java.util.Date)1 HistoryEntry (org.opengrok.indexer.history.HistoryEntry)1 HistoryEntryDTO (org.opengrok.web.api.v1.controller.HistoryController.HistoryEntryDTO)1 CorsEnable (org.opengrok.web.api.v1.filter.CorsEnable)1 PathAuthorized (org.opengrok.web.api.v1.filter.PathAuthorized)1 FileUtil.toFile (org.opengrok.web.util.FileUtil.toFile)1