DeleteBranchIT: Add assertion on expected ref-updated events

Assert that there is a ref-updated event for both the creation
and deletion of the branch.

Change-Id: I8a40ffa174e247ad455c90a2166e16b0dd12eb56
This commit is contained in:
David Pursehouse 2016-06-16 15:02:31 +09:00
parent 171c9da6b7
commit 450332bd94
2 changed files with 24 additions and 1 deletions

View File

@ -34,6 +34,7 @@ import com.google.gerrit.server.events.RefUpdatedEvent;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.revwalk.RevCommit;
public class EventRecorder {
@ -128,6 +129,25 @@ public class EventRecorder {
return events;
}
public void assertRefUpdatedEvents(String project, String branch,
String... expected) throws Exception {
ImmutableList<RefUpdatedEvent> events = getRefUpdatedEvents(project,
branch, expected.length / 2);
int i = 0;
for (RefUpdatedEvent event : events) {
RefUpdateAttribute actual = event.refUpdate.get();
String oldRev = expected[i] == null
? ObjectId.zeroId().name()
: expected[i];
String newRev = expected[i+1] == null
? ObjectId.zeroId().name()
: expected[i+1];
assertThat(actual.oldRev).isEqualTo(oldRev);
assertThat(actual.newRev).isEqualTo(newRev);
i += 2;
}
}
public void assertRefUpdatedEvents(String project, String branch,
RevCommit... expected) throws Exception {
ImmutableList<RefUpdatedEvent> events = getRefUpdatedEvents(project,

View File

@ -88,7 +88,11 @@ public class DeleteBranchIT extends AbstractDaemonTest {
}
private void assertDeleteSucceeds() throws Exception {
String branchRev = branch().get().revision;
branch().delete();
eventRecorder.assertRefUpdatedEvents(project.get(), branch.get(),
null, branchRev,
branchRev, null);
exception.expect(ResourceNotFoundException.class);
branch().get();
}
@ -96,6 +100,5 @@ public class DeleteBranchIT extends AbstractDaemonTest {
private void assertDeleteForbidden() throws Exception {
exception.expect(AuthException.class);
branch().delete();
branch().get();
}
}