aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2024-04-10 16:01:48 +0200
committersonartech <sonartech@sonarsource.com>2024-04-15 20:02:44 +0000
commit4b060fef8076c324bc0c0cfe4f64804753c91e29 (patch)
treef02d1dcae8de61b40fbf4b9431c737110c12c1dc /sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap
parent60fee355ef174e184b5c3a477a3c81e95302c754 (diff)
downloadsonarqube-4b060fef8076c324bc0c0cfe4f64804753c91e29.tar.gz
sonarqube-4b060fef8076c324bc0c0cfe4f64804753c91e29.zip
SONAR-22036 Add a main to the scanner engine
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerLogbackEncoderTest.java76
1 files changed, 76 insertions, 0 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerLogbackEncoderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerLogbackEncoderTest.java
new file mode 100644
index 00000000000..e63985da428
--- /dev/null
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerLogbackEncoderTest.java
@@ -0,0 +1,76 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.bootstrap;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.classic.spi.ThrowableProxy;
+import java.nio.charset.StandardCharsets;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class ScannerLogbackEncoderTest {
+
+ ScannerLogbackEncoder underTest = new ScannerLogbackEncoder();
+
+ @Test
+ void no_headers_and_footers() {
+ assertThat(underTest.headerBytes()).isEmpty();
+ assertThat(underTest.footerBytes()).isEmpty();
+ }
+
+ @Test
+ void should_encode_when_no_level_and_no_stacktrace() {
+ var logEvent = mock(ILoggingEvent.class);
+ when(logEvent.getLevel()).thenReturn(null);
+ when(logEvent.getFormattedMessage()).thenReturn("message");
+
+ var bytes = underTest.encode(logEvent);
+
+ assertThat(new String(bytes, StandardCharsets.UTF_8)).isEqualTo("{\"message\":\"message\"}\n");
+ }
+
+ @Test
+ void should_encode_when_no_stacktrace() {
+ var logEvent = mock(ILoggingEvent.class);
+ when(logEvent.getLevel()).thenReturn(Level.DEBUG);
+ when(logEvent.getFormattedMessage()).thenReturn("message");
+
+ var bytes = underTest.encode(logEvent);
+
+ assertThat(new String(bytes, StandardCharsets.UTF_8)).isEqualTo("{\"level\":\"DEBUG\",\"message\":\"message\"}\n");
+ }
+
+ @Test
+ void should_encode_with_stacktrace() {
+ var logEvent = mock(ILoggingEvent.class);
+ when(logEvent.getLevel()).thenReturn(Level.DEBUG);
+ when(logEvent.getFormattedMessage()).thenReturn("message");
+ when(logEvent.getThrowableProxy()).thenReturn(new ThrowableProxy(new IllegalArgumentException("foo")));
+
+ var bytes = underTest.encode(logEvent);
+
+ assertThat(new String(bytes, StandardCharsets.UTF_8)).isEqualTo("{\"level\":\"DEBUG\",\"message\":\"message\",\"stacktrace\":\"java.lang.IllegalArgumentException: foo\\n\"}\n");
+ }
+
+} \ No newline at end of file