Search in sources :

Example 11 with Plugin

use of io.apiman.common.plugin.Plugin 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

Plugin (io.apiman.common.plugin.Plugin)11 PluginCoordinates (io.apiman.common.plugin.PluginCoordinates)8 File (java.io.File)7 IOException (java.io.IOException)5 Test (org.junit.Test)5 PluginClassLoader (io.apiman.common.plugin.PluginClassLoader)4 IPluginRegistry (io.apiman.gateway.engine.IPluginRegistry)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 Path (java.nio.file.Path)4 InvalidPluginException (io.apiman.manager.api.core.exceptions.InvalidPluginException)3 URL (java.net.URL)3 PluginSpec (io.apiman.common.plugin.PluginSpec)2 NewPluginBean (io.apiman.manager.api.beans.plugins.NewPluginBean)2 PluginBean (io.apiman.manager.api.beans.plugins.PluginBean)2 PolicyDefinitionBean (io.apiman.manager.api.beans.policies.PolicyDefinitionBean)2 StorageException (io.apiman.manager.api.core.exceptions.StorageException)2 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)2 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)2