Search in sources :

Example 1 with PluggableViewModelFactory

use of com.thoughtworks.go.plugins.presentation.PluggableViewModelFactory in project gocd by gocd.

the class ConfigElementImplementationRegistryTest method registerAllConfigTagImplementationsProvidedByPlugins.

@Test
public void registerAllConfigTagImplementationsProvidedByPlugins() throws MalformedURLException {
    BundleContext execCtx = PluginTestUtil.bundleCtxWithHeaders(DataStructureUtils.m(PluginNamespace.XSD_NAMESPACE_PREFIX, "exec", PluginNamespace.XSD_NAMESPACE_URI, "uri-exec"));
    PluggableViewModelFactory<PluginExec> factory = mock(PluggableViewModelFactory.class);
    ConfigTypeExtension exec = new TestTaskConfigTypeExtension<>(PluginExec.class, factory);
    ConfigurationExtension execTag = new ConfigurationExtension<>(new PluginNamespace(execCtx, new URL("file:///exec")), exec);
    BundleContext antCtx = PluginTestUtil.bundleCtxWithHeaders(DataStructureUtils.m(PluginNamespace.XSD_NAMESPACE_PREFIX, "ant", PluginNamespace.XSD_NAMESPACE_URI, "uri-ant"));
    ConfigTypeExtension ant = new TestTaskConfigTypeExtension<>(PluginAnt.class, mock(PluggableViewModelFactory.class));
    ConfigurationExtension antTag = new ConfigurationExtension<>(new PluginNamespace(antCtx, new URL("file:///ant")), ant);
    when(pluginExtns.configTagImplementations()).thenReturn(Arrays.asList(execTag, antTag));
    ConfigElementImplementationRegistry registry = new ConfigElementImplementationRegistry(pluginExtns);
    assertThat(registry.xsds(), containsString("uri-exec file:/exec"));
    assertThat(registry.xsds(), containsString("uri-ant file:/ant"));
    List<Class<? extends Task>> implementationTypes = registry.implementersOf(Task.class);
    assertThat(implementationTypes.contains(PluginExec.class), is(true));
    assertThat(implementationTypes.contains(PluginAnt.class), is(true));
    Element mock = mock(Element.class);
    registry.registerNamespacesInto(mock);
    verify(mock).addNamespaceDeclaration(Namespace.getNamespace("exec", "uri-exec"));
    verify(mock).addNamespaceDeclaration(Namespace.getNamespace("ant", "uri-ant"));
}
Also used : Task(com.thoughtworks.go.domain.Task) BuildTask(com.thoughtworks.go.config.BuildTask) Element(org.jdom2.Element) PluggableViewModelFactory(com.thoughtworks.go.plugins.presentation.PluggableViewModelFactory) URL(java.net.URL) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

BuildTask (com.thoughtworks.go.config.BuildTask)1 Task (com.thoughtworks.go.domain.Task)1 PluggableViewModelFactory (com.thoughtworks.go.plugins.presentation.PluggableViewModelFactory)1 URL (java.net.URL)1 Element (org.jdom2.Element)1 Test (org.junit.Test)1 BundleContext (org.osgi.framework.BundleContext)1