Search in sources :

Example 1 with SpiExtensionFactory

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)));
    }
}
Also used : SpiExtensionFactory(com.hotels.styx.spi.config.SpiExtensionFactory) Test(org.junit.jupiter.api.Test)

Example 2 with SpiExtensionFactory

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"));
}
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 SpiExtensionFactory

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)));
}
Also used : SpiExtensionFactory(com.hotels.styx.spi.config.SpiExtensionFactory) Test(org.junit.jupiter.api.Test)

Example 4 with SpiExtensionFactory

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" + "\\}\\}"));
}
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

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