Merge "Integration Tests for assignee"

This commit is contained in:
David Pursehouse 2016-09-23 09:00:41 +00:00 committed by Gerrit Code Review
commit 1fa13826f0
3 changed files with 229 additions and 0 deletions

View File

@ -0,0 +1,130 @@
// Copyright (C) 2016 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.change;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.TruthJUnit.assume;
import static java.util.concurrent.TimeUnit.SECONDS;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.NoHttpd;
import com.google.gerrit.acceptance.PushOneCommit;
import com.google.gerrit.extensions.api.changes.AssigneeInput;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.testutil.TestTimeUtil;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.Iterator;
import java.util.Set;
@NoHttpd
public class AssigneeIT extends AbstractDaemonTest {
@Before
public void before() {
assume().that(notesMigration.readChanges()).isTrue();
}
@BeforeClass
public static void setTimeForTesting() {
TestTimeUtil.resetWithClockStep(1, SECONDS);
}
@AfterClass
public static void restoreTime() {
TestTimeUtil.useSystemTime();
}
@Test
public void testGetNoAssignee() throws Exception {
PushOneCommit.Result r = createChange();
assertThat(getAssignee(r)).isNull();
}
@Test
public void testAddGetAssignee() throws Exception {
PushOneCommit.Result r = createChange();
assertThat(setAssignee(r, user.email)._accountId)
.isEqualTo(user.getId().get());
assertThat(getAssignee(r)._accountId).isEqualTo(user.getId().get());
}
@Test
public void testSetNewAssigneeWhenExists() throws Exception {
PushOneCommit.Result r = createChange();
setAssignee(r, user.email);
assertThat(setAssignee(r, user.email)._accountId)
.isEqualTo(user.getId().get());
}
@Test
public void testGetPastAssignees() throws Exception {
PushOneCommit.Result r = createChange();
setAssignee(r, user.email);
setAssignee(r, admin.email);
Set<AccountInfo> assignees = getPastAssignees(r);
assertThat(assignees).hasSize(2);
Iterator<AccountInfo> itr = assignees.iterator();
assertThat(itr.next()._accountId).isEqualTo(user.getId().get());
assertThat(itr.next()._accountId).isEqualTo(admin.getId().get());
}
@Test
public void testSetAlreadyExistingAssignee() throws Exception {
PushOneCommit.Result r = createChange();
setAssignee(r, user.email);
assertThat(setAssignee(r, user.email)._accountId)
.isEqualTo(user.getId().get());
}
@Test
public void testDeleteAssignee() throws Exception {
PushOneCommit.Result r = createChange();
assertThat(setAssignee(r, user.email)._accountId)
.isEqualTo(user.getId().get());
assertThat(deleteAssignee(r)._accountId).isEqualTo(user.getId().get());
assertThat(getAssignee(r)).isNull();
}
@Test
public void testDeleteAssigneeWhenNoAssignee() throws Exception {
PushOneCommit.Result r = createChange();
assertThat(deleteAssignee(r)).isNull();
}
private AccountInfo getAssignee(PushOneCommit.Result r) throws Exception {
return gApi.changes().id(r.getChange().getId().get()).getAssignee();
}
private Set<AccountInfo> getPastAssignees(PushOneCommit.Result r)
throws Exception {
return gApi.changes().id(r.getChange().getId().get()).getPastAssignees();
}
private AccountInfo setAssignee(PushOneCommit.Result r, String identifieer)
throws Exception {
AssigneeInput input = new AssigneeInput();
input.assignee = identifieer;
return gApi.changes().id(r.getChange().getId().get()).setAssignee(input);
}
private AccountInfo deleteAssignee(PushOneCommit.Result r) throws Exception {
return gApi.changes().id(r.getChange().getId().get()).deleteAssignee();
}
}

View File

@ -15,6 +15,7 @@
package com.google.gerrit.extensions.api.changes;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.CommentInfo;
import com.google.gerrit.extensions.common.EditInfo;
@ -141,6 +142,26 @@ public interface ChangeApi {
*/
Set<String> getHashtags() throws RestApiException;
/**
* Set the assignee of a change.
*/
AccountInfo setAssignee(AssigneeInput input) throws RestApiException;
/**
* Get the assignee of a change.
*/
AccountInfo getAssignee() throws RestApiException;
/**
* Get all past assignees.
*/
Set<AccountInfo> getPastAssignees() throws RestApiException;
/**
* Delete the assignee of a change.
*/
AccountInfo deleteAssignee() throws RestApiException;
/**
* Get all published comments on a change.
*
@ -328,6 +349,27 @@ public interface ChangeApi {
throw new NotImplementedException();
}
@Override
public AccountInfo setAssignee(AssigneeInput input)
throws RestApiException {
throw new NotImplementedException();
}
@Override
public AccountInfo getAssignee() throws RestApiException {
throw new NotImplementedException();
}
@Override
public Set<AccountInfo> getPastAssignees() throws RestApiException {
throw new NotImplementedException();
}
@Override
public AccountInfo deleteAssignee() throws RestApiException {
throw new NotImplementedException();
}
@Override
public Map<String, List<CommentInfo>> comments() throws RestApiException {
throw new NotImplementedException();

View File

@ -16,6 +16,7 @@ package com.google.gerrit.server.api.changes;
import com.google.gerrit.extensions.api.changes.AbandonInput;
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
import com.google.gerrit.extensions.api.changes.AssigneeInput;
import com.google.gerrit.extensions.api.changes.ChangeApi;
import com.google.gerrit.extensions.api.changes.Changes;
import com.google.gerrit.extensions.api.changes.FixInput;
@ -28,6 +29,7 @@ import com.google.gerrit.extensions.api.changes.RevisionApi;
import com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo;
import com.google.gerrit.extensions.api.changes.SubmittedTogetherOption;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.CommentInfo;
import com.google.gerrit.extensions.common.EditInfo;
@ -40,8 +42,11 @@ import com.google.gerrit.server.change.ChangeEdits;
import com.google.gerrit.server.change.ChangeJson;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.change.Check;
import com.google.gerrit.server.change.DeleteAssignee;
import com.google.gerrit.server.change.DeleteDraftChange;
import com.google.gerrit.server.change.GetAssignee;
import com.google.gerrit.server.change.GetHashtags;
import com.google.gerrit.server.change.GetPastAssignees;
import com.google.gerrit.server.change.GetTopic;
import com.google.gerrit.server.change.Index;
import com.google.gerrit.server.change.ListChangeComments;
@ -50,6 +55,7 @@ import com.google.gerrit.server.change.Move;
import com.google.gerrit.server.change.PostHashtags;
import com.google.gerrit.server.change.PostReviewers;
import com.google.gerrit.server.change.PublishDraftPatchSet;
import com.google.gerrit.server.change.PutAssignee;
import com.google.gerrit.server.change.PutTopic;
import com.google.gerrit.server.change.Restore;
import com.google.gerrit.server.change.Revert;
@ -95,6 +101,10 @@ class ChangeApiImpl implements ChangeApi {
private final ChangeJson.Factory changeJson;
private final PostHashtags postHashtags;
private final GetHashtags getHashtags;
private final PutAssignee putAssignee;
private final GetAssignee getAssignee;
private final GetPastAssignees getPastAssignees;
private final DeleteAssignee deleteAssignee;
private final ListChangeComments listComments;
private final ListChangeDrafts listDrafts;
private final Check check;
@ -121,6 +131,10 @@ class ChangeApiImpl implements ChangeApi {
ChangeJson.Factory changeJson,
PostHashtags postHashtags,
GetHashtags getHashtags,
PutAssignee putAssignee,
GetAssignee getAssignee,
GetPastAssignees getPastAssignees,
DeleteAssignee deleteAssignee,
ListChangeComments listComments,
ListChangeDrafts listDrafts,
Check check,
@ -146,6 +160,10 @@ class ChangeApiImpl implements ChangeApi {
this.changeJson = changeJson;
this.postHashtags = postHashtags;
this.getHashtags = getHashtags;
this.putAssignee = putAssignee;
this.getAssignee = getAssignee;
this.getPastAssignees = getPastAssignees;
this.deleteAssignee = deleteAssignee;
this.listComments = listComments;
this.listDrafts = listDrafts;
this.check = check;
@ -402,6 +420,45 @@ class ChangeApiImpl implements ChangeApi {
}
}
@Override
public AccountInfo setAssignee(AssigneeInput input)
throws RestApiException {
try {
return putAssignee.apply(change, input).value();
} catch (UpdateException e) {
throw new RestApiException("Cannot set assignee", e);
}
}
@Override
public AccountInfo getAssignee() throws RestApiException {
try {
Response<AccountInfo> r = getAssignee.apply(change);
return r.isNone() ? null : r.value();
} catch (OrmException e) {
throw new RestApiException("Cannot get assignee", e);
}
}
@Override
public Set<AccountInfo> getPastAssignees() throws RestApiException {
try {
return getPastAssignees.apply(change).value();
} catch (Exception e) {
throw new RestApiException("Cannot get past assignees", e);
}
}
@Override
public AccountInfo deleteAssignee() throws RestApiException {
try {
Response<AccountInfo> r = deleteAssignee.apply(change, null);
return r.isNone() ? null : r.value();
} catch (UpdateException e) {
throw new RestApiException("Cannot delete assignee", e);
}
}
@Override
public Map<String, List<CommentInfo>> comments() throws RestApiException {
try {