-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
${%Verify}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
${%Code Review}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+ |
+ ${instance.verdictValue}
+ |
+ |
+
+
+
+
+ | ${%Started} |
+
+
+ |
+
+
+ | ${%Successful} |
+
+
+ |
+
+
+
+ | ${%Failed} |
+
+
+ |
+
+
+
+ | ${%Unstable} |
+
+
+ |
+
+
+
+ | ${%Not Built} |
+
+
+ |
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
+ help="/plugin/gerrit-trigger/trigger/help-TopicAssociation.html" />
-
+ help="/plugin/gerrit-trigger/trigger/help-GerritEventType.html">
+
-
-
+
+
+
-
-
+ checkUrl="'descriptorByName/com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger/urlCheck?value='+escape(this.value)"/>
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+ |
-
+ |
+
+ ${%Type}
+ |
+
+ ${%Pattern}
+ |
+
+ ${%Branches}
+ |
+
+
+ |
+
+ |
+
+
+ |
+
+
+ |
+
+
+
+ |
+ ${%Type}
+ |
+
+ ${%Pattern}
+ |
+
+
+ |
+
+
+ |
+
+
+
+
+
+
+ |
+
+ |
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+ |
+ ${%Topic}
+ |
+
+
+ |
+
+
+ |
+
+
+ |
+
+
-
-
-
-
-
-
- ${%Forbidden File}
-
-
-
-
-
-
-
-
-
-
+ |
+
+
+
+
+
+
+
+ |
+ ${%File}
+ |
+
+
+ |
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+ |
+ ${%Forbidden File}
+ |
+
+
+ |
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+ |
+
+
+ |
+
+
+
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/JcascTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/JcascTest.java
index 4198d65e1..1fe5affc2 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/JcascTest.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/JcascTest.java
@@ -25,9 +25,7 @@
*/
package com.sonyericsson.hudson.plugins.gerrit.trigger;
-import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Config;
-import com.sonyericsson.hudson.plugins.gerrit.trigger.config.PluginConfig;
-import com.sonyericsson.hudson.plugins.gerrit.trigger.config.ReplicationConfig;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.*;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.BuildCancellationPolicy;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritSlave;
import com.sonymobile.tools.gerrit.gerritevents.watchdog.WatchTimeExceptionData;
@@ -116,19 +114,19 @@ private void verifyDefaultSetup(boolean checkPasswords) {
assertTrue(bcp.isAbortNewPatchsets());
assertTrue(bcp.isAbortSameTopic());
- assertEquals(4, c.getGerritBuildStartedVerifiedValue().intValue());
- assertEquals(4, c.getGerritBuildSuccessfulVerifiedValue().intValue());
- assertEquals(4, c.getGerritBuildFailedVerifiedValue().intValue());
- assertEquals(4, c.getGerritBuildUnstableVerifiedValue().intValue());
- assertEquals(4, c.getGerritBuildNotBuiltVerifiedValue().intValue());
- assertEquals(4, c.getGerritBuildAbortedVerifiedValue().intValue());
+ assertEquals(4, c.getLabelVote(Constants.VERIFIED_LABEL, BuildStatus.STARTED).intValue());
+ assertEquals(4, c.getLabelVote(Constants.VERIFIED_LABEL, BuildStatus.SUCCESSFUL).intValue());
+ assertEquals(4, c.getLabelVote(Constants.VERIFIED_LABEL, BuildStatus.FAILED).intValue());
+ assertEquals(4, c.getLabelVote(Constants.VERIFIED_LABEL, BuildStatus.UNSTABLE).intValue());
+ assertEquals(4, c.getLabelVote(Constants.VERIFIED_LABEL, BuildStatus.NOT_BUILT).intValue());
+ assertEquals(4, c.getLabelVote(Constants.VERIFIED_LABEL, BuildStatus.ABORTED).intValue());
- assertEquals(4, c.getGerritBuildStartedCodeReviewValue().intValue());
- assertEquals(4, c.getGerritBuildSuccessfulCodeReviewValue().intValue());
- assertEquals(4, c.getGerritBuildFailedCodeReviewValue().intValue());
- assertEquals(4, c.getGerritBuildUnstableCodeReviewValue().intValue());
- assertEquals(4, c.getGerritBuildNotBuiltCodeReviewValue().intValue());
- assertEquals(4, c.getGerritBuildAbortedCodeReviewValue().intValue());
+ assertEquals(4, c.getLabelVote(Constants.CODE_REVIEW_LABEL, BuildStatus.STARTED).intValue());
+ assertEquals(4, c.getLabelVote(Constants.CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL).intValue());
+ assertEquals(4, c.getLabelVote(Constants.CODE_REVIEW_LABEL, BuildStatus.FAILED).intValue());
+ assertEquals(4, c.getLabelVote(Constants.CODE_REVIEW_LABEL, BuildStatus.UNSTABLE).intValue());
+ assertEquals(4, c.getLabelVote(Constants.CODE_REVIEW_LABEL, BuildStatus.NOT_BUILT).intValue());
+ assertEquals(4, c.getLabelVote(Constants.CODE_REVIEW_LABEL, BuildStatus.ABORTED).intValue());
assertThat(c.getGerritCmdBuildStarted(), containsString("Build Started CMD"));
assertThat(c.getGerritCmdBuildSuccessful(), containsString("Build Successful CMD"));
@@ -146,9 +144,9 @@ private void verifyDefaultSetup(boolean checkPasswords) {
assertEquals(3636, c.getProjectListRefreshInterval());
assertEquals(OWNER_REVIEWERS, c.getNotificationLevel());
List cats = c.getCategories();
- assertThat(cats, iterableWithSize(2));
- VerdictCategory c1 = cats.get(0);
- VerdictCategory c2 = cats.get(1);
+ assertThat(cats, iterableWithSize(4));
+ VerdictCategory c1 = cats.get(2);
+ VerdictCategory c2 = cats.get(3);
assertEquals("foo", c1.getVerdictValue());
assertEquals("bar", c1.getVerdictDescription());
assertEquals("baz", c2.getVerdictValue());
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/config/ConfigTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/config/ConfigTest.java
index ce0d65517..40306fbcc 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/config/ConfigTest.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/config/ConfigTest.java
@@ -24,22 +24,21 @@
*/
package com.sonyericsson.hudson.plugins.gerrit.trigger.config;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.mock.Setup;
+import com.sonymobile.tools.gerrit.gerritevents.GerritDefaultValues;
import com.sonymobile.tools.gerrit.gerritevents.dto.events.PatchsetCreated;
import com.sonymobile.tools.gerrit.gerritevents.dto.rest.Notify;
-import com.sonymobile.tools.gerrit.gerritevents.GerritDefaultValues;
-import com.sonyericsson.hudson.plugins.gerrit.trigger.mock.Setup;
-
+import hudson.util.Secret;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
-
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
-import hudson.util.Secret;
-
import java.io.File;
+import static com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants.CODE_REVIEW_LABEL;
+import static com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants.VERIFIED_LABEL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -78,18 +77,6 @@ public void testSetValues() {
+ "--message 'Aborted oupsy ' --verified --code-review \","
+ "\"gerritAuthKeyFile\":\"/home/local/gerrit/.ssh/id_rsa\","
+ "\"gerritAuthKeyFilePassword\":\"passis\","
- + "\"gerritBuildFailedCodeReviewValue\":\"1\","
- + "\"gerritBuildFailedVerifiedValue\":\"-1\","
- + "\"gerritBuildStartedCodeReviewValue\":\"2\","
- + "\"gerritBuildStartedVerifiedValue\":\"-2\","
- + "\"gerritBuildSuccessfulCodeReviewValue\":\"3\","
- + "\"gerritBuildSuccessfulVerifiedValue\":\"-3\","
- + "\"gerritBuildUnstableCodeReviewValue\":\"4\","
- + "\"gerritBuildUnstableVerifiedValue\":\"-4\","
- + "\"gerritBuildNotBuiltCodeReviewValue\":\"5\","
- + "\"gerritBuildNotBuiltVerifiedValue\":\"-5\","
- + "\"gerritBuildAbortedCodeReviewValue\":\"6\","
- + "\"gerritBuildAbortedVerifiedValue\":\"-6\","
+ "\"gerritFrontEndUrl\":\"http://gerrit:8088\","
+ "\"gerritHostName\":\"gerrit\","
+ "\"gerritSshPort\":\"1337\","
@@ -98,7 +85,25 @@ public void testSetValues() {
+ "\"useRestApi\":{\"gerritHttpUserName\":\"httpgerrit\",\"gerritHttpPassword\":\"httppass\"},"
+ "\"numberOfSendingWorkerThreads\":\"4\","
+ "\"numberOfReceivingWorkerThreads\":\"6\","
- + "\"notificationLevel\":\"OWNER\"}";
+ + "\"notificationLevel\":\"OWNER\","
+ + "\"verdictCategories\":["
+ + "{\"verdictValue\":\"Code-Review\","
+ + "\"verdictDescription\":\"Code-Review\","
+ + "\"buildStartedVote\":\"1\","
+ + "\"buildSuccessfulVote\":\"2\","
+ + "\"buildFailedVote\":\"3\","
+ + "\"buildUnstableVote\":\"4\","
+ + "\"buildNotBuiltVote\":\"5\","
+ + "\"buildAbortedVote\":\"6\"},"
+ + "{\"verdictValue\":\"Verified\","
+ + "\"verdictDescription\":\"Verified\","
+ + "\"buildStartedVote\":\"7\","
+ + "\"buildSuccessfulVote\":\"8\","
+ + "\"buildFailedVote\":\"9\","
+ + "\"buildUnstableVote\":\"10\","
+ + "\"buildNotBuiltVote\":\"11\","
+ + "\"buildAbortedVote\":\"12\"}]"
+ + "}";
JSONObject form = (JSONObject)JSONSerializer.toJSON(formString);
Config config = new Config(form);
assertEquals("gerrit review --project , "
@@ -122,18 +127,20 @@ public void testSetValues() {
assertEquals(new File("/home/local/gerrit/.ssh/id_rsa").getPath(),
config.getGerritAuthKeyFile().getPath());
assertEquals("passis", config.getGerritAuthKeyFilePassword());
- assertEquals(Integer.valueOf(1), config.getGerritBuildFailedCodeReviewValue());
- assertEquals(Integer.valueOf(-1), config.getGerritBuildFailedVerifiedValue());
- assertEquals(Integer.valueOf(2), config.getGerritBuildStartedCodeReviewValue());
- assertEquals(Integer.valueOf(-2), config.getGerritBuildStartedVerifiedValue());
- assertEquals(Integer.valueOf(3), config.getGerritBuildSuccessfulCodeReviewValue());
- assertEquals(Integer.valueOf(-3), config.getGerritBuildSuccessfulVerifiedValue());
- assertEquals(Integer.valueOf(4), config.getGerritBuildUnstableCodeReviewValue());
- assertEquals(Integer.valueOf(-4), config.getGerritBuildUnstableVerifiedValue());
- assertEquals(Integer.valueOf(5), config.getGerritBuildNotBuiltCodeReviewValue());
- assertEquals(Integer.valueOf(-5), config.getGerritBuildNotBuiltVerifiedValue());
- assertEquals(Integer.valueOf(6), config.getGerritBuildAbortedCodeReviewValue());
- assertEquals(Integer.valueOf(-6), config.getGerritBuildAbortedVerifiedValue());
+ assertEquals(Integer.valueOf(1), config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.STARTED));
+ assertEquals(Integer.valueOf(2), config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL));
+ assertEquals(Integer.valueOf(3), config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.FAILED));
+ assertEquals(Integer.valueOf(4), config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.UNSTABLE));
+ assertEquals(Integer.valueOf(5), config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.NOT_BUILT));
+ assertEquals(Integer.valueOf(6), config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.ABORTED));
+
+ assertEquals(Integer.valueOf(7), config.getLabelVote(VERIFIED_LABEL, BuildStatus.STARTED));
+ assertEquals(Integer.valueOf(8), config.getLabelVote(VERIFIED_LABEL, BuildStatus.SUCCESSFUL));
+ assertEquals(Integer.valueOf(9), config.getLabelVote(VERIFIED_LABEL, BuildStatus.FAILED));
+ assertEquals(Integer.valueOf(10), config.getLabelVote(VERIFIED_LABEL, BuildStatus.UNSTABLE));
+ assertEquals(Integer.valueOf(11), config.getLabelVote(VERIFIED_LABEL, BuildStatus.NOT_BUILT));
+ assertEquals(Integer.valueOf(12), config.getLabelVote(VERIFIED_LABEL, BuildStatus.ABORTED));
+
assertEquals("http://gerrit:8088/", config.getGerritFrontEndUrl());
assertEquals("gerrit", config.getGerritHostName());
assertEquals(1337, config.getGerritSshPort());
@@ -183,18 +190,23 @@ public void testCopyConfig() {
+ "--message 'Aborted oupsy ' --verified --code-review \","
+ "\"gerritAuthKeyFile\":\"/home/local/gerrit/.ssh/id_rsa\","
+ "\"gerritAuthKeyFilePassword\":\"passis\","
- + "\"gerritBuildFailedCodeReviewValue\":\"1\","
- + "\"gerritBuildFailedVerifiedValue\":\"-1\","
- + "\"gerritBuildStartedCodeReviewValue\":\"2\","
- + "\"gerritBuildStartedVerifiedValue\":\"-2\","
- + "\"gerritBuildSuccessfulCodeReviewValue\":\"3\","
- + "\"gerritBuildSuccessfulVerifiedValue\":\"-3\","
- + "\"gerritBuildUnstableCodeReviewValue\":\"4\","
- + "\"gerritBuildUnstableVerifiedValue\":\"-4\","
- + "\"gerritBuildNotBuiltCodeReviewValue\":\"5\","
- + "\"gerritBuildNotBuiltVerifiedValue\":\"-5\","
- + "\"gerritBuildAbortedCodeReviewValue\":\"6\","
- + "\"gerritBuildAbortedVerifiedValue\":\"-6\","
+ + "\"verdictCategories\":["
+ + "{\"verdictValue\":\"Code-Review\","
+ + "\"verdictDescription\":\"Code-Review\","
+ + "\"buildStartedVote\":\"1\","
+ + "\"buildSuccessfulVote\":\"2\","
+ + "\"buildFailedVote\":\"3\","
+ + "\"buildUnstableVote\":\"4\","
+ + "\"buildNotBuiltVote\":\"5\","
+ + "\"buildAbortedVote\":\"6\"},"
+ + "{\"verdictValue\":\"Verified\","
+ + "\"verdictDescription\":\"Verified\","
+ + "\"buildStartedVote\":\"7\","
+ + "\"buildSuccessfulVote\":\"8\","
+ + "\"buildFailedVote\":\"9\","
+ + "\"buildUnstableVote\":\"10\","
+ + "\"buildNotBuiltVote\":\"11\","
+ + "\"buildAbortedVote\":\"12\"}],"
+ "\"gerritFrontEndUrl\":\"http://gerrit:8088\","
+ "\"gerritHostName\":\"gerrit\","
+ "\"gerritSshPort\":\"1337\","
@@ -228,18 +240,20 @@ public void testCopyConfig() {
assertEquals(new File("/home/local/gerrit/.ssh/id_rsa").getPath(),
config.getGerritAuthKeyFile().getPath());
assertEquals("passis", config.getGerritAuthKeyFilePassword());
- assertEquals(Integer.valueOf(1), config.getGerritBuildFailedCodeReviewValue());
- assertEquals(Integer.valueOf(-1), config.getGerritBuildFailedVerifiedValue());
- assertEquals(Integer.valueOf(2), config.getGerritBuildStartedCodeReviewValue());
- assertEquals(Integer.valueOf(-2), config.getGerritBuildStartedVerifiedValue());
- assertEquals(Integer.valueOf(3), config.getGerritBuildSuccessfulCodeReviewValue());
- assertEquals(Integer.valueOf(-3), config.getGerritBuildSuccessfulVerifiedValue());
- assertEquals(Integer.valueOf(4), config.getGerritBuildUnstableCodeReviewValue());
- assertEquals(Integer.valueOf(-4), config.getGerritBuildUnstableVerifiedValue());
- assertEquals(Integer.valueOf(5), config.getGerritBuildNotBuiltCodeReviewValue());
- assertEquals(Integer.valueOf(-5), config.getGerritBuildNotBuiltVerifiedValue());
- assertEquals(Integer.valueOf(6), config.getGerritBuildAbortedCodeReviewValue());
- assertEquals(Integer.valueOf(-6), config.getGerritBuildAbortedVerifiedValue());
+ assertEquals(Integer.valueOf(1), config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.STARTED));
+ assertEquals(Integer.valueOf(2), config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL));
+ assertEquals(Integer.valueOf(3), config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.FAILED));
+ assertEquals(Integer.valueOf(4), config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.UNSTABLE));
+ assertEquals(Integer.valueOf(5), config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.NOT_BUILT));
+ assertEquals(Integer.valueOf(6), config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.ABORTED));
+
+ assertEquals(Integer.valueOf(7), config.getLabelVote(VERIFIED_LABEL, BuildStatus.STARTED));
+ assertEquals(Integer.valueOf(8), config.getLabelVote(VERIFIED_LABEL, BuildStatus.SUCCESSFUL));
+ assertEquals(Integer.valueOf(9), config.getLabelVote(VERIFIED_LABEL, BuildStatus.FAILED));
+ assertEquals(Integer.valueOf(10), config.getLabelVote(VERIFIED_LABEL, BuildStatus.UNSTABLE));
+ assertEquals(Integer.valueOf(11), config.getLabelVote(VERIFIED_LABEL, BuildStatus.NOT_BUILT));
+ assertEquals(Integer.valueOf(12), config.getLabelVote(VERIFIED_LABEL, BuildStatus.ABORTED));
+
assertEquals("http://gerrit:8088/", config.getGerritFrontEndUrl());
assertEquals("gerrit", config.getGerritHostName());
assertEquals(1337, config.getGerritSshPort());
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ParameterExpanderParameterizedTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ParameterExpanderParameterizedTest.java
index b806f367f..2eef25a0a 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ParameterExpanderParameterizedTest.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ParameterExpanderParameterizedTest.java
@@ -24,12 +24,11 @@
package com.sonyericsson.hudson.plugins.gerrit.trigger.gerritnotifier;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.BuildStatus;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.IGerritHudsonTriggerConfig;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger;
import com.sonyericsson.hudson.plugins.gerrit.trigger.mock.Setup;
-
import hudson.model.Result;
-
import jenkins.model.Jenkins;
import org.junit.After;
import org.junit.Before;
@@ -43,17 +42,16 @@
import java.util.LinkedList;
import java.util.List;
+import static com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants.CODE_REVIEW_LABEL;
+import static com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants.VERIFIED_LABEL;
import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.mockStatic;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
//CS IGNORE MagicNumber FOR NEXT 200 LINES. REASON: Mocks tests.
/**
* Tests a bunch of different scenarios.
- * For {@link ParameterExpander#getCodeReviewValue(hudson.model.Result, GerritTrigger)}
- * and {@link ParameterExpander#getVerifiedValue(hudson.model.Result, GerritTrigger)}
+ * For {@link ParameterExpander#getLabelVoteValue(Result, GerritTrigger, String)} with various labels
* @author Robert Sandell <robert.sandell@sonyericsson.com>
*/
@RunWith(Parameterized.class)
@@ -92,7 +90,7 @@ public void tearDown() {
public void testGetVerifiedValue() {
ParameterExpander instance = new ParameterExpander(parameters.config);
assertEquals(Integer.valueOf(parameters.expectedVerified),
- instance.getVerifiedValue(parameters.result, parameters.trigger));
+ instance.getLabelVoteValue(parameters.result, parameters.trigger, VERIFIED_LABEL));
}
/**
@@ -102,7 +100,7 @@ public void testGetVerifiedValue() {
public void testGetCodeReviewValue() {
ParameterExpander instance = new ParameterExpander(parameters.config);
assertEquals(Integer.valueOf(parameters.expectedCodeReview),
- instance.getCodeReviewValue(parameters.result, parameters.trigger));
+ instance.getLabelVoteValue(parameters.result, parameters.trigger, CODE_REVIEW_LABEL));
}
/**
@@ -113,60 +111,60 @@ public void testGetCodeReviewValue() {
public static Collection getParameters() {
List list = new LinkedList();
- IGerritHudsonTriggerConfig config = Setup.createConfig();
+ IGerritHudsonTriggerConfig config = Setup.createMockableConfig();
//SUCCESS, FAILURE, ABORTED, UNSTABLE, other
//not overridden, overridden
//SUCCESS Not overridden
GerritTrigger trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(null);
- when(trigger.getGerritBuildSuccessfulVerifiedValue()).thenReturn(null);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(null);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(null);
list.add(new TestParameters[]{new TestParameters(config, Result.SUCCESS, trigger, 4, 3)});
//SUCCESS overridden
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(21);
- when(trigger.getGerritBuildSuccessfulVerifiedValue()).thenReturn(22);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(21);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(22);
list.add(new TestParameters[]{new TestParameters(config, Result.SUCCESS, trigger, 21, 22)});
//FAILURE Not overridden
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildFailedCodeReviewValue()).thenReturn(null);
- when(trigger.getGerritBuildFailedVerifiedValue()).thenReturn(null);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.FAILED)).thenReturn(null);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.FAILED)).thenReturn(null);
list.add(new TestParameters[]{new TestParameters(config, Result.FAILURE, trigger, -2, -1)});
//FAILURE overridden
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildFailedCodeReviewValue()).thenReturn(31);
- when(trigger.getGerritBuildFailedVerifiedValue()).thenReturn(32);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.FAILED)).thenReturn(31);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.FAILED)).thenReturn(32);
list.add(new TestParameters[]{new TestParameters(config, Result.FAILURE, trigger, 31, 32)});
//UNSTABLE overridden
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildUnstableCodeReviewValue()).thenReturn(-21);
- when(trigger.getGerritBuildUnstableVerifiedValue()).thenReturn(-22);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.UNSTABLE)).thenReturn(-21);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.UNSTABLE)).thenReturn(-22);
list.add(new TestParameters[]{new TestParameters(config, Result.UNSTABLE, trigger, -21, -22)});
//OTHER Not overridden
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildNotBuiltCodeReviewValue()).thenReturn(null);
- when(trigger.getGerritBuildNotBuiltVerifiedValue()).thenReturn(null);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.NOT_BUILT)).thenReturn(null);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.NOT_BUILT)).thenReturn(null);
list.add(new TestParameters[]{new TestParameters(config, Result.NOT_BUILT, trigger, -6, -5)});
//OTHER overridden
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildNotBuiltCodeReviewValue()).thenReturn(-51);
- when(trigger.getGerritBuildNotBuiltVerifiedValue()).thenReturn(-52);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.NOT_BUILT)).thenReturn(-51);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.NOT_BUILT)).thenReturn(-52);
list.add(new TestParameters[]{new TestParameters(config, Result.NOT_BUILT, trigger, -51, -52)});
//ABORTED Not overridden
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildAbortedCodeReviewValue()).thenReturn(null);
- when(trigger.getGerritBuildAbortedVerifiedValue()).thenReturn(null);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.ABORTED)).thenReturn(null);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.ABORTED)).thenReturn(null);
list.add(new TestParameters[]{new TestParameters(config, Result.ABORTED, trigger, 3, -2)});
//ABORTED overridden
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildAbortedCodeReviewValue()).thenReturn(41);
- when(trigger.getGerritBuildAbortedVerifiedValue()).thenReturn(42);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.ABORTED)).thenReturn(41);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.ABORTED)).thenReturn(42);
list.add(new TestParameters[]{new TestParameters(config, Result.ABORTED, trigger, 41, 42)});
//UNSTABLE Not overridden
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildUnstableCodeReviewValue()).thenReturn(null);
- when(trigger.getGerritBuildUnstableVerifiedValue()).thenReturn(null);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.UNSTABLE)).thenReturn(null);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.UNSTABLE)).thenReturn(null);
list.add(new TestParameters[]{new TestParameters(config, Result.UNSTABLE, trigger, -4, -3)});
return list;
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ParameterExpanderSkipVoteParameterTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ParameterExpanderSkipVoteParameterTest.java
index d710a4bc1..7dcd842a3 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ParameterExpanderSkipVoteParameterTest.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ParameterExpanderSkipVoteParameterTest.java
@@ -92,7 +92,7 @@ public void tearDown() throws Exception {
*/
@Test
public void testCodeReview() {
- IGerritHudsonTriggerConfig config = Setup.createConfig();
+ IGerritHudsonTriggerConfig config = Setup.createMockableConfig();
ParameterExpander instance = new ParameterExpander(config);
Integer result = instance.getMinimumCodeReviewValue(parameter.memoryImprint, true);
if (parameter.expectedCodeReview == null) {
@@ -108,7 +108,7 @@ public void testCodeReview() {
*/
@Test
public void testVerified() {
- IGerritHudsonTriggerConfig config = Setup.createConfig();
+ IGerritHudsonTriggerConfig config = Setup.createMockableConfig();
ParameterExpander instance = new ParameterExpander(config);
Integer result = instance.getMinimumVerifiedValue(parameter.memoryImprint, true, Integer.MAX_VALUE);
if (parameter.expectedVerified == null) {
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ParameterExpanderTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ParameterExpanderTest.java
index 43ea014a4..062d91aa2 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ParameterExpanderTest.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ParameterExpanderTest.java
@@ -24,6 +24,7 @@
*/
package com.sonyericsson.hudson.plugins.gerrit.trigger.gerritnotifier;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.BuildStatus;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Config;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.IGerritHudsonTriggerConfig;
import com.sonyericsson.hudson.plugins.gerrit.trigger.gerritnotifier.model.BuildMemory.MemoryImprint;
@@ -35,19 +36,8 @@
import com.sonymobile.tools.gerrit.gerritevents.dto.events.ChangeBasedEvent;
import com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent;
import com.sonymobile.tools.gerrit.gerritevents.dto.events.PatchsetCreated;
-
import hudson.EnvVars;
-import hudson.model.Result;
-import hudson.model.Run;
-import hudson.model.TaskListener;
-import hudson.model.AbstractBuild;
-import hudson.model.AbstractProject;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-
+import hudson.model.*;
import jenkins.model.Jenkins;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
@@ -55,17 +45,27 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.MockedStatic;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.stream.Stream;
+
+import static com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants.CODE_REVIEW_LABEL;
+import static com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants.VERIFIED_LABEL;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.not;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
-import static org.junit.Assert.assertEquals;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.mockStatic;
-import static org.mockito.Mockito.when;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
//CS IGNORE MagicNumber FOR NEXT 700 LINES. REASON: Mocks tests.
@@ -83,6 +83,7 @@ public class ParameterExpanderTest {
* Mock Jenkins.
*/
@Before
+ @BeforeEach
public void setup() {
jenkinsMockedStatic = mockStatic(Jenkins.class);
jenkins = mock(Jenkins.class);
@@ -91,6 +92,7 @@ public void setup() {
}
@After
+ @AfterEach
public void tearDown() throws Exception {
jenkinsMockedStatic.close();
}
@@ -104,9 +106,10 @@ public void testGetBuildStartedCommand() throws Exception {
TaskListener taskListener = mock(TaskListener.class);
GerritTrigger trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildStartedVerifiedValue()).thenReturn(null);
- when(trigger.getGerritBuildStartedCodeReviewValue()).thenReturn(32);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.STARTED)).thenReturn(null);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.STARTED)).thenReturn(32);
when(trigger.getBuildStartMessage()).thenReturn("${START_MESSAGE_VAR}");
+ when(trigger.getLabelVote("Custom-Label", BuildStatus.STARTED)).thenReturn(3);
AbstractProject project = mock(AbstractProject.class);
Setup.setTrigger(trigger, project);
@@ -115,8 +118,7 @@ public void testGetBuildStartedCommand() throws Exception {
PatchsetCreated event = Setup.createPatchsetCreated();
BuildsStartedStats stats = Setup.createBuildStartedStats(event);
- IGerritHudsonTriggerConfig config = Setup.createConfig();
-
+ IGerritHudsonTriggerConfig config = Setup.createMockableConfig();
try (MockedStatic messageProviderMockedStatic = mockStatic(GerritMessageProvider.class)) {
List messageProviderExtensionList = new LinkedList();
@@ -132,16 +134,17 @@ public void testGetBuildStartedCommand() throws Exception {
System.out.println("result: " + result);
assertTrue("Missing START_MESSAGE_VAL from getBuildStartMessage()",
result.contains("START_MESSAGE_VAL"));
- assertTrue("Missing CHANGE_ID", result.contains("CHANGE_ID=Iddaaddaa123456789"));
- assertTrue("Missing PATCHSET", result.contains("PATCHSET=1"));
- assertTrue("Missing VERIFIED", result.contains("VERIFIED=1"));
- assertTrue("Missing CODEREVIEW", result.contains("CODEREVIEW=32"));
- assertTrue("Missing NOTIFICATION_LEVEL", result.contains("NOTIFICATION_LEVEL=ALL"));
- assertTrue("Missing REFSPEC", result.contains("REFSPEC=" + expectedRefSpec));
- assertTrue("Missing ENV_BRANCH", result.contains("ENV_BRANCH=branch"));
- assertTrue("Missing ENV_CHANGE", result.contains("ENV_CHANGE=1000"));
- assertTrue("Missing ENV_REFSPEC", result.contains("ENV_REFSPEC=" + expectedRefSpec));
- assertTrue("Missing ENV_CHANGEURL", result.contains("ENV_CHANGEURL=http://gerrit/1000"));
+ assertTrue("Missing CHANGE_ID", result.contains("change-id Iddaaddaa123456789"));
+ assertTrue("Missing PATCHSET or CHANGE", result.contains("1000,1"));
+ assertTrue("Missing VERIFIED", result.contains("--verified 1"));
+ assertTrue("Missing CODEREVIEW", result.contains("--code-review 32"));
+ assertTrue("Missing CUSTOMLABEL", result.contains("--custom-label 3"));
+ assertTrue("Missing NOTIFICATION_LEVEL", result.contains("notification-level ALL"));
+ assertTrue("Missing REFSPEC", result.contains("refspec " + expectedRefSpec));
+ assertTrue("Missing ENV_BRANCH", result.contains("ENV_BRANCH branch"));
+ assertTrue("Missing ENV_CHANGE", result.contains("ENV_CHANGE 1000"));
+ assertTrue("Missing ENV_REFSPEC", result.contains("ENV_REFSPEC " + expectedRefSpec));
+ assertTrue("Missing ENV_CHANGEURL", result.contains("ENV_CHANGEURL http://gerrit/1000"));
assertTrue("Missing CUSTOM_MESSAGE", result.contains("CUSTOM_MESSAGE_BUILD_STARTED"));
assertTrue("Newlines are stripped", result.contains("Message\nwith newline"));
}
@@ -159,31 +162,31 @@ public void testGetMinimumVerifiedValue() {
MemoryImprint.Entry[] entries = new MemoryImprint.Entry[4];
GerritTrigger trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildSuccessfulVerifiedValue()).thenReturn(3);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(3);
entries[0] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.SUCCESS);
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildUnstableVerifiedValue()).thenReturn(1);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.UNSTABLE)).thenReturn(1);
entries[1] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.UNSTABLE);
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildUnstableVerifiedValue()).thenReturn(-1);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.UNSTABLE)).thenReturn(-1);
entries[2] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.UNSTABLE);
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildNotBuiltVerifiedValue()).thenReturn(-4);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.NOT_BUILT)).thenReturn(-4);
entries[3] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.NOT_BUILT);
when(memoryImprint.getEntries()).thenReturn(entries);
// When not all results are NOT_BUILT, we should ignore NOT_BUILT.
int expResult = -1;
- int result = instance.getMinimumVerifiedValue(memoryImprint, true, Integer.MAX_VALUE);
+ int result = instance.getMinimumLabelVoteValue(memoryImprint, true, VERIFIED_LABEL);
assertEquals(expResult, result);
// Otherwise, we should use NOT_BUILT.
expResult = -4;
- result = instance.getMinimumVerifiedValue(memoryImprint, false, Integer.MAX_VALUE);
+ result = instance.getMinimumLabelVoteValue(memoryImprint, false, VERIFIED_LABEL);
assertEquals(expResult, result);
}
@@ -199,35 +202,35 @@ public void testGetMinimumCodeReviewValue() {
MemoryImprint.Entry[] entries = new MemoryImprint.Entry[4];
GerritTrigger trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(3);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(3);
entries[0] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.SUCCESS);
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildUnstableCodeReviewValue()).thenReturn(1);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.UNSTABLE)).thenReturn(1);
entries[1] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.UNSTABLE);
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildUnstableCodeReviewValue()).thenReturn(-1);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.UNSTABLE)).thenReturn(-1);
entries[2] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.UNSTABLE);
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildNotBuiltCodeReviewValue()).thenReturn(-4);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.NOT_BUILT)).thenReturn(-4);
entries[3] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.NOT_BUILT);
when(memoryImprint.getEntries()).thenReturn(entries);
// When not all results are NOT_BUILT, we should ignore NOT_BUILT.
- Integer result = instance.getMinimumCodeReviewValue(memoryImprint, true);
+ Integer result = instance.getMinimumLabelVoteValue(memoryImprint, true, CODE_REVIEW_LABEL);
assertEquals(Integer.valueOf(-1), result);
// Otherwise, we should use NOT_BUILT.
- result = instance.getMinimumCodeReviewValue(memoryImprint, false);
+ result = instance.getMinimumLabelVoteValue(memoryImprint, false, CODE_REVIEW_LABEL);
assertEquals(Integer.valueOf(-4), result);
}
/**
- * Tests {@link ParameterExpander#getMinimumCodeReviewValue(MemoryImprint, boolean)} with one
- * unstable build vote skipped.
+ * Tests {@link ParameterExpander#getMinimumLabelVoteValue(MemoryImprint, boolean, String)} with one
+ * unstable build vote skipped for Code-Review label.
*
* @see com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger#getSkipVote()
*/
@@ -240,29 +243,29 @@ public void testGetMinimumCodeReviewValueOneUnstableSkipped() {
MemoryImprint.Entry[] entries = new MemoryImprint.Entry[3];
GerritTrigger trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(1);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(1);
entries[0] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.SUCCESS);
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildUnstableCodeReviewValue()).thenReturn(-1);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.UNSTABLE)).thenReturn(-1);
SkipVote skipVote = new SkipVote(false, false, true, false, false);
when(trigger.getSkipVote()).thenReturn(skipVote);
entries[1] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.UNSTABLE);
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(2);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(2);
entries[2] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.SUCCESS);
when(memoryImprint.getEntries()).thenReturn(entries);
- Integer result = instance.getMinimumCodeReviewValue(memoryImprint, true);
+ Integer result = instance.getMinimumLabelVoteValue(memoryImprint, true, CODE_REVIEW_LABEL);
assertEquals(Integer.valueOf(1), result);
}
/**
- * Tests {@link ParameterExpander#getMinimumCodeReviewValue(MemoryImprint, boolean)} with one
- * successful build vote skipped.
+ * Tests {@link ParameterExpander#getMinimumLabelVoteValue(MemoryImprint, boolean, String)} with one
+ * successful build vote skipped for Code-Review label.
*
* @see com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger#getSkipVote()
*/
@@ -275,20 +278,20 @@ public void testGetMinimumCodeReviewValueOneSuccessfulSkipped() {
MemoryImprint.Entry[] entries = new MemoryImprint.Entry[1];
GerritTrigger trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(1);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(1);
SkipVote skipVote = new SkipVote(true, false, false, false, false);
when(trigger.getSkipVote()).thenReturn(skipVote);
entries[0] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.SUCCESS);
when(memoryImprint.getEntries()).thenReturn(entries);
- Integer result = instance.getMinimumCodeReviewValue(memoryImprint, true);
+ Integer result = instance.getMinimumLabelVoteValue(memoryImprint, true, CODE_REVIEW_LABEL);
assertNull(result);
}
/**
- * Tests {@link ParameterExpander#getMinimumCodeReviewValue(MemoryImprint, boolean)} with one
- * job that has override core review value on build successful.
+ * Tests {@link ParameterExpander#getMinimumLabelVoteValue(MemoryImprint, boolean, String)} with one
+ * job that has override core review value on build successful for Code-Review label.
*
* @see com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger#getSkipVote()
*/
@@ -301,24 +304,24 @@ public void testGetMinimumCodeReviewValueForOneJobOverridenBuildSuccessful() {
MemoryImprint.Entry[] entries = new MemoryImprint.Entry[2];
GerritTrigger trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(null);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(null);
entries[0] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.SUCCESS);
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(Integer.valueOf(2));
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(Integer.valueOf(2));
entries[1] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.SUCCESS);
when(memoryImprint.getEntries()).thenReturn(entries);
// Since one job has overriden CR value, it is the only one inspected
// and therefore the only one that contributes.
- Integer result = instance.getMinimumCodeReviewValue(memoryImprint, false);
+ Integer result = instance.getMinimumLabelVoteValue(memoryImprint, false, CODE_REVIEW_LABEL);
assertEquals(Integer.valueOf(2), result);
}
/**
- * Tests {@link ParameterExpander#getMinimumCodeReviewValue(MemoryImprint, boolean)} with one
- * job that has override core review value on build successful.
+ * Tests {@link ParameterExpander#getMinimumLabelVoteValue(MemoryImprint, boolean, String)} with one
+ * job that has override core review value on build successful for Code-Review label.
*
* @see com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger#getSkipVote()
*/
@@ -331,24 +334,24 @@ public void testGetMinimumCodeReviewValueForOneJobOverridenBuildFailed() {
MemoryImprint.Entry[] entries = new MemoryImprint.Entry[2];
GerritTrigger trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildFailedCodeReviewValue()).thenReturn(null);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.FAILED)).thenReturn(null);
entries[0] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.FAILURE);
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildFailedCodeReviewValue()).thenReturn(Integer.valueOf(-2));
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.FAILED)).thenReturn(Integer.valueOf(-2));
entries[1] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.FAILURE);
when(memoryImprint.getEntries()).thenReturn(entries);
// Since one job has overriden CR value, it is the only one inspected
// and therefore the only one that contributes.
- Integer result = instance.getMinimumCodeReviewValue(memoryImprint, false);
+ Integer result = instance.getMinimumLabelVoteValue(memoryImprint, false, CODE_REVIEW_LABEL);
assertEquals(Integer.valueOf(-2), result);
}
/**
- * Tests {@link ParameterExpander#getMinimumCodeReviewValue(MemoryImprint, boolean)} with one
- * job that has override core review value on build successful.
+ * Tests {@link ParameterExpander#getMinimumLabelVoteValue(MemoryImprint, boolean, String)} with one
+ * job that has override core review value on build successful for Code-Review label.
*
* @see com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger#getSkipVote()
*/
@@ -361,50 +364,21 @@ public void testGetMinimumCodeReviewValueForOneJobOverridenMixed() {
MemoryImprint.Entry[] entries = new MemoryImprint.Entry[2];
GerritTrigger trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildFailedCodeReviewValue()).thenReturn(null);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.FAILED)).thenReturn(null);
entries[0] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.FAILURE);
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(Integer.valueOf(2));
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(Integer.valueOf(2));
entries[1] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.SUCCESS);
when(memoryImprint.getEntries()).thenReturn(entries);
// Since one job has overriden CR value, it is the only one inspected
// and therefore the only one that contributes.
- Integer result = instance.getMinimumCodeReviewValue(memoryImprint, false);
+ Integer result = instance.getMinimumLabelVoteValue(memoryImprint, false, CODE_REVIEW_LABEL);
assertEquals(Integer.valueOf(2), result);
}
- /**
- * Tests {@link ParameterExpander#getMinimumVerifiedValue(MemoryImprint, boolean, Integer)} with two
- * jobs. One successful build, the other failed missing build (null).
- *
- */
- @Test
- public void testGetVerifiedValueOneSuccessJobAndMissingFailedJob() {
- IGerritHudsonTriggerConfig config = Setup.createConfigWithCodeReviewsNull();
-
- ParameterExpander instance = new ParameterExpander(config, jenkins);
- MemoryImprint memoryImprint = mock(MemoryImprint.class);
- MemoryImprint.Entry[] entries = new MemoryImprint.Entry[2];
-
- GerritTrigger trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildFailedVerifiedValue()).thenReturn(Integer.valueOf(2));
- entries[0] = Setup.createAndSetupMemoryImprintEntry(trigger, Result.SUCCESS);
-
- trigger = mock(GerritTrigger.class);
- entries[1] = Setup.createAndSetupMemoryImprintEntryWithEmptyBuild(trigger);
-
- when(memoryImprint.getEntries()).thenReturn(entries);
-
- // The only verified value available is of successful build,
- // but score should be saturated to Failed verified value from config.
- Integer result = instance.getMinimumVerifiedValue(memoryImprint, false,
- config.getGerritBuildFailedVerifiedValue());
- assertEquals(Integer.valueOf(config.getGerritBuildFailedVerifiedValue()), result);
- }
-
/**
* test.
* @throws IOException IOException
@@ -428,8 +402,13 @@ public void testGetBuildCompletedCommandSuccessful() throws IOException, Interru
@Test
public void testGetBuildCompletedCommandNotBuilt() throws IOException, InterruptedException {
tryGetBuildCompletedCommandEventWithResults("", new String[] {},
- new Result[] {Result.NOT_BUILT}, Setup.createPatchsetCreated(),
- null, null, "NONE", false);
+ new Result[] {Result.NOT_BUILT},
+ Setup.createPatchsetCreated(),
+ not(containsStrings("--verified")),
+ not(containsStrings("--code-review")),
+ not(containsStrings("--custom-label")),
+ "NONE",
+ false);
}
/**
@@ -493,7 +472,10 @@ public void testGetBuildCompletedCommandMulipleBuildsMessageOrder() throws IOExc
"\n\nhttp://localhost/test/ : UNSTABLE",
"\n\nhttp://localhost/test/ : SUCCESS", },
new Result[] {Result.SUCCESS, Result.FAILURE, Result.UNSTABLE},
- Setup.createPatchsetCreated(), -1, 0);
+ Setup.createPatchsetCreated(),
+ containsString("--verified -1"),
+ containsStrings("--code-review 0"),
+ containsStrings("--custom-label 0"));
}
/**
@@ -503,8 +485,8 @@ public void testGetBuildCompletedCommandMulipleBuildsMessageOrder() throws IOExc
@Test
public void testGetBuildCompletedMissingFailedBuild() throws IOException, InterruptedException {
int buildResults = 2;
- IGerritHudsonTriggerConfig config = Setup.createConfig();
- Integer expectedVerifiedVote = config.getGerritBuildFailedVerifiedValue();
+ IGerritHudsonTriggerConfig config = Setup.createMockableConfig();
+ Integer expectedVerifiedVote = config.getLabelVote(VERIFIED_LABEL, BuildStatus.FAILED);
PatchsetCreated event = Setup.createPatchsetCreated();
TaskListener taskListener = mock(TaskListener.class);
@@ -528,7 +510,7 @@ public void testGetBuildCompletedMissingFailedBuild() throws IOException, Interr
ParameterExpander instance = new ParameterExpander(config, jenkins);
String result = instance.getBuildCompletedCommand(memoryImprint, taskListener, null);
- assertThat("Missing VERIFIED", result, containsString("VERIFIED=" + expectedVerifiedVote));
+ assertThat("Missing VERIFIED", result, containsString("--verified " + expectedVerifiedVote));
}
/**
@@ -541,7 +523,11 @@ public void testGetBuildCompletedMissingFailedBuild() throws IOException, Interr
*/
public void tryGetBuildCompletedCommandSuccessful(String customUrl, String expectedBuildsStats)
throws IOException, InterruptedException {
- tryGetBuildCompletedCommandSuccessfulEvent(customUrl, expectedBuildsStats, Setup.createPatchsetCreated(), 3, 32);
+ tryGetBuildCompletedCommandSuccessfulEvent(customUrl,
+ expectedBuildsStats,
+ Setup.createPatchsetCreated(),
+ containsString("--verified 3"),
+ containsStrings("--code-review 32"));
}
/**
@@ -599,10 +585,13 @@ public void tryGetBuildCompletedCommandSuccessfulChangeRestored(String customUrl
* @throws InterruptedException if so.
*/
public void tryGetBuildCompletedCommandSuccessfulEvent(String customUrl, String expectedBuildsStats,
- GerritTriggeredEvent event, Integer expectedVerifiedVote, Integer expectedCodeReviewVote)
+ GerritTriggeredEvent event, Matcher expectedVerifiedVote, Matcher expectedCodeReviewVote)
throws IOException, InterruptedException {
tryGetBuildCompletedCommandEventWithResults(customUrl, new String[] {expectedBuildsStats},
- new Result[] {Result.SUCCESS}, Setup.createChangeRestored(), null, null);
+ new Result[] {Result.SUCCESS}, Setup.createChangeRestored(),
+ not(containsStrings("--verified")),
+ not(containsStrings("--code-review")),
+ not(containsStrings("--custom-label")));
}
/**
@@ -622,13 +611,76 @@ public void tryGetBuildCompletedCommandSuccessfulEvent(String customUrl, String
*/
public void tryGetBuildCompletedCommandEventWithResults(String customUrl, String[] expectedBuildsStats,
Result[] expectedBuildResults, GerritTriggeredEvent event,
- Integer expectedVerifiedVote, Integer expectedCodeReviewVote)
- throws IOException, InterruptedException {
+ Matcher expectedVerifiedVote,
+ Matcher expectedCodeReviewVote,
+ Matcher expectedCustomLabelVote) throws IOException, InterruptedException {
tryGetBuildCompletedCommandEventWithResults(customUrl, expectedBuildsStats,
- expectedBuildResults, event, expectedVerifiedVote, expectedCodeReviewVote,
+ expectedBuildResults, event, expectedVerifiedVote, expectedCodeReviewVote, expectedCustomLabelVote,
"ALL", true);
}
+ private static Stream gerritCommandsWithVariousConfigsCases() {
+ return Stream.of(
+ Arguments.of(-1, 2, 3, Setup.createChangeMerged(), Result.SUCCESS,
+ not(containsStrings("--verified")),
+ not(containsString("--code-review")),
+ not(containsString("--custom-label"))),
+ Arguments.of(null, 2, 3, Setup.createPatchsetCreated(), Result.SUCCESS,
+ containsStrings("--verified 3"),
+ containsStrings("--code-review 2"),
+ containsStrings("--custom-label 3")),
+ Arguments.of(null, null, 3, Setup.createPatchsetCreated(), Result.SUCCESS,
+ containsStrings("--verified 3"),
+ containsStrings("--code-review 4"),
+ containsStrings("--custom-label 3")),
+ Arguments.of(null, null, null, Setup.createPatchsetCreated(), Result.SUCCESS,
+ containsStrings("--verified 3"),
+ containsStrings("--code-review 4"),
+ containsStrings("--custom-label 0"))
+ );
+ }
+
+ @ParameterizedTest
+ @MethodSource("gerritCommandsWithVariousConfigsCases")
+ public void testGerritCommandsWithVariousConfigs(
+ Integer givenVerifiedVote,
+ Integer givenCodeReviewVote,
+ Integer givenCustomLabelVote,
+ GerritTriggeredEvent event,
+ Result givenBuildResult,
+ Matcher expectedCodeReviewVote,
+ Matcher expectedVerifiedVote,
+ Matcher expectedCustomLabelVote) throws IOException, InterruptedException {
+
+ IGerritHudsonTriggerConfig config = Setup.createMockableConfig();
+ TaskListener taskListener = mock(TaskListener.class);
+
+ GerritTrigger trigger = mock(GerritTrigger.class);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(givenVerifiedVote);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(givenCodeReviewVote);
+ when(trigger.getLabelVote("Custom-Label", BuildStatus.SUCCESSFUL)).thenReturn(givenCustomLabelVote);
+ when(trigger.getCustomUrl()).thenReturn("");
+ AbstractProject project = mock(AbstractProject.class);
+ Setup.setTrigger(trigger, project);
+
+ EnvVars envVars = Setup.createEnvVars();
+ AbstractBuild build = Setup.createBuild(project, taskListener, envVars);
+ when(build.getResult()).thenReturn(givenBuildResult);
+ MemoryImprint.Entry entry = Setup.createImprintEntry(project, build);
+
+ MemoryImprint memoryImprint = mock(MemoryImprint.class);
+ when(memoryImprint.getEvent()).thenReturn(event);
+ when(memoryImprint.getEntries()).thenReturn(new MemoryImprint.Entry[] {entry});
+ when(memoryImprint.wereAllBuildsSuccessful()).thenReturn(true);
+
+ ParameterExpander instance = new ParameterExpander(config, jenkins);
+ String result = instance.getBuildCompletedCommand(memoryImprint, taskListener, null);
+
+ assertThat("Incorrect Verified vote value", result, expectedVerifiedVote);
+ assertThat("Incorrect Code-Review vote value", result, expectedCodeReviewVote);
+ assertThat("Incorrect Custom label vote value", result, expectedCustomLabelVote);
+ }
+
/**
* Sub test for {@link #testGetBuildCompletedCommandSuccessful()} and
* {@link #testGetBuildCompletedCommandSuccessfulChangeMerged()}.
@@ -646,8 +698,10 @@ public void tryGetBuildCompletedCommandEventWithResults(String customUrl, String
*/
public void tryGetBuildCompletedCommandEventWithResults(String customUrl, String[] expectedBuildsStats,
Result[] expectedBuildResults, GerritTriggeredEvent event,
- Integer expectedVerifiedVote, Integer expectedCodeReviewVote, String expectedNotificationLevel,
- boolean createBuild)
+ Matcher expectedVerifiedVote,
+ Matcher expectedCodeReviewVote,
+ Matcher expectedCustomLabelVote,
+ String expectedNotificationLevel, boolean createBuild)
throws IOException, InterruptedException {
IGerritHudsonTriggerConfig config = Setup.createConfig();
@@ -656,8 +710,9 @@ public void tryGetBuildCompletedCommandEventWithResults(String customUrl, String
TaskListener taskListener = mock(TaskListener.class);
GerritTrigger trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildSuccessfulVerifiedValue()).thenReturn(null);
- when(trigger.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(32);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(null);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(32);
+ when(trigger.getLabelVote("Custom-Label", BuildStatus.SUCCESSFUL)).thenReturn(2);
when(trigger.getCustomUrl()).thenReturn(customUrl);
AbstractProject project = mock(AbstractProject.class);
Setup.setTrigger(trigger, project);
@@ -717,8 +772,9 @@ public void tryGetBuildCompletedCommandEventWithResults(String customUrl, String
assertThat("Missing ENV_CHANGEURL", result, containsString("ENV_CHANGEURL=http://gerrit/1000"));
assertThat("Missing CUSTOM_MESSAGES", result, containsString("CUSTOM_MESSAGE_BUILD_COMPLETED"));
}
- assertThat("Missing VERIFIED", result, containsString("VERIFIED=" + expectedVerifiedVote));
- assertThat("Missing CODEREVIEW", result, containsString("CODEREVIEW=" + expectedCodeReviewVote));
+ assertThat("Missing VERIFIED", result, expectedVerifiedVote);
+ assertThat("Missing CODEREVIEW", result, expectedCodeReviewVote);
+ assertThat("Missing CUSTOMLABEL", result, expectedCustomLabelVote);
}
}
@@ -749,8 +805,8 @@ public void tryBuildStatsFailureCommand(String unsuccessfulMessage, String expec
TaskListener taskListener = mock(TaskListener.class);
GerritTrigger trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildSuccessfulVerifiedValue()).thenReturn(null);
- when(trigger.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(32);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(null);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(32);
AbstractProject project = mock(AbstractProject.class);
Setup.setTrigger(trigger, project);
@@ -811,7 +867,7 @@ public void getBuildStatsFailureCommandWithNullsForCodeReviewValues() throws Exc
GerritTrigger trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildFailedCodeReviewValue()).thenReturn(null);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.FAILED)).thenReturn(null);
AbstractProject project = mock(AbstractProject.class);
Setup.setTrigger(trigger, project);
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/job/rest/BuildCompletedRestCommandJobHudsonTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/job/rest/BuildCompletedRestCommandJobHudsonTest.java
index 92b95fb72..8add4d1f9 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/job/rest/BuildCompletedRestCommandJobHudsonTest.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/job/rest/BuildCompletedRestCommandJobHudsonTest.java
@@ -26,7 +26,9 @@
import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer;
import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.BuildStatus;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Config;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.CompareType;
@@ -53,6 +55,8 @@
import java.io.PrintWriter;
import java.util.Collections;
+import static com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants.CODE_REVIEW_LABEL;
+import static com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants.VERIFIED_LABEL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -107,8 +111,8 @@ private void runTest() throws Exception {
null, null, null, false)
));
trigger.setSilentMode(false);
- trigger.setGerritBuildSuccessfulCodeReviewValue(1);
- trigger.setGerritBuildSuccessfulVerifiedValue(1);
+ trigger.setLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL, 1);
+ trigger.setLabelVote(VERIFIED_LABEL, BuildStatus.SUCCESSFUL, 1);
PluginImpl.getInstance().getHandler().post(event);
@@ -129,8 +133,8 @@ private void runTest() throws Exception {
j.assertStringContains(json.getString("message"), "Build Successful");
JSONObject labels = json.getJSONObject("labels");
- assertEquals(1, labels.getInt("Code-Review"));
- assertEquals(1, labels.getInt("Verified"));
+ assertEquals(1, labels.getInt(CODE_REVIEW_LABEL));
+ assertEquals(1, labels.getInt(Constants.VERIFIED_LABEL));
}
/**
* The test with a locked down instance.
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/WorkflowTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/WorkflowTest.java
index 0a44fa527..03e8a27c0 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/WorkflowTest.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/WorkflowTest.java
@@ -25,7 +25,9 @@
import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer;
import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.BuildStatus;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Config;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.CompareType;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject;
@@ -52,6 +54,8 @@
import java.io.PrintWriter;
import java.util.Collections;
+import static com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants.CODE_REVIEW_LABEL;
+import static com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants.VERIFIED_LABEL;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.beans.HasPropertyWithValue.hasProperty;
import static org.hamcrest.core.AllOf.allOf;
@@ -105,7 +109,7 @@ public void testTriggerWorkflow() throws Exception {
Assert.assertTrue(message.startsWith("Build Successful"));
Assert.assertTrue(message.contains("job/WFJob/1/"));
JSONObject labels = verifiedMessage.getJSONObject("labels");
- assertEquals(1, labels.getInt("Verified"));
+ assertEquals(1, labels.getInt(Constants.VERIFIED_LABEL));
} finally {
gerritServer.stop();
}
@@ -145,7 +149,7 @@ public void testWorkflowStepSetsCustomUrl() throws Exception {
Assert.assertTrue(message.startsWith("Build Successful"));
Assert.assertTrue(message.contains("myCustomUrl"));
JSONObject labels = verifiedMessage.getJSONObject("labels");
- assertEquals(1, labels.getInt("Verified"));
+ assertEquals(1, labels.getInt(Constants.VERIFIED_LABEL));
} finally {
gerritServer.stop();
}
@@ -187,7 +191,7 @@ public void testWorkflowStepSetsUnsuccessfulMessage() throws Exception {
Assert.assertTrue(message.startsWith("Build Failed"));
Assert.assertTrue(message.contains("myMessage"));
JSONObject labels = verifiedMessage.getJSONObject("labels");
- assertEquals(0, labels.getInt("Verified"));
+ assertEquals(0, labels.getInt(Constants.VERIFIED_LABEL));
} finally {
gerritServer.stop();
}
@@ -228,37 +232,12 @@ public void testWorkflowStepSetsUnsuccessfulMessageWithSuccessfulBuild() throws
Assert.assertTrue(message.startsWith("Build Successful"));
Assert.assertFalse(message.contains("myMessage"));
JSONObject labels = verifiedMessage.getJSONObject("labels");
- assertEquals(1, labels.getInt("Verified"));
+ assertEquals(1, labels.getInt(Constants.VERIFIED_LABEL));
} finally {
gerritServer.stop();
}
}
- /**
- * Tests a {@link JenkinsRule#configRoundtrip(hudson.model.Job)} on the workflow job.
- *
- * @throws Exception if so.
- */
- @Test
- public void testConfigRoundTrip() throws Exception {
- PatchsetCreated event = Setup.createPatchsetCreated(PluginImpl.DEFAULT_SERVER_NAME);
- WorkflowJob job = createWorkflowJob(event);
- jenkinsRule.configRoundtrip(job);
- job = (WorkflowJob)jenkinsRule.jenkins.getItem("WFJob");
- GerritTrigger trigger = GerritTrigger.getTrigger(job);
- assertFalse(trigger.isSilentMode());
- assertEquals(1, trigger.getGerritBuildSuccessfulCodeReviewValue().intValue());
- assertEquals(1, trigger.getGerritBuildSuccessfulVerifiedValue().intValue());
- assertEquals(0, trigger.getGerritBuildFailedCodeReviewValue().intValue());
- assertThat(trigger.getGerritProjects(), hasItem(
- allOf(
- instanceOf(GerritProject.class),
- hasProperty("compareType", is(CompareType.PLAIN)),
- hasProperty("pattern", equalTo(event.getChange().getProject()))
- )
- ));
- }
-
/**
* Creates a {@link WorkflowJob} with a configured {@link GerritTrigger}.
*
@@ -274,6 +253,39 @@ private WorkflowJob createWorkflowJob(PatchsetCreated event) throws IOException
+ "}}\n");
}
+ /**
+ * Tests a {@link JenkinsRule#configRoundtrip(hudson.model.Job)} on the workflow job.
+ *
+ * @throws Exception if so.
+ */
+ @Test
+ public void testConfigRoundTrip() throws Exception {
+ MockGerritServer gerritServer = MockGerritServer.get(jenkinsRule);
+
+ gerritServer.start();
+ try {
+ PatchsetCreated event = Setup.createPatchsetCreated(gerritServer.getName());
+ WorkflowJob job = createWorkflowJob(event);
+ jenkinsRule.configRoundtrip(job);
+ job = (WorkflowJob)jenkinsRule.jenkins.getItem("WFJob");
+ GerritTrigger trigger = GerritTrigger.getTrigger(job);
+ assertFalse(trigger.isSilentMode());
+ assertEquals(1, trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL).intValue());
+ assertEquals(1, trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.SUCCESSFUL).intValue());
+ assertEquals(0, trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.FAILED).intValue());
+ assertThat(trigger.getGerritProjects(), hasItem(
+ allOf(
+ instanceOf(GerritProject.class),
+ hasProperty("compareType", is(CompareType.PLAIN)),
+ hasProperty("pattern", equalTo(event.getChange().getProject()))
+ )
+ ));
+ }
+ finally {
+ gerritServer.stop();
+ }
+ }
+
/**
* Creates a {@link WorkflowJob} with a configured {@link GerritTrigger} and given workflow DSL script.
*
@@ -293,8 +305,8 @@ private WorkflowJob createWorkflowJob(PatchsetCreated event, String script) thro
null, null, null, false)
));
trigger.setSilentMode(false);
- trigger.setGerritBuildSuccessfulCodeReviewValue(1);
- trigger.setGerritBuildSuccessfulVerifiedValue(1);
+ trigger.setLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL, 1);
+ trigger.setLabelVote(VERIFIED_LABEL, BuildStatus.SUCCESSFUL, 1);
return job;
}
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/actions/manual/ManualTriggerActionTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/actions/manual/ManualTriggerActionTest.java
index 49363a585..35c55ca41 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/actions/manual/ManualTriggerActionTest.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/actions/manual/ManualTriggerActionTest.java
@@ -29,6 +29,7 @@
import static org.mockito.Mockito.any;
import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer;
import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import com.sonyericsson.hudson.plugins.gerrit.trigger.mock.Setup;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@@ -66,19 +67,19 @@ public void testGetCodeReview() throws Exception {
JSONArray approvals = new JSONArray();
JSONObject crw = new JSONObject();
- crw.put("type", "Code-Review");
+ crw.put("type", Constants.CODE_REVIEW_LABEL);
crw.put("value", "2");
approvals.add(crw);
crw = new JSONObject();
- crw.put("type", "Code-Review");
+ crw.put("type", Constants.CODE_REVIEW_LABEL);
crw.put("value", "1");
approvals.add(crw);
crw = new JSONObject();
- crw.put("type", "Verified");
+ crw.put("type", Constants.VERIFIED_LABEL);
crw.put("value", "1");
approvals.add(crw);
crw = new JSONObject();
- crw.put("type", "Code-Review");
+ crw.put("type", Constants.CODE_REVIEW_LABEL);
crw.put("value", "-1");
approvals.add(crw);
currentPatchSet.put("approvals", approvals);
@@ -128,19 +129,19 @@ public void testGetVerified() throws Exception {
JSONArray approvals = new JSONArray();
JSONObject crw = new JSONObject();
- crw.put("type", "Verified");
+ crw.put("type", Constants.VERIFIED_LABEL);
crw.put("value", "2");
approvals.add(crw);
crw = new JSONObject();
- crw.put("type", "Verified");
+ crw.put("type", Constants.VERIFIED_LABEL);
crw.put("value", "1");
approvals.add(crw);
crw = new JSONObject();
- crw.put("type", "Code-Review");
+ crw.put("type", Constants.CODE_REVIEW_LABEL);
crw.put("value", "1");
approvals.add(crw);
crw = new JSONObject();
- crw.put("type", "Verified");
+ crw.put("type", Constants.VERIFIED_LABEL);
crw.put("value", "-1");
approvals.add(crw);
currentPatchSet.put("approvals", approvals);
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/DuplicatesUtil.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/DuplicatesUtil.java
index a4643e305..965371251 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/DuplicatesUtil.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/DuplicatesUtil.java
@@ -24,6 +24,7 @@
package com.sonyericsson.hudson.plugins.gerrit.trigger.mock;
import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.CompareType;
@@ -158,7 +159,7 @@ public static FreeStyleProject createGerritTriggeredJobForCommentAdded(JenkinsRu
List projects = new LinkedList();
projects.add(new GerritProject(CompareType.ANT, "**",
Collections.singletonList(new Branch(CompareType.ANT, "**")), null, null, null, false));
- PluginCommentAddedEvent event = new PluginCommentAddedEvent("Code-Review", "1");
+ PluginCommentAddedEvent event = new PluginCommentAddedEvent(Constants.CODE_REVIEW_LABEL, "1");
List list = new LinkedList();
list.add(event);
p.addTrigger(new GerritTrigger(projects, null,
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/MockGerritHudsonTriggerConfig.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/MockGerritHudsonTriggerConfig.java
index f36bf1d8b..b685c9e02 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/MockGerritHudsonTriggerConfig.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/MockGerritHudsonTriggerConfig.java
@@ -24,6 +24,7 @@
package com.sonyericsson.hudson.plugins.gerrit.trigger.mock;
import com.sonyericsson.hudson.plugins.gerrit.trigger.VerdictCategory;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.BuildStatus;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Config;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.IGerritHudsonTriggerConfig;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.ReplicationConfig;
@@ -43,6 +44,9 @@
import org.apache.http.auth.Credentials;
+import static com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants.CODE_REVIEW_LABEL;
+import static com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants.VERIFIED_LABEL;
+
/**
* Mock class of a Config.
* @author Robert Sandell <robert.sandell@sonyericsson.com>
@@ -55,8 +59,9 @@ public String getGerritCmdBuildStarted() {
return "CHANGE="
+ " CHANGE_ID="
+ " PATCHSET="
- + " VERIFIED="
- + " CODEREVIEW="
+ + " --verified "
+ + " --code-review "
+ + " --custom-label "
+ " NOTIFICATION_LEVEL="
+ " REFSPEC= MSG=I started a build."
+ " BUILDURL="
@@ -74,8 +79,9 @@ public String getGerritCmdBuildSuccessful() {
return "CHANGE="
+ " CHANGE_ID="
+ " PATCHSET="
- + " VERIFIED="
- + " CODEREVIEW="
+ + " --verified "
+ + " --code-review "
+ + " --custom-label "
+ " NOTIFICATION_LEVEL="
+ " REFSPEC= MSG='Build Successful '"
+ " BUILDURL="
@@ -92,8 +98,9 @@ public String getGerritCmdBuildFailed() {
return "CHANGE="
+ " CHANGE_ID="
+ " PATCHSET="
- + " VERIFIED=-1"
- + " CODEREVIEW="
+ + " --verified -1"
+ + " --code-review "
+ + " --custom-label "
+ " NOTIFICATION_LEVEL="
+ " REFSPEC= MSG='Build Failed '"
+ " BUILDURL="
@@ -110,8 +117,9 @@ public String getGerritCmdBuildUnstable() {
return "CHANGE="
+ " CHANGE_ID="
+ " PATCHSET="
- + " VERIFIED="
- + " CODEREVIEW="
+ + " --verified "
+ + " --code-review "
+ + " --custom-label "
+ " NOTIFICATION_LEVEL="
+ " REFSPEC= MSG='The build is Unstable. BS='"
+ " BUILDURL="
@@ -129,8 +137,9 @@ public String getGerritCmdBuildNotBuilt() {
return "CHANGE="
+ " CHANGE_ID="
+ " PATCHSET="
- + " VERIFIED="
- + " CODEREVIEW="
+ + " --verified "
+ + " --code-review "
+ + " --custom-label "
+ " NOTIFICATION_LEVEL="
+ " REFSPEC="
+ " MSG='No Builds Executed '";
@@ -141,8 +150,9 @@ public String getGerritCmdBuildAborted() {
return "CHANGE="
+ " CHANGE_ID="
+ " PATCHSET="
- + " VERIFIED=-1"
- + " CODEREVIEW="
+ + " --verified -1"
+ + " --code-review "
+ + " --custom-label "
+ " NOTIFICATION_LEVEL="
+ " REFSPEC= MSG='The build was Aborted. BS='"
+ " BUILDURL="
@@ -169,6 +179,11 @@ public Secret getGerritAuthKeyFileSecretPassword() {
return Secret.decrypt("{Secret}");
}
+ @Override
+ public Integer getLabelVote(String label, BuildStatus status) {
+ return null;
+ }
+
@Override
public String getGerritFrontEndUrl() {
return "http://gerrit/";
@@ -402,7 +417,15 @@ public String getGerritFrontEndUrlFor(GerritTriggeredEvent event) {
@Override
public List getCategories() {
- return new LinkedList();
+ VerdictCategory verdictCategory = new VerdictCategory("Custom-Label",
+ "Custom-Label", -1,-2,-3,-4,-5,-6);
+ return new LinkedList<>() {
+ {
+ add(new VerdictCategory(VERIFIED_LABEL, VERIFIED_LABEL, 1, 2, 3, 4, 5, 6));
+ add(new VerdictCategory(CODE_REVIEW_LABEL, CODE_REVIEW_LABEL, -1, -2, -3, -4, -5, -6));
+ add(verdictCategory);
+ }
+ };
}
@Override
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/Setup.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/Setup.java
index e53a08f8f..53d5c5e0c 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/Setup.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/Setup.java
@@ -23,6 +23,9 @@
*/
package com.sonyericsson.hudson.plugins.gerrit.trigger.mock;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.BuildStatus;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.IGerritHudsonTriggerConfig;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerDescriptor;
import com.sonymobile.tools.gerrit.gerritevents.dto.attr.Account;
import com.sonymobile.tools.gerrit.gerritevents.dto.attr.Approval;
@@ -64,6 +67,7 @@
import hudson.model.Job;
import hudson.model.Result;
import hudson.model.TaskListener;
+import hudson.os.SU;
import hudson.security.SecurityRealm;
import hudson.triggers.Trigger;
import hudson.triggers.TriggerDescriptor;
@@ -84,6 +88,8 @@
import java.util.LinkedList;
import java.util.List;
+import static com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants.CODE_REVIEW_LABEL;
+import static com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants.VERIFIED_LABEL;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -126,6 +132,73 @@ public static MockGerritHudsonTriggerConfig createConfig() {
return new MockGerritHudsonTriggerConfig();
}
+ /**
+ * Gives you a mocked Config that can be furthered configured
+ * @return IGerritHudsonTriggerConfig mock
+ */
+ public static IGerritHudsonTriggerConfig createMockableConfig() {
+ IGerritHudsonTriggerConfig config = mock(IGerritHudsonTriggerConfig.class);
+ when(config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.STARTED)).thenReturn(2);
+ when(config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(4);
+ when(config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.FAILED)).thenReturn(-2);
+ when(config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.UNSTABLE)).thenReturn(-4);
+ when(config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.NOT_BUILT)).thenReturn(-6);
+ when(config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.ABORTED)).thenReturn(3);
+
+ when(config.getLabelVote(VERIFIED_LABEL, BuildStatus.STARTED)).thenReturn(1);
+ when(config.getLabelVote(VERIFIED_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(3);
+ when(config.getLabelVote(VERIFIED_LABEL, BuildStatus.FAILED)).thenReturn(-1);
+ when(config.getLabelVote(VERIFIED_LABEL, BuildStatus.UNSTABLE)).thenReturn(-3);
+ when(config.getLabelVote(VERIFIED_LABEL, BuildStatus.NOT_BUILT)).thenReturn(-5);
+ when(config.getLabelVote(VERIFIED_LABEL, BuildStatus.ABORTED)).thenReturn(-2);
+
+ when(config.getGerritCmdBuildFailed()).thenReturn(Constants.GERRIT_CMD_BUILD_FAILED_DEFAULT_VALUE +
+ " --custom-label " +
+ " change-id " +
+ " notification-level " +
+ " refspec " +
+ " ENV_BRANCH $BRANCH" +
+ " ENV_CHANGE $CHANGE" +
+ " ENV_PATCHSET $PATCHSET" +
+ " ENV_REFSPEC $REFSPEC" +
+ " ENV_CHANGEURL $CHANGE_URL" +
+ " Message\nwith newline");
+ when(config.getGerritCmdBuildStarted()).thenReturn(Constants.GERRIT_CMD_BUILD_STARTED_DEFAULT_VALUE +
+ " --custom-label " +
+ " change-id " +
+ " notification-level " +
+ " refspec " +
+ " ENV_BRANCH $BRANCH" +
+ " ENV_CHANGE $CHANGE" +
+ " ENV_PATCHSET $PATCHSET" +
+ " ENV_REFSPEC $REFSPEC" +
+ " ENV_CHANGEURL $CHANGE_URL" +
+ " Message\nwith newline");
+ when(config.getGerritCmdBuildSuccessful()).thenReturn(Constants.GERRIT_CMD_BUILD_SUCCESSFUL_DEFAULT_VALUE +
+ " --custom-label " +
+ " change-id " +
+ " notification-level " +
+ " refspec " +
+ " ENV_BRANCH $BRANCH" +
+ " ENV_CHANGE $CHANGE" +
+ " ENV_PATCHSET $PATCHSET" +
+ " ENV_REFSPEC $REFSPEC" +
+ " ENV_CHANGEURL $CHANGE_URL" +
+ " Message\nwith newline");
+
+ when(config.isEnablePluginMessages()).thenReturn(true);
+ when(config.getCategories()).thenReturn(
+ new LinkedList<>() {
+ {
+ add(new VerdictCategory(VERIFIED_LABEL, VERIFIED_LABEL, 1, 2, 3, 4, 5, 6));
+ add(new VerdictCategory(CODE_REVIEW_LABEL, CODE_REVIEW_LABEL, -1, -2, -3, -4, -5, -6));
+ add(new VerdictCategory("Custom-Label", "Custom-Label", -1, -2, -3, -4, -5, -6));
+ }
+ });
+
+ return config;
+ }
+
/**
* Gives you a Config mock with nulled code review values.
* @return MockGerritHudsonTriggerConfig mock.
@@ -519,7 +592,7 @@ public static CommentAdded createCommentAdded() {
event.setPatchset(patch);
List approvals = new LinkedList();
Approval approval = new Approval();
- approval.setType("Code-Review");
+ approval.setType(Constants.CODE_REVIEW_LABEL);
approval.setValue("1");
approvals.add(approval);
event.setApprovals(approvals);
@@ -692,18 +765,18 @@ public static GerritTrigger createDefaultTrigger(Job job) {
trigger.setTriggerOnEvents(triggerOnEvents);
trigger.setSilentMode(silentMode);
trigger.setSilentStartMode(silentStart);
- trigger.setGerritBuildStartedVerifiedValue(0);
- trigger.setGerritBuildStartedCodeReviewValue(0);
- trigger.setGerritBuildSuccessfulVerifiedValue(0);
- trigger.setGerritBuildSuccessfulCodeReviewValue(0);
- trigger.setGerritBuildFailedVerifiedValue(0);
- trigger.setGerritBuildFailedCodeReviewValue(0);
- trigger.setGerritBuildUnstableVerifiedValue(0);
- trigger.setGerritBuildUnstableCodeReviewValue(0);
- trigger.setGerritBuildNotBuiltVerifiedValue(0);
- trigger.setGerritBuildNotBuiltCodeReviewValue(0);
- trigger.setGerritBuildAbortedVerifiedValue(0);
- trigger.setGerritBuildAbortedCodeReviewValue(0);
+ trigger.setLabelVote(CODE_REVIEW_LABEL, BuildStatus.STARTED, 0);
+ trigger.setLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL, 0);
+ trigger.setLabelVote(CODE_REVIEW_LABEL, BuildStatus.FAILED, 0);
+ trigger.setLabelVote(CODE_REVIEW_LABEL, BuildStatus.UNSTABLE, 0);
+ trigger.setLabelVote(CODE_REVIEW_LABEL, BuildStatus.NOT_BUILT, 0);
+ trigger.setLabelVote(CODE_REVIEW_LABEL, BuildStatus.ABORTED, 0);
+ trigger.setLabelVote(VERIFIED_LABEL, BuildStatus.STARTED, 0);
+ trigger.setLabelVote(VERIFIED_LABEL, BuildStatus.SUCCESSFUL, 0);
+ trigger.setLabelVote(VERIFIED_LABEL, BuildStatus.FAILED, 0);
+ trigger.setLabelVote(VERIFIED_LABEL, BuildStatus.UNSTABLE, 0);
+ trigger.setLabelVote(VERIFIED_LABEL, BuildStatus.NOT_BUILT, 0);
+ trigger.setLabelVote(VERIFIED_LABEL, BuildStatus.ABORTED, 0);
trigger.setServerName(PluginImpl.DEFAULT_SERVER_NAME);
if (job != null) {
@@ -790,7 +863,7 @@ public static ToGerritRunListener createFailureMessageRunListener(final Abstract
* @return the List.
*/
public static List createCodeReviewVerdictCategoryList() {
- VerdictCategory cat = new VerdictCategory("Code-Review", "Code review");
+ VerdictCategory cat = new VerdictCategory(Constants.CODE_REVIEW_LABEL, Constants.CODE_REVIEW_LABEL);
List list = new LinkedList();
list.add(cat);
return list;
@@ -869,32 +942,32 @@ public static MemoryImprint.Entry createAndSetupMemoryImprintEntry(Result result
GerritTrigger trigger = mock(GerritTrigger.class);
SkipVote skipVote = null;
if (result == Result.SUCCESS) {
- when(trigger.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(resultsCodeReviewVote);
- when(trigger.getGerritBuildSuccessfulVerifiedValue()).thenReturn(resultsVerifiedVote);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(resultsCodeReviewVote);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(resultsVerifiedVote);
if (shouldSkip) {
skipVote = new SkipVote(true, false, false, false, false);
}
} else if (result == Result.FAILURE) {
- when(trigger.getGerritBuildFailedCodeReviewValue()).thenReturn(resultsCodeReviewVote);
- when(trigger.getGerritBuildFailedVerifiedValue()).thenReturn(resultsVerifiedVote);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.FAILED)).thenReturn(resultsCodeReviewVote);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.FAILED)).thenReturn(resultsVerifiedVote);
if (shouldSkip) {
skipVote = new SkipVote(false, true, false, false, false);
}
} else if (result == Result.UNSTABLE) {
- when(trigger.getGerritBuildUnstableCodeReviewValue()).thenReturn(resultsCodeReviewVote);
- when(trigger.getGerritBuildUnstableVerifiedValue()).thenReturn(resultsVerifiedVote);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.UNSTABLE)).thenReturn(resultsCodeReviewVote);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.UNSTABLE)).thenReturn(resultsVerifiedVote);
if (shouldSkip) {
skipVote = new SkipVote(false, false, true, false, false);
}
} else if (result == Result.NOT_BUILT) {
- when(trigger.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(1);
- when(trigger.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(1);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(1);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(1);
if (shouldSkip) {
skipVote = new SkipVote(false, false, false, true, false);
}
} else if (result == Result.ABORTED) {
- when(trigger.getGerritBuildAbortedCodeReviewValue()).thenReturn(resultsCodeReviewVote);
- when(trigger.getGerritBuildAbortedVerifiedValue()).thenReturn(resultsVerifiedVote);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.ABORTED)).thenReturn(resultsCodeReviewVote);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.ABORTED)).thenReturn(resultsVerifiedVote);
if (shouldSkip) {
skipVote = new SkipVote(false, false, false, false, true);
}
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/project/GerritTriggerProjectHudsonTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/project/GerritTriggerProjectHudsonTest.java
index f6b9609fa..71027a3f2 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/project/GerritTriggerProjectHudsonTest.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/project/GerritTriggerProjectHudsonTest.java
@@ -23,6 +23,7 @@
*/
package com.sonyericsson.hudson.plugins.gerrit.trigger.project;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import org.htmlunit.html.DomElement;
import org.htmlunit.html.HtmlElement;
import org.htmlunit.html.HtmlPage;
@@ -82,7 +83,7 @@ public void testPopulateDropDown() throws Exception {
final List elements = page.getDocumentElement()
.getElementsByAttribute("select", "name", "_.verdictCategory");
assertThat(elements, hasSize(1));
- List expected = Arrays.asList("Verified", "Code-Review");
+ List expected = Arrays.asList(Constants.VERIFIED_LABEL, Constants.CODE_REVIEW_LABEL);
verifyOptions((HtmlSelect)elements.get(0), expected);
}
}
@@ -115,7 +116,7 @@ public void testPopulateDropDownFromTwoServers() throws Exception {
final List elements = page.getDocumentElement()
.getElementsByAttribute("select", "name", "_.verdictCategory");
assertThat(elements, hasSize(1));
- List expected = Arrays.asList("Verified", "Code-Review", "Code-Review2", "Verified2");
+ List expected = Arrays.asList(Constants.VERIFIED_LABEL, Constants.CODE_REVIEW_LABEL, "Code-Review2", "Verified2");
verifyOptions((HtmlSelect)elements.get(0), expected);
}
}
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/BackCompat2173JenkinsTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/BackCompat2173JenkinsTest.java
index d060518e9..4dc528836 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/BackCompat2173JenkinsTest.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/BackCompat2173JenkinsTest.java
@@ -90,9 +90,6 @@ private void verifyAllOff(GerritTrigger trigger) {
assertNotNull(trigger);
assertNotNull(trigger.getSkipVote());
assertFalse("Skip not built", trigger.getSkipVote().isOnNotBuilt());
- assertNotNull(trigger.getGerritBuildFailedCodeReviewValue());
- assertEquals("Build Failed Code Review value", Integer.valueOf(0),
- trigger.getGerritBuildFailedCodeReviewValue());
assertFalse("Silent Mode", trigger.isSilentMode());
assertEquals("Notification level", "ALL", trigger.getNotificationLevel());
assertFalse("Silent start", trigger.isSilentStartMode());
@@ -164,9 +161,6 @@ private void verifyAllOn(GerritTrigger trigger) {
assertNotNull(trigger);
assertNotNull(trigger.getSkipVote());
assertTrue("Skip not built", trigger.getSkipVote().isOnNotBuilt());
- assertNotNull(trigger.getGerritBuildNotBuiltCodeReviewValue());
- assertEquals("Build Failed Code Review value", Integer.valueOf(0),
- trigger.getGerritBuildNotBuiltCodeReviewValue());
assertFalse("Silent Mode", trigger.isSilentMode());
assertEquals("Notification level", "OWNER", trigger.getNotificationLevel());
assertTrue("Silent start", trigger.isSilentStartMode());
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/ParameterModeJenkinsTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/ParameterModeJenkinsTest.java
index b6ec60e16..194b78eb2 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/ParameterModeJenkinsTest.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/ParameterModeJenkinsTest.java
@@ -2,6 +2,7 @@
import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer;
import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerParameters;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch;
@@ -368,7 +369,7 @@ public void testCommitMessageParameterModeNone() throws Exception {
@Test
public void testCommentTextParameterModeDefault() throws Exception {
assertSame(GerritTriggerParameters.ParameterMode.BASE64, trigger.getCommentTextParameterMode());
- trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent("Code-Review", "1"));
+ trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent(Constants.CODE_REVIEW_LABEL, "1"));
String expected = "Triggering comment";
CommentAdded event = Setup.createCommentAdded();
event.setComment(expected);
@@ -390,7 +391,7 @@ public void testCommentTextParameterModeDefault() throws Exception {
@Test
public void testCommentTextParameterModePlain() throws Exception {
trigger.setCommentTextParameterMode(GerritTriggerParameters.ParameterMode.PLAIN);
- trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent("Code-Review", "1"));
+ trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent(Constants.CODE_REVIEW_LABEL, "1"));
String expected = "Triggering comment";
CommentAdded event = Setup.createCommentAdded();
event.setComment(expected);
@@ -412,7 +413,7 @@ public void testCommentTextParameterModePlain() throws Exception {
@Test
public void testCommentTextParameterModeNone() throws Exception {
trigger.setCommentTextParameterMode(GerritTriggerParameters.ParameterMode.NONE);
- trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent("Code-Review", "1"));
+ trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent(Constants.CODE_REVIEW_LABEL, "1"));
String expected = "Triggering comment";
CommentAdded event = Setup.createCommentAdded();
event.setComment(expected);
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/TopicAssociationTriggerTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/TopicAssociationTriggerTest.java
index c6e80b035..8d8c673b2 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/TopicAssociationTriggerTest.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/TopicAssociationTriggerTest.java
@@ -3,6 +3,7 @@
import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer;
import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Config;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.CompareType;
@@ -68,7 +69,7 @@ private FreeStyleProject createJob(String pattern) throws IOException {
job.getBuildersList().add(new ParametersBuilder());
GerritTrigger trigger = Setup.createDefaultTrigger(job);
trigger.setTopicAssociation(new TopicAssociation());
- trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent("Code-Review", "1"));
+ trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent(Constants.CODE_REVIEW_LABEL, "1"));
trigger.setGerritProjects(Collections.singletonList(new GerritProject(CompareType.ANT, pattern,
Collections.singletonList(new Branch(CompareType.ANT, "**")),
Collections.emptyList(), Collections.emptyList(),
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/VoteSameTopicTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/VoteSameTopicTest.java
index 27bb86ebe..f6fe67f4a 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/VoteSameTopicTest.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/VoteSameTopicTest.java
@@ -3,6 +3,7 @@
import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer;
import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Config;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.CompareType;
@@ -67,7 +68,7 @@ private FreeStyleProject createJob(String pattern) throws IOException {
GerritTrigger trigger = Setup.createDefaultTrigger(job);
trigger.setTopicAssociation(new TopicAssociation());
- trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent("Code-Review", "1"));
+ trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent(Constants.CODE_REVIEW_LABEL, "1"));
trigger.setGerritProjects(Collections.singletonList(new GerritProject(CompareType.ANT, pattern,
Collections.singletonList(new Branch(CompareType.ANT, "**")),
Collections.emptyList(), Collections.emptyList(),
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/gerritnotifier/SpecGerritVerifiedSetterTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/gerritnotifier/SpecGerritVerifiedSetterTest.java
index 18477780a..a9d9bfa58 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/gerritnotifier/SpecGerritVerifiedSetterTest.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/gerritnotifier/SpecGerritVerifiedSetterTest.java
@@ -24,6 +24,7 @@
*/
package com.sonyericsson.hudson.plugins.gerrit.trigger.spec.gerritnotifier;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.BuildStatus;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.IGerritHudsonTriggerConfig;
import com.sonyericsson.hudson.plugins.gerrit.trigger.extensions.GerritTriggeredBuildListener;
import com.sonyericsson.hudson.plugins.gerrit.trigger.gerritnotifier.GerritMessageProvider;
@@ -48,6 +49,8 @@
import java.io.IOException;
+import static com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants.CODE_REVIEW_LABEL;
+import static com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants.VERIFIED_LABEL;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.same;
@@ -101,10 +104,10 @@ public void setUp() throws Exception {
doReturn(build).when(project).getBuild(anyString());
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(null);
- when(trigger.getGerritBuildSuccessfulVerifiedValue()).thenReturn(null);
- when(trigger.getGerritBuildFailedCodeReviewValue()).thenReturn(null);
- when(trigger.getGerritBuildFailedVerifiedValue()).thenReturn(null);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(null);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(null);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.FAILED)).thenReturn(null);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.FAILED)).thenReturn(null);
Setup.setTrigger(trigger, project);
jenkinsMockedStatic = mockStatic(Jenkins.class);
@@ -143,12 +146,12 @@ public void shouldCallGerritWithVerifiedOkFlagWhenBuildWasSuccessful()
BuildMemory memory = new BuildMemory();
memory.completed(event, build);
- IGerritHudsonTriggerConfig config = mock(IGerritHudsonTriggerConfig.class);
+ IGerritHudsonTriggerConfig config = Setup.createMockableConfig();
String parameterString = "gerrit review MSG=OK VERIFIED= CODEREVIEW=";
when(config.getGerritCmdBuildSuccessful()).thenReturn(parameterString);
- when(config.getGerritBuildSuccessfulVerifiedValue()).thenReturn(1);
- when(config.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(1);
+ when(config.getLabelVote(VERIFIED_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(1);
+ when(config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(1);
GerritNotifier notifier = new GerritNotifier(config, mockGerritCmdRunner, jenkins);
notifier.buildCompleted(memory.getMemoryImprint(event), taskListener);
@@ -173,12 +176,12 @@ public void shouldCallGerritWithVerifiedRejectFlagWhenBuildWasNotSuccessful()
memory.completed(event, build);
- IGerritHudsonTriggerConfig config = mock(IGerritHudsonTriggerConfig.class);
+ IGerritHudsonTriggerConfig config = Setup.createMockableConfig();
String parameterString = "gerrit review MSG=Failed VERIFIED= CODEREVIEW=";
when(config.getGerritCmdBuildFailed()).thenReturn(parameterString);
- when(config.getGerritBuildFailedVerifiedValue()).thenReturn(-1);
- when(config.getGerritBuildFailedCodeReviewValue()).thenReturn(-1);
+ when(config.getLabelVote(VERIFIED_LABEL, BuildStatus.FAILED)).thenReturn(-1);
+ when(config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.FAILED)).thenReturn(-1);
GerritNotifier notifier = new GerritNotifier(config, mockGerritCmdRunner, jenkins);
notifier.buildCompleted(memory.getMemoryImprint(event), taskListener);
@@ -218,20 +221,20 @@ public void shouldCallGerritWithVerifiedFailedFlagWhenBuildOneBuildFailedAndAnot
when(jenkins.getItemByFullName(eq("MockProject2"), same(Job.class))).thenReturn(project);
trigger = mock(GerritTrigger.class);
- when(trigger.getGerritBuildFailedCodeReviewValue()).thenReturn(null);
- when(trigger.getGerritBuildFailedVerifiedValue()).thenReturn(null);
+ when(trigger.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.FAILED)).thenReturn(null);
+ when(trigger.getLabelVote(VERIFIED_LABEL, BuildStatus.FAILED)).thenReturn(null);
Setup.setTrigger(trigger, project);
memory.completed(event, build);
- IGerritHudsonTriggerConfig config = mock(IGerritHudsonTriggerConfig.class);
+ IGerritHudsonTriggerConfig config = Setup.createMockableConfig();
String parameterString = "gerrit review MSG=FAILED VERIFIED= CODEREVIEW=";
when(config.getGerritCmdBuildFailed()).thenReturn(parameterString);
- when(config.getGerritBuildSuccessfulVerifiedValue()).thenReturn(1);
- when(config.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(1);
- when(config.getGerritBuildFailedCodeReviewValue()).thenReturn(-1);
- when(config.getGerritBuildFailedVerifiedValue()).thenReturn(-1);
+ when(config.getLabelVote(VERIFIED_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(1);
+ when(config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.SUCCESSFUL)).thenReturn(1);
+ when(config.getLabelVote(CODE_REVIEW_LABEL, BuildStatus.FAILED)).thenReturn(-1);
+ when(config.getLabelVote(VERIFIED_LABEL, BuildStatus.FAILED)).thenReturn(-1);
GerritNotifier notifier = new GerritNotifier(config, mockGerritCmdRunner, jenkins);
notifier.buildCompleted(memory.getMemoryImprint(event), taskListener);
diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/utils/MockPluginCheckerConfig.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/utils/MockPluginCheckerConfig.java
index af579f3c8..b77d6b8bf 100644
--- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/utils/MockPluginCheckerConfig.java
+++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/utils/MockPluginCheckerConfig.java
@@ -1,6 +1,7 @@
package com.sonyericsson.hudson.plugins.gerrit.trigger.utils;
import com.sonyericsson.hudson.plugins.gerrit.trigger.VerdictCategory;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.BuildStatus;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.IGerritHudsonTriggerConfig;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.ReplicationConfig;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.BuildCancellationPolicy;
@@ -283,6 +284,11 @@ public Secret getGerritAuthKeyFileSecretPassword() {
return null;
}
+ @Override
+ public Integer getLabelVote(String label, BuildStatus status) {
+ return null;
+ }
+
@Override
public int getWatchdogTimeoutMinutes() {
return 0;
diff --git a/src/test/java/com/sonymobile/tools/gerrit/gerritevents/mock/SshdServerMock.java b/src/test/java/com/sonymobile/tools/gerrit/gerritevents/mock/SshdServerMock.java
index 567138c4b..9f2634774 100644
--- a/src/test/java/com/sonymobile/tools/gerrit/gerritevents/mock/SshdServerMock.java
+++ b/src/test/java/com/sonymobile/tools/gerrit/gerritevents/mock/SshdServerMock.java
@@ -29,6 +29,7 @@
import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer;
import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Config;
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.IGerritHudsonTriggerConfig;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.auth.UserAuthNoneFactory;
@@ -804,32 +805,32 @@ public void start(final ChannelSession channel, final Environment environment) t
JSONArray approvals = new JSONArray();
JSONObject crw = new JSONObject();
- crw.put(TYPE, "Code-Review");
+ crw.put(TYPE, Constants.CODE_REVIEW_LABEL);
crw.put(VALUE, "2");
approvals.add(crw);
crw = new JSONObject();
- crw.put(TYPE, "Code-Review");
+ crw.put(TYPE, Constants.CODE_REVIEW_LABEL);
crw.put(VALUE, "1");
approvals.add(crw);
crw = new JSONObject();
- crw.put(TYPE, "Code-Review");
+ crw.put(TYPE, Constants.CODE_REVIEW_LABEL);
crw.put(VALUE, "-1");
approvals.add(crw);
crw = new JSONObject();
- crw.put(TYPE, "Verified");
+ crw.put(TYPE, Constants.VERIFIED_LABEL);
crw.put(VALUE, "2");
approvals.add(crw);
crw = new JSONObject();
- crw.put(TYPE, "Verified");
+ crw.put(TYPE, Constants.VERIFIED_LABEL);
crw.put(VALUE, "1");
approvals.add(crw);
crw = new JSONObject();
- crw.put(TYPE, "Verified");
+ crw.put(TYPE, Constants.VERIFIED_LABEL);
crw.put(VALUE, "-1");
approvals.add(crw);
@@ -899,32 +900,32 @@ public void start(final ChannelSession channel, final Environment environment) t
JSONArray approvals = new JSONArray();
JSONObject crw = new JSONObject();
- crw.put(TYPE, "Code-Review");
+ crw.put(TYPE, Constants.CODE_REVIEW_LABEL);
crw.put(VALUE, "2");
approvals.add(crw);
crw = new JSONObject();
- crw.put(TYPE, "Code-Review");
+ crw.put(TYPE, Constants.CODE_REVIEW_LABEL);
crw.put(VALUE, "1");
approvals.add(crw);
crw = new JSONObject();
- crw.put(TYPE, "Code-Review");
+ crw.put(TYPE, Constants.CODE_REVIEW_LABEL);
crw.put(VALUE, "-1");
approvals.add(crw);
crw = new JSONObject();
- crw.put(TYPE, "Verified");
+ crw.put(TYPE, Constants.VERIFIED_LABEL);
crw.put(VALUE, "2");
approvals.add(crw);
crw = new JSONObject();
- crw.put(TYPE, "Verified");
+ crw.put(TYPE, Constants.VERIFIED_LABEL);
crw.put(VALUE, "1");
approvals.add(crw);
crw = new JSONObject();
- crw.put(TYPE, "Verified");
+ crw.put(TYPE, Constants.VERIFIED_LABEL);
crw.put(VALUE, "-1");
approvals.add(crw);
@@ -1008,32 +1009,32 @@ public void start(final ChannelSession channel, final Environment environment) t
JSONArray approvals = new JSONArray();
JSONObject crw = new JSONObject();
- crw.put(TYPE, "Code-Review");
+ crw.put(TYPE, Constants.CODE_REVIEW_LABEL);
crw.put(VALUE, "2");
approvals.add(crw);
crw = new JSONObject();
- crw.put(TYPE, "Code-Review");
+ crw.put(TYPE, Constants.CODE_REVIEW_LABEL);
crw.put(VALUE, "1");
approvals.add(crw);
crw = new JSONObject();
- crw.put(TYPE, "Code-Review");
+ crw.put(TYPE, Constants.CODE_REVIEW_LABEL);
crw.put(VALUE, "-1");
approvals.add(crw);
crw = new JSONObject();
- crw.put(TYPE, "Verified");
+ crw.put(TYPE, Constants.VERIFIED_LABEL);
crw.put(VALUE, "2");
approvals.add(crw);
crw = new JSONObject();
- crw.put(TYPE, "Verified");
+ crw.put(TYPE, Constants.VERIFIED_LABEL);
crw.put(VALUE, "1");
approvals.add(crw);
crw = new JSONObject();
- crw.put(TYPE, "Verified");
+ crw.put(TYPE, Constants.VERIFIED_LABEL);
crw.put(VALUE, "-1");
approvals.add(crw);
diff --git a/src/test/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/extensions/GerritTriggeredBuildListenerTest/gerrit-trigger.xml b/src/test/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/extensions/GerritTriggeredBuildListenerTest/gerrit-trigger.xml
index 7717a6352..2373a3ca6 100644
--- a/src/test/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/extensions/GerritTriggeredBuildListenerTest/gerrit-trigger.xml
+++ b/src/test/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/extensions/GerritTriggeredBuildListenerTest/gerrit-trigger.xml
@@ -12,14 +12,24 @@
gerrit review --project <GERRIT_NAME> --message 'Build Failed <BUILDS_STATS>' --label Verified=<VERIFIED> --label Code-Review=<CODE_REVIEW> <CHANGE>,<PATCHSET>
gerrit review --project <GERRIT_NAME> --message 'Build Started <BUILDURL> <STARTED_STATS>' --label Verified=<VERIFIED> --label Code-Review=<CODE_REVIEW> <CHANGE>,<PATCHSET>
http://localhost/
- 0
- 0
- 1
- 0
- 0
- -1
- 0
- -1
+
+
+ Code-Review
+ Code-Review
+ 0
+ 0
+ -1
+ -1
+
+
+ Verified
+ Verified
+ 0
+ 1
+ 0
+ 0
+
+
true
1
1