Skip to content

Commit

Permalink
merge: #9159
Browse files Browse the repository at this point in the history
9159: test(gateway): add tests for the `io.camunda.zeebe.util.jar.ExternalJarClassLoader` and resources in jar. r=npepinpe a=aivinog1

## Description

<!-- Please explain the changes you made here. -->
I've decided to create this one to be sure that my resources will be properly loaded and could be accessible from the class loader.

## Related issues

<!-- Which issues are closed by this PR or are related -->

closes #8982 



Co-authored-by: Alexey Vinogradov <vinogradov.a.i.93@gmail.com>
  • Loading branch information
zeebe-bors-camunda[bot] and aivinog1 committed Apr 21, 2022
2 parents acf67e3 + dfba964 commit 32736ed
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

import io.camunda.zeebe.util.jar.ExternalService.Service;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.api.parallel.Execution;
Expand Down Expand Up @@ -52,4 +56,26 @@ void shouldUseSystemClassLoaderAsFallback(final @TempDir File tempDir)
.isEqualTo(getClass().getClassLoader())
.isEqualTo(ClassLoader.getSystemClassLoader());
}

@Test
void shouldLoadResourceFiles(final @TempDir File tempDir) throws Exception {
final var testResourceValue = "test-value";
final var resourceName = "test-resource.txt";
final var jarFile = new File(tempDir, "with-resource.jar");
try (final var fileOutputStream = new FileOutputStream(jarFile)) {
try (final var jarOutputStream = new JarOutputStream(fileOutputStream)) {
jarOutputStream.putNextEntry(new JarEntry(resourceName));
jarOutputStream.write(testResourceValue.getBytes(StandardCharsets.UTF_8));
jarOutputStream.closeEntry();
}
}
final var classLoader = ExternalJarClassLoader.ofPath(jarFile.toPath());

// when
final var storedValue =
new String(classLoader.getResourceAsStream(resourceName).readAllBytes());

// then
assertThat(storedValue).isEqualTo(testResourceValue);
}
}

0 comments on commit 32736ed

Please sign in to comment.