Merge "ChangeEdits.Put: Split inner static Input class to own file"

This commit is contained in:
Edwin Kempin
2019-12-20 11:06:13 +00:00
committed by Gerrit Code Review
3 changed files with 32 additions and 12 deletions

View File

@@ -0,0 +1,23 @@
// Copyright (C) 2019 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.extensions.api.changes;
import com.google.gerrit.extensions.restapi.DefaultInput;
import com.google.gerrit.extensions.restapi.RawInput;
/** Content to be added to a file (new or existing) via change edit. */
public class FileContentInput {
@DefaultInput public RawInput content;
}

View File

@@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableList;
import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.api.changes.FileContentInput;
import com.google.gerrit.extensions.common.DiffWebLinkInfo;
import com.google.gerrit.extensions.common.EditInfo;
import com.google.gerrit.extensions.common.Input;
@@ -109,7 +110,7 @@ public class ChangeEdits implements ChildCollection<ChangeResource, ChangeEditRe
*/
@Singleton
public static class Create
implements RestCollectionCreateView<ChangeResource, ChangeEditResource, Put.Input> {
implements RestCollectionCreateView<ChangeResource, ChangeEditResource, FileContentInput> {
private final Put putEdit;
@Inject
@@ -118,7 +119,7 @@ public class ChangeEdits implements ChildCollection<ChangeResource, ChangeEditRe
}
@Override
public Response<?> apply(ChangeResource resource, IdString id, Put.Input input)
public Response<?> apply(ChangeResource resource, IdString id, FileContentInput input)
throws AuthException, ResourceConflictException, IOException, PermissionBackendException {
putEdit.apply(resource, id.get(), input.content);
return Response.none();
@@ -267,11 +268,7 @@ public class ChangeEdits implements ChildCollection<ChangeResource, ChangeEditRe
/** Put handler that is activated when PUT request is called on collection element. */
@Singleton
public static class Put implements RestModifyView<ChangeEditResource, Put.Input> {
public static class Input {
@DefaultInput public RawInput content;
}
public static class Put implements RestModifyView<ChangeEditResource, FileContentInput> {
private final ChangeEditModifier editModifier;
private final GitRepositoryManager repositoryManager;
@@ -282,7 +279,7 @@ public class ChangeEdits implements ChildCollection<ChangeResource, ChangeEditRe
}
@Override
public Response<?> apply(ChangeEditResource rsrc, Input input)
public Response<?> apply(ChangeEditResource rsrc, FileContentInput input)
throws AuthException, ResourceConflictException, IOException, PermissionBackendException {
return apply(rsrc.getChangeResource(), rsrc.getPath(), input.content);
}

View File

@@ -45,6 +45,7 @@ import com.google.gerrit.common.data.Permission;
import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
import com.google.gerrit.extensions.api.changes.FileContentInput;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.api.changes.PublishChangeEditInput;
import com.google.gerrit.extensions.api.changes.ReviewInput;
@@ -64,7 +65,6 @@ import com.google.gerrit.server.ChangeMessagesUtil;
import com.google.gerrit.server.project.testing.TestLabels;
import com.google.gerrit.server.restapi.change.ChangeEdits.EditMessage;
import com.google.gerrit.server.restapi.change.ChangeEdits.Post;
import com.google.gerrit.server.restapi.change.ChangeEdits.Put;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.inject.Inject;
@@ -501,7 +501,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test
public void createAndChangeEditInOneRequestRest() throws Exception {
Put.Input in = new Put.Input();
FileContentInput in = new FileContentInput();
in.content = RawInputUtil.create(CONTENT_NEW);
adminRestSession.putRaw(urlEditFile(changeId, FILE_NAME), in.content).assertNoContent();
ensureSameBytes(getFileContentOfEdit(changeId, FILE_NAME), CONTENT_NEW);
@@ -513,7 +513,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test
public void changeEditRest() throws Exception {
createEmptyEditFor(changeId);
Put.Input in = new Put.Input();
FileContentInput in = new FileContentInput();
in.content = RawInputUtil.create(CONTENT_NEW);
adminRestSession.putRaw(urlEditFile(changeId, FILE_NAME), in.content).assertNoContent();
ensureSameBytes(getFileContentOfEdit(changeId, FILE_NAME), CONTENT_NEW);
@@ -534,7 +534,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test
public void getFileContentRest() throws Exception {
Put.Input in = new Put.Input();
FileContentInput in = new FileContentInput();
in.content = RawInputUtil.create(CONTENT_NEW);
adminRestSession.putRaw(urlEditFile(changeId, FILE_NAME), in.content).assertNoContent();
gApi.changes().id(changeId).edit().modifyFile(FILE_NAME, RawInputUtil.create(CONTENT_NEW2));