Search in sources :

Example 6 with IPluginRegistry

use of io.apiman.gateway.engine.IPluginRegistry in project apiman by apiman.

the class VertxPluginRegistryTest method getRealPluginFromDefaultRegistry.

@Test
public void getRealPluginFromDefaultRegistry(TestContext context) throws java.io.IOException {
    Async waitForPlugin1 = context.async();
    // Preparing JSON config Object
    List<String> pluginRepositories = null;
    String pluginsDir = null;
    JsonObject jsonObject = new JsonObject(getJsonConfig(pluginRepositories, pluginsDir));
    File TempParentDir = Files.createTempDirectory("apiman-gateway-plugins-tmp").getParent().toFile();
    // Delete all old temp dirs
    File[] TempDirs = TempParentDir.listFiles((dir, name) -> name.contains("apiman-gateway-plugins-tmp"));
    for (File td : TempDirs) {
        FileUtils.deleteDirectory(td);
    }
    // Loading VertX configuration
    VertxEngineConfig config = new VertxEngineConfig(jsonObject);
    // Create a fake engine for test plugins loading
    TestVerticle v = new TestVerticle(config);
    // Get pluginRegistry from engine
    IPluginRegistry pluginRegistry = v.createPluginRegistry();
    // Find generated Plugin Temp Dir
    TempDirs = TempParentDir.listFiles((dir, name) -> name.contains("apiman-gateway-plugins-tmp"));
    Arrays.sort(TempDirs, Comparator.comparingLong(File::lastModified).reversed());
    File Tempdir = TempDirs[0];
    // Define simple header policy plugin coordinates
    PluginCoordinates coordinates = PluginCoordinates.fromPolicySpec(RealPluginCoordinates);
    // Download the Real plugin (must succeed)
    pluginRegistry.loadPlugin(coordinates, result -> {
        if (result.isSuccess()) {
            // Get downloaded plugin
            Plugin plugin = result.getResult();
            // Assert that's the right plugin
            context.assertEquals(plugin.getCoordinates(), coordinates);
            // Assert plugin is in the right dir
            Path pluginPath = Paths.get(Tempdir + "/io.apiman.plugins/apiman-plugins-simple-header-policy/1.5.1.Final/apiman-plugins-simple-header-policy.war");
            context.assertTrue(Files.exists(pluginPath));
            waitForPlugin1.complete();
        } else {
            context.fail(result.getError());
        }
    });
    waitForPlugin1.awaitSuccess();
    Async waitForPlugin2 = context.async();
    // Define simple header policy plugin coordinates
    PluginCoordinates testcoordinates = PluginCoordinates.fromPolicySpec(testPluginCoordinates);
    // Try download the test plugin (must failed)
    pluginRegistry.loadPlugin(testcoordinates, result -> {
        context.assertFalse(result.isSuccess());
        waitForPlugin2.complete();
    });
    waitForPlugin2.awaitSuccess();
}
Also used : IPluginRegistry(io.apiman.gateway.engine.IPluginRegistry) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Handler(org.eclipse.jetty.server.Handler) StringUtils(org.apache.commons.lang.StringUtils) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) PathResource(org.eclipse.jetty.util.resource.PathResource) java.util(java.util) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) VertxEngineConfig(io.apiman.gateway.platforms.vertx3.common.config.VertxEngineConfig) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) Plugin(io.apiman.common.plugin.Plugin) Is.is(org.hamcrest.core.Is.is) JsonObject(io.vertx.core.json.JsonObject) URI(java.net.URI) Server(org.eclipse.jetty.server.Server) Path(java.nio.file.Path) AfterClass(org.junit.AfterClass) HandlerList(org.eclipse.jetty.server.handler.HandlerList) Files(java.nio.file.Files) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) File(java.io.File) JsonArray(io.vertx.core.json.JsonArray) ServerConnector(org.eclipse.jetty.server.ServerConnector) IPluginRegistry(io.apiman.gateway.engine.IPluginRegistry) Paths(java.nio.file.Paths) PluginUtils(io.apiman.common.plugin.PluginUtils) Assert(org.junit.Assert) PluginCoordinates(io.apiman.common.plugin.PluginCoordinates) Path(java.nio.file.Path) JsonObject(io.vertx.core.json.JsonObject) Async(io.vertx.ext.unit.Async) VertxEngineConfig(io.apiman.gateway.platforms.vertx3.common.config.VertxEngineConfig) PluginCoordinates(io.apiman.common.plugin.PluginCoordinates) File(java.io.File) Plugin(io.apiman.common.plugin.Plugin) Test(org.junit.Test)

Aggregations

IPluginRegistry (io.apiman.gateway.engine.IPluginRegistry)6 Test (org.junit.Test)5 Plugin (io.apiman.common.plugin.Plugin)4 PluginCoordinates (io.apiman.common.plugin.PluginCoordinates)4 VertxEngineConfig (io.apiman.gateway.platforms.vertx3.common.config.VertxEngineConfig)4 JsonObject (io.vertx.core.json.JsonObject)4 Async (io.vertx.ext.unit.Async)4 File (java.io.File)4 Path (java.nio.file.Path)4 IConnectorFactory (io.apiman.gateway.engine.IConnectorFactory)2 PluginUtils (io.apiman.common.plugin.PluginUtils)1 IDataEncrypter (io.apiman.common.util.crypt.IDataEncrypter)1 IApiConnectionResponse (io.apiman.gateway.engine.IApiConnectionResponse)1 IApiConnector (io.apiman.gateway.engine.IApiConnector)1 IApiRequestExecutor (io.apiman.gateway.engine.IApiRequestExecutor)1 IApiRequestPathParser (io.apiman.gateway.engine.IApiRequestPathParser)1 IComponentRegistry (io.apiman.gateway.engine.IComponentRegistry)1 IConnectorConfig (io.apiman.gateway.engine.IConnectorConfig)1 IEngine (io.apiman.gateway.engine.IEngine)1 IEngineResult (io.apiman.gateway.engine.IEngineResult)1