GitLabProvider extends DefaultProvider { @Override public List<Map<String, Object>> validateConfig(Map<String, Object> fields) { List<Map<String, Object>> errors = new ArrayList<Map<String, Object>>(); if (!validateUrl(getValueFromPluginSettings(fields.get(PLUGIN_SETTINGS_END_POINT)))) { errors.add(getValidationError( PLUGIN_SETTINGS_END_POINT, "GitLab Endpoint not set correctly" )); } if (!validateUrl(getValueFromPluginSettings(fields.get(PLUGIN_SETTINGS_SERVER_BASE_URL)))) { errors.add(getValidationError( PLUGIN_SETTINGS_SERVER_BASE_URL, "GoCD Server URL not set correctly" )); } if (getValueFromPluginSettings(fields.get(PLUGIN_SETTINGS_OAUTH_TOKEN)).equals("")) { errors.add(getValidationError( PLUGIN_SETTINGS_OAUTH_TOKEN, "GitLab OAuth Token not set" )); } return errors; } GitLabProvider(); @Override String pluginId(); @Override String pollerPluginId(); @Override List<Map<String, Object>> validateConfig(Map<String, Object> fields); @Override void updateStatus(String url, PluginSettings pluginSettings, String prIdStr, String revision, String pipelineStage,
                             String result, String trackbackURL); String getRepository(String url);  }
@Test public void checkValidationWithValidValues () throws Exception { Map<String, Object> config = new LinkedHashTreeMap<String, Object>(); List<Map<String, Object>> errors = new ArrayList<Map<String, Object>>(); Map<String, String> dummyUrl = new LinkedHashTreeMap<String, String>(); dummyUrl.put("value", "http: Map<String, String> dummyToken = new LinkedHashTreeMap<String, String>(); dummyToken.put("value", "abcdef"); config.put(PLUGIN_SETTINGS_SERVER_BASE_URL, dummyUrl); config.put(PLUGIN_SETTINGS_END_POINT, dummyUrl); config.put(PLUGIN_SETTINGS_OAUTH_TOKEN, dummyToken); List<Map<String, Object>> returnedErrors = provider.validateConfig(config); assertEquals(errors, returnedErrors); }
@Test public void checkValidationWithInvalidValues () throws Exception { Map<String, Object> config = new LinkedHashTreeMap<String, Object>(); Map<String, String> dummyUrl = new LinkedHashTreeMap<String, String>(); dummyUrl.put("value", "localhost:8153"); Map<String, String> dummyToken = new LinkedHashTreeMap<String, String>(); dummyToken.put("value", ""); config.put(PLUGIN_SETTINGS_SERVER_BASE_URL, dummyUrl); config.put(PLUGIN_SETTINGS_END_POINT, dummyUrl); config.put(PLUGIN_SETTINGS_OAUTH_TOKEN, dummyToken); List<Map<String, Object>> returnedErrors = provider.validateConfig(config); assertEquals(3, returnedErrors.size()); }