aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce-task
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2020-09-16 15:42:44 +0200
committersonartech <sonartech@sonarsource.com>2020-09-29 20:07:41 +0000
commitdae0f392c72132be88af4a73d98875fdf477de50 (patch)
treeca2687ae56e80f773baef2aafa9671613e1e635a /server/sonar-ce-task
parent1c53c91568bc9af10ca78ae5aff7a1e79f255074 (diff)
downloadsonarqube-dae0f392c72132be88af4a73d98875fdf477de50.tar.gz
sonarqube-dae0f392c72132be88af4a73d98875fdf477de50.zip
SONAR-13862 Add dismiss information to 'api/ce/analysis_status' WS
Diffstat (limited to 'server/sonar-ce-task')
-rw-r--r--server/sonar-ce-task/src/main/java/org/sonar/ce/task/log/CeTaskMessages.java19
-rw-r--r--server/sonar-ce-task/src/main/java/org/sonar/ce/task/log/CeTaskMessagesImpl.java1
-rw-r--r--server/sonar-ce-task/src/test/java/org/sonar/ce/task/log/CeTaskMessagesMessageTest.java64
3 files changed, 42 insertions, 42 deletions
diff --git a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/log/CeTaskMessages.java b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/log/CeTaskMessages.java
index 75ffe9d74ec..7e92a255c10 100644
--- a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/log/CeTaskMessages.java
+++ b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/log/CeTaskMessages.java
@@ -25,6 +25,7 @@ import javax.annotation.concurrent.Immutable;
import org.sonar.api.ce.ComputeEngineSide;
import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
/**
* Provides the ability to record message attached to the current task.
@@ -47,12 +48,19 @@ public interface CeTaskMessages {
class Message {
private final String text;
private final long timestamp;
+ private final boolean dismissible;
- public Message(String text, long timestamp) {
- checkArgument(text != null && !text.isEmpty(), "Text can't be null nor empty");
- checkArgument(timestamp >= 0, "Text can't be less than 0");
+ public Message(String text, long timestamp, boolean dismissible) {
+ requireNonNull(text, "Text can't be null");
+ checkArgument(!text.isEmpty(), "Text can't be empty");
+ checkArgument(timestamp >= 0, "Timestamp can't be less than 0");
this.text = text;
this.timestamp = timestamp;
+ this.dismissible = dismissible;
+ }
+
+ public Message(String text, long timestamp) {
+ this(text, timestamp, false);
}
public String getText() {
@@ -63,6 +71,10 @@ public interface CeTaskMessages {
return timestamp;
}
+ public boolean isDismissible() {
+ return dismissible;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -86,6 +98,7 @@ public interface CeTaskMessages {
return "Message{" +
"text='" + text + '\'' +
", timestamp=" + timestamp +
+ ", dismissible=" + dismissible +
'}';
}
}
diff --git a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/log/CeTaskMessagesImpl.java b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/log/CeTaskMessagesImpl.java
index 608567b8311..153e9ce393d 100644
--- a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/log/CeTaskMessagesImpl.java
+++ b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/log/CeTaskMessagesImpl.java
@@ -74,6 +74,7 @@ public class CeTaskMessagesImpl implements CeTaskMessages {
.setUuid(uuidFactory.create())
.setTaskUuid(ceTask.getUuid())
.setMessage(message.getText())
+ .setDismissible(message.isDismissible())
.setCreatedAt(message.getTimestamp()));
}
diff --git a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/log/CeTaskMessagesMessageTest.java b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/log/CeTaskMessagesMessageTest.java
index 69d83bfa9d9..5133b51cb93 100644
--- a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/log/CeTaskMessagesMessageTest.java
+++ b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/log/CeTaskMessagesMessageTest.java
@@ -19,76 +19,62 @@
*/
package org.sonar.ce.task.log;
-import java.util.Random;
-import java.util.stream.LongStream;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.sonar.ce.task.log.CeTaskMessages.Message;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
public class CeTaskMessagesMessageTest {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
@Test
public void constructor_throws_IAE_if_text_is_null() {
- expectTextCantBeNullNorEmptyIAE();
-
- new Message(null, 12L);
+ assertThatThrownBy(() -> new Message(null, 12L))
+ .isInstanceOf(NullPointerException.class)
+ .hasMessage("Text can't be null");
}
@Test
public void constructor_throws_IAE_if_text_is_empty() {
- expectTextCantBeNullNorEmptyIAE();
-
- new Message("", 12L);
- }
-
- private void expectTextCantBeNullNorEmptyIAE() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Text can't be null nor empty");
+ assertThatThrownBy(() -> new Message("", 12L))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Text can't be empty");
}
@Test
public void constructor_throws_IAE_if_timestamp_is_less_than_0() {
- LongStream.of(0, 1 + new Random().nextInt(12))
- .forEach(timestamp -> assertThat(new Message("foo", timestamp).getTimestamp()).isEqualTo(timestamp));
-
- long lessThanZero = -1 - new Random().nextInt(33);
-
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Text can't be less than 0");
-
- new Message("bar", lessThanZero);
+ assertThatThrownBy(() -> new Message("bar", -1))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Timestamp can't be less than 0");
}
@Test
public void equals_is_based_on_text_and_timestamp() {
- long timestamp = new Random().nextInt(10_999);
+ long timestamp = 10_000_000_000L;
String text = randomAlphabetic(23);
Message underTest = new Message(text, timestamp);
- assertThat(underTest).isEqualTo(underTest);
- assertThat(underTest).isEqualTo(new Message(text, timestamp));
- assertThat(underTest).isNotEqualTo(new Message(text + "ç", timestamp));
- assertThat(underTest).isNotEqualTo(new Message(text, timestamp + 10_999L));
- assertThat(underTest).isNotEqualTo(null);
- assertThat(underTest).isNotEqualTo(new Object());
+ assertThat(underTest)
+ .isEqualTo(underTest)
+ .isEqualTo(new Message(text, timestamp))
+ .isNotEqualTo(new Message(text + "ç", timestamp))
+ .isNotEqualTo(new Message(text, timestamp + 10_999L))
+ .isNotEqualTo(null)
+ .isNotEqualTo(new Object());
}
@Test
public void hashsode_is_based_on_text_and_timestamp() {
- long timestamp = new Random().nextInt(10_999);
+ long timestamp = 10_000_000_000L;
String text = randomAlphabetic(23);
Message underTest = new Message(text, timestamp);
- assertThat(underTest.hashCode()).isEqualTo(underTest.hashCode());
- assertThat(underTest.hashCode()).isEqualTo(new Message(text, timestamp).hashCode());
- assertThat(underTest.hashCode()).isNotEqualTo(new Message(text + "ç", timestamp).hashCode());
- assertThat(underTest.hashCode()).isNotEqualTo(new Message(text, timestamp + 10_999L).hashCode());
- assertThat(underTest.hashCode()).isNotEqualTo(new Object().hashCode());
+ assertThat(underTest.hashCode())
+ .isEqualTo(underTest.hashCode())
+ .isEqualTo(new Message(text, timestamp).hashCode())
+ .isNotEqualTo(new Message(text + "ç", timestamp).hashCode())
+ .isNotEqualTo(new Message(text, timestamp + 10_999L).hashCode())
+ .isNotEqualTo(new Object().hashCode());
}
}