Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
Draft
  • Loading branch information
thachlp committed Feb 27, 2024
1 parent f729c8f commit c25f990
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand Down

0 comments on commit c25f990

Please sign in to comment.