use of io.cdap.cdap.api.feature.FeatureFlagsProvider in project cdap by caskdata.
the class ArtifactRepositoryTest method testMacroPlugin.
@Test
public void testMacroPlugin() throws Exception {
File pluginDir = TMP_FOLDER.newFolder();
addPluginArtifact();
SortedMap<ArtifactDescriptor, Set<PluginClass>> plugins = getPlugins();
copyArtifacts(pluginDir, plugins);
// set up test macro evaluator's substitutions
Map<String, String> propertySubstitutions = ImmutableMap.<String, String>builder().put("expansiveHostname", "${hostname}/${path}:${port}").put("hostname", "${one}").put("path", "${two}").put("port", "${three}").put("one", "${host${hostScopeMacro}}").put("hostScopeMacro", "-local").put("host-local", "${l}${o}${c}${a}${l}${hostSuffix}").put("l", "l").put("o", "o").put("c", "c").put("a", "a").put("hostSuffix", "host").put("two", "${filename${fileTypeMacro}}").put("three", "${firstPortDigit}${secondPortDigit}").put("filename", "index").put("fileTypeMacro", "-html").put("filename-html", "index.html").put("filename-php", "index.php").put("firstPortDigit", "8").put("secondPortDigit", "0").put("aBoolean", "true").put("aByte", "101").put("aChar", "k").put("aDouble", "64.0").put("aFloat", "52.0").put("anInt", "42").put("aLong", "32").put("aShort", "81").put("authInfo", new Gson().toJson(new TestPlugin.AuthInfo("token", "id"))).build();
// Instantiate the plugins and execute them
try (PluginInstantiator instantiator = new PluginInstantiator(cConf, appClassLoader, pluginDir)) {
for (Map.Entry<ArtifactDescriptor, Set<PluginClass>> entry : plugins.entrySet()) {
for (PluginClass pluginClass : entry.getValue()) {
Plugin pluginInfo = new Plugin(new ArrayList<>(), entry.getKey().getArtifactId(), pluginClass, PluginProperties.builder().add("class.name", TEST_EMPTY_CLASS).add("nullableLongFlag", "10").add("host", "${expansiveHostname}").add("aBoolean", "${aBoolean}").add("aByte", "${aByte}").add("aChar", "${aChar}").add("aDouble", "${aDouble}").add("anInt", "${anInt}").add("aFloat", "${aFloat}").add("aLong", "${aLong}").add("aShort", "${aShort}").add("authInfo", "${authInfo}").build());
TestMacroEvaluator testMacroEvaluator = new TestMacroEvaluator(propertySubstitutions, new HashMap<>());
Callable<String> plugin = instantiator.newInstance(pluginInfo, testMacroEvaluator);
Assert.assertEquals("localhost/index.html:80,true,101,k,64.0,52.0,42,32,81,AuthInfo{token='token', id='id'}", plugin.call());
String pluginId = "5";
PluginContext pluginContext = new DefaultPluginContext(instantiator, NamespaceId.DEFAULT.app("abc").worker("w"), ImmutableMap.of(pluginId, pluginInfo), new FeatureFlagsProvider() {
});
PluginProperties resolvedProperties = pluginContext.getPluginProperties(pluginId, testMacroEvaluator);
Map<String, String> expected = new HashMap<>();
expected.put("class.name", TEST_EMPTY_CLASS);
expected.put("nullableLongFlag", "10");
expected.put("host", "localhost/index.html:80");
expected.put("aBoolean", "true");
expected.put("aByte", "101");
expected.put("aChar", "k");
expected.put("aDouble", "64.0");
expected.put("anInt", "42");
expected.put("aFloat", "52.0");
expected.put("aLong", "32");
expected.put("aShort", "81");
expected.put("authInfo", propertySubstitutions.get("authInfo"));
Assert.assertEquals(expected, resolvedProperties.getProperties());
}
}
}
}
Aggregations