### Question:
UpdateResourceConfigurationRunner implements Runnable, Callable<ConfigurationUpdateResponse> { public ConfigurationUpdateResponse call() throws Exception { ConfigurationUpdateResponse response; int requestId = request.getConfigurationUpdateId(); try { response = new ConfigurationUpdateResponse(requestId, request.getConfiguration(), SUCCESS, null); try { configMgmt.executeUpdate(request.getResourceId(), request.getConfiguration()); } catch (UpdateInProgressException e) { response.setStatus(INPROGRESS); response.setErrorMessage("Configuration facet did not indicate success or failure - assuming failure."); } catch (ConfigurationUpdateException e) { response.setStatus(FAILURE); response.setErrorMessage(e.getMessage()); } ConfigurationDefinition configurationDefinition = resourceType.getResourceConfigurationDefinition(); configUtilService.normalizeConfiguration(response.getConfiguration(), configurationDefinition); List<String> errorMessages = configUtilService.validateConfiguration(response.getConfiguration(), configurationDefinition); for (String errorMessage : errorMessages) { log.warn("Plugin Error: Invalid " + resourceType.getName() + " Resource configuration returned by " + resourceType.getPlugin() + " plugin - " + errorMessage); } if (response.getStatus() == ConfigurationUpdateStatus.SUCCESS) { response.setConfiguration(null); } } catch (Throwable t) { log.error("Plugin Error: Exception thrown while updating Resource configuration for " + resourceType.getName() + " Resource with id [" + request.getResourceId() + "].", t); response = new ConfigurationUpdateResponse(requestId, request.getConfiguration(), t); } if (this.configurationServerService != null) { this.configurationServerService.completeConfigurationUpdate(response); } return response; } UpdateResourceConfigurationRunner(ConfigurationServerService configurationServerService, ResourceType type,
        ConfigManagement configMgmt, ConfigurationUpdateRequest request); void run(); ConfigurationUpdateResponse call();  }### Answer:
@Test public void failureResponseShouldBeSentToServerWhenUnexpectedExceptionThrown() throws Exception { final Configuration config = createStructuredConfig(); int configUpdateId = -1; ConfigurationUpdateRequest updateRequest = new ConfigurationUpdateRequest(configUpdateId, config, resourceId); UpdateResourceConfigurationRunner updateRunner = new UpdateResourceConfigurationRunner(configServerService, resourceType, configMgmt, updateRequest); final NullPointerException exception = new NullPointerException("Unexpected error during update"); final ConfigurationUpdateResponse failureResponse = new ConfigurationUpdateResponse(configUpdateId, config, exception); context.checking(new Expectations() {{ oneOf(configMgmt).executeUpdate(resourceId, config); will(throwExceptionFromFacet(exception)); oneOf(configServerService).completeConfigurationUpdate(with(matchingResponse(failureResponse))); }}); ConfigurationUpdateResponse actualResponse = updateRunner.call(); assertConfigurationUpdateResponseMatches(failureResponse, actualResponse, "Expected a failure response"); }
@Test public void failureResponseShouldBeReturnedWhenUnexpectedExceptionThrownInEmbeddedMode() throws Exception { final Configuration config = createStructuredConfig(); int configUpdateId = -1; ConfigurationUpdateRequest updateRequest = new ConfigurationUpdateRequest(configUpdateId, config, resourceId); UpdateResourceConfigurationRunner updateRunner = new UpdateResourceConfigurationRunner(null, resourceType, configMgmt, updateRequest); final NullPointerException exception = new NullPointerException("Unexpected error during update"); final ConfigurationUpdateResponse failureResponse = new ConfigurationUpdateResponse(configUpdateId, config, exception); context.checking(new Expectations() {{ oneOf(configMgmt).executeUpdate(resourceId, config); will(throwExceptionFromFacet(exception)); }}); ConfigurationUpdateResponse actualResponse = updateRunner.call(); assertConfigurationUpdateResponseMatches(failureResponse, actualResponse, "Expected a failure response"); }