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