public class CeActivityDto {
+ private static final int MAX_SIZE_ERROR_MESSAGE = 1000;
+
public enum Status {
SUCCESS, FAILED, CANCELED
}
}
public CeActivityDto setErrorMessage(@Nullable String errorMessage) {
- this.errorMessage = errorMessage;
+ this.errorMessage = ensureNotTooBig(errorMessage, MAX_SIZE_ERROR_MESSAGE);
return this;
}
+ @CheckForNull
+ private static String ensureNotTooBig(@Nullable String str, int maxSize) {
+ if (str == null) {
+ return null;
+ }
+ if (str.length() <= maxSize) {
+ return str;
+ }
+ return str.substring(0, maxSize);
+ }
+
@CheckForNull
public String getErrorStacktrace() {
return errorStacktrace;
import com.google.common.base.Function;
import com.google.common.base.Optional;
+import com.google.common.base.Strings;
import com.google.common.collect.FluentIterable;
import java.util.Collections;
import java.util.List;
assertThat(dto.getErrorStacktrace()).isNull();
}
+ @Test
+ public void test_insert_of_errorMessage_of_1_000_chars() {
+ CeActivityDto dto = createActivityDto("TASK_1", REPORT, "PROJECT_1", CeActivityDto.Status.FAILED)
+ .setErrorMessage(Strings.repeat("x", 1_000));
+ underTest.insert(db.getSession(), dto);
+
+ Optional<CeActivityDto> saved = underTest.selectByUuid(db.getSession(), "TASK_1");
+ assertThat(saved.get().getErrorMessage()).isEqualTo(dto.getErrorMessage());
+ }
+
+ @Test
+ public void test_insert_of_errorMessage_of_1_001_chars_is_truncated_to_1000() {
+ String expected = Strings.repeat("x", 1_000);
+ CeActivityDto dto = createActivityDto("TASK_1", REPORT, "PROJECT_1", CeActivityDto.Status.FAILED)
+ .setErrorMessage(expected + "y");
+ underTest.insert(db.getSession(), dto);
+
+ Optional<CeActivityDto> saved = underTest.selectByUuid(db.getSession(), "TASK_1");
+ assertThat(saved.get().getErrorMessage()).isEqualTo(expected);
+ }
+
@Test
public void test_insert_error_message_and_stacktrace() {
CeActivityDto dto = createActivityDto("TASK_1", REPORT, "PROJECT_1", CeActivityDto.Status.FAILED)