Merge "Merge branch 'stable-3.3' into master"

This commit is contained in:
Marco Miller
2020-12-09 14:11:31 +00:00
committed by Gerrit Code Review
13 changed files with 237 additions and 37 deletions

View File

@@ -899,7 +899,19 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
GitUtil.fetch(user2Repo, r.getPatchSet().refName() + ":ps");
user2Repo.reset("ps");
r = amendChange(r.getChangeId(), "refs/for/master%ready", user2, user2Repo);
r.assertErrorStatus(ReceiveConstants.ONLY_CHANGE_OWNER_OR_PROJECT_OWNER_CAN_MODIFY_WIP);
r.assertErrorStatus(ReceiveConstants.ONLY_USERS_WITH_TOGGLE_WIP_STATE_PERM_CAN_MODIFY_WIP);
// Non owner, non admin and non project owner with toggleWipState should succeed.
projectOperations
.project(project)
.forUpdate()
.add(
allow(Permission.TOGGLE_WORK_IN_PROGRESS_STATE)
.ref(RefNames.REFS_HEADS + "*")
.group(REGISTERED_USERS))
.update();
r = amendChange(r.getChangeId(), "refs/for/master%ready", user2, user2Repo);
r.assertOkStatus();
// Project owner trying to move from WIP to ready should succeed.
projectOperations

View File

@@ -0,0 +1,76 @@
// Copyright (C) 2020 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.acceptance.rest;
import static com.google.common.truth.Truth.assertThat;
import static org.apache.http.HttpStatus.SC_OK;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.httpd.restapi.RestApiServlet;
import java.io.IOException;
import java.util.regex.Pattern;
import org.apache.http.message.BasicHeader;
import org.junit.Test;
public class RestApiServletIT extends AbstractDaemonTest {
private static String ANY_REST_API = "/accounts/self/capabilities";
private static BasicHeader ACCEPT_STAR_HEADER = new BasicHeader("Accept", "*/*");
private static Pattern ANY_SPACE = Pattern.compile("\\s");
@Test
public void restResponseBodyShouldBeCompactWithoutSpaces() throws Exception {
RestResponse response = adminRestSession.getWithHeader(ANY_REST_API, ACCEPT_STAR_HEADER);
assertThat(response.getStatusCode()).isEqualTo(SC_OK);
assertThat(contentWithoutMagicJson(response)).doesNotContainMatch(ANY_SPACE);
}
@Test
public void restResponseBodyShouldBeCompactWithoutSpacesWhenPPIsZero() throws Exception {
assertThat(contentWithoutMagicJson(prettyJsonRestResponse("prettyPrint", 0)))
.doesNotContainMatch(ANY_SPACE);
}
@Test
public void restResponseBodyShouldBeCompactWithoutSpacesWhenPrerryPrintIsZero() throws Exception {
assertThat(contentWithoutMagicJson(prettyJsonRestResponse("pp", 0)))
.doesNotContainMatch(ANY_SPACE);
}
@Test
public void restResponseBodyShouldBePrettyfiedWhenPPIsOne() throws Exception {
assertThat(contentWithoutMagicJson(prettyJsonRestResponse("pp", 1))).containsMatch(ANY_SPACE);
}
@Test
public void restResponseBodyShouldBePrettyfiedWhenPrettyPrintIsOne() throws Exception {
assertThat(contentWithoutMagicJson(prettyJsonRestResponse("prettyPrint", 1)))
.containsMatch(ANY_SPACE);
}
private RestResponse prettyJsonRestResponse(String ppArgument, int ppValue) throws Exception {
RestResponse response =
adminRestSession.getWithHeader(
ANY_REST_API + "?" + ppArgument + "=" + ppValue, ACCEPT_STAR_HEADER);
assertThat(response.getStatusCode()).isEqualTo(SC_OK);
return response;
}
private String contentWithoutMagicJson(RestResponse response) throws IOException {
return response.getEntityContent().substring(RestApiServlet.JSON_MAGIC.length);
}
}

View File

@@ -56,4 +56,19 @@ public class StoredCommentLinkInfoSerializerTest {
.build();
assertThat(deserialize(serialize(autoValue))).isEqualTo(autoValue);
}
@Test
public void nullEnabled_roundTrip() {
StoredCommentLinkInfo sourceAutoValue =
StoredCommentLinkInfo.builder("name").setLink("<p>html").setMatch("*").build();
StoredCommentLinkInfo storedAutoValue =
StoredCommentLinkInfo.builder("name")
.setLink("<p>html")
.setMatch("*")
.setEnabled(true)
.build();
assertThat(deserialize(serialize(sourceAutoValue))).isEqualTo(storedAutoValue);
}
}