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();
}
Aggregations