Search in sources :

Example 6 with NamedPlugin

use of com.hotels.styx.proxy.plugin.NamedPlugin in project styx by ExpediaGroup.

the class StyxServerComponentsTest method loadsPlugins.

@Test
public void loadsPlugins() {
    ConfiguredPluginFactory f1 = new ConfiguredPluginFactory("plugin1", any -> stubPlugin("MyResponse1"));
    ConfiguredPluginFactory f2 = new ConfiguredPluginFactory("plugin2", any -> stubPlugin("MyResponse2"));
    StyxServerComponents components = new StyxServerComponents.Builder().registry(new MicrometerRegistry(new CompositeMeterRegistry())).styxConfig(new StyxConfig()).pluginFactories(List.of(f1, f2)).build();
    List<NamedPlugin> plugins = components.plugins();
    List<String> names = plugins.stream().map(NamedPlugin::name).collect(toList());
    assertThat(names, contains("plugin1", "plugin2"));
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) StyxConfig(com.hotels.styx.StyxConfig) NamedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin) ConfiguredPluginFactory(com.hotels.styx.startup.extensions.ConfiguredPluginFactory) Test(org.junit.jupiter.api.Test)

Example 7 with NamedPlugin

use of com.hotels.styx.proxy.plugin.NamedPlugin in project styx by ExpediaGroup.

the class StaticPipelineBuilderTest method appliesPluginsInOrderTheyAreConfigured.

@Test
public void appliesPluginsInOrderTheyAreConfigured() throws Exception {
    Iterable<NamedPlugin> plugins = List.of(interceptor("Test-A", appendResponseHeader("X-From-Plugin", "A")), interceptor("Test-B", appendResponseHeader("X-From-Plugin", "B")));
    HttpHandler handler = new StaticPipelineFactory(clientFactory, environment, registry, plugins, executor, false).build();
    LiveHttpResponse response = Mono.from(handler.handle(get("/foo").build(), requestContext())).block();
    assertThat(response.status(), is(OK));
    assertThat(response.headers("X-From-Plugin"), hasItems("B", "A"));
}
Also used : HttpHandler(com.hotels.styx.api.HttpHandler) NamedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 8 with NamedPlugin

use of com.hotels.styx.proxy.plugin.NamedPlugin in project styx by ExpediaGroup.

the class PluginLoadingForStartupTest method suppliesConfiguredPlugin.

@Test
public void suppliesConfiguredPlugin() {
    String yaml = "" + "plugins:\n" + "  active: myPlugin\n" + "  all:\n" + "    myPlugin:\n" + "      factory:\n" + "        class: com.hotels.styx.startup.extensions.PluginLoadingForStartupTest$MyPluginFactory\n" + "        classPath: " + FIXTURES_CLASS_PATH + "\n" + "      config:\n" + "        testConfiguration: test-foo-bar\n";
    List<NamedPlugin> plugins = PluginLoadingForStartup.loadPlugins(environment(yaml));
    NamedPlugin plugin = plugins.get(0);
    assertThat(plugin.originalPlugin(), is(instanceOf(MyPlugin.class)));
    assertThat(plugin.name(), is("myPlugin"));
    assertThat(((MyPlugin) plugin.originalPlugin()).myPluginConfig, is(new MyPluginConfig("test-foo-bar")));
}
Also used : NamedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin) Test(org.junit.jupiter.api.Test)

Aggregations

NamedPlugin (com.hotels.styx.proxy.plugin.NamedPlugin)8 Test (org.junit.jupiter.api.Test)6 Environment (com.hotels.styx.Environment)2 StyxConfig (com.hotels.styx.StyxConfig)2 HttpHandler (com.hotels.styx.api.HttpHandler)2 HttpResponse (com.hotels.styx.api.HttpResponse)2 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)2 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)2 NamedPlugin.namedPlugin (com.hotels.styx.proxy.plugin.NamedPlugin.namedPlugin)2 Eventual (com.hotels.styx.api.Eventual)1 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)1 OK (com.hotels.styx.api.HttpResponseStatus.OK)1 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1 LiveHttpRequest.get (com.hotels.styx.api.LiveHttpRequest.get)1 LiveHttpResponse.response (com.hotels.styx.api.LiveHttpResponse.response)1 Plugin (com.hotels.styx.api.plugins.spi.Plugin)1 PluginFactory (com.hotels.styx.api.plugins.spi.PluginFactory)1 RoutingObject (com.hotels.styx.routing.RoutingObject)1 ConfiguredPluginFactory (com.hotels.styx.startup.extensions.ConfiguredPluginFactory)1 Support.requestContext (com.hotels.styx.support.Support.requestContext)1