use of com.thoughtworks.go.plugin.api.task.TaskView in project gocd by gocd.
the class PluggableTaskPreferenceLoaderTest method shouldLoadPreferencesOnlyForTaskPlugins.
@Test
public void shouldLoadPreferencesOnlyForTaskPlugins() {
final GoPluginDescriptor descriptor = mock(GoPluginDescriptor.class);
String pluginId = "test-plugin-id";
when(descriptor.id()).thenReturn(pluginId);
final Task task = mock(Task.class);
TaskConfig config = new TaskConfig();
TaskView taskView = mock(TaskView.class);
when(task.config()).thenReturn(config);
when(task.view()).thenReturn(taskView);
PluginManager pluginManager = mock(PluginManager.class);
final TaskExtension taskExtension = mock(TaskExtension.class);
when(taskExtension.canHandlePlugin(pluginId)).thenReturn(false);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
final Action<Task> action = (Action<Task>) invocationOnMock.getArguments()[1];
action.execute(task, descriptor);
return null;
}
}).when(taskExtension).doOnTask(eq(pluginId), any(Action.class));
PluggableTaskPreferenceLoader pluggableTaskPreferenceLoader = new PluggableTaskPreferenceLoader(pluginManager, taskExtension);
pluggableTaskPreferenceLoader.pluginLoaded(descriptor);
assertThat(PluggableTaskConfigStore.store().hasPreferenceFor(pluginId), is(false));
verify(pluginManager).addPluginChangeListener(pluggableTaskPreferenceLoader);
}
use of com.thoughtworks.go.plugin.api.task.TaskView in project gocd by gocd.
the class PluggableTaskPluginInfoBuilderTest method pluginInfoFor_ShouldProvidePluginInfoForAPlugin.
@Test
public void pluginInfoFor_ShouldProvidePluginInfoForAPlugin() throws Exception {
GoPluginDescriptor.About about = new GoPluginDescriptor.About("Plugin Descriptor Validator", "1.0.1", "12.4", "Validates its own plugin descriptor", new GoPluginDescriptor.Vendor("ThoughtWorks Go Team", "www.thoughtworks.com"), Arrays.asList("Linux", "Windows", "Mac OS X"));
GoPluginDescriptor plugin = new GoPluginDescriptor("docker-plugin", "1.0", about, null, null, false);
PluginManager pluginManager = mock(PluginManager.class);
PluggableTaskConfigStore packageMetadataStore = mock(PluggableTaskConfigStore.class);
when(packageMetadataStore.pluginIds()).thenReturn(Collections.singleton(plugin.id()));
when(pluginManager.getPluginDescriptorFor(plugin.id())).thenReturn(plugin);
JsonBasedPluggableTask jsonBasedPluggableTask = mock(JsonBasedPluggableTask.class);
TaskView taskView = new TaskView() {
@Override
public String displayValue() {
return "task display value";
}
@Override
public String template() {
return "pluggable task view template";
}
};
TaskConfig taskConfig = new TaskConfig();
taskConfig.add(new TaskConfigProperty("key1", null));
taskConfig.add(new TaskConfigProperty("key2", null));
when(jsonBasedPluggableTask.config()).thenReturn(taskConfig);
when(jsonBasedPluggableTask.view()).thenReturn(taskView);
TaskPreference taskPreference = new TaskPreference(jsonBasedPluggableTask);
when(packageMetadataStore.preferenceFor(plugin.id())).thenReturn(taskPreference);
PluggableTaskPluginInfoBuilder builder = new PluggableTaskPluginInfoBuilder(pluginManager, packageMetadataStore);
PluggableTaskPluginInfo pluginInfo = builder.pluginInfoFor(plugin.id());
PluggableTaskPluginInfo expectedPluginInfo = new PluggableTaskPluginInfo(plugin, taskView.displayValue(), new PluggableInstanceSettings(configurations(taskConfig), new PluginView(taskView.template())));
assertEquals(expectedPluginInfo, pluginInfo);
}
use of com.thoughtworks.go.plugin.api.task.TaskView in project gocd by gocd.
the class PluggableTaskViewModelBuilderTest method setUp.
@Before
public void setUp() {
initMocks(this);
builder = new PluggableTaskViewModelBuilder(manager);
xunitConvertor = new GoPluginDescriptor("xunit.convertor", "version1", new GoPluginDescriptor.About("Xunit Convertor", "1.0", null, null, null, null), null, null, false);
powershellTask = new GoPluginDescriptor("powershell.task", "version1", new GoPluginDescriptor.About("Powershell Task", "2.0", null, null, null, null), null, null, false);
JsonBasedPluggableTask jsonBasedPluggableTask = mock(JsonBasedPluggableTask.class);
TaskView taskView = new TaskView() {
@Override
public String displayValue() {
return "task display value";
}
@Override
public String template() {
return "pluggable task view template";
}
};
TaskConfig taskConfig = new TaskConfig();
taskConfig.add(new TaskConfigProperty("key1", null));
taskConfig.add(new TaskConfigProperty("key2", null));
when(jsonBasedPluggableTask.config()).thenReturn(taskConfig);
when(jsonBasedPluggableTask.view()).thenReturn(taskView);
taskPreference = new TaskPreference(jsonBasedPluggableTask);
PluggableTaskConfigStore.store().setPreferenceFor("xunit.convertor", taskPreference);
PluggableTaskConfigStore.store().setPreferenceFor("powershell.task", taskPreference);
}
use of com.thoughtworks.go.plugin.api.task.TaskView in project gocd by gocd.
the class PluginInfoBuilderTest method setUp.
@Before
public void setUp() {
initMocks(this);
githubDescriptor = new GoPluginDescriptor("github.oauth", "version1", new GoPluginDescriptor.About("Github OAuth Plugin", "1.0", null, null, null, null), null, null, false);
emailNotifier = new GoPluginDescriptor("email.notifier", "version1", new GoPluginDescriptor.About("Email Notifier", "1.0", null, null, null, null), null, null, false);
yumPoller = new GoPluginDescriptor("yum.poller", "version1", new GoPluginDescriptor.About("Yum Poller", "1.0", null, null, null, null), null, null, false);
xunitConvertor = new GoPluginDescriptor("xunit.convertor", "version1", new GoPluginDescriptor.About("Xunit Convertor", "1.0", null, null, null, null), null, null, false);
githubPR = new GoPluginDescriptor("github.pr", "version1", new GoPluginDescriptor.About("Github PR", "1.0", null, null, null, null), null, null, false);
dockerElasticAgentPlugin = new GoPluginDescriptor("cd.go.elastic-agent.docker", "1.0", new GoPluginDescriptor.About("GoCD Docker Elastic Agent Plugin", "1.0", null, null, null, null), null, null, false);
ldapAuthPlugin = new GoPluginDescriptor("cd.go.authorization.ldap", "1.0", new GoPluginDescriptor.About("GoCD LDAP Plugin", "1.0", null, null, null, null), null, null, false);
JsonBasedPluggableTask jsonBasedPluggableTask = mock(JsonBasedPluggableTask.class);
TaskView taskView = new TaskView() {
@Override
public String displayValue() {
return "task display value";
}
@Override
public String template() {
return "pluggable task view template";
}
};
when(authenticationPluginRegistry.getAuthenticationPlugins()).thenReturn(new HashSet<>(Arrays.asList("github.oauth")));
when(notificationPluginRegistry.getNotificationPlugins()).thenReturn(new HashSet<>(Arrays.asList("email.notifier")));
when(elasticPluginConfigMetadataStore.getPlugins()).thenReturn(new ArrayList<>(Arrays.asList(dockerElasticAgentPlugin)));
when(authorizationPluginConfigMetadataStore.getPlugins()).thenReturn(new ArrayList<>(Arrays.asList(ldapAuthPlugin)));
when(jsonBasedPluggableTask.view()).thenReturn(taskView);
when(manager.getPluginDescriptorFor("github.oauth")).thenReturn(githubDescriptor);
when(manager.getPluginDescriptorFor("email.notifier")).thenReturn(emailNotifier);
when(manager.getPluginDescriptorFor("yum.poller")).thenReturn(yumPoller);
when(manager.getPluginDescriptorFor("xunit.convertor")).thenReturn(xunitConvertor);
when(manager.getPluginDescriptorFor("github.pr")).thenReturn(githubPR);
when(manager.getPluginDescriptorFor("cd.go.elastic-agent.docker")).thenReturn(dockerElasticAgentPlugin);
when(manager.getPluginDescriptorFor(ldapAuthPlugin.id())).thenReturn(ldapAuthPlugin);
MetadataStoreHelper.clear();
PackageMetadataStore.getInstance().addMetadataFor(yumPoller.id(), new PackageConfigurations());
PluggableTaskConfigStore.store().setPreferenceFor("xunit.convertor", new TaskPreference(jsonBasedPluggableTask));
SCMMetadataStore.getInstance().setPreferenceFor("github.pr", new SCMPreference(new SCMConfigurations(), mock(SCMView.class)));
pluginViewModelBuilder = new PluginInfoBuilder(authenticationPluginRegistry, notificationPluginRegistry, elasticPluginConfigMetadataStore, authorizationPluginConfigMetadataStore, manager);
}
use of com.thoughtworks.go.plugin.api.task.TaskView in project gocd by gocd.
the class PluggableTaskPluginInfoBuilderTest method setUp.
@BeforeEach
public void setUp() throws Exception {
extension = mock(TaskExtension.class);
TaskConfig taskConfig = new TaskConfig();
taskConfig.add(new TaskConfigProperty("username", null).with(Property.REQUIRED, true).with(Property.SECURE, false));
taskConfig.add(new TaskConfigProperty("password", null).with(Property.REQUIRED, true).with(Property.SECURE, true));
TaskView taskView = new TaskView() {
@Override
public String displayValue() {
return "my task plugin";
}
@Override
public String template() {
return "some html";
}
};
final Task task = mock(Task.class);
when(task.config()).thenReturn(taskConfig);
when(task.view()).thenReturn(taskView);
final GoPluginDescriptor descriptor = mock(GoPluginDescriptor.class);
String pluginId = "plugin1";
when(descriptor.id()).thenReturn(pluginId);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
final Action<Task> action = (Action<Task>) invocation.getArguments()[1];
action.execute(task, descriptor);
return null;
}
}).when(extension).doOnTask(eq("plugin1"), any(Action.class));
}
Aggregations