diff --git a/common/src/main/java/com/linecorp/centraldogma/internal/api/v1/HttpApiV1Constants.java b/common/src/main/java/com/linecorp/centraldogma/internal/api/v1/HttpApiV1Constants.java index 78c2e5c4be..8abe1142c7 100644 --- a/common/src/main/java/com/linecorp/centraldogma/internal/api/v1/HttpApiV1Constants.java +++ b/common/src/main/java/com/linecorp/centraldogma/internal/api/v1/HttpApiV1Constants.java @@ -24,12 +24,16 @@ public final class HttpApiV1Constants { // For legacy API public static final String API_V0_PATH_PREFIX = "/api/v0/"; + public static final String REPOSITORIES = "/repositories"; + public static final String API_V1_PATH_PREFIX = "/api/v1/"; public static final String PROJECTS = "projects"; public static final String PROJECTS_PREFIX = API_V1_PATH_PREFIX + PROJECTS; + public static final String PROJECTS_V0_PREFIX = API_V0_PATH_PREFIX + PROJECTS; + public static final String REPOS = "/repos"; public static final String COMMITS = "/commits"; diff --git a/server/src/test/java/com/linecorp/centraldogma/server/internal/api/RepositoryServiceV1Test.java b/server/src/test/java/com/linecorp/centraldogma/server/internal/api/RepositoryServiceV1Test.java index 4697f11a1e..210cf91fe4 100644 --- a/server/src/test/java/com/linecorp/centraldogma/server/internal/api/RepositoryServiceV1Test.java +++ b/server/src/test/java/com/linecorp/centraldogma/server/internal/api/RepositoryServiceV1Test.java @@ -16,8 +16,7 @@ package com.linecorp.centraldogma.server.internal.api; -import static com.linecorp.centraldogma.internal.api.v1.HttpApiV1Constants.PROJECTS_PREFIX; -import static com.linecorp.centraldogma.internal.api.v1.HttpApiV1Constants.REPOS; +import static com.linecorp.centraldogma.internal.api.v1.HttpApiV1Constants.*; import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson; import static org.assertj.core.api.Assertions.assertThat; @@ -58,6 +57,12 @@ protected void configureHttpClient(WebClientBuilder builder) { private static final String REPOS_PREFIX = PROJECTS_PREFIX + "/myPro" + REPOS; + private static final String REPOS_VO_PREFIX = PROJECTS_V0_PREFIX + "/myPro" + REPOS; + + private static final String FILES_VO_PREFIX = PROJECTS_V0_PREFIX + "/myPro" + REPOSITORIES + "/myRepo/files/revisions/head"; + + private static final String HISTORY_VO_PREFIX = PROJECTS_V0_PREFIX + "/myPro" + REPOSITORIES + "/myRepo/history"; + @BeforeAll static void setUp() { createProject(dogma); @@ -79,6 +84,17 @@ void createRepository() throws IOException { assertThat(jsonNode.get("createdAt").asText()).isNotNull(); } + @Test + void getHistory() throws IOException { + final WebClient client = dogma.httpClient(); + final AggregatedHttpResponse repoResponse = createRepository(client, "myRepo"); + System.out.println(repoResponse.contentUtf8()); + final AggregatedHttpResponse barResponse = createFile(client, "/foo/bar.txt", "bar.txt"); + final AggregatedHttpResponse bar2Response = createFile(client, "/foo2/bar2.txt", "bar2.txt"); + System.out.println(barResponse.contentUtf8()); + System.out.println(bar2Response.contentUtf8()); + } + private static AggregatedHttpResponse createRepository(WebClient client, String repoName) { final RequestHeaders headers = RequestHeaders.of(HttpMethod.POST, REPOS_PREFIX, HttpHeaderNames.CONTENT_TYPE, MediaType.JSON); @@ -87,6 +103,35 @@ private static AggregatedHttpResponse createRepository(WebClient client, String return client.execute(headers, body).aggregate().join(); } + private static AggregatedHttpResponse getHistories(WebClient client, String param) { + final RequestHeaders headers = RequestHeaders.of(HttpMethod.GET, HISTORY_VO_PREFIX, + HttpHeaderNames.CONTENT_TYPE, MediaType.JSON); + + return client.execute(headers).aggregate().join(); + } + + private static AggregatedHttpResponse createFile(WebClient client, String filePath, String fileName) { + final RequestHeaders headers = RequestHeaders.of(RequestHeaders.of(HttpMethod.GET, FILES_VO_PREFIX, + HttpHeaderNames.AUTHORIZATION, "Bearer anonymous")); + final String body = "{\n" + + " \"file\": {\n" + + " \"name\":" + fileName + ",\n" + + " \"type\": \"TEXT\",\n" + + " \"content\": \"This is test file\",\n" + + " \"path\": "+ filePath + ",\n" + + " },\n" + + " \"commitMessage\": {\n" + + " \"summary\": \"Add " + filePath + ",\n" + + " \"detail\": {\n" + + " \"content\": \"\",\n" + + " \"markup\": \"PLAINTEXT\"\n" + + " }\n" + + " }\n" + + "}"; + System.out.println(headers.path()); + return client.execute(headers, body).aggregate().join(); + } + @Test void createRepositoryWithSameName() { final WebClient client = dogma.httpClient();