public Result checkConnection(final SCM scmConfig) { final String pluginId = scmConfig.getPluginConfiguration().getId(); final SCMPropertyConfiguration configuration = getScmPropertyConfiguration(scmConfig); return scmExtension.checkConnectionToSCM(pluginId, configuration); }
@Test public void shouldHandleExceptionDuringPluginInteraction() throws Exception { when(pluginManager.submitTo(eq(PLUGIN_ID), eq(SCM_EXTENSION), requestArgumentCaptor.capture())).thenThrow(new RuntimeException("exception-from-plugin")); try { scmExtension.checkConnectionToSCM(PLUGIN_ID, scmPropertyConfiguration); } catch (Exception e) { assertThat(e.getMessage(), is("Interaction with plugin with id 'plugin-id' implementing 'scm' extension failed while requesting for 'check-scm-connection'. Reason: [exception-from-plugin]")); } }
@Test public void shouldTalkToPluginToCheckSCMConnectionSuccessful() throws Exception { when(jsonMessageHandler.requestMessageForCheckConnectionToSCM(scmPropertyConfiguration)).thenReturn(requestBody); Result deserializedResponse = new Result(); when(jsonMessageHandler.responseMessageForCheckConnectionToSCM(responseBody)).thenReturn(deserializedResponse); Result response = scmExtension.checkConnectionToSCM(PLUGIN_ID, scmPropertyConfiguration); assertRequest(requestArgumentCaptor.getValue(), SCM_EXTENSION, "1.0", SCMExtension.REQUEST_CHECK_SCM_CONNECTION, requestBody); verify(jsonMessageHandler).requestMessageForCheckConnectionToSCM(scmPropertyConfiguration); verify(jsonMessageHandler).responseMessageForCheckConnectionToSCM(responseBody); assertSame(response, deserializedResponse); }