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

View File

@@ -15,7 +15,6 @@
package com.google.gerrit.acceptance.rest.account; package com.google.gerrit.acceptance.rest.account;
import static com.google.common.truth.Truth.assertThat; 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.AbstractDaemonTest;
import com.google.gerrit.acceptance.RestResponse; 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.DiffPreferencesInfo.Whitespace;
import com.google.gerrit.extensions.client.Theme; import com.google.gerrit.extensions.client.Theme;
import org.apache.http.HttpStatus;
import org.junit.Test; import org.junit.Test;
public class DiffPreferencesIT extends AbstractDaemonTest { public class DiffPreferencesIT extends AbstractDaemonTest {
@Test @Test
public void getDiffPreferencesOfNonExistingAccount_NotFound() public void getDiffPreferencesOfNonExistingAccount_NotFound()
throws Exception { throws Exception {
assertEquals(HttpStatus.SC_NOT_FOUND, adminSession.get("/accounts/non-existing/preferences.diff")
adminSession.get("/accounts/non-existing/preferences.diff") .assertNotFound();
.getStatusCode());
} }
@Test @Test
public void getDiffPreferences() throws Exception { public void getDiffPreferences() throws Exception {
RestResponse r = adminSession.get("/accounts/" + admin.email RestResponse r = adminSession.get("/accounts/" + admin.email
+ "/preferences.diff"); + "/preferences.diff");
assertEquals(HttpStatus.SC_OK, r.getStatusCode()); r.assertOK();
DiffPreferencesInfo d = DiffPreferencesInfo.defaults(); DiffPreferencesInfo d = DiffPreferencesInfo.defaults();
DiffPreferencesInfo o = DiffPreferencesInfo o =
newGson().fromJson(r.getReader(), DiffPreferencesInfo.class); newGson().fromJson(r.getReader(), DiffPreferencesInfo.class);
@@ -98,7 +95,7 @@ public class DiffPreferencesIT extends AbstractDaemonTest {
RestResponse r = adminSession.put("/accounts/" + admin.email RestResponse r = adminSession.put("/accounts/" + admin.email
+ "/preferences.diff", i); + "/preferences.diff", i);
assertEquals(HttpStatus.SC_OK, r.getStatusCode()); r.assertOK();
DiffPreferencesInfo o = newGson().fromJson(r.getReader(), DiffPreferencesInfo o = newGson().fromJson(r.getReader(),
DiffPreferencesInfo.class); 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.KeyMapType;
import com.google.gerrit.extensions.client.Theme; import com.google.gerrit.extensions.client.Theme;
import org.apache.http.HttpStatus;
import org.junit.Test; import org.junit.Test;
import java.io.IOException; import java.io.IOException;
@@ -32,7 +31,7 @@ public class EditPreferencesIT extends AbstractDaemonTest {
public void getSetEditPreferences() throws Exception { public void getSetEditPreferences() throws Exception {
String endPoint = "/accounts/" + admin.email + "/preferences.edit"; String endPoint = "/accounts/" + admin.email + "/preferences.edit";
RestResponse r = adminSession.get(endPoint); RestResponse r = adminSession.get(endPoint);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
EditPreferencesInfo out = getEditPrefInfo(r); EditPreferencesInfo out = getEditPrefInfo(r);
assertThat(out.lineLength).isEqualTo(100); assertThat(out.lineLength).isEqualTo(100);
@@ -62,22 +61,20 @@ public class EditPreferencesIT extends AbstractDaemonTest {
out.theme = Theme.TWILIGHT; out.theme = Theme.TWILIGHT;
out.keyMapType = KeyMapType.EMACS; out.keyMapType = KeyMapType.EMACS;
r = adminSession.put(endPoint, out); adminSession.put(endPoint, out).assertNoContent();
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
r = adminSession.get(endPoint); r = adminSession.get(endPoint);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
EditPreferencesInfo info = getEditPrefInfo(r); EditPreferencesInfo info = getEditPrefInfo(r);
assertEditPreferences(info, out); assertEditPreferences(info, out);
// Partially filled input record // Partially filled input record
EditPreferencesInfo in = new EditPreferencesInfo(); EditPreferencesInfo in = new EditPreferencesInfo();
in.tabSize = 42; in.tabSize = 42;
r = adminSession.put(endPoint, in); adminSession.put(endPoint, in).assertNoContent();
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
r = adminSession.get(endPoint); r = adminSession.get(endPoint);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
info = getEditPrefInfo(r); info = getEditPrefInfo(r);
out.tabSize = in.tabSize; out.tabSize = in.tabSize;
assertEditPreferences(info, out); assertEditPreferences(info, out);

View File

@@ -26,7 +26,6 @@ import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.SchemaFactory; import com.google.gwtorm.server.SchemaFactory;
import com.google.inject.Inject; import com.google.inject.Inject;
import org.apache.http.HttpStatus;
import org.junit.Test; import org.junit.Test;
import java.util.Collections; import java.util.Collections;
@@ -41,7 +40,7 @@ public class PutUsernameIT extends AbstractDaemonTest {
in.username = "myUsername"; in.username = "myUsername";
RestResponse r = RestResponse r =
adminSession.put("/accounts/" + createUser().get() + "/username", in); adminSession.put("/accounts/" + createUser().get() + "/username", in);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
assertThat(newGson().fromJson(r.getReader(), String.class)).isEqualTo( assertThat(newGson().fromJson(r.getReader(), String.class)).isEqualTo(
in.username); in.username);
} }
@@ -50,25 +49,25 @@ public class PutUsernameIT extends AbstractDaemonTest {
public void setExisting_Conflict() throws Exception { public void setExisting_Conflict() throws Exception {
PutUsername.Input in = new PutUsername.Input(); PutUsername.Input in = new PutUsername.Input();
in.username = admin.username; in.username = admin.username;
RestResponse r = adminSession
adminSession.put("/accounts/" + createUser().get() + "/username", in); .put("/accounts/" + createUser().get() + "/username", in)
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT); .assertConflict();
} }
@Test @Test
public void setNew_MethodNotAllowed() throws Exception { public void setNew_MethodNotAllowed() throws Exception {
PutUsername.Input in = new PutUsername.Input(); PutUsername.Input in = new PutUsername.Input();
in.username = "newUsername"; in.username = "newUsername";
RestResponse r = adminSession
adminSession.put("/accounts/" + admin.username + "/username", in); .put("/accounts/" + admin.username + "/username", in)
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_METHOD_NOT_ALLOWED); .assertMethodNotAllowed();
} }
@Test @Test
public void delete_MethodNotAllowed() throws Exception { public void delete_MethodNotAllowed() throws Exception {
RestResponse r = adminSession
adminSession.put("/accounts/" + admin.username + "/username"); .put("/accounts/" + admin.username + "/username")
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_METHOD_NOT_ALLOWED); .assertMethodNotAllowed();
} }
private Account.Id createUser() throws OrmException { 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.gerrit.server.query.change.ChangeData;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import org.apache.http.HttpStatus;
import org.junit.Test; import org.junit.Test;
import java.io.IOException; import java.io.IOException;
@@ -45,7 +44,7 @@ public class DeleteDraftPatchSetIT extends AbstractDaemonTest {
assertThat(c.status).isEqualTo(ChangeStatus.NEW); assertThat(c.status).isEqualTo(ChangeStatus.NEW);
RestResponse r = deletePatchSet(changeId, ps, adminSession); RestResponse r = deletePatchSet(changeId, ps, adminSession);
assertThat(r.getEntityContent()).isEqualTo("Patch set is not a draft"); assertThat(r.getEntityContent()).isEqualTo("Patch set is not a draft");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT); r.assertConflict();
} }
@Test @Test
@@ -58,7 +57,7 @@ public class DeleteDraftPatchSetIT extends AbstractDaemonTest {
assertThat(c.status).isEqualTo(ChangeStatus.DRAFT); assertThat(c.status).isEqualTo(ChangeStatus.DRAFT);
RestResponse r = deletePatchSet(changeId, ps, userSession); RestResponse r = deletePatchSet(changeId, ps, userSession);
assertThat(r.getEntityContent()).isEqualTo("Not found: " + changeId); assertThat(r.getEntityContent()).isEqualTo("Not found: " + changeId);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND); r.assertNotFound();
} }
@Test @Test
@@ -69,12 +68,10 @@ public class DeleteDraftPatchSetIT extends AbstractDaemonTest {
ChangeInfo c = get(triplet); ChangeInfo c = get(triplet);
assertThat(c.id).isEqualTo(triplet); assertThat(c.id).isEqualTo(triplet);
assertThat(c.status).isEqualTo(ChangeStatus.DRAFT); assertThat(c.status).isEqualTo(ChangeStatus.DRAFT);
RestResponse r = deletePatchSet(changeId, ps, adminSession); deletePatchSet(changeId, ps, adminSession).assertNoContent();
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
assertThat(getChange(changeId).patchSets()).hasSize(1); assertThat(getChange(changeId).patchSets()).hasSize(1);
ps = getCurrentPatchSet(changeId); ps = getCurrentPatchSet(changeId);
r = deletePatchSet(changeId, ps, adminSession); deletePatchSet(changeId, ps, adminSession).assertNoContent();
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
assertThat(queryProvider.get().byKeyPrefix(changeId)).isEmpty(); 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.gerrit.testutil.ConfigSuite;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import org.apache.http.HttpStatus;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.junit.Test; import org.junit.Test;
@@ -52,7 +51,7 @@ public class DraftChangeIT extends AbstractDaemonTest {
assertThat(c.status).isEqualTo(ChangeStatus.NEW); assertThat(c.status).isEqualTo(ChangeStatus.NEW);
RestResponse response = deleteChange(changeId, adminSession); RestResponse response = deleteChange(changeId, adminSession);
assertThat(response.getEntityContent()).isEqualTo("Change is not a draft"); assertThat(response.getEntityContent()).isEqualTo("Change is not a draft");
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT); response.assertConflict();
} }
@Test @Test
@@ -65,8 +64,7 @@ public class DraftChangeIT extends AbstractDaemonTest {
ChangeInfo c = get(triplet); ChangeInfo c = get(triplet);
assertThat(c.id).isEqualTo(triplet); assertThat(c.id).isEqualTo(triplet);
assertThat(c.status).isEqualTo(ChangeStatus.DRAFT); assertThat(c.status).isEqualTo(ChangeStatus.DRAFT);
RestResponse response = deleteChange(changeId, adminSession); deleteChange(changeId, adminSession).assertNoContent();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
exception.expect(ResourceNotFoundException.class); exception.expect(ResourceNotFoundException.class);
get(triplet); get(triplet);
@@ -83,8 +81,7 @@ public class DraftChangeIT extends AbstractDaemonTest {
assertThat(c.id).isEqualTo(triplet); assertThat(c.id).isEqualTo(triplet);
assertThat(c.status).isEqualTo(ChangeStatus.DRAFT); assertThat(c.status).isEqualTo(ChangeStatus.DRAFT);
assertThat(c.revisions.get(c.currentRevision).draft).isTrue(); assertThat(c.revisions.get(c.currentRevision).draft).isTrue();
RestResponse response = publishChange(changeId); publishChange(changeId).assertNoContent();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
c = get(triplet); c = get(triplet);
assertThat(c.status).isEqualTo(ChangeStatus.NEW); assertThat(c.status).isEqualTo(ChangeStatus.NEW);
assertThat(c.revisions.get(c.currentRevision).draft).isNull(); assertThat(c.revisions.get(c.currentRevision).draft).isNull();
@@ -100,8 +97,7 @@ public class DraftChangeIT extends AbstractDaemonTest {
ChangeInfo c = get(triplet); ChangeInfo c = get(triplet);
assertThat(c.id).isEqualTo(triplet); assertThat(c.id).isEqualTo(triplet);
assertThat(c.status).isEqualTo(ChangeStatus.DRAFT); assertThat(c.status).isEqualTo(ChangeStatus.DRAFT);
RestResponse response = publishPatchSet(changeId); publishPatchSet(changeId).assertNoContent();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
assertThat(get(triplet).status).isEqualTo(ChangeStatus.NEW); assertThat(get(triplet).status).isEqualTo(ChangeStatus.NEW);
} }

View File

@@ -14,27 +14,25 @@
package com.google.gerrit.acceptance.rest.change; 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.AbstractDaemonTest;
import com.google.gerrit.acceptance.RestResponse;
import org.apache.http.HttpStatus;
import org.junit.Test; import org.junit.Test;
public class IndexChangeIT extends AbstractDaemonTest { public class IndexChangeIT extends AbstractDaemonTest {
@Test @Test
public void indexChange() throws Exception { public void indexChange() throws Exception {
String changeId = createChange().getChangeId(); String changeId = createChange().getChangeId();
RestResponse r = adminSession.post("/changes/" + changeId + "/index/"); adminSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT); .post("/changes/" + changeId + "/index/")
.assertNoContent();
} }
@Test @Test
public void indexChangeOnNonVisibleBranch() throws Exception { public void indexChangeOnNonVisibleBranch() throws Exception {
String changeId = createChange().getChangeId(); String changeId = createChange().getChangeId();
blockRead(project, "refs/heads/master"); blockRead(project, "refs/heads/master");
RestResponse r = userSession.post("/changes/" + changeId + "/index/"); userSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND); .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.ListCaches.CacheInfo;
import com.google.gerrit.server.config.PostCaches; import com.google.gerrit.server.config.PostCaches;
import org.apache.http.HttpStatus;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays; import java.util.Arrays;
@@ -39,7 +38,7 @@ public class CacheOperationsIT extends AbstractDaemonTest {
assertThat(cacheInfo.entries.mem).isGreaterThan((long) 0); assertThat(cacheInfo.entries.mem).isGreaterThan((long) 0);
r = adminSession.post("/config/server/caches/", new PostCaches.Input(FLUSH_ALL)); r = adminSession.post("/config/server/caches/", new PostCaches.Input(FLUSH_ALL));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
r.consume(); r.consume();
r = adminSession.get("/config/server/caches/project_list"); r = adminSession.get("/config/server/caches/project_list");
@@ -49,16 +48,16 @@ public class CacheOperationsIT extends AbstractDaemonTest {
@Test @Test
public void flushAll_Forbidden() throws Exception { public void flushAll_Forbidden() throws Exception {
RestResponse r = userSession.post("/config/server/caches/", userSession.post("/config/server/caches/",
new PostCaches.Input(FLUSH_ALL)); new PostCaches.Input(FLUSH_ALL)).assertForbidden();
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN);
} }
@Test @Test
public void flushAll_BadRequest() throws Exception { public void flushAll_BadRequest() throws Exception {
RestResponse r = adminSession.post("/config/server/caches/", adminSession
new PostCaches.Input(FLUSH_ALL, Arrays.asList("projects"))); .post("/config/server/caches/",
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); new PostCaches.Input(FLUSH_ALL, Arrays.asList("projects")))
.assertBadRequest();
} }
@Test @Test
@@ -73,7 +72,7 @@ public class CacheOperationsIT extends AbstractDaemonTest {
r = adminSession.post("/config/server/caches/", r = adminSession.post("/config/server/caches/",
new PostCaches.Input(FLUSH, Arrays.asList("accounts", "project_list"))); new PostCaches.Input(FLUSH, Arrays.asList("accounts", "project_list")));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
r.consume(); r.consume();
r = adminSession.get("/config/server/caches/project_list"); r = adminSession.get("/config/server/caches/project_list");
@@ -87,16 +86,18 @@ public class CacheOperationsIT extends AbstractDaemonTest {
@Test @Test
public void flush_Forbidden() throws Exception { public void flush_Forbidden() throws Exception {
RestResponse r = userSession.post("/config/server/caches/", userSession
new PostCaches.Input(FLUSH, Arrays.asList("projects"))); .post("/config/server/caches/",
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN); new PostCaches.Input(FLUSH, Arrays.asList("projects")))
.assertForbidden();
} }
@Test @Test
public void flush_BadRequest() throws Exception { public void flush_BadRequest() throws Exception {
RestResponse r = adminSession.post("/config/server/caches/", adminSession
new PostCaches.Input(FLUSH)); .post("/config/server/caches/",
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); new PostCaches.Input(FLUSH))
.assertBadRequest();
} }
@Test @Test
@@ -107,7 +108,7 @@ public class CacheOperationsIT extends AbstractDaemonTest {
r = adminSession.post("/config/server/caches/", r = adminSession.post("/config/server/caches/",
new PostCaches.Input(FLUSH, Arrays.asList("projects", "unprocessable"))); new PostCaches.Input(FLUSH, Arrays.asList("projects", "unprocessable")));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY); r.assertUnprocessableEntity();
r.consume(); r.consume();
r = adminSession.get("/config/server/caches/projects"); r = adminSession.get("/config/server/caches/projects");
@@ -122,12 +123,13 @@ public class CacheOperationsIT extends AbstractDaemonTest {
try { try {
RestResponse r = userSession.post("/config/server/caches/", RestResponse r = userSession.post("/config/server/caches/",
new PostCaches.Input(FLUSH, Arrays.asList("projects"))); new PostCaches.Input(FLUSH, Arrays.asList("projects")));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
r.consume(); r.consume();
r = userSession.post("/config/server/caches/", userSession
new PostCaches.Input(FLUSH, Arrays.asList("web_sessions"))); .post("/config/server/caches/",
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN); new PostCaches.Input(FLUSH, Arrays.asList("web_sessions")))
.assertForbidden();
} finally { } finally {
removeGlobalCapabilities(REGISTERED_USERS, removeGlobalCapabilities(REGISTERED_USERS,
GlobalCapability.FLUSH_CACHES, GlobalCapability.VIEW_CACHES); GlobalCapability.FLUSH_CACHES, GlobalCapability.VIEW_CACHES);

View File

@@ -14,17 +14,13 @@
package com.google.gerrit.acceptance.rest.config; 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.AbstractDaemonTest;
import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.server.config.ConfirmEmail; import com.google.gerrit.server.config.ConfirmEmail;
import com.google.gerrit.server.mail.EmailTokenVerifier; import com.google.gerrit.server.mail.EmailTokenVerifier;
import com.google.gerrit.testutil.ConfigSuite; import com.google.gerrit.testutil.ConfigSuite;
import com.google.gwtjsonrpc.server.SignedToken; import com.google.gwtjsonrpc.server.SignedToken;
import com.google.inject.Inject; import com.google.inject.Inject;
import org.apache.http.HttpStatus;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.junit.Test; import org.junit.Test;
@@ -44,23 +40,26 @@ public class ConfirmEmailIT extends AbstractDaemonTest {
public void confirm() throws Exception { public void confirm() throws Exception {
ConfirmEmail.Input in = new ConfirmEmail.Input(); ConfirmEmail.Input in = new ConfirmEmail.Input();
in.token = emailTokenVerifier.encode(admin.getId(), "new.mail@example.com"); in.token = emailTokenVerifier.encode(admin.getId(), "new.mail@example.com");
RestResponse r = adminSession.put("/config/server/email.confirm", in); adminSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT); .put("/config/server/email.confirm", in)
.assertNoContent();
} }
@Test @Test
public void confirmForOtherUser_UnprocessableEntity() throws Exception { public void confirmForOtherUser_UnprocessableEntity() throws Exception {
ConfirmEmail.Input in = new ConfirmEmail.Input(); ConfirmEmail.Input in = new ConfirmEmail.Input();
in.token = emailTokenVerifier.encode(user.getId(), "new.mail@example.com"); in.token = emailTokenVerifier.encode(user.getId(), "new.mail@example.com");
RestResponse r = adminSession.put("/config/server/email.confirm", in); adminSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY); .put("/config/server/email.confirm", in)
.assertUnprocessableEntity();
} }
@Test @Test
public void confirmInvalidToken_UnprocessableEntity() throws Exception { public void confirmInvalidToken_UnprocessableEntity() throws Exception {
ConfirmEmail.Input in = new ConfirmEmail.Input(); ConfirmEmail.Input in = new ConfirmEmail.Input();
in.token = "invalidToken"; in.token = "invalidToken";
RestResponse r = adminSession.put("/config/server/email.confirm", in); adminSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY); .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.common.data.GlobalCapability;
import com.google.gerrit.server.config.ListCaches.CacheInfo; import com.google.gerrit.server.config.ListCaches.CacheInfo;
import org.apache.http.HttpStatus;
import org.junit.Test; import org.junit.Test;
public class FlushCacheIT extends AbstractDaemonTest { public class FlushCacheIT extends AbstractDaemonTest {
@@ -34,7 +33,7 @@ public class FlushCacheIT extends AbstractDaemonTest {
assertThat(result.entries.mem).isGreaterThan((long)0); assertThat(result.entries.mem).isGreaterThan((long)0);
r = adminSession.post("/config/server/caches/groups/flush"); r = adminSession.post("/config/server/caches/groups/flush");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
r.consume(); r.consume();
r = adminSession.get("/config/server/caches/groups"); r = adminSession.get("/config/server/caches/groups");
@@ -44,26 +43,30 @@ public class FlushCacheIT extends AbstractDaemonTest {
@Test @Test
public void flushCache_Forbidden() throws Exception { public void flushCache_Forbidden() throws Exception {
RestResponse r = userSession.post("/config/server/caches/accounts/flush"); userSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN); .post("/config/server/caches/accounts/flush")
.assertForbidden();
} }
@Test @Test
public void flushCache_NotFound() throws Exception { public void flushCache_NotFound() throws Exception {
RestResponse r = adminSession.post("/config/server/caches/nonExisting/flush"); adminSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND); .post("/config/server/caches/nonExisting/flush")
.assertNotFound();
} }
@Test @Test
public void flushCacheWithGerritPrefix() throws Exception { public void flushCacheWithGerritPrefix() throws Exception {
RestResponse r = adminSession.post("/config/server/caches/gerrit-accounts/flush"); adminSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); .post("/config/server/caches/gerrit-accounts/flush")
.assertOK();
} }
@Test @Test
public void flushWebSessionsCache() throws Exception { public void flushWebSessionsCache() throws Exception {
RestResponse r = adminSession.post("/config/server/caches/web_sessions/flush"); adminSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); .post("/config/server/caches/web_sessions/flush")
.assertOK();
} }
@Test @Test
@@ -72,11 +75,12 @@ public class FlushCacheIT extends AbstractDaemonTest {
GlobalCapability.VIEW_CACHES, GlobalCapability.FLUSH_CACHES); GlobalCapability.VIEW_CACHES, GlobalCapability.FLUSH_CACHES);
try { try {
RestResponse r = userSession.post("/config/server/caches/accounts/flush"); RestResponse r = userSession.post("/config/server/caches/accounts/flush");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
r.consume(); r.consume();
r = userSession.post("/config/server/caches/web_sessions/flush"); userSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN); .post("/config/server/caches/web_sessions/flush")
.assertForbidden();
} finally { } finally {
removeGlobalCapabilities(REGISTERED_USERS, removeGlobalCapabilities(REGISTERED_USERS,
GlobalCapability.VIEW_CACHES, GlobalCapability.FLUSH_CACHES); 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.CacheInfo;
import com.google.gerrit.server.config.ListCaches.CacheType; import com.google.gerrit.server.config.ListCaches.CacheType;
import org.apache.http.HttpStatus;
import org.junit.Test; import org.junit.Test;
public class GetCacheIT extends AbstractDaemonTest { public class GetCacheIT extends AbstractDaemonTest {
@@ -29,7 +28,7 @@ public class GetCacheIT extends AbstractDaemonTest {
@Test @Test
public void getCache() throws Exception { public void getCache() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/accounts"); 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); CacheInfo result = newGson().fromJson(r.getReader(), CacheInfo.class);
assertThat(result.name).isEqualTo("accounts"); assertThat(result.name).isEqualTo("accounts");
@@ -45,26 +44,29 @@ public class GetCacheIT extends AbstractDaemonTest {
userSession.get("/config/server/version").consume(); userSession.get("/config/server/version").consume();
r = adminSession.get("/config/server/caches/accounts"); r = adminSession.get("/config/server/caches/accounts");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
result = newGson().fromJson(r.getReader(), CacheInfo.class); result = newGson().fromJson(r.getReader(), CacheInfo.class);
assertThat(result.entries.mem).isEqualTo(2); assertThat(result.entries.mem).isEqualTo(2);
} }
@Test @Test
public void getCache_Forbidden() throws Exception { public void getCache_Forbidden() throws Exception {
RestResponse r = userSession.get("/config/server/caches/accounts"); userSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN); .get("/config/server/caches/accounts")
.assertForbidden();
} }
@Test @Test
public void getCache_NotFound() throws Exception { public void getCache_NotFound() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/nonExisting"); adminSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND); .get("/config/server/caches/nonExisting")
.assertNotFound();
} }
@Test @Test
public void getCacheWithGerritPrefix() throws Exception { public void getCacheWithGerritPrefix() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/gerrit-accounts"); adminSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); .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.gerrit.server.config.ListTasks.TaskInfo;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import org.apache.http.HttpStatus;
import org.junit.Test; import org.junit.Test;
import java.util.List; import java.util.List;
@@ -32,7 +31,7 @@ public class GetTaskIT extends AbstractDaemonTest {
public void getTask() throws Exception { public void getTask() throws Exception {
RestResponse r = RestResponse r =
adminSession.get("/config/server/tasks/" + getLogFileCompressorTaskId()); adminSession.get("/config/server/tasks/" + getLogFileCompressorTaskId());
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
TaskInfo info = TaskInfo info =
newGson().fromJson(r.getReader(), newGson().fromJson(r.getReader(),
new TypeToken<TaskInfo>() {}.getType()); new TypeToken<TaskInfo>() {}.getType());
@@ -44,9 +43,9 @@ public class GetTaskIT extends AbstractDaemonTest {
@Test @Test
public void getTask_NotFound() throws Exception { public void getTask_NotFound() throws Exception {
RestResponse r = userSession
userSession.get("/config/server/tasks/" + getLogFileCompressorTaskId()); .get("/config/server/tasks/" + getLogFileCompressorTaskId())
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND); .assertNotFound();
} }
private String getLogFileCompressorTaskId() throws Exception { 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.gerrit.server.config.ListTasks.TaskInfo;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import org.apache.http.HttpStatus;
import org.junit.Test; import org.junit.Test;
import java.util.List; import java.util.List;
@@ -37,7 +36,7 @@ public class KillTaskIT extends AbstractDaemonTest {
assertThat(taskCount).isGreaterThan(0); assertThat(taskCount).isGreaterThan(0);
r = adminSession.delete("/config/server/tasks/" + result.get(0).id); r = adminSession.delete("/config/server/tasks/" + result.get(0).id);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT); r.assertNoContent();
r.consume(); r.consume();
r = adminSession.get("/config/server/tasks/"); r = adminSession.get("/config/server/tasks/");
@@ -54,8 +53,9 @@ public class KillTaskIT extends AbstractDaemonTest {
r.consume(); r.consume();
assertThat(result.size()).isGreaterThan(0); assertThat(result.size()).isGreaterThan(0);
r = userSession.delete("/config/server/tasks/" + result.get(0).id); userSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND); .delete("/config/server/tasks/" + result.get(0).id)
.assertNotFound();
} }
@Test @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.gerrit.server.config.ListCaches.CacheType;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import org.apache.http.HttpStatus;
import org.eclipse.jgit.util.Base64; import org.eclipse.jgit.util.Base64;
import org.junit.Test; import org.junit.Test;
@@ -37,7 +36,7 @@ public class ListCachesIT extends AbstractDaemonTest {
@Test @Test
public void listCaches() throws Exception { public void listCaches() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/"); RestResponse r = adminSession.get("/config/server/caches/");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
Map<String, CacheInfo> result = Map<String, CacheInfo> result =
newGson().fromJson(r.getReader(), newGson().fromJson(r.getReader(),
new TypeToken<Map<String, CacheInfo>>() {}.getType()); new TypeToken<Map<String, CacheInfo>>() {}.getType());
@@ -56,7 +55,7 @@ public class ListCachesIT extends AbstractDaemonTest {
userSession.get("/config/server/version").consume(); userSession.get("/config/server/version").consume();
r = adminSession.get("/config/server/caches/"); r = adminSession.get("/config/server/caches/");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
result = newGson().fromJson(r.getReader(), result = newGson().fromJson(r.getReader(),
new TypeToken<Map<String, CacheInfo>>() {}.getType()); new TypeToken<Map<String, CacheInfo>>() {}.getType());
assertThat(result.get("accounts").entries.mem).isEqualTo(2); assertThat(result.get("accounts").entries.mem).isEqualTo(2);
@@ -64,14 +63,15 @@ public class ListCachesIT extends AbstractDaemonTest {
@Test @Test
public void listCaches_Forbidden() throws Exception { public void listCaches_Forbidden() throws Exception {
RestResponse r = userSession.get("/config/server/caches/"); userSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN); .get("/config/server/caches/")
.assertForbidden();
} }
@Test @Test
public void listCacheNames() throws Exception { public void listCacheNames() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/?format=LIST"); RestResponse r = adminSession.get("/config/server/caches/?format=LIST");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
List<String> result = List<String> result =
newGson().fromJson(r.getReader(), newGson().fromJson(r.getReader(),
new TypeToken<List<String>>() {}.getType()); new TypeToken<List<String>>() {}.getType());
@@ -83,7 +83,7 @@ public class ListCachesIT extends AbstractDaemonTest {
@Test @Test
public void listCacheNamesTextList() throws Exception { public void listCacheNamesTextList() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/?format=TEXT_LIST"); 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()); String result = new String(Base64.decode(r.getEntityContent()), UTF_8.name());
List<String> list = Arrays.asList(result.split("\n")); List<String> list = Arrays.asList(result.split("\n"));
assertThat(list).contains("accounts"); assertThat(list).contains("accounts");
@@ -93,7 +93,8 @@ public class ListCachesIT extends AbstractDaemonTest {
@Test @Test
public void listCaches_BadRequest() throws Exception { public void listCaches_BadRequest() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/?format=NONSENSE"); adminSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); .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.gerrit.server.config.ListTasks.TaskInfo;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import org.apache.http.HttpStatus;
import org.junit.Test; import org.junit.Test;
import java.util.List; import java.util.List;
@@ -31,7 +30,7 @@ public class ListTasksIT extends AbstractDaemonTest {
@Test @Test
public void listTasks() throws Exception { public void listTasks() throws Exception {
RestResponse r = adminSession.get("/config/server/tasks/"); RestResponse r = adminSession.get("/config/server/tasks/");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
List<TaskInfo> result = List<TaskInfo> result =
newGson().fromJson(r.getReader(), newGson().fromJson(r.getReader(),
new TypeToken<List<TaskInfo>>() {}.getType()); new TypeToken<List<TaskInfo>>() {}.getType());
@@ -52,7 +51,7 @@ public class ListTasksIT extends AbstractDaemonTest {
@Test @Test
public void listTasksWithoutViewQueueCapability() throws Exception { public void listTasksWithoutViewQueueCapability() throws Exception {
RestResponse r = userSession.get("/config/server/tasks/"); RestResponse r = userSession.get("/config/server/tasks/");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
List<TaskInfo> result = List<TaskInfo> result =
newGson().fromJson(r.getReader(), newGson().fromJson(r.getReader(),
new TypeToken<List<TaskInfo>>() {}.getType()); new TypeToken<List<TaskInfo>>() {}.getType());

View File

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

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;
import com.google.gerrit.server.project.BanCommit.BanResultInfo; import com.google.gerrit.server.project.BanCommit.BanResultInfo;
import org.apache.http.HttpStatus;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.PushResult; import org.eclipse.jgit.transport.PushResult;
import org.junit.Test; import org.junit.Test;
@@ -39,7 +38,7 @@ public class BanCommitIT extends AbstractDaemonTest {
RestResponse r = RestResponse r =
adminSession.put("/projects/" + project.get() + "/ban/", adminSession.put("/projects/" + project.get() + "/ban/",
BanCommit.Input.fromCommits(c.name())); BanCommit.Input.fromCommits(c.name()));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
BanResultInfo info = newGson().fromJson(r.getReader(), BanResultInfo.class); BanResultInfo info = newGson().fromJson(r.getReader(), BanResultInfo.class);
assertThat(Iterables.getOnlyElement(info.newlyBanned)).isEqualTo(c.name()); assertThat(Iterables.getOnlyElement(info.newlyBanned)).isEqualTo(c.name());
assertThat(info.alreadyBanned).isNull(); assertThat(info.alreadyBanned).isNull();
@@ -59,7 +58,7 @@ public class BanCommitIT extends AbstractDaemonTest {
r = adminSession.put("/projects/" + project.get() + "/ban/", r = adminSession.put("/projects/" + project.get() + "/ban/",
BanCommit.Input.fromCommits("a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96")); BanCommit.Input.fromCommits("a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96"));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
BanResultInfo info = newGson().fromJson(r.getReader(), BanResultInfo.class); BanResultInfo info = newGson().fromJson(r.getReader(), BanResultInfo.class);
assertThat(Iterables.getOnlyElement(info.alreadyBanned)) assertThat(Iterables.getOnlyElement(info.alreadyBanned))
.isEqualTo("a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96"); .isEqualTo("a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96");
@@ -69,9 +68,9 @@ public class BanCommitIT extends AbstractDaemonTest {
@Test @Test
public void banCommit_Forbidden() throws Exception { public void banCommit_Forbidden() throws Exception {
RestResponse r = userSession
userSession.put("/projects/" + project.get() + "/ban/", .put("/projects/" + project.get() + "/ban/", BanCommit.Input.fromCommits(
BanCommit.Input.fromCommits("a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96")); "a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96"))
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN); .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.group.SystemGroupBackend;
import com.google.gerrit.server.project.ProjectState; import com.google.gerrit.server.project.ProjectState;
import org.apache.http.HttpStatus;
import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicHeader;
import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
@@ -58,7 +57,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
public void testCreateProjectHttp() throws Exception { public void testCreateProjectHttp() throws Exception {
String newProjectName = name("newProject"); String newProjectName = name("newProject");
RestResponse r = adminSession.put("/projects/" + newProjectName); RestResponse r = adminSession.put("/projects/" + newProjectName);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CREATED); r.assertCreated();
ProjectInfo p = newGson().fromJson(r.getReader(), ProjectInfo.class); ProjectInfo p = newGson().fromJson(r.getReader(), ProjectInfo.class);
assertThat(p.name).isEqualTo(newProjectName); assertThat(p.name).isEqualTo(newProjectName);
ProjectState projectState = projectCache.get(new Project.NameKey(newProjectName)); ProjectState projectState = projectCache.get(new Project.NameKey(newProjectName));
@@ -70,32 +69,36 @@ public class CreateProjectIT extends AbstractDaemonTest {
@Test @Test
public void testCreateProjectHttpWhenProjectAlreadyExists_Conflict() public void testCreateProjectHttpWhenProjectAlreadyExists_Conflict()
throws Exception { throws Exception {
RestResponse r = adminSession.put("/projects/" + allProjects.get()); adminSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT); .put("/projects/" + allProjects.get())
.assertConflict();
} }
@Test @Test
public void testCreateProjectHttpWhenProjectAlreadyExists_PreconditionFailed() public void testCreateProjectHttpWhenProjectAlreadyExists_PreconditionFailed()
throws Exception { throws Exception {
RestResponse r = adminSession.putWithHeader("/projects/" + allProjects.get(), adminSession
new BasicHeader(HttpHeaders.IF_NONE_MATCH, "*")); .putWithHeader("/projects/" + allProjects.get(),
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_PRECONDITION_FAILED); new BasicHeader(HttpHeaders.IF_NONE_MATCH, "*"))
.assertPreconditionFailed();
} }
@Test @Test
@UseLocalDisk @UseLocalDisk
public void testCreateProjectHttpWithUnreasonableName_BadRequest() public void testCreateProjectHttpWithUnreasonableName_BadRequest()
throws Exception { throws Exception {
RestResponse r = adminSession.put("/projects/" + Url.encode(name("invalid/../name"))); adminSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); .put("/projects/" + Url.encode(name("invalid/../name")))
.assertBadRequest();
} }
@Test @Test
public void testCreateProjectHttpWithNameMismatch_BadRequest() throws Exception { public void testCreateProjectHttpWithNameMismatch_BadRequest() throws Exception {
ProjectInput in = new ProjectInput(); ProjectInput in = new ProjectInput();
in.name = name("otherName"); in.name = name("otherName");
RestResponse r = adminSession.put("/projects/" + name("someName"), in); adminSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); .put("/projects/" + name("someName"), in)
.assertBadRequest();
} }
@Test @Test
@@ -103,8 +106,9 @@ public class CreateProjectIT extends AbstractDaemonTest {
throws Exception { throws Exception {
ProjectInput in = new ProjectInput(); ProjectInput in = new ProjectInput();
in.branches = Collections.singletonList(name("invalid ref name")); in.branches = Collections.singletonList(name("invalid ref name"));
RestResponse r = adminSession.put("/projects/" + name("newProject"), in); adminSession
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); .put("/projects/" + name("newProject"), in)
.assertBadRequest();
} }
@Test @Test

View File

@@ -14,8 +14,6 @@
package com.google.gerrit.acceptance.rest.project; 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.AbstractDaemonTest;
import com.google.gerrit.acceptance.GcAssert; import com.google.gerrit.acceptance.GcAssert;
import com.google.gerrit.acceptance.RestResponse; 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.gerrit.reviewdb.client.Project;
import com.google.inject.Inject; import com.google.inject.Inject;
import org.apache.http.HttpStatus;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -43,29 +40,27 @@ public class GarbageCollectionIT extends AbstractDaemonTest {
@Test @Test
public void testGcNonExistingProject_NotFound() throws Exception { public void testGcNonExistingProject_NotFound() throws Exception {
assertThat(POST("/projects/non-existing/gc")).isEqualTo( POST("/projects/non-existing/gc").assertNotFound();
HttpStatus.SC_NOT_FOUND);
} }
@Test @Test
public void testGcNotAllowed_Forbidden() throws Exception { public void testGcNotAllowed_Forbidden() throws Exception {
assertThat( userSession
userSession.post("/projects/" + allProjects.get() + "/gc") .post("/projects/" + allProjects.get() + "/gc")
.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN); .assertForbidden();
} }
@Test @Test
@UseLocalDisk @UseLocalDisk
public void testGcOneProject() throws Exception { public void testGcOneProject() throws Exception {
assertThat(POST("/projects/" + allProjects.get() + "/gc")).isEqualTo( POST("/projects/" + allProjects.get() + "/gc").assertOK();
HttpStatus.SC_OK);
gcAssert.assertHasPackFile(allProjects); gcAssert.assertHasPackFile(allProjects);
gcAssert.assertHasNoPackFile(project, project2); gcAssert.assertHasNoPackFile(project, project2);
} }
private int POST(String endPoint) throws IOException { private RestResponse POST(String endPoint) throws IOException {
RestResponse r = adminSession.post(endPoint); RestResponse r = adminSession.post(endPoint);
r.consume(); 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.extensions.common.CommitInfo;
import com.google.gerrit.server.git.ProjectConfig; import com.google.gerrit.server.git.ProjectConfig;
import org.apache.http.HttpStatus;
import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
@@ -130,15 +129,15 @@ public class GetCommitIT extends AbstractDaemonTest {
} }
private void assertNotFound(ObjectId id) throws Exception { private void assertNotFound(ObjectId id) throws Exception {
RestResponse r = userSession.get( userSession
"/projects/" + project.get() + "/commits/" + id.name()); .get("/projects/" + project.get() + "/commits/" + id.name())
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND); .assertNotFound();
} }
private CommitInfo getCommit(ObjectId id) throws Exception { private CommitInfo getCommit(ObjectId id) throws Exception {
RestResponse r = userSession.get( RestResponse r = userSession.get(
"/projects/" + project.get() + "/commits/" + id.name()); "/projects/" + project.get() + "/commits/" + id.name());
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
CommitInfo result = newGson().fromJson(r.getReader(), CommitInfo.class); CommitInfo result = newGson().fromJson(r.getReader(), CommitInfo.class);
r.consume(); r.consume();
return result; 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.reviewdb.client.Project;
import com.google.gerrit.server.project.SetParent; import com.google.gerrit.server.project.SetParent;
import org.apache.http.HttpStatus;
import org.junit.Test; import org.junit.Test;
public class SetParentIT extends AbstractDaemonTest { public class SetParentIT extends AbstractDaemonTest {
@@ -31,7 +30,7 @@ public class SetParentIT extends AbstractDaemonTest {
RestResponse r = RestResponse r =
userSession.put("/projects/" + project.get() + "/parent", userSession.put("/projects/" + project.get() + "/parent",
newParentInput(parent)); newParentInput(parent));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN); r.assertForbidden();
r.consume(); r.consume();
} }
@@ -41,11 +40,11 @@ public class SetParentIT extends AbstractDaemonTest {
RestResponse r = RestResponse r =
adminSession.put("/projects/" + project.get() + "/parent", adminSession.put("/projects/" + project.get() + "/parent",
newParentInput(parent)); newParentInput(parent));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
r.consume(); r.consume();
r = adminSession.get("/projects/" + project.get() + "/parent"); r = adminSession.get("/projects/" + project.get() + "/parent");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK); r.assertOK();
String newParent = String newParent =
newGson().fromJson(r.getReader(), String.class); newGson().fromJson(r.getReader(), String.class);
assertThat(newParent).isEqualTo(parent); assertThat(newParent).isEqualTo(parent);
@@ -57,7 +56,7 @@ public class SetParentIT extends AbstractDaemonTest {
RestResponse r = RestResponse r =
adminSession.put("/projects/" + allProjects.get() + "/parent", adminSession.put("/projects/" + allProjects.get() + "/parent",
newParentInput(project.get())); newParentInput(project.get()));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT); r.assertConflict();
r.consume(); r.consume();
} }
@@ -66,19 +65,19 @@ public class SetParentIT extends AbstractDaemonTest {
RestResponse r = RestResponse r =
adminSession.put("/projects/" + project.get() + "/parent", adminSession.put("/projects/" + project.get() + "/parent",
newParentInput(project.get())); newParentInput(project.get()));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT); r.assertConflict();
r.consume(); r.consume();
Project.NameKey child = createProject("child", project, true); Project.NameKey child = createProject("child", project, true);
r = adminSession.put("/projects/" + project.get() + "/parent", r = adminSession.put("/projects/" + project.get() + "/parent",
newParentInput(child.get())); newParentInput(child.get()));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT); r.assertConflict();
r.consume(); r.consume();
String grandchild = createProject("grandchild", child, true).get(); String grandchild = createProject("grandchild", child, true).get();
r = adminSession.put("/projects/" + project.get() + "/parent", r = adminSession.put("/projects/" + project.get() + "/parent",
newParentInput(grandchild)); newParentInput(grandchild));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_CONFLICT); r.assertConflict();
r.consume(); r.consume();
} }
@@ -87,7 +86,7 @@ public class SetParentIT extends AbstractDaemonTest {
RestResponse r = RestResponse r =
adminSession.put("/projects/" + project.get() + "/parent", adminSession.put("/projects/" + project.get() + "/parent",
newParentInput("non-existing")); newParentInput("non-existing"));
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY); r.assertUnprocessableEntity();
r.consume(); 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.api.projects.TagInfo;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException; import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import org.apache.http.HttpStatus;
import org.eclipse.jgit.api.PushCommand; import org.eclipse.jgit.api.PushCommand;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.transport.PushResult; import org.eclipse.jgit.transport.PushResult;
@@ -42,8 +41,9 @@ public class TagsIT extends AbstractDaemonTest {
@Test @Test
public void listTagsOfNonExistingProject() throws Exception { public void listTagsOfNonExistingProject() throws Exception {
assertThat(adminSession.get("/projects/non-existing/tags").getStatusCode()) adminSession
.isEqualTo(HttpStatus.SC_NOT_FOUND); .get("/projects/non-existing/tags")
.assertNotFound();
} }
@Test @Test
@@ -57,9 +57,9 @@ public class TagsIT extends AbstractDaemonTest {
@Test @Test
public void listTagsOfNonVisibleProject() throws Exception { public void listTagsOfNonVisibleProject() throws Exception {
blockRead(project, "refs/*"); blockRead(project, "refs/*");
assertThat( userSession
userSession.get("/projects/" + project.get() + "/tags").getStatusCode()) .get("/projects/" + project.get() + "/tags")
.isEqualTo(HttpStatus.SC_NOT_FOUND); .assertNotFound();
} }
@Test @Test