use of com.hotels.styx.spi.config.SpiExtensionFactory in project styx by ExpediaGroup.
the class ExtensionObjectFactoryTest method throwsAppropriateExceptionIfObjectCannotBeInstantiated.
@Test
public void throwsAppropriateExceptionIfObjectCannotBeInstantiated() {
ExtensionObjectFactory factory = new ExtensionObjectFactory(extensionFactory -> DEFAULT_CLASS_LOADER);
String className = CannotInstantiate.class.getName();
try {
factory.newInstance(new SpiExtensionFactory(className, "/fake/class/path"), Object.class);
fail("No exception thrown");
} catch (ExtensionLoadingException e) {
assertThat(e.getMessage(), is("error instantiating class=" + className));
assertThat(e.getCause(), is(instanceOf(IllegalAccessException.class)));
}
}
use of com.hotels.styx.spi.config.SpiExtensionFactory 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"));
}
use of com.hotels.styx.spi.config.SpiExtensionFactory in project styx by ExpediaGroup.
the class ExtensionObjectFactoryTest method instantiatesObjects.
@Test
public void instantiatesObjects() {
ExtensionObjectFactory factory = new ExtensionObjectFactory(extensionFactory -> DEFAULT_CLASS_LOADER);
String className = String.class.getName();
Object object = factory.newInstance(new SpiExtensionFactory(className, "/fake/class/path"), Object.class);
assertThat(object, is(instanceOf(String.class)));
}
use of com.hotels.styx.spi.config.SpiExtensionFactory 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" + "\\}\\}"));
}
Aggregations