RestResponse: Add helper methods to perform assertions on status code

Add new helper methods on RestResponse to do assertions on the status code
using the assertThat method from Google Truth.

Modify tests to use the new helper methods.

Change-Id: Ia91199d4e254a3a47d6828b964be3ff37f55ff8e
This commit is contained in:
David Pursehouse
2015-11-06 14:17:08 +09:00
parent 312c546a76
commit 86d184672e
24 changed files with 243 additions and 241 deletions

View File

@@ -14,9 +14,12 @@
package com.google.gerrit.acceptance;
import static com.google.common.truth.Truth.assert_;
import static com.google.gerrit.httpd.restapi.RestApiServlet.JSON_MAGIC;
import static java.nio.charset.StandardCharsets.UTF_8;
import org.apache.http.HttpStatus;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
@@ -36,4 +39,51 @@ public class RestResponse extends HttpResponse {
}
return reader;
}
public void assertStatus(int status) throws Exception {
assert_()
.withFailureMessage(String.format("Expected status code %d", status))
.that(getStatusCode())
.isEqualTo(status);
}
public void assertOK() throws Exception {
assertStatus(HttpStatus.SC_OK);
}
public void assertNotFound() throws Exception {
assertStatus(HttpStatus.SC_NOT_FOUND);
}
public void assertConflict() throws Exception {
assertStatus(HttpStatus.SC_CONFLICT);
}
public void assertForbidden() throws Exception {
assertStatus(HttpStatus.SC_FORBIDDEN);
}
public void assertNoContent() throws Exception {
assertStatus(HttpStatus.SC_NO_CONTENT);
}
public void assertBadRequest() throws Exception {
assertStatus(HttpStatus.SC_BAD_REQUEST);
}
public void assertUnprocessableEntity() throws Exception {
assertStatus(HttpStatus.SC_UNPROCESSABLE_ENTITY);
}
public void assertMethodNotAllowed() throws Exception {
assertStatus(HttpStatus.SC_METHOD_NOT_ALLOWED);
}
public void assertCreated() throws Exception {
assertStatus(HttpStatus.SC_CREATED);
}
public void assertPreconditionFailed() throws Exception {
assertStatus(HttpStatus.SC_PRECONDITION_FAILED);
}
}

View File

@@ -19,11 +19,6 @@ import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.http.HttpStatus.SC_CONFLICT;
import static org.apache.http.HttpStatus.SC_FORBIDDEN;
import static org.apache.http.HttpStatus.SC_NOT_FOUND;
import static org.apache.http.HttpStatus.SC_NO_CONTENT;
import static org.apache.http.HttpStatus.SC_OK;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
@@ -185,8 +180,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
modifier.modifyFile(editUtil.byChange(change).get(), FILE_NAME,
RestSession.newRawInput(CONTENT_NEW))).isEqualTo(RefUpdate.Result.FORCED);
Optional<ChangeEdit> edit = editUtil.byChange(change);
RestResponse r = adminSession.post(urlPublish());
assertThat(r.getStatusCode()).isEqualTo(SC_NO_CONTENT);
adminSession.post(urlPublish()).assertNoContent();
edit = editUtil.byChange(change);
assertThat(edit.isPresent()).isFalse();
PatchSet newCurrentPatchSet = getCurrentPatchSet(changeId);
@@ -204,8 +198,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
modifier.modifyFile(editUtil.byChange(change).get(), FILE_NAME,
RestSession.newRawInput(CONTENT_NEW))).isEqualTo(RefUpdate.Result.FORCED);
Optional<ChangeEdit> edit = editUtil.byChange(change);
RestResponse r = adminSession.delete(urlEdit());
assertThat(r.getStatusCode()).isEqualTo(SC_NO_CONTENT);
adminSession.delete(urlEdit()).assertNoContent();
edit = editUtil.byChange(change);
assertThat(edit.isPresent()).isFalse();
}
@@ -219,11 +212,9 @@ public class ChangeEditIT extends AbstractDaemonTest {
assertThat(
modifier.modifyFile(editUtil.byChange(change).get(), FILE_NAME,
RestSession.newRawInput(CONTENT_NEW))).isEqualTo(RefUpdate.Result.FORCED);
RestResponse r = adminSession.post(urlPublish());
assertThat(r.getStatusCode()).isEqualTo(SC_FORBIDDEN);
adminSession.post(urlPublish()).assertForbidden();
setUseContributorAgreements(InheritableBoolean.FALSE);
r = adminSession.post(urlPublish());
assertThat(r.getStatusCode()).isEqualTo(SC_NO_CONTENT);
adminSession.post(urlPublish()).assertNoContent();
}
@Test
@@ -260,8 +251,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
assertThat(edit.getBasePatchSet().getPatchSetId()).isEqualTo(
current.getPatchSetId() - 1);
Date beforeRebase = edit.getEditCommit().getCommitterIdent().getWhen();
RestResponse r = adminSession.post(urlRebase());
assertThat(r.getStatusCode()).isEqualTo(SC_NO_CONTENT);
adminSession.post(urlRebase()).assertNoContent();
edit = editUtil.byChange(change).get();
assertByteArray(fileUtil.getContent(projectCache.get(edit.getChange().getProject()),
ObjectId.fromString(edit.getRevision().get()), FILE_NAME), CONTENT_NEW);
@@ -287,8 +277,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, FILE_NAME,
new String(CONTENT_NEW2), changeId2);
push.to("refs/for/master").assertOkStatus();
RestResponse r = adminSession.post(urlRebase());
assertThat(r.getStatusCode()).isEqualTo(SC_CONFLICT);
adminSession.post(urlRebase()).assertConflict();
}
@Test
@@ -370,24 +359,21 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test
public void updateMessageRest() throws Exception {
assertThat(adminSession.get(urlEditMessage()).getStatusCode())
.isEqualTo(SC_NOT_FOUND);
adminSession.get(urlEditMessage()).assertNotFound();
EditMessage.Input in = new EditMessage.Input();
in.message = String.format("New commit message\n\n" +
CONTENT_NEW2_STR + "\n\nChange-Id: %s\n",
change.getKey());
assertThat(adminSession.put(urlEditMessage(), in).getStatusCode())
.isEqualTo(SC_NO_CONTENT);
adminSession.put(urlEditMessage(), in).assertNoContent();
RestResponse r = adminSession.getJsonAccept(urlEditMessage());
assertThat(r.getStatusCode()).isEqualTo(SC_OK);
r.assertOK();
assertThat(readContentFromJson(r)).isEqualTo(in.message);
Optional<ChangeEdit> edit = editUtil.byChange(change);
assertThat(edit.get().getEditCommit().getFullMessage())
.isEqualTo(in.message);
in.message = String.format("New commit message2\n\nChange-Id: %s\n",
change.getKey());
assertThat(adminSession.put(urlEditMessage(), in).getStatusCode())
.isEqualTo(SC_NO_CONTENT);
adminSession.put(urlEditMessage(), in).assertNoContent();
edit = editUtil.byChange(change);
assertThat(edit.get().getEditCommit().getFullMessage())
.isEqualTo(in.message);
@@ -400,8 +386,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test
public void retrieveEdit() throws Exception {
RestResponse r = adminSession.get(urlEdit());
assertThat(r.getStatusCode()).isEqualTo(SC_NO_CONTENT);
adminSession.get(urlEdit()).assertNoContent();
assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW);
Optional<ChangeEdit> edit = editUtil.byChange(change);
assertThat(modifier.modifyFile(edit.get(), FILE_NAME, RestSession.newRawInput(CONTENT_NEW)))
@@ -414,8 +399,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
edit = editUtil.byChange(change);
editUtil.delete(edit.get());
r = adminSession.get(urlEdit());
assertThat(r.getStatusCode()).isEqualTo(SC_NO_CONTENT);
adminSession.get(urlEdit()).assertNoContent();
}
@Test
@@ -460,8 +444,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test
public void createEditByDeletingExistingFileRest() throws Exception {
RestResponse r = adminSession.delete(urlEditFile());
assertThat(r.getStatusCode()).isEqualTo(SC_NO_CONTENT);
adminSession.delete(urlEditFile()).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change);
exception.expect(ResourceNotFoundException.class);
fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
@@ -470,15 +453,13 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test
public void deletingNonExistingEditRest() throws Exception {
RestResponse r = adminSession.delete(urlEdit());
assertThat(r.getStatusCode()).isEqualTo(SC_NOT_FOUND);
adminSession.delete(urlEdit()).assertNotFound();
}
@Test
public void deleteExistingFileRest() throws Exception {
assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW);
assertThat(adminSession.delete(urlEditFile()).getStatusCode()).isEqualTo(
SC_NO_CONTENT);
adminSession.delete(urlEditFile()).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change);
exception.expect(ResourceNotFoundException.class);
fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
@@ -527,8 +508,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
Post.Input in = new Post.Input();
in.oldPath = FILE_NAME;
in.newPath = FILE_NAME3;
assertThat(adminSession.post(urlEdit(), in).getStatusCode()).isEqualTo(
SC_NO_CONTENT);
adminSession.post(urlEdit(), in).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change);
assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME3), CONTENT_OLD);
@@ -541,8 +521,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
public void restoreDeletedFileInPatchSetRest() throws Exception {
Post.Input in = new Post.Input();
in.restorePath = FILE_NAME;
assertThat(adminSession.post(urlEdit2(), in).getStatusCode()).isEqualTo(
SC_NO_CONTENT);
adminSession.post(urlEdit2(), in).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change2);
assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), CONTENT_OLD);
@@ -568,14 +547,12 @@ public class ChangeEditIT extends AbstractDaemonTest {
public void createAndChangeEditInOneRequestRest() throws Exception {
Put.Input in = new Put.Input();
in.content = RestSession.newRawInput(CONTENT_NEW);
assertThat(adminSession.putRaw(urlEditFile(), in.content).getStatusCode())
.isEqualTo(SC_NO_CONTENT);
adminSession.putRaw(urlEditFile(), in.content).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change);
assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), CONTENT_NEW);
in.content = RestSession.newRawInput(CONTENT_NEW2);
assertThat(adminSession.putRaw(urlEditFile(), in.content).getStatusCode())
.isEqualTo(SC_NO_CONTENT);
adminSession.putRaw(urlEditFile(), in.content).assertNoContent();
edit = editUtil.byChange(change);
assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), CONTENT_NEW2);
@@ -586,8 +563,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW);
Put.Input in = new Put.Input();
in.content = RestSession.newRawInput(CONTENT_NEW);
assertThat(adminSession.putRaw(urlEditFile(), in.content).getStatusCode())
.isEqualTo(SC_NO_CONTENT);
adminSession.putRaw(urlEditFile(), in.content).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change);
assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), CONTENT_NEW);
@@ -596,8 +572,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test
public void emptyPutRequest() throws Exception {
assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW);
assertThat(adminSession.put(urlEditFile()).getStatusCode()).isEqualTo(
SC_NO_CONTENT);
adminSession.put(urlEditFile()).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change);
assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), "".getBytes());
@@ -605,8 +580,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test
public void createEmptyEditRest() throws Exception {
assertThat(adminSession.post(urlEdit()).getStatusCode()).isEqualTo(
SC_NO_CONTENT);
adminSession.post(urlEdit()).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change);
assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), CONTENT_OLD);
@@ -616,14 +590,13 @@ public class ChangeEditIT extends AbstractDaemonTest {
public void getFileContentRest() throws Exception {
Put.Input in = new Put.Input();
in.content = RestSession.newRawInput(CONTENT_NEW);
assertThat(adminSession.putRaw(urlEditFile(), in.content).getStatusCode())
.isEqualTo(SC_NO_CONTENT);
adminSession.putRaw(urlEditFile(), in.content).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change);
assertThat(modifier.modifyFile(edit.get(), FILE_NAME, RestSession.newRawInput(CONTENT_NEW2)))
.isEqualTo(RefUpdate.Result.FORCED);
edit = editUtil.byChange(change);
RestResponse r = adminSession.getJsonAccept(urlEditFile());
assertThat(r.getStatusCode()).isEqualTo(SC_OK);
r.assertOK();
assertThat(readContentFromJson(r)).isEqualTo(
StringUtils.newStringUtf8(CONTENT_NEW2));
}
@@ -631,11 +604,9 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test
public void getFileNotFoundRest() throws Exception {
assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW);
assertThat(adminSession.delete(urlEditFile()).getStatusCode()).isEqualTo(
SC_NO_CONTENT);
adminSession.delete(urlEditFile()).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change);
RestResponse r = adminSession.get(urlEditFile());
assertThat(r.getStatusCode()).isEqualTo(SC_NO_CONTENT);
adminSession.get(urlEditFile()).assertNoContent();
exception.expect(ResourceNotFoundException.class);
fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME);
@@ -832,9 +803,9 @@ public class ChangeEditIT extends AbstractDaemonTest {
+ "/edit:rebase";
}
private EditInfo toEditInfo(boolean files) throws IOException {
private EditInfo toEditInfo(boolean files) throws Exception {
RestResponse r = adminSession.get(files ? urlGetFiles() : urlEdit());
assertThat(r.getStatusCode()).isEqualTo(SC_OK);
r.assertOK();
return newGson().fromJson(r.getReader(), EditInfo.class);
}

View File

@@ -34,7 +34,6 @@ import com.google.gerrit.common.data.GlobalCapability;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.http.HttpStatus;
import org.junit.Test;
public class CapabilitiesIT extends AbstractDaemonTest {
@@ -53,7 +52,7 @@ public class CapabilitiesIT extends AbstractDaemonTest {
try {
RestResponse r =
userSession.get("/accounts/self/capabilities");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
CapabilityInfo info = (new Gson()).fromJson(r.getReader(),
new TypeToken<CapabilityInfo>() {}.getType());
for (String c : GlobalCapability.getAllNames()) {
@@ -81,7 +80,7 @@ public class CapabilitiesIT extends AbstractDaemonTest {
public void testCapabilitiesAdmin() throws Exception {
RestResponse r =
adminSession.get("/accounts/self/capabilities");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
CapabilityInfo info = (new Gson()).fromJson(r.getReader(),
new TypeToken<CapabilityInfo>() {}.getType());
for (String c : GlobalCapability.getAllNames()) {

View File

@@ -15,7 +15,6 @@
package com.google.gerrit.acceptance.rest.account;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.RestResponse;
@@ -23,23 +22,21 @@ import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
import com.google.gerrit.extensions.client.Theme;
import org.apache.http.HttpStatus;
import org.junit.Test;
public class DiffPreferencesIT extends AbstractDaemonTest {
@Test
public void getDiffPreferencesOfNonExistingAccount_NotFound()
throws Exception {
assertEquals(HttpStatus.SC_NOT_FOUND,
adminSession.get("/accounts/non-existing/preferences.diff")
.getStatusCode());
adminSession.get("/accounts/non-existing/preferences.diff")
.assertNotFound();
}
@Test
public void getDiffPreferences() throws Exception {
RestResponse r = adminSession.get("/accounts/" + admin.email
+ "/preferences.diff");
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
r.assertOK();
DiffPreferencesInfo d = DiffPreferencesInfo.defaults();
DiffPreferencesInfo o =
newGson().fromJson(r.getReader(), DiffPreferencesInfo.class);
@@ -98,7 +95,7 @@ public class DiffPreferencesIT extends AbstractDaemonTest {
RestResponse r = adminSession.put("/accounts/" + admin.email
+ "/preferences.diff", i);
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
r.assertOK();
DiffPreferencesInfo o = newGson().fromJson(r.getReader(),
DiffPreferencesInfo.class);

View File

@@ -22,7 +22,6 @@ import com.google.gerrit.extensions.client.EditPreferencesInfo;
import com.google.gerrit.extensions.client.KeyMapType;
import com.google.gerrit.extensions.client.Theme;
import org.apache.http.HttpStatus;
import org.junit.Test;
import java.io.IOException;
@@ -32,7 +31,7 @@ public class EditPreferencesIT extends AbstractDaemonTest {
public void getSetEditPreferences() throws Exception {
String endPoint = "/accounts/" + admin.email + "/preferences.edit";
RestResponse r = adminSession.get(endPoint);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
EditPreferencesInfo out = getEditPrefInfo(r);
assertThat(out.lineLength).isEqualTo(100);
@@ -62,22 +61,20 @@ public class EditPreferencesIT extends AbstractDaemonTest {
out.theme = Theme.TWILIGHT;
out.keyMapType = KeyMapType.EMACS;
r = adminSession.put(endPoint, out);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
adminSession.put(endPoint, out).assertNoContent();
r = adminSession.get(endPoint);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
EditPreferencesInfo info = getEditPrefInfo(r);
assertEditPreferences(info, out);
// Partially filled input record
EditPreferencesInfo in = new EditPreferencesInfo();
in.tabSize = 42;
r = adminSession.put(endPoint, in);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
adminSession.put(endPoint, in).assertNoContent();
r = adminSession.get(endPoint);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
info = getEditPrefInfo(r);
out.tabSize = in.tabSize;
assertEditPreferences(info, out);

View File

@@ -26,7 +26,6 @@ import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.SchemaFactory;
import com.google.inject.Inject;
import org.apache.http.HttpStatus;
import org.junit.Test;
import java.util.Collections;
@@ -41,7 +40,7 @@ public class PutUsernameIT extends AbstractDaemonTest {
in.username = "myUsername";
RestResponse r =
adminSession.put("/accounts/" + createUser().get() + "/username", in);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
assertThat(newGson().fromJson(r.getReader(), String.class)).isEqualTo(
in.username);
}
@@ -50,25 +49,25 @@ public class PutUsernameIT extends AbstractDaemonTest {
public void setExisting_Conflict() throws Exception {
PutUsername.Input in = new PutUsername.Input();
in.username = admin.username;
RestResponse r =
adminSession.put("/accounts/" + createUser().get() + "/username", in);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT);
adminSession
.put("/accounts/" + createUser().get() + "/username", in)
.assertConflict();
}
@Test
public void setNew_MethodNotAllowed() throws Exception {
PutUsername.Input in = new PutUsername.Input();
in.username = "newUsername";
RestResponse r =
adminSession.put("/accounts/" + admin.username + "/username", in);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_METHOD_NOT_ALLOWED);
adminSession
.put("/accounts/" + admin.username + "/username", in)
.assertMethodNotAllowed();
}
@Test
public void delete_MethodNotAllowed() throws Exception {
RestResponse r =
adminSession.put("/accounts/" + admin.username + "/username");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_METHOD_NOT_ALLOWED);
adminSession
.put("/accounts/" + admin.username + "/username")
.assertMethodNotAllowed();
}
private Account.Id createUser() throws OrmException {

View File

@@ -28,7 +28,6 @@ import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gwtorm.server.OrmException;
import org.apache.http.HttpStatus;
import org.junit.Test;
import java.io.IOException;
@@ -45,7 +44,7 @@ public class DeleteDraftPatchSetIT extends AbstractDaemonTest {
assertThat(c.status).isEqualTo(ChangeStatus.NEW);
RestResponse r = deletePatchSet(changeId, ps, adminSession);
assertThat(r.getEntityContent()).isEqualTo("Patch set is not a draft");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT);
r.assertConflict();
}
@Test
@@ -58,7 +57,7 @@ public class DeleteDraftPatchSetIT extends AbstractDaemonTest {
assertThat(c.status).isEqualTo(ChangeStatus.DRAFT);
RestResponse r = deletePatchSet(changeId, ps, userSession);
assertThat(r.getEntityContent()).isEqualTo("Not found: " + changeId);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND);
r.assertNotFound();
}
@Test
@@ -69,12 +68,10 @@ public class DeleteDraftPatchSetIT extends AbstractDaemonTest {
ChangeInfo c = get(triplet);
assertThat(c.id).isEqualTo(triplet);
assertThat(c.status).isEqualTo(ChangeStatus.DRAFT);
RestResponse r = deletePatchSet(changeId, ps, adminSession);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
deletePatchSet(changeId, ps, adminSession).assertNoContent();
assertThat(getChange(changeId).patchSets()).hasSize(1);
ps = getCurrentPatchSet(changeId);
r = deletePatchSet(changeId, ps, adminSession);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
deletePatchSet(changeId, ps, adminSession).assertNoContent();
assertThat(queryProvider.get().byKeyPrefix(changeId)).isEmpty();
}

View File

@@ -29,7 +29,6 @@ import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.testutil.ConfigSuite;
import com.google.gwtorm.server.OrmException;
import org.apache.http.HttpStatus;
import org.eclipse.jgit.lib.Config;
import org.junit.Test;
@@ -52,7 +51,7 @@ public class DraftChangeIT extends AbstractDaemonTest {
assertThat(c.status).isEqualTo(ChangeStatus.NEW);
RestResponse response = deleteChange(changeId, adminSession);
assertThat(response.getEntityContent()).isEqualTo("Change is not a draft");
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT);
response.assertConflict();
}
@Test
@@ -65,8 +64,7 @@ public class DraftChangeIT extends AbstractDaemonTest {
ChangeInfo c = get(triplet);
assertThat(c.id).isEqualTo(triplet);
assertThat(c.status).isEqualTo(ChangeStatus.DRAFT);
RestResponse response = deleteChange(changeId, adminSession);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
deleteChange(changeId, adminSession).assertNoContent();
exception.expect(ResourceNotFoundException.class);
get(triplet);
@@ -83,8 +81,7 @@ public class DraftChangeIT extends AbstractDaemonTest {
assertThat(c.id).isEqualTo(triplet);
assertThat(c.status).isEqualTo(ChangeStatus.DRAFT);
assertThat(c.revisions.get(c.currentRevision).draft).isTrue();
RestResponse response = publishChange(changeId);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
publishChange(changeId).assertNoContent();
c = get(triplet);
assertThat(c.status).isEqualTo(ChangeStatus.NEW);
assertThat(c.revisions.get(c.currentRevision).draft).isNull();
@@ -100,8 +97,7 @@ public class DraftChangeIT extends AbstractDaemonTest {
ChangeInfo c = get(triplet);
assertThat(c.id).isEqualTo(triplet);
assertThat(c.status).isEqualTo(ChangeStatus.DRAFT);
RestResponse response = publishPatchSet(changeId);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
publishPatchSet(changeId).assertNoContent();
assertThat(get(triplet).status).isEqualTo(ChangeStatus.NEW);
}

View File

@@ -14,27 +14,25 @@
package com.google.gerrit.acceptance.rest.change;
import static com.google.common.truth.Truth.assertThat;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.RestResponse;
import org.apache.http.HttpStatus;
import org.junit.Test;
public class IndexChangeIT extends AbstractDaemonTest {
@Test
public void indexChange() throws Exception {
String changeId = createChange().getChangeId();
RestResponse r = adminSession.post("/changes/" + changeId + "/index/");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
adminSession
.post("/changes/" + changeId + "/index/")
.assertNoContent();
}
@Test
public void indexChangeOnNonVisibleBranch() throws Exception {
String changeId = createChange().getChangeId();
blockRead(project, "refs/heads/master");
RestResponse r = userSession.post("/changes/" + changeId + "/index/");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND);
userSession
.post("/changes/" + changeId + "/index/")
.assertNotFound();
}
}

View File

@@ -25,7 +25,6 @@ import com.google.gerrit.common.data.GlobalCapability;
import com.google.gerrit.server.config.ListCaches.CacheInfo;
import com.google.gerrit.server.config.PostCaches;
import org.apache.http.HttpStatus;
import org.junit.Test;
import java.util.Arrays;
@@ -39,7 +38,7 @@ public class CacheOperationsIT extends AbstractDaemonTest {
assertThat(cacheInfo.entries.mem).isGreaterThan((long) 0);
r = adminSession.post("/config/server/caches/", new PostCaches.Input(FLUSH_ALL));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
r.consume();
r = adminSession.get("/config/server/caches/project_list");
@@ -49,16 +48,16 @@ public class CacheOperationsIT extends AbstractDaemonTest {
@Test
public void flushAll_Forbidden() throws Exception {
RestResponse r = userSession.post("/config/server/caches/",
new PostCaches.Input(FLUSH_ALL));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN);
userSession.post("/config/server/caches/",
new PostCaches.Input(FLUSH_ALL)).assertForbidden();
}
@Test
public void flushAll_BadRequest() throws Exception {
RestResponse r = adminSession.post("/config/server/caches/",
new PostCaches.Input(FLUSH_ALL, Arrays.asList("projects")));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
adminSession
.post("/config/server/caches/",
new PostCaches.Input(FLUSH_ALL, Arrays.asList("projects")))
.assertBadRequest();
}
@Test
@@ -73,7 +72,7 @@ public class CacheOperationsIT extends AbstractDaemonTest {
r = adminSession.post("/config/server/caches/",
new PostCaches.Input(FLUSH, Arrays.asList("accounts", "project_list")));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
r.consume();
r = adminSession.get("/config/server/caches/project_list");
@@ -87,16 +86,18 @@ public class CacheOperationsIT extends AbstractDaemonTest {
@Test
public void flush_Forbidden() throws Exception {
RestResponse r = userSession.post("/config/server/caches/",
new PostCaches.Input(FLUSH, Arrays.asList("projects")));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN);
userSession
.post("/config/server/caches/",
new PostCaches.Input(FLUSH, Arrays.asList("projects")))
.assertForbidden();
}
@Test
public void flush_BadRequest() throws Exception {
RestResponse r = adminSession.post("/config/server/caches/",
new PostCaches.Input(FLUSH));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
adminSession
.post("/config/server/caches/",
new PostCaches.Input(FLUSH))
.assertBadRequest();
}
@Test
@@ -107,7 +108,7 @@ public class CacheOperationsIT extends AbstractDaemonTest {
r = adminSession.post("/config/server/caches/",
new PostCaches.Input(FLUSH, Arrays.asList("projects", "unprocessable")));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY);
r.assertUnprocessableEntity();
r.consume();
r = adminSession.get("/config/server/caches/projects");
@@ -122,12 +123,13 @@ public class CacheOperationsIT extends AbstractDaemonTest {
try {
RestResponse r = userSession.post("/config/server/caches/",
new PostCaches.Input(FLUSH, Arrays.asList("projects")));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
r.consume();
r = userSession.post("/config/server/caches/",
new PostCaches.Input(FLUSH, Arrays.asList("web_sessions")));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN);
userSession
.post("/config/server/caches/",
new PostCaches.Input(FLUSH, Arrays.asList("web_sessions")))
.assertForbidden();
} finally {
removeGlobalCapabilities(REGISTERED_USERS,
GlobalCapability.FLUSH_CACHES, GlobalCapability.VIEW_CACHES);

View File

@@ -14,17 +14,13 @@
package com.google.gerrit.acceptance.rest.config;
import static com.google.common.truth.Truth.assertThat;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.server.config.ConfirmEmail;
import com.google.gerrit.server.mail.EmailTokenVerifier;
import com.google.gerrit.testutil.ConfigSuite;
import com.google.gwtjsonrpc.server.SignedToken;
import com.google.inject.Inject;
import org.apache.http.HttpStatus;
import org.eclipse.jgit.lib.Config;
import org.junit.Test;
@@ -44,23 +40,26 @@ public class ConfirmEmailIT extends AbstractDaemonTest {
public void confirm() throws Exception {
ConfirmEmail.Input in = new ConfirmEmail.Input();
in.token = emailTokenVerifier.encode(admin.getId(), "new.mail@example.com");
RestResponse r = adminSession.put("/config/server/email.confirm", in);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
adminSession
.put("/config/server/email.confirm", in)
.assertNoContent();
}
@Test
public void confirmForOtherUser_UnprocessableEntity() throws Exception {
ConfirmEmail.Input in = new ConfirmEmail.Input();
in.token = emailTokenVerifier.encode(user.getId(), "new.mail@example.com");
RestResponse r = adminSession.put("/config/server/email.confirm", in);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY);
adminSession
.put("/config/server/email.confirm", in)
.assertUnprocessableEntity();
}
@Test
public void confirmInvalidToken_UnprocessableEntity() throws Exception {
ConfirmEmail.Input in = new ConfirmEmail.Input();
in.token = "invalidToken";
RestResponse r = adminSession.put("/config/server/email.confirm", in);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY);
adminSession
.put("/config/server/email.confirm", in)
.assertUnprocessableEntity();
}
}

View File

@@ -22,7 +22,6 @@ import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.common.data.GlobalCapability;
import com.google.gerrit.server.config.ListCaches.CacheInfo;
import org.apache.http.HttpStatus;
import org.junit.Test;
public class FlushCacheIT extends AbstractDaemonTest {
@@ -34,7 +33,7 @@ public class FlushCacheIT extends AbstractDaemonTest {
assertThat(result.entries.mem).isGreaterThan((long)0);
r = adminSession.post("/config/server/caches/groups/flush");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
r.consume();
r = adminSession.get("/config/server/caches/groups");
@@ -44,26 +43,30 @@ public class FlushCacheIT extends AbstractDaemonTest {
@Test
public void flushCache_Forbidden() throws Exception {
RestResponse r = userSession.post("/config/server/caches/accounts/flush");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN);
userSession
.post("/config/server/caches/accounts/flush")
.assertForbidden();
}
@Test
public void flushCache_NotFound() throws Exception {
RestResponse r = adminSession.post("/config/server/caches/nonExisting/flush");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND);
adminSession
.post("/config/server/caches/nonExisting/flush")
.assertNotFound();
}
@Test
public void flushCacheWithGerritPrefix() throws Exception {
RestResponse r = adminSession.post("/config/server/caches/gerrit-accounts/flush");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
adminSession
.post("/config/server/caches/gerrit-accounts/flush")
.assertOK();
}
@Test
public void flushWebSessionsCache() throws Exception {
RestResponse r = adminSession.post("/config/server/caches/web_sessions/flush");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
adminSession
.post("/config/server/caches/web_sessions/flush")
.assertOK();
}
@Test
@@ -72,11 +75,12 @@ public class FlushCacheIT extends AbstractDaemonTest {
GlobalCapability.VIEW_CACHES, GlobalCapability.FLUSH_CACHES);
try {
RestResponse r = userSession.post("/config/server/caches/accounts/flush");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
r.consume();
r = userSession.post("/config/server/caches/web_sessions/flush");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN);
userSession
.post("/config/server/caches/web_sessions/flush")
.assertForbidden();
} finally {
removeGlobalCapabilities(REGISTERED_USERS,
GlobalCapability.VIEW_CACHES, GlobalCapability.FLUSH_CACHES);

View File

@@ -21,7 +21,6 @@ import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.server.config.ListCaches.CacheInfo;
import com.google.gerrit.server.config.ListCaches.CacheType;
import org.apache.http.HttpStatus;
import org.junit.Test;
public class GetCacheIT extends AbstractDaemonTest {
@@ -29,7 +28,7 @@ public class GetCacheIT extends AbstractDaemonTest {
@Test
public void getCache() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/accounts");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
CacheInfo result = newGson().fromJson(r.getReader(), CacheInfo.class);
assertThat(result.name).isEqualTo("accounts");
@@ -45,26 +44,29 @@ public class GetCacheIT extends AbstractDaemonTest {
userSession.get("/config/server/version").consume();
r = adminSession.get("/config/server/caches/accounts");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
result = newGson().fromJson(r.getReader(), CacheInfo.class);
assertThat(result.entries.mem).isEqualTo(2);
}
@Test
public void getCache_Forbidden() throws Exception {
RestResponse r = userSession.get("/config/server/caches/accounts");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN);
userSession
.get("/config/server/caches/accounts")
.assertForbidden();
}
@Test
public void getCache_NotFound() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/nonExisting");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND);
adminSession
.get("/config/server/caches/nonExisting")
.assertNotFound();
}
@Test
public void getCacheWithGerritPrefix() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/gerrit-accounts");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
adminSession
.get("/config/server/caches/gerrit-accounts")
.assertOK();
}
}

View File

@@ -21,7 +21,6 @@ import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.server.config.ListTasks.TaskInfo;
import com.google.gson.reflect.TypeToken;
import org.apache.http.HttpStatus;
import org.junit.Test;
import java.util.List;
@@ -32,7 +31,7 @@ public class GetTaskIT extends AbstractDaemonTest {
public void getTask() throws Exception {
RestResponse r =
adminSession.get("/config/server/tasks/" + getLogFileCompressorTaskId());
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
TaskInfo info =
newGson().fromJson(r.getReader(),
new TypeToken<TaskInfo>() {}.getType());
@@ -44,9 +43,9 @@ public class GetTaskIT extends AbstractDaemonTest {
@Test
public void getTask_NotFound() throws Exception {
RestResponse r =
userSession.get("/config/server/tasks/" + getLogFileCompressorTaskId());
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND);
userSession
.get("/config/server/tasks/" + getLogFileCompressorTaskId())
.assertNotFound();
}
private String getLogFileCompressorTaskId() throws Exception {

View File

@@ -21,7 +21,6 @@ import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.server.config.ListTasks.TaskInfo;
import com.google.gson.reflect.TypeToken;
import org.apache.http.HttpStatus;
import org.junit.Test;
import java.util.List;
@@ -37,7 +36,7 @@ public class KillTaskIT extends AbstractDaemonTest {
assertThat(taskCount).isGreaterThan(0);
r = adminSession.delete("/config/server/tasks/" + result.get(0).id);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
r.assertNoContent();
r.consume();
r = adminSession.get("/config/server/tasks/");
@@ -54,8 +53,9 @@ public class KillTaskIT extends AbstractDaemonTest {
r.consume();
assertThat(result.size()).isGreaterThan(0);
r = userSession.delete("/config/server/tasks/" + result.get(0).id);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND);
userSession
.delete("/config/server/tasks/" + result.get(0).id)
.assertNotFound();
}
@Test

View File

@@ -24,7 +24,6 @@ import com.google.gerrit.server.config.ListCaches.CacheInfo;
import com.google.gerrit.server.config.ListCaches.CacheType;
import com.google.gson.reflect.TypeToken;
import org.apache.http.HttpStatus;
import org.eclipse.jgit.util.Base64;
import org.junit.Test;
@@ -37,7 +36,7 @@ public class ListCachesIT extends AbstractDaemonTest {
@Test
public void listCaches() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
Map<String, CacheInfo> result =
newGson().fromJson(r.getReader(),
new TypeToken<Map<String, CacheInfo>>() {}.getType());
@@ -56,7 +55,7 @@ public class ListCachesIT extends AbstractDaemonTest {
userSession.get("/config/server/version").consume();
r = adminSession.get("/config/server/caches/");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
result = newGson().fromJson(r.getReader(),
new TypeToken<Map<String, CacheInfo>>() {}.getType());
assertThat(result.get("accounts").entries.mem).isEqualTo(2);
@@ -64,14 +63,15 @@ public class ListCachesIT extends AbstractDaemonTest {
@Test
public void listCaches_Forbidden() throws Exception {
RestResponse r = userSession.get("/config/server/caches/");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN);
userSession
.get("/config/server/caches/")
.assertForbidden();
}
@Test
public void listCacheNames() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/?format=LIST");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
List<String> result =
newGson().fromJson(r.getReader(),
new TypeToken<List<String>>() {}.getType());
@@ -83,7 +83,7 @@ public class ListCachesIT extends AbstractDaemonTest {
@Test
public void listCacheNamesTextList() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/?format=TEXT_LIST");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
String result = new String(Base64.decode(r.getEntityContent()), UTF_8.name());
List<String> list = Arrays.asList(result.split("\n"));
assertThat(list).contains("accounts");
@@ -93,7 +93,8 @@ public class ListCachesIT extends AbstractDaemonTest {
@Test
public void listCaches_BadRequest() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/?format=NONSENSE");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
adminSession
.get("/config/server/caches/?format=NONSENSE")
.assertBadRequest();
}
}

View File

@@ -21,7 +21,6 @@ import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.server.config.ListTasks.TaskInfo;
import com.google.gson.reflect.TypeToken;
import org.apache.http.HttpStatus;
import org.junit.Test;
import java.util.List;
@@ -31,7 +30,7 @@ public class ListTasksIT extends AbstractDaemonTest {
@Test
public void listTasks() throws Exception {
RestResponse r = adminSession.get("/config/server/tasks/");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
List<TaskInfo> result =
newGson().fromJson(r.getReader(),
new TypeToken<List<TaskInfo>>() {}.getType());
@@ -52,7 +51,7 @@ public class ListTasksIT extends AbstractDaemonTest {
@Test
public void listTasksWithoutViewQueueCapability() throws Exception {
RestResponse r = userSession.get("/config/server/tasks/");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
List<TaskInfo> result =
newGson().fromJson(r.getReader(),
new TypeToken<List<TaskInfo>>() {}.getType());

View File

@@ -14,19 +14,15 @@
package com.google.gerrit.acceptance.rest.group;
import static com.google.common.truth.Truth.assertThat;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import org.apache.http.HttpStatus;
import org.junit.Test;
public class AddMemberIT extends AbstractDaemonTest {
@Test
public void addNonExistingMember_NotFound() throws Exception {
int status =
adminSession.put("/groups/Administrators/members/non-existing")
.getStatusCode();
assertThat(status).isEqualTo(HttpStatus.SC_NOT_FOUND);
adminSession
.put("/groups/Administrators/members/non-existing")
.assertNotFound();
}
}

View File

@@ -23,7 +23,6 @@ import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.server.project.BanCommit;
import com.google.gerrit.server.project.BanCommit.BanResultInfo;
import org.apache.http.HttpStatus;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.PushResult;
import org.junit.Test;
@@ -39,7 +38,7 @@ public class BanCommitIT extends AbstractDaemonTest {
RestResponse r =
adminSession.put("/projects/" + project.get() + "/ban/",
BanCommit.Input.fromCommits(c.name()));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
BanResultInfo info = newGson().fromJson(r.getReader(), BanResultInfo.class);
assertThat(Iterables.getOnlyElement(info.newlyBanned)).isEqualTo(c.name());
assertThat(info.alreadyBanned).isNull();
@@ -59,7 +58,7 @@ public class BanCommitIT extends AbstractDaemonTest {
r = adminSession.put("/projects/" + project.get() + "/ban/",
BanCommit.Input.fromCommits("a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96"));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
BanResultInfo info = newGson().fromJson(r.getReader(), BanResultInfo.class);
assertThat(Iterables.getOnlyElement(info.alreadyBanned))
.isEqualTo("a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96");
@@ -69,9 +68,9 @@ public class BanCommitIT extends AbstractDaemonTest {
@Test
public void banCommit_Forbidden() throws Exception {
RestResponse r =
userSession.put("/projects/" + project.get() + "/ban/",
BanCommit.Input.fromCommits("a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96"));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN);
userSession
.put("/projects/" + project.get() + "/ban/", BanCommit.Input.fromCommits(
"a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96"))
.assertForbidden();
}
}

View File

@@ -39,7 +39,6 @@ import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.group.SystemGroupBackend;
import com.google.gerrit.server.project.ProjectState;
import org.apache.http.HttpStatus;
import org.apache.http.message.BasicHeader;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Constants;
@@ -58,7 +57,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
public void testCreateProjectHttp() throws Exception {
String newProjectName = name("newProject");
RestResponse r = adminSession.put("/projects/" + newProjectName);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CREATED);
r.assertCreated();
ProjectInfo p = newGson().fromJson(r.getReader(), ProjectInfo.class);
assertThat(p.name).isEqualTo(newProjectName);
ProjectState projectState = projectCache.get(new Project.NameKey(newProjectName));
@@ -70,32 +69,36 @@ public class CreateProjectIT extends AbstractDaemonTest {
@Test
public void testCreateProjectHttpWhenProjectAlreadyExists_Conflict()
throws Exception {
RestResponse r = adminSession.put("/projects/" + allProjects.get());
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT);
adminSession
.put("/projects/" + allProjects.get())
.assertConflict();
}
@Test
public void testCreateProjectHttpWhenProjectAlreadyExists_PreconditionFailed()
throws Exception {
RestResponse r = adminSession.putWithHeader("/projects/" + allProjects.get(),
new BasicHeader(HttpHeaders.IF_NONE_MATCH, "*"));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_PRECONDITION_FAILED);
adminSession
.putWithHeader("/projects/" + allProjects.get(),
new BasicHeader(HttpHeaders.IF_NONE_MATCH, "*"))
.assertPreconditionFailed();
}
@Test
@UseLocalDisk
public void testCreateProjectHttpWithUnreasonableName_BadRequest()
throws Exception {
RestResponse r = adminSession.put("/projects/" + Url.encode(name("invalid/../name")));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
adminSession
.put("/projects/" + Url.encode(name("invalid/../name")))
.assertBadRequest();
}
@Test
public void testCreateProjectHttpWithNameMismatch_BadRequest() throws Exception {
ProjectInput in = new ProjectInput();
in.name = name("otherName");
RestResponse r = adminSession.put("/projects/" + name("someName"), in);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
adminSession
.put("/projects/" + name("someName"), in)
.assertBadRequest();
}
@Test
@@ -103,8 +106,9 @@ public class CreateProjectIT extends AbstractDaemonTest {
throws Exception {
ProjectInput in = new ProjectInput();
in.branches = Collections.singletonList(name("invalid ref name"));
RestResponse r = adminSession.put("/projects/" + name("newProject"), in);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
adminSession
.put("/projects/" + name("newProject"), in)
.assertBadRequest();
}
@Test

View File

@@ -14,8 +14,6 @@
package com.google.gerrit.acceptance.rest.project;
import static com.google.common.truth.Truth.assertThat;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.GcAssert;
import com.google.gerrit.acceptance.RestResponse;
@@ -23,7 +21,6 @@ import com.google.gerrit.acceptance.UseLocalDisk;
import com.google.gerrit.reviewdb.client.Project;
import com.google.inject.Inject;
import org.apache.http.HttpStatus;
import org.junit.Before;
import org.junit.Test;
@@ -43,29 +40,27 @@ public class GarbageCollectionIT extends AbstractDaemonTest {
@Test
public void testGcNonExistingProject_NotFound() throws Exception {
assertThat(POST("/projects/non-existing/gc")).isEqualTo(
HttpStatus.SC_NOT_FOUND);
POST("/projects/non-existing/gc").assertNotFound();
}
@Test
public void testGcNotAllowed_Forbidden() throws Exception {
assertThat(
userSession.post("/projects/" + allProjects.get() + "/gc")
.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN);
userSession
.post("/projects/" + allProjects.get() + "/gc")
.assertForbidden();
}
@Test
@UseLocalDisk
public void testGcOneProject() throws Exception {
assertThat(POST("/projects/" + allProjects.get() + "/gc")).isEqualTo(
HttpStatus.SC_OK);
POST("/projects/" + allProjects.get() + "/gc").assertOK();
gcAssert.assertHasPackFile(allProjects);
gcAssert.assertHasNoPackFile(project, project2);
}
private int POST(String endPoint) throws IOException {
private RestResponse POST(String endPoint) throws IOException {
RestResponse r = adminSession.post(endPoint);
r.consume();
return r.getStatusCode();
return r;
}
}

View File

@@ -25,7 +25,6 @@ import com.google.gerrit.common.data.Permission;
import com.google.gerrit.extensions.common.CommitInfo;
import com.google.gerrit.server.git.ProjectConfig;
import org.apache.http.HttpStatus;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
@@ -130,15 +129,15 @@ public class GetCommitIT extends AbstractDaemonTest {
}
private void assertNotFound(ObjectId id) throws Exception {
RestResponse r = userSession.get(
"/projects/" + project.get() + "/commits/" + id.name());
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND);
userSession
.get("/projects/" + project.get() + "/commits/" + id.name())
.assertNotFound();
}
private CommitInfo getCommit(ObjectId id) throws Exception {
RestResponse r = userSession.get(
"/projects/" + project.get() + "/commits/" + id.name());
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
CommitInfo result = newGson().fromJson(r.getReader(), CommitInfo.class);
r.consume();
return result;

View File

@@ -21,7 +21,6 @@ import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.project.SetParent;
import org.apache.http.HttpStatus;
import org.junit.Test;
public class SetParentIT extends AbstractDaemonTest {
@@ -31,7 +30,7 @@ public class SetParentIT extends AbstractDaemonTest {
RestResponse r =
userSession.put("/projects/" + project.get() + "/parent",
newParentInput(parent));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN);
r.assertForbidden();
r.consume();
}
@@ -41,11 +40,11 @@ public class SetParentIT extends AbstractDaemonTest {
RestResponse r =
adminSession.put("/projects/" + project.get() + "/parent",
newParentInput(parent));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
r.consume();
r = adminSession.get("/projects/" + project.get() + "/parent");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
r.assertOK();
String newParent =
newGson().fromJson(r.getReader(), String.class);
assertThat(newParent).isEqualTo(parent);
@@ -57,7 +56,7 @@ public class SetParentIT extends AbstractDaemonTest {
RestResponse r =
adminSession.put("/projects/" + allProjects.get() + "/parent",
newParentInput(project.get()));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT);
r.assertConflict();
r.consume();
}
@@ -66,19 +65,19 @@ public class SetParentIT extends AbstractDaemonTest {
RestResponse r =
adminSession.put("/projects/" + project.get() + "/parent",
newParentInput(project.get()));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT);
r.assertConflict();
r.consume();
Project.NameKey child = createProject("child", project, true);
r = adminSession.put("/projects/" + project.get() + "/parent",
newParentInput(child.get()));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT);
r.assertConflict();
r.consume();
String grandchild = createProject("grandchild", child, true).get();
r = adminSession.put("/projects/" + project.get() + "/parent",
newParentInput(grandchild));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT);
r.assertConflict();
r.consume();
}
@@ -87,7 +86,7 @@ public class SetParentIT extends AbstractDaemonTest {
RestResponse r =
adminSession.put("/projects/" + project.get() + "/parent",
newParentInput("non-existing"));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY);
r.assertUnprocessableEntity();
r.consume();
}

View File

@@ -26,7 +26,6 @@ import com.google.gerrit.extensions.api.projects.ProjectApi.ListRefsRequest;
import com.google.gerrit.extensions.api.projects.TagInfo;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import org.apache.http.HttpStatus;
import org.eclipse.jgit.api.PushCommand;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.transport.PushResult;
@@ -42,8 +41,9 @@ public class TagsIT extends AbstractDaemonTest {
@Test
public void listTagsOfNonExistingProject() throws Exception {
assertThat(adminSession.get("/projects/non-existing/tags").getStatusCode())
.isEqualTo(HttpStatus.SC_NOT_FOUND);
adminSession
.get("/projects/non-existing/tags")
.assertNotFound();
}
@Test
@@ -57,9 +57,9 @@ public class TagsIT extends AbstractDaemonTest {
@Test
public void listTagsOfNonVisibleProject() throws Exception {
blockRead(project, "refs/*");
assertThat(
userSession.get("/projects/" + project.get() + "/tags").getStatusCode())
.isEqualTo(HttpStatus.SC_NOT_FOUND);
userSession
.get("/projects/" + project.get() + "/tags")
.assertNotFound();
}
@Test