Search in sources :

Example 1 with SpiExtension

use of com.hotels.styx.spi.config.SpiExtension in project styx by ExpediaGroup.

the class PluginLoadingForStartup method loadPluginFactory.

private static ConfiguredPluginFactory loadPluginFactory(Pair<String, SpiExtension> pair) {
    String pluginName = pair.key();
    SpiExtension spiExtension = pair.value();
    PluginFactory factory = new FileSystemPluginFactoryLoader().load(spiExtension);
    return new ConfiguredPluginFactory(pluginName, factory, spiExtension::config);
}
Also used : FileSystemPluginFactoryLoader(com.hotels.styx.proxy.plugin.FileSystemPluginFactoryLoader) SpiExtension(com.hotels.styx.spi.config.SpiExtension) PluginFactory(com.hotels.styx.api.plugins.spi.PluginFactory)

Example 2 with SpiExtension

use of com.hotels.styx.spi.config.SpiExtension in project styx by ExpediaGroup.

the class FileSystemPluginFactoryLoaderTest method pluginLoaderLoadsPluginFromJarFile.

@Test
public void pluginLoaderLoadsPluginFromJarFile() {
    SpiExtensionFactory factory = new SpiExtensionFactory("testgrp.TestPluginModule", pluginsPath.toString());
    PluginFactory plugin = pluginFactoryLoader.load(new SpiExtension(factory, config, null));
    assertThat(plugin, is(not(nullValue())));
    assertThat(plugin.getClass().getName(), is("testgrp.TestPluginModule"));
}
Also used : SpiExtension(com.hotels.styx.spi.config.SpiExtension) PluginFactory(com.hotels.styx.api.plugins.spi.PluginFactory) SpiExtensionFactory(com.hotels.styx.spi.config.SpiExtensionFactory) Test(org.junit.jupiter.api.Test)

Example 3 with SpiExtension

use of com.hotels.styx.spi.config.SpiExtension in project styx by ExpediaGroup.

the class FileSystemPluginFactoryLoaderTest method providesMeaningfulErrorMessageWhenConfiguredFactoryClassCannotBeLoaded.

@Test
public void providesMeaningfulErrorMessageWhenConfiguredFactoryClassCannotBeLoaded() {
    String jarFile = "/plugins/oneplugin/testPluginA-1.0-SNAPSHOT.jar";
    Path pluginsPath = fixturesHome(FileSystemPluginFactoryLoader.class, jarFile);
    SpiExtensionFactory factory = new SpiExtensionFactory("incorrect.plugin.class.name.TestPluginModule", pluginsPath.toString());
    SpiExtension spiExtension = new SpiExtension(factory, config, null);
    Exception e = assertThrows(ConfigurationException.class, () -> new FileSystemPluginFactoryLoader().load(spiExtension));
    assertThat(e.getMessage(), matchesPattern("Could not load a plugin factory for configuration=SpiExtension\\{" + "factory=SpiExtensionFactory\\{" + "class=incorrect.plugin.class.name.TestPluginModule, " + "classPath=.*[\\\\/]components[\\\\/]proxy[\\\\/]target[\\\\/]test-classes[\\\\/]plugins[\\\\/]oneplugin[\\\\/]testPluginA-1.0-SNAPSHOT.jar" + "\\}\\}"));
}
Also used : Path(java.nio.file.Path) SpiExtension(com.hotels.styx.spi.config.SpiExtension) SpiExtensionFactory(com.hotels.styx.spi.config.SpiExtensionFactory) ConfigurationException(com.hotels.styx.api.configuration.ConfigurationException) Test(org.junit.jupiter.api.Test)

Aggregations

SpiExtension (com.hotels.styx.spi.config.SpiExtension)3 PluginFactory (com.hotels.styx.api.plugins.spi.PluginFactory)2 SpiExtensionFactory (com.hotels.styx.spi.config.SpiExtensionFactory)2 Test (org.junit.jupiter.api.Test)2 ConfigurationException (com.hotels.styx.api.configuration.ConfigurationException)1 FileSystemPluginFactoryLoader (com.hotels.styx.proxy.plugin.FileSystemPluginFactoryLoader)1 Path (java.nio.file.Path)1