@Test public void shouldTalkToPluginToGetPluginSettingsView() throws Exception { extension.registerHandler("1.0", pluginSettingsJSONMessageHandler); extension.messageHandlerMap.put("1.0", jsonMessageHandler); String responseBody = "expected-response"; String deserializedResponse = ""; when(pluginSettingsJSONMessageHandler.responseMessageForPluginSettingsView(responseBody)).thenReturn(deserializedResponse); when(pluginManager.isPluginOfType(PACKAGE_MATERIAL_EXTENSION, PLUGIN_ID)).thenReturn(true); when(pluginManager.submitTo(eq(PLUGIN_ID), eq(PACKAGE_MATERIAL_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody)); String response = extension.getPluginSettingsView(PLUGIN_ID); assertRequest(requestArgumentCaptor.getValue(), PACKAGE_MATERIAL_EXTENSION, "1.0", PluginSettingsConstants.REQUEST_PLUGIN_SETTINGS_VIEW, null); verify(pluginSettingsJSONMessageHandler).responseMessageForPluginSettingsView(responseBody); assertSame(response, deserializedResponse); }
@Test public void shouldNotFailWhenAPluginWithMultipleExtensionsHasMoreThanOneExtensionRespondingWithSettings_BUT_OneIsValidAndOtherThrowsException() throws Exception { PluginSettingsConfiguration configuration = new PluginSettingsConfiguration(); configuration.add(new PluginSettingsProperty("k1").with(Property.REQUIRED, true).with(Property.SECURE, false)); String pluginID = "plugin-id"; GoPluginDescriptor pluginDescriptor = new GoPluginDescriptor(pluginID, "1.0", null, null, null, true); setupSettingsResponses(notificationExtension, pluginID, configuration, "view"); when(packageRepositoryExtension.canHandlePlugin(pluginID)).thenReturn(false); when(scmExtension.canHandlePlugin(pluginID)).thenReturn(true); when(scmExtension.getPluginSettingsConfiguration(pluginID)).thenThrow(new RuntimeException("Ouch!")); when(scmExtension.getPluginSettingsView(pluginID)).thenReturn("view"); metadataLoader.fetchPluginSettingsMetaData(pluginDescriptor); assertThat(PluginSettingsMetadataStore.getInstance().hasPlugin(pluginID), is(true)); verify(packageRepositoryExtension, never()).getPluginSettingsConfiguration(pluginID); verify(packageRepositoryExtension, never()).getPluginSettingsView(pluginID); }
@Before public void setUp() throws Exception { extension = mock(PackageRepositoryExtension.class); com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration packageSettings = new com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration(); packageSettings.add(new PackageMaterialProperty("username", null).with(Property.REQUIRED, true).with(Property.SECURE, false).with(Property.PART_OF_IDENTITY, false).with(Property.DISPLAY_NAME, "foo").with(Property.DISPLAY_ORDER, 1)); packageSettings.add(new PackageMaterialProperty("password", null).with(Property.REQUIRED, true).with(Property.SECURE, true).with(Property.DISPLAY_ORDER, 2)); RepositoryConfiguration repoSettings = new RepositoryConfiguration(); repoSettings.add(new PackageMaterialProperty("foo", null).with(Property.REQUIRED, true).with(Property.SECURE, false).with(Property.DISPLAY_ORDER, 1)); repoSettings.add(new PackageMaterialProperty("bar", null).with(Property.REQUIRED, true).with(Property.SECURE, true).with(Property.DISPLAY_ORDER, 2)); when(extension.getPackageConfiguration("plugin1")).thenReturn(packageSettings); when(extension.getRepositoryConfiguration("plugin1")).thenReturn(repoSettings); when(extension.getPluginSettingsView("plugin1")).thenReturn("some-html"); PluginSettingsConfiguration pluginSettingsConfiguration = new PluginSettingsConfiguration(); pluginSettingsConfiguration.add(new PluginSettingsProperty("k1", null).with(Property.REQUIRED, true).with(Property.SECURE, false).with(Property.DISPLAY_ORDER, 3)); when(extension.getPluginSettingsConfiguration("plugin1")).thenReturn(pluginSettingsConfiguration); }