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:
@@ -34,6 +34,7 @@ import com.google.gerrit.server.events.RefUpdatedEvent;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
|
|
||||||
public class EventRecorder {
|
public class EventRecorder {
|
||||||
@@ -128,6 +129,25 @@ public class EventRecorder {
|
|||||||
return events;
|
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,
|
public void assertRefUpdatedEvents(String project, String branch,
|
||||||
RevCommit... expected) throws Exception {
|
RevCommit... expected) throws Exception {
|
||||||
ImmutableList<RefUpdatedEvent> events = getRefUpdatedEvents(project,
|
ImmutableList<RefUpdatedEvent> events = getRefUpdatedEvents(project,
|
||||||
|
|||||||
@@ -88,7 +88,11 @@ public class DeleteBranchIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void assertDeleteSucceeds() throws Exception {
|
private void assertDeleteSucceeds() throws Exception {
|
||||||
|
String branchRev = branch().get().revision;
|
||||||
branch().delete();
|
branch().delete();
|
||||||
|
eventRecorder.assertRefUpdatedEvents(project.get(), branch.get(),
|
||||||
|
null, branchRev,
|
||||||
|
branchRev, null);
|
||||||
exception.expect(ResourceNotFoundException.class);
|
exception.expect(ResourceNotFoundException.class);
|
||||||
branch().get();
|
branch().get();
|
||||||
}
|
}
|
||||||
@@ -96,6 +100,5 @@ public class DeleteBranchIT extends AbstractDaemonTest {
|
|||||||
private void assertDeleteForbidden() throws Exception {
|
private void assertDeleteForbidden() throws Exception {
|
||||||
exception.expect(AuthException.class);
|
exception.expect(AuthException.class);
|
||||||
branch().delete();
|
branch().delete();
|
||||||
branch().get();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user