Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @ConsumseJson to contents API. #999

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.linecorp.armeria.common.HttpStatus;
import com.linecorp.armeria.common.util.Exceptions;
import com.linecorp.armeria.server.ServiceRequestContext;
import com.linecorp.armeria.server.annotation.ConsumesJson;
import com.linecorp.armeria.server.annotation.Default;
import com.linecorp.armeria.server.annotation.Get;
import com.linecorp.armeria.server.annotation.Param;
Expand Down Expand Up @@ -187,6 +188,7 @@ private static String normalizePath(String path) {
* <p>Pushes a commit.
*/
@Post("/projects/{projectName}/repos/{repoName}/contents")
@ConsumesJson
@RequiresWritePermission
public CompletableFuture<PushResultDto> push(
ServiceRequestContext ctx,
Expand Down Expand Up @@ -226,6 +228,7 @@ private CompletableFuture<Revision> push(long commitTimeMills, Author author, Re
* <p>Previews the actual changes which will be resulted by the given changes.
*/
@Post("/projects/{projectName}/repos/{repoName}/preview")
@ConsumesJson
public CompletableFuture<Iterable<ChangeDto<?>>> preview(
ServiceRequestContext ctx,
@Param @Default("-1") String revision,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import com.fasterxml.jackson.databind.JsonNode;

Expand Down Expand Up @@ -407,6 +409,39 @@ void getFile() {
assertThatJson(actualJson).isEqualTo(expectedJson);
}

@ParameterizedTest
@CsvSource({
"application/json, 200",
"text/plain, 415",
"text/xml, 415",
"application/xml, 415",
"application/x-www-form-urlencoded, 415"
})
void getFileWithVariusContentType(String mediaType, int expectedStatusCode) {
// Given:
final WebClient client = dogma.httpClient();
final String body =
'{' +
" \"path\" : \"/foo.json\"," +
" \"type\" : \"UPSERT_JSON\"," +
" \"content\" : {\"a\": \"bar\"}," +
" \"commitMessage\" : {" +
" \"summary\" : \"Add foo.json\"," +
" \"detail\": \"Add because we need it.\"," +
" \"markup\": \"PLAINTEXT\"" +
" }" +
'}';

final RequestHeaders headers = RequestHeaders.of(HttpMethod.POST, CONTENTS_PREFIX,
HttpHeaderNames.CONTENT_TYPE, mediaType);

// When:
final AggregatedHttpResponse aRes = client.execute(headers, body).aggregate().join();

// Then:
assertThatJson(aRes.headers().status().code()).isEqualTo(expectedStatusCode);
}

@Test
void getFileWithJsonPath() {
final WebClient client = dogma.httpClient();
Expand Down
Loading