Skip to content

Commit

Permalink
šŸµšŸ¶šŸ»
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsuter committed Jul 19, 2024
1 parent b0fa07d commit f5172aa
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 30 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@
<version>3.26.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.simple.SimpleLogger;

import ch.ivyteam.ivy.maven.engine.Slf4jSimpleEngineProperties;

public class TestSlf4jWarningConfiguration {
class TestSlf4jWarningConfiguration {
/*
* XIVY-3123 Streamline the log output to be maven-like, instead of logging
* [WARN] we want [WARNING]. This allows us to use the maven log parser on our
* jenkins pipelines to avoid introducing new warnings.
*/
@Test
public void mavenLikeWarning() {
void mavenLikeWarning() {
Slf4jSimpleEngineProperties.install();

assertThat(System.getProperty(SimpleLogger.WARN_LEVEL_STRING_KEY))
.as("SLF4J warning string is not maven-like [WARNING]")
.isEqualTo("WARNING");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,72 @@
package ch.ivyteam.ivy.maven.engine.deploy.dir;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import ch.ivyteam.ivy.maven.log.LogCollector;
import ch.ivyteam.ivy.maven.log.LogCollector.LogEntry;

public class TestFileLogForwarder {
class TestFileLogForwarder {

@TempDir
Path tempDir;

@Test
public void fileToMavenLog() throws Exception {
File fakeEngineLog = Files.createTempFile("myProject.iar", ".deploymentLog").toFile();
LogCollector mavenLog = new LogCollector();
FileLogForwarder logForwarder = new FileLogForwarder(fakeEngineLog, mavenLog,
new EngineLogLineHandler(mavenLog));
void fileToMavenLog() throws Exception {
var fakeEngineLog = tempDir.resolve("myProject.iar.deploymentLog");
Files.createFile(fakeEngineLog);
var mavenLog = new LogCollector();
var logForwarder = new FileLogForwarder(fakeEngineLog.toFile(), mavenLog, new EngineLogLineHandler(mavenLog));
var log = new FakeLogger(fakeEngineLog);

try {
logForwarder.activate();

logAndWait(fakeEngineLog, "WARNING: starting");
assertThat(mavenLog.getWarnings()).hasSize(1);
log.write("WARNING: starting");
await().untilAsserted(() -> assertThat(mavenLog.getWarnings()).hasSize(1));
LogEntry firstEntry = mavenLog.getWarnings().get(mavenLog.getWarnings().size() - 1);
assertThat(firstEntry.toString()).isEqualTo(" ENGINE: starting");

logAndWait(fakeEngineLog, "WARNING: finished");
assertThat(mavenLog.getWarnings()).hasSize(2);
log.write("WARNING: finished");
await().untilAsserted(() -> assertThat(mavenLog.getWarnings()).hasSize(2));
LogEntry lastEntry = mavenLog.getWarnings().get(mavenLog.getWarnings().size() - 1);
assertThat(lastEntry.toString()).isEqualTo(" ENGINE: finished");

logAndWait(fakeEngineLog, "INFO: hi");
assertThat(mavenLog.getDebug()).hasSize(1);
log.write("INFO: hi");
await().untilAsserted(() -> assertThat(mavenLog.getDebug()).hasSize(1));
LogEntry debugEntry = mavenLog.getDebug().get(mavenLog.getDebug().size() - 1);
assertThat(debugEntry.toString()).isEqualTo(" ENGINE: hi");

} finally {
logForwarder.deactivate();
}

logAndWait(fakeEngineLog, "WARNING: illegal");
assertThat(mavenLog.getWarnings()).hasSize(2);
log.write("WARNING: illegal");
await().untilAsserted(() -> assertThat(mavenLog.getWarnings()).hasSize(2));
}

private static void logAndWait(File fakeEngineLog, String log) throws IOException, InterruptedException {
boolean append = true;
FileUtils.write(fakeEngineLog, log, StandardCharsets.UTF_8, append);
Thread.sleep(1000);
}
private static final class FakeLogger {

private final Path file;

private FakeLogger(Path file) {
this.file = file;
}

private void write(String log) {
try {
Files.writeString(file, log, StandardOpenOption.APPEND);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class TestLatestMinorVersionRange {
class TestLatestMinorVersionRange {

@Test
public void get() {
void get() {
assertThat(new LatestMinorVersionRange("8.0.0").get().toString()).isEqualTo("[8.0.0,8.1.0)");
assertThat(new LatestMinorVersionRange("8.0.1").get().toString()).isEqualTo("[8.0.1,8.1.0)");
assertThat(new LatestMinorVersionRange("8.1.0").get().toString()).isEqualTo("[8.1.0,8.2.0)");
Expand Down

0 comments on commit f5172aa

Please sign in to comment.