Search in sources :

Example 1 with VertxEngineConfig

use of io.apiman.gateway.platforms.vertx3.common.config.VertxEngineConfig in project apiman by apiman.

the class ApiResourceImplTest method testGetApiEndpoint.

@Test
public void testGetApiEndpoint() {
    String matchingEndpoint = "https://gateway.acme-corp.com/TestOrg/TestAPI/1.0";
    // Test correct user input
    endpoint = apiResource.getApiEndpoint("TestOrg", "TestAPI", "1.0");
    Assert.assertEquals(matchingEndpoint, endpoint.getEndpoint());
    // Test with trailing slash
    apimanConfig.put("publicEndpoint", "https://gateway.acme-corp.com/");
    apiResource = new ApiResourceImpl(new VertxEngineConfig(apimanConfig), new DummyEngine());
    endpoint = apiResource.getApiEndpoint("TestOrg", "TestAPI", "1.0");
    Assert.assertEquals(matchingEndpoint, endpoint.getEndpoint());
    // Test with path
    matchingEndpoint = "https://gateway.acme-corp.com/TestPath/TestOrg/TestAPI/1.0";
    apimanConfig.put("publicEndpoint", "https://gateway.acme-corp.com/TestPath");
    apiResource = new ApiResourceImpl(new VertxEngineConfig(apimanConfig), new DummyEngine());
    endpoint = apiResource.getApiEndpoint("TestOrg", "TestAPI", "1.0");
    Assert.assertEquals(matchingEndpoint, endpoint.getEndpoint());
    // Test with path and trailing slash
    apimanConfig.put("publicEndpoint", "https://gateway.acme-corp.com/TestPath/");
    apiResource = new ApiResourceImpl(new VertxEngineConfig(apimanConfig), new DummyEngine());
    endpoint = apiResource.getApiEndpoint("TestOrg", "TestAPI", "1.0");
    Assert.assertEquals(matchingEndpoint, endpoint.getEndpoint());
    // Test with other port in config
    matchingEndpoint = "https://gateway.acme-corp.com:4444/TestOrg/TestAPI/1.0";
    apimanConfig = new JsonObject(config);
    apimanConfig.getJsonObject("verticles").getJsonObject("https").put("port", "4444");
    apiResource = new ApiResourceImpl(new VertxEngineConfig(apimanConfig), new DummyEngine());
    endpoint = apiResource.getApiEndpoint("TestOrg", "TestAPI", "1.0");
    Assert.assertEquals(matchingEndpoint, endpoint.getEndpoint());
    // Test with other port in config and path
    matchingEndpoint = "https://gateway.acme-corp.com:4444/TestPath/TestOrg/TestAPI/1.0";
    apimanConfig.put("publicEndpoint", "https://gateway.acme-corp.com/TestPath");
    apiResource = new ApiResourceImpl(new VertxEngineConfig(apimanConfig), new DummyEngine());
    endpoint = apiResource.getApiEndpoint("TestOrg", "TestAPI", "1.0");
    Assert.assertEquals(matchingEndpoint, endpoint.getEndpoint());
    // Test with other port in config, path and trailing slash
    apimanConfig.put("publicEndpoint", "https://gateway.acme-corp.com/TestPath/");
    apiResource = new ApiResourceImpl(new VertxEngineConfig(apimanConfig), new DummyEngine());
    endpoint = apiResource.getApiEndpoint("TestOrg", "TestAPI", "1.0");
    Assert.assertEquals(matchingEndpoint, endpoint.getEndpoint());
    // Test with other port in publicEndpoint, path and trailing slash
    matchingEndpoint = "https://gateway.acme-corp.com:5555/TestPath/TestOrg/TestAPI/1.0";
    apimanConfig.put("publicEndpoint", "https://gateway.acme-corp.com:5555/TestPath/");
    apiResource = new ApiResourceImpl(new VertxEngineConfig(apimanConfig), new DummyEngine());
    endpoint = apiResource.getApiEndpoint("TestOrg", "TestAPI", "1.0");
    Assert.assertEquals(matchingEndpoint, endpoint.getEndpoint());
}
Also used : VertxEngineConfig(io.apiman.gateway.platforms.vertx3.common.config.VertxEngineConfig) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 2 with VertxEngineConfig

use of io.apiman.gateway.platforms.vertx3.common.config.VertxEngineConfig in project apiman by apiman.

the class Vertx3GatewayTestServer method getResetter.

protected Resetter getResetter(String name) {
    @SuppressWarnings("unchecked") Class<Resetter> c = (Class<Resetter>) ReflectionUtils.loadClass(name);
    VertxEngineConfig vxEngineConf = new VertxEngineConfig(vertxConf);
    try {
        return c.newInstance();
    } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | SecurityException e) {
        try {
            return c.getConstructor(VertxEngineConfig.class).newInstance(vxEngineConf);
        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | SecurityException | InvocationTargetException | NoSuchMethodException f) {
            throw new RuntimeException(f);
        }
    }
}
Also used : VertxEngineConfig(io.apiman.gateway.platforms.vertx3.common.config.VertxEngineConfig)

Example 3 with VertxEngineConfig

use of io.apiman.gateway.platforms.vertx3.common.config.VertxEngineConfig in project apiman by apiman.

the class VertxPluginRegistryTest method getFakePluginFromCustomRegistry.

/**
 * Test with custom configuration (pluginRepositories and pluginsDir) to download a fake plugin from a fake Maven repo
 *
 * @param context
 * @throws java.io.IOException
 */
@Test
public void getFakePluginFromCustomRegistry(TestContext context) throws java.io.IOException {
    Async waitForPlugin = context.async();
    // Preparing JSON config Object
    List<String> pluginRepositories = Arrays.asList(mavenServerUri.toString());
    String pluginsDir = "/tmp/plugins-test2";
    JsonObject jsonObject = new JsonObject(getJsonConfig(pluginRepositories, pluginsDir));
    // Delete temp folder
    File TempDir = new File(pluginsDir);
    if (TempDir.exists())
        FileUtils.deleteDirectory(TempDir);
    // Referenced values to test
    Map<String, String> expected = new LinkedHashMap<String, String>() {

        {
            put("pluginRepositories", String.join(",", pluginRepositories));
            put("pluginsDir", pluginsDir);
        }
    };
    // Loading VertX configuration
    VertxEngineConfig config = new VertxEngineConfig(jsonObject);
    Map<String, String> pluginRegistryConfig = config.getPluginRegistryConfig();
    // Assert that JSON config object contains the rights parameters
    Assert.assertThat(pluginRegistryConfig, is(expected));
    // Create a fake engine for test plugins loading
    TestVerticle v = new TestVerticle(config);
    // Get pluginRegistry from engine
    IPluginRegistry pluginRegistry = v.createPluginRegistry();
    // Define simple header policy plugin coordinates
    PluginCoordinates coordinates = PluginCoordinates.fromPolicySpec(testPluginCoordinates);
    // Download the plugin
    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(pluginsDir + "/io.apiman.test/testPlugin/1.0.0.Final/testPlugin.war");
            context.assertTrue(Files.exists(pluginPath));
            waitForPlugin.complete();
        } else {
            context.fail(result.getError());
        }
    });
    waitForPlugin.awaitSuccess();
}
Also used : IPluginRegistry(io.apiman.gateway.engine.IPluginRegistry) 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)

Example 4 with VertxEngineConfig

use of io.apiman.gateway.platforms.vertx3.common.config.VertxEngineConfig in project apiman by apiman.

the class VertxPluginRegistryTest method getFakePluginUnreachableRegistry.

/**
 * Test with custom configuration (pluginRepositories and pluginsDir) to download a fake plugin from a fake Maven repo
 * Despite a unreachable repository in the pluginRepositories array.
 *
 * @param context
 * @throws java.io.IOException
 */
@Test
public void getFakePluginUnreachableRegistry(TestContext context) throws java.io.IOException {
    Async waitForPlugin = context.async();
    // Preparing JSON config Object with 2 custom repo : a real and a fake
    List<String> pluginRepositories = Arrays.asList("https://unreachable.maven.org/maven2/", mavenServerUri.toString());
    String pluginsDir = "/tmp/plugins-test3";
    JsonObject jsonObject = new JsonObject(getJsonConfig(pluginRepositories, pluginsDir));
    // Delete temp folder
    File TempDir = new File(pluginsDir);
    if (TempDir.exists())
        FileUtils.deleteDirectory(TempDir);
    // Referenced values to test
    Map<String, String> expected = new LinkedHashMap<String, String>() {

        {
            put("pluginRepositories", String.join(",", pluginRepositories));
            put("pluginsDir", pluginsDir);
        }
    };
    // Loading VertX configuration
    VertxEngineConfig config = new VertxEngineConfig(jsonObject);
    Map<String, String> pluginRegistryConfig = config.getPluginRegistryConfig();
    // Assert that JSON config object contains the rights parameters
    Assert.assertThat(pluginRegistryConfig, is(expected));
    // Create a fake engine for test plugins loading
    TestVerticle v = new TestVerticle(config);
    // Get pluginRegistry from engine
    IPluginRegistry pluginRegistry = v.createPluginRegistry();
    // Define simple header policy plugin coordinates
    PluginCoordinates coordinates = PluginCoordinates.fromPolicySpec(testPluginCoordinates);
    // Download the plugin
    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(pluginsDir + "/io.apiman.test/testPlugin/1.0.0.Final/testPlugin.war");
            context.assertTrue(Files.exists(pluginPath));
            waitForPlugin.complete();
        } else {
            context.fail(result.getError());
        }
    });
    waitForPlugin.awaitSuccess();
}
Also used : IPluginRegistry(io.apiman.gateway.engine.IPluginRegistry) 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)

Example 5 with VertxEngineConfig

use of io.apiman.gateway.platforms.vertx3.common.config.VertxEngineConfig in project apiman by apiman.

the class VertxPluginRegistryTest method getRealPluginFromCustomRegistry.

/**
 * Test with custom configuration (pluginRepositories and pluginsDir) to download a real plugin from Maven Central
 *
 * @param context
 * @throws java.io.IOException
 */
@Test
public void getRealPluginFromCustomRegistry(TestContext context) throws java.io.IOException {
    Async waitForPlugin = context.async();
    // Preparing JSON config Object
    List<String> pluginRepositories = Arrays.asList("https://repo1.maven.org/maven2/");
    String pluginsDir = "/tmp/plugins-test1";
    JsonObject jsonObject = new JsonObject(getJsonConfig(pluginRepositories, pluginsDir));
    // Delete temp folder
    File TempDir = new File(pluginsDir);
    if (TempDir.exists())
        FileUtils.deleteDirectory(TempDir);
    // Referenced values to test
    Map<String, String> expected = new LinkedHashMap<String, String>() {

        {
            put("pluginRepositories", String.join(",", pluginRepositories));
            put("pluginsDir", pluginsDir);
        }
    };
    // Loading VertX configuration
    VertxEngineConfig config = new VertxEngineConfig(jsonObject);
    Map<String, String> pluginRegistryConfig = config.getPluginRegistryConfig();
    // Assert that JSON config object contains the rights parameters
    Assert.assertThat(pluginRegistryConfig, is(expected));
    // Create a fake engine for test plugins loading
    TestVerticle v = new TestVerticle(config);
    // Get pluginRegistry from engine
    IPluginRegistry pluginRegistry = v.createPluginRegistry();
    // Define simple header policy plugin coordinates
    PluginCoordinates coordinates = PluginCoordinates.fromPolicySpec(RealPluginCoordinates);
    // Download the plugin
    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(pluginsDir + "/io.apiman.plugins/apiman-plugins-simple-header-policy/1.5.1.Final/apiman-plugins-simple-header-policy.war");
            context.assertTrue(Files.exists(pluginPath));
            waitForPlugin.complete();
        } else {
            context.fail(result.getError());
        }
    });
    waitForPlugin.awaitSuccess();
}
Also used : IPluginRegistry(io.apiman.gateway.engine.IPluginRegistry) 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

VertxEngineConfig (io.apiman.gateway.platforms.vertx3.common.config.VertxEngineConfig)7 JsonObject (io.vertx.core.json.JsonObject)6 Test (org.junit.Test)6 Plugin (io.apiman.common.plugin.Plugin)4 PluginCoordinates (io.apiman.common.plugin.PluginCoordinates)4 IPluginRegistry (io.apiman.gateway.engine.IPluginRegistry)4 Async (io.vertx.ext.unit.Async)4 File (java.io.File)4 Path (java.nio.file.Path)4 PluginUtils (io.apiman.common.plugin.PluginUtils)1 JsonArray (io.vertx.core.json.JsonArray)1 TestContext (io.vertx.ext.unit.TestContext)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 URI (java.net.URI)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 java.util (java.util)1 FileUtils (org.apache.commons.io.FileUtils)1 StringUtils (org.apache.commons.lang.StringUtils)1 Handler (org.eclipse.jetty.server.Handler)1