public SCMConfigurations getConfigurationMetadata(String pluginId) { if (isEmpty(pluginId) || !hasPreferenceFor(pluginId)) { return null; } return preferenceFor(pluginId).getScmConfigurations(); }
public void addMetadataFor(String pluginId, SCMConfigurations configuration, SCMView scmView) { SCMPreference scmPreference = new SCMPreference(configuration, scmView); setPreferenceFor(pluginId, scmPreference); }
public SCMView getViewMetadata(String pluginId) { if (isEmpty(pluginId) || !hasPreferenceFor(pluginId)) { return null; } return preferenceFor(pluginId).getScmView(); }
@Test public void shouldNotOverwriteValuesIfTheyAreNotAvailableInConfigAttributesMap() throws Exception { SCMConfigurations scmConfigurations = new SCMConfigurations(); scmConfigurations.add(new SCMConfiguration("KEY1")); scmConfigurations.add(new SCMConfiguration("Key2")); SCMPreference scmPreference = mock(SCMPreference.class); when(scmPreference.getScmConfigurations()).thenReturn(scmConfigurations); SCMMetadataStore.getInstance().setPreferenceFor("plugin-id", scmPreference); Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"), ConfigurationPropertyMother.create("Key2")); SCM scm = new SCM("scm-id", new PluginConfiguration("plugin-id", "1"), configuration); Map<String, String> attributeMap = DataStructureUtils.m("KEY1", "value1"); scm.setConfigAttributes(attributeMap); assertThat(scm.getConfigAsMap().get("KEY1").get(SCM.VALUE_KEY), is("value1")); assertThat(scm.getConfigAsMap().get("Key2").get(SCM.VALUE_KEY), is(nullValue())); }
public String displayValue(String pluginId) { if (isEmpty(pluginId) || !hasPreferenceFor(pluginId)) { return null; } SCMView scmView = preferenceFor(pluginId).getScmView(); if (scmView == null) { return null; } return scmView.displayValue(); }
@Test public void shouldIgnoreKeysPresentInConfigAttributesMapButNotPresentInConfigStore() throws Exception { SCMConfigurations scmConfigurations = new SCMConfigurations(); scmConfigurations.add(new SCMConfiguration("KEY1")); SCMPreference scmPreference = mock(SCMPreference.class); when(scmPreference.getScmConfigurations()).thenReturn(scmConfigurations); SCMMetadataStore.getInstance().setPreferenceFor("plugin-id", scmPreference); Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1")); SCM scm = new SCM("scm-id", new PluginConfiguration("plugin-id", "1"), configuration); Map<String, String> attributeMap = DataStructureUtils.m("KEY1", "value1", "Key2", "value2"); scm.setConfigAttributes(attributeMap); assertThat(scm.getConfigAsMap().get("KEY1").get(SCM.VALUE_KEY), is("value1")); assertFalse(scm.getConfigAsMap().containsKey("Key2")); }
public String template(String pluginId) { if (isEmpty(pluginId) || !hasPreferenceFor(pluginId)) { return null; } SCMView scmView = preferenceFor(pluginId).getScmView(); if (scmView == null) { return null; } return scmView.template(); }
@Test public void shouldAddPropertyComingFromAttributesMapIfPresentInConfigStoreEvenIfItISNotPresentInCurrentConfiguration() throws Exception { SCMConfigurations scmConfigurations = new SCMConfigurations(); scmConfigurations.add(new SCMConfiguration("KEY1")); scmConfigurations.add(new SCMConfiguration("Key2")); SCMPreference scmPreference = mock(SCMPreference.class); when(scmPreference.getScmConfigurations()).thenReturn(scmConfigurations); SCMMetadataStore.getInstance().setPreferenceFor("plugin-id", scmPreference); Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1")); SCM scm = new SCM("scm-id", new PluginConfiguration("plugin-id", "1"), configuration); Map<String, String> attributeMap = DataStructureUtils.m("KEY1", "value1", "Key2", "value2"); scm.setConfigAttributes(attributeMap); assertThat(scm.getConfigAsMap().get("KEY1").get(SCM.VALUE_KEY), is("value1")); assertThat(scm.getConfigAsMap().get("Key2").get(SCM.VALUE_KEY), is("value2")); }
@Test public void shouldPopulateItselfFromConfigAttributesMap() throws Exception { SCMConfigurations scmConfigurations = new SCMConfigurations(); scmConfigurations.add(new SCMConfiguration("KEY1")); scmConfigurations.add(new SCMConfiguration("Key2")); SCMPreference scmPreference = mock(SCMPreference.class); when(scmPreference.getScmConfigurations()).thenReturn(scmConfigurations); SCMMetadataStore.getInstance().setPreferenceFor("plugin-id", scmPreference); Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"), ConfigurationPropertyMother.create("Key2")); SCM scm = new SCM("scm-id", new PluginConfiguration("plugin-id", "1"), configuration); Map<String, String> attributeMap = DataStructureUtils.m("KEY1", "value1", "Key2", "value2"); scm.setConfigAttributes(attributeMap); assertThat(scm.getConfigAsMap().get("KEY1").get(SCM.VALUE_KEY), is("value1")); assertThat(scm.getConfigAsMap().get("Key2").get(SCM.VALUE_KEY), is("value2")); }