Want to test an extension with KeycloakTestcontainer but missing resources. What am I doing wrong? #119
Replies: 3 comments 1 reply
-
|
Hi, |
Beta Was this translation helpful? Give feedback.
-
|
OK. Thank you for the response (and for the KeycloakTestcontainer!). As i see in #112 you have no option to test the behaviour with gradle. Would it be an option to give the problem back to the user by supporting a list of "ImporterContentModifiers"? I changed my implementation to this: public class XKeycloakContainer extends ExtendableKeycloakContainer<XKeycloakContainer> {
private List<Consumer<ExplodedImporter>> importerModifierList = null;
...
@Override
protected void configure() {
super.configure();
if( this.importerModifierList!=null && !this.importerModifierList.isEmpty() ) {
createKeycloakExtensionDeployment(
DEFAULT_KEYCLOAK_PROVIDERS_LOCATION,
DEFAULT_KEYCLOAK_PROVIDERS_NAME
);
}
}
public XKeycloakContainer withJarContentModifier(Consumer<ExplodedImporter> importerModifier) {
if( importerModifierList==null ) {
this.importerModifierList = new ArrayList<>();
}
this.importerModifierList.add(importerModifier);
return self();
}
...
@Override
protected void createKeycloakExtensionDeployment(String deploymentLocation, String extensionName) {
requireNonNull(deploymentLocation, "deploymentLocation must not be null");
requireNonNull(extensionName, "extensionName must not be null");
if (importerModifierList!=null && !importerModifierList.isEmpty()) {
final File file;
try {
file = Files.createTempFile("keycloak", ".jar").toFile();
file.setReadable(true, false);
file.deleteOnExit();
ExplodedImporter importer = ShrinkWrap.create(JavaArchive.class, extensionName)
.as(ExplodedImporter.class)
;
if( this.importerModifierList != null ) {
for (Consumer<ExplodedImporter> explodedImporterConsumer : this.importerModifierList) {
explodedImporterConsumer.accept(importer);
}
}
importer
.as(ZipExporter.class)
.exportTo(file, true);
withCopyFileToContainer(MountableFile.forHostPath(file.getAbsolutePath()), deploymentLocation + "/" + extensionName);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
}With this approach you should be able to write some test cases and a gradle user can do: @Container
private XKeycloakContainer keycloak = new XKeycloakContainer()
.withJarContentModifier(i -> i.importDirectory(resolveExtensionClassLocation("java/main")))
.withJarContentModifier(i -> i.importDirectory("build/resources/main"))
; |
Beta Was this translation helpful? Give feedback.
-
|
Hello,
Maybe it can help. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Dear Keycloakers.
I'm trying to test a little extension with the keycloak test container. I'm using gradle as a build system. I added the provider classes to the container with:
.withProviderClassesFrom("java/main")The container starts, but the extension is not loaded. I'm using gradle as built system.
So I derived the class
ExtendableKeycloakContainerand added a method to set the resource directory also. Now it works. But may I missed something and there is an easier way. Here is myXKeycloakContainer:In the Test i can now write:
Beta Was this translation helpful? Give feedback.
All reactions