Fix update finished field in check and add more update check tests
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I995dc95a1ecaaa4d376dc2ae3606a7d7601676d1
diff --git a/java/com/google/gerrit/plugins/checks/api/UpdateCheck.java b/java/com/google/gerrit/plugins/checks/api/UpdateCheck.java
index fb5b653..2b24640 100644
--- a/java/com/google/gerrit/plugins/checks/api/UpdateCheck.java
+++ b/java/com/google/gerrit/plugins/checks/api/UpdateCheck.java
@@ -46,7 +46,7 @@
} else if (!checkResource.getCheckerUuid().get().equals(input.checkerUuid)) {
throw new BadRequestException(
String.format(
- "checkerUuid must either be null or the same as on the resource:\n"
+ "checker UUID in input must either be null or the same as on the resource:\n"
+ "the check resource belongs to checker %s,"
+ " but in the input checker %s was specified",
checkResource.getCheckerUuid(), input.checkerUuid));
diff --git a/java/com/google/gerrit/plugins/checks/db/NoteDbCheck.java b/java/com/google/gerrit/plugins/checks/db/NoteDbCheck.java
index c29d3e5..8f6482a 100644
--- a/java/com/google/gerrit/plugins/checks/db/NoteDbCheck.java
+++ b/java/com/google/gerrit/plugins/checks/db/NoteDbCheck.java
@@ -67,7 +67,7 @@
started = update.started().get();
modified = true;
}
- if (update.finished().isPresent() && update.finished().get().equals(finished)) {
+ if (update.finished().isPresent() && !update.finished().get().equals(finished)) {
finished = update.finished().get();
modified = true;
}
diff --git a/javatests/com/google/gerrit/plugins/checks/acceptance/api/UpdateCheckIT.java b/javatests/com/google/gerrit/plugins/checks/acceptance/api/UpdateCheckIT.java
index a671b18..c356056 100644
--- a/javatests/com/google/gerrit/plugins/checks/acceptance/api/UpdateCheckIT.java
+++ b/javatests/com/google/gerrit/plugins/checks/acceptance/api/UpdateCheckIT.java
@@ -18,6 +18,7 @@
import com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations;
import com.google.gerrit.extensions.restapi.AuthException;
+import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.plugins.checks.CheckKey;
import com.google.gerrit.plugins.checks.CheckerUuid;
import com.google.gerrit.plugins.checks.acceptance.AbstractCheckersTest;
@@ -27,6 +28,7 @@
import com.google.gerrit.plugins.checks.api.CheckState;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.server.util.time.TimeUtil;
import com.google.gerrit.testing.TestTimeUtil;
import com.google.inject.Inject;
import java.sql.Timestamp;
@@ -69,6 +71,52 @@
}
@Test
+ public void cannotUpdateCheckerUuid() throws Exception {
+ CheckInput input = new CheckInput();
+ input.checkerUuid = "foo:bar";
+
+ exception.expect(BadRequestException.class);
+ exception.expectMessage(
+ "checker UUID in input must either be null or the same as on the resource");
+ checksApiFactory.revision(patchSetId).id(checkKey.checkerUuid()).update(input);
+ }
+
+ @Test
+ public void specifyingCheckerUuidInInputThatMatchesTheCheckerUuidInTheUrlIsOkay()
+ throws Exception {
+ CheckInput input = new CheckInput();
+ input.checkerUuid = checkKey.checkerUuid().get();
+ checksApiFactory.revision(patchSetId).id(checkKey.checkerUuid()).update(input);
+ }
+
+ @Test
+ public void updateUrl() throws Exception {
+ CheckInput input = new CheckInput();
+ input.url = "http://example.com/my-check";
+
+ CheckInfo info = checksApiFactory.revision(patchSetId).id(checkKey.checkerUuid()).update(input);
+ assertThat(info.url).isEqualTo(input.url);
+ }
+
+ @Test
+ public void updateStarted() throws Exception {
+ CheckInput input = new CheckInput();
+ input.started = TimeUtil.nowTs();
+
+ CheckInfo info = checksApiFactory.revision(patchSetId).id(checkKey.checkerUuid()).update(input);
+ assertThat(info.started).isEqualTo(input.started);
+ }
+
+ @Test
+ public void updateFinished() throws Exception {
+ CheckInput input = new CheckInput();
+ input.finished = TimeUtil.nowTs();
+
+ CheckInfo info = checksApiFactory.revision(patchSetId).id(checkKey.checkerUuid()).update(input);
+ assertThat(info.finished).isEqualTo(input.finished);
+ }
+
+ @Test
public void updateResultsInNewUpdatedTimestamp() throws Exception {
CheckInput input = new CheckInput();
input.state = CheckState.FAILED;