@Test public void shouldGetAttributesForXml() { ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1"); SCM scmConfig = SCMMother.create("scm-id", "scm-name", "pluginid", "version", new Configuration(k1)); PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setSCMConfig(scmConfig); Map<String, Object> attributesForXml = material.getAttributesForXml(); assertThat(attributesForXml.get("type").toString(), is(PluggableSCMMaterial.class.getSimpleName())); assertThat(attributesForXml.get("scmName").toString(), is("scm-name")); }
@Test public void shouldGetEmailContentForPluggableSCMMaterial() { ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1"); SCM scmConfig = SCMMother.create("scm-id", "scm-name", "pluginid", "version", new Configuration(k1)); PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setSCMConfig(scmConfig); StringBuilder content = new StringBuilder(); Date date = new Date(1367472329111L); material.emailContent(content, new Modification(null, "comment", null, date, "rev123")); assertThat(content.toString(), is(String.format("SCM : scm-name\nrevision: rev123, completed on %s\ncomment", date.toString()))); }
@Test public void shouldNotCalculateFingerprintWhenAvailable() { String fingerprint = "fingerprint"; SCM scmConfig = mock(SCM.class); PluggableSCMMaterial pluggableSCMMaterial = new PluggableSCMMaterial(); pluggableSCMMaterial.setSCMConfig(scmConfig); pluggableSCMMaterial.setFingerprint(fingerprint); assertThat(pluggableSCMMaterial.getFingerprint(), is(fingerprint)); verify(scmConfig, never()).getFingerprint(); }
@Test public void shouldGetJsonRepresentationForPluggableSCMMaterial() { ConfigurationProperty k1 = create("k1", false, "v1"); SCM scmConfig = SCMMother.create("scm-id", "scm-name", "pluginid", "version", new Configuration(k1)); PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setSCMConfig(scmConfig); material.setFolder("folder"); Map<String, String> jsonMap = new LinkedHashMap<>(); material.toJson(jsonMap, new PluggableSCMMaterialRevision("rev123", new Date())); assertThat(jsonMap.get("scmType"), is("SCM")); assertThat(jsonMap.get("materialName"), is("scm-name")); assertThat(jsonMap.get("location"), is(material.getUriForDisplay())); assertThat(jsonMap.get("folder"), is("folder")); assertThat(jsonMap.get("action"), is("Modified")); }
@Test public void shouldGetSqlCriteria() { SCM scmConfig = SCMMother.create("scm-id", "scm-name", "pluginid", "version", new Configuration(ConfigurationPropertyMother.create("k1", false, "v1"))); PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setSCMConfig(scmConfig); Map<String, Object> criteria = material.getSqlCriteria(); assertThat(criteria.get("type"), is(PluggableSCMMaterial.class.getSimpleName())); assertThat(criteria.get("fingerprint"), is(material.getFingerprint())); }
public static PluggableSCMMaterial pluggableSCMMaterial(String scmId, String scmName, final String pluginid, final String version, List<ConfigurationProperty> properties) { PluggableSCMMaterial material = new PluggableSCMMaterial(scmId); material.setId(1); SCM scmConfig = SCMMother.create(scmId, scmName, pluginid, version, new Configuration(properties)); material.setSCMConfig(scmConfig); return material; }
@Test public void shouldGetDifferentFingerprintWhenPluginIdChanges() { SCM scmConfig = SCMMother.create("scm-id", "scm-name", "plugin-1", "version", new Configuration(ConfigurationPropertyMother.create("k1", false, "v1"))); PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setSCMConfig(scmConfig); SCM anotherSCMConfig = SCMMother.create("scm-id", "scm-name", "plugin-2", "version", new Configuration(ConfigurationPropertyMother.create("k1", false, "v1"))); PluggableSCMMaterial anotherMaterial = new PluggableSCMMaterial(); anotherMaterial.setSCMConfig(anotherSCMConfig); assertThat(material.getFingerprint().equals(anotherMaterial.getFingerprint()), is(false)); }
@Test public void shouldGetDisplayName() { ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1"); SCM scmConfig = SCMMother.create("scm-id", "scm-name", "pluginid", "version", new Configuration(k1)); PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setSCMConfig(scmConfig); assertThat(material.getDisplayName(), is("scm-name")); }
@Test public void shouldCorrectlyGetTypeDisplay() { PluggableSCMMaterial pluggableSCMMaterial = new PluggableSCMMaterial("scm-id"); assertThat(pluggableSCMMaterial.getTypeForDisplay(), is("SCM")); pluggableSCMMaterial.setSCMConfig(SCMMother.create("scm-id")); assertThat(pluggableSCMMaterial.getTypeForDisplay(), is("SCM")); SCMMetadataStore.getInstance().addMetadataFor("plugin", null, null); assertThat(pluggableSCMMaterial.getTypeForDisplay(), is("SCM")); SCMView scmView = mock(SCMView.class); when(scmView.displayValue()).thenReturn("scm-name"); SCMMetadataStore.getInstance().addMetadataFor("plugin", null, scmView); assertThat(pluggableSCMMaterial.getTypeForDisplay(), is("scm-name")); }
@Test public void shouldGetDescription() { ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1"); SCM scmConfig = SCMMother.create("scm-id", "scm-name", "pluginid", "version", new Configuration(k1)); PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setSCMConfig(scmConfig); assertThat(material.getDescription(), is("scm-name")); }
@Test public void shouldReturnMatchedRevisionForPluggableSCMMaterial() { ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1"); SCM scmConfig = SCMMother.create("scm-id", "scm-name", "pluginid", "version", new Configuration(k1)); PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setSCMConfig(scmConfig); Date timestamp = new Date(); MatchedRevision matchedRevision = material.createMatchedRevision(new Modification("go", "comment", null, timestamp, "rev123"), "rev"); assertThat(matchedRevision.getShortRevision(), is("rev123")); assertThat(matchedRevision.getLongRevision(), is("rev123")); assertThat(matchedRevision.getCheckinTime(), is(timestamp)); assertThat(matchedRevision.getUser(), is("go")); assertThat(matchedRevision.getComment(), is("comment")); }
@Test public void shouldGetNameFromSCMName() { ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1"); SCM scmConfig = SCMMother.create("scm-id", "scm-name", "pluginid", "version", new Configuration(k1)); PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setSCMConfig(scmConfig); assertThat(material.getName().toString(), is("scm-name")); }
@Test public void shouldGetFingerprintForMaterial() { ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1"); ConfigurationProperty k2 = ConfigurationPropertyMother.create("secure-key", true, "secure-value"); SCM scmConfig = SCMMother.create("scm-id", "scm-name", "pluginid", "version", new Configuration(k1, k2)); PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setSCMConfig(scmConfig); assertThat(material.getFingerprint(), is(CachedDigestUtils.sha256Hex("plugin-id=pluginid<|>k1=v1<|>secure-key=secure-value"))); }
@Test public void shouldNotThrowUpWhenAdditionalDataIsRandomJunkAndNotJSON() { ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1"); SCM scmConfig = SCMMother.create("scm-id", "tw-dev", "pluginid", "version", new Configuration(k1)); PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setSCMConfig(scmConfig); material.setName(new CaseInsensitiveString("tw-dev:go-agent")); Modifications modifications = new Modifications(new Modification("loser", "comment", "email", new Date(), "revision-123", "salkdfjdsa-jjgkj!!!vcxknbvkjk")); EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext(); material.populateEnvironmentContext(environmentVariableContext, new MaterialRevision(material, modifications), null); assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_LABEL"), is("revision-123")); assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_K1"), is("v1")); }
@Test public void shouldNotThrowUpWhenAdditionalDataIsNull() { ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1"); SCM scmConfig = SCMMother.create("scm-id", "tw-dev", "pluginid", "version", new Configuration(k1)); PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setSCMConfig(scmConfig); material.setName(new CaseInsensitiveString("tw-dev:go-agent")); Modifications modifications = new Modifications(new Modification("loser", "comment", "email", new Date(), "revision-123", null)); EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext(); material.populateEnvironmentContext(environmentVariableContext, new MaterialRevision(material, modifications), null); assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_LABEL"), is("revision-123")); assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_K1"), is("v1")); }
@Test public void shouldGetUriForDisplayNameIfNameIsNull() { ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "scm-v1"); ConfigurationProperty k2 = ConfigurationPropertyMother.create("k2", false, "scm-v2"); SCM scmConfig = SCMMother.create("scm-id", null, "pluginid", "version", new Configuration(k1, k2)); PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setSCMConfig(scmConfig); assertThat(material.getDisplayName(), is(material.getUriForDisplay())); }
@Test public void shouldGetLongDescription() { ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "scm-v1"); ConfigurationProperty k2 = ConfigurationPropertyMother.create("k2", false, "scm-v2"); Configuration configuration = new Configuration(k1, k2); SCM scmConfig = SCMMother.create("scm-id", "scm-name", "pluginid", "version", configuration); PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setSCMConfig(scmConfig); assertThat(material.getLongDescription(), is(material.getUriForDisplay())); }
@Test public void shouldPopulateEnvironmentContext() { ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1"); ConfigurationProperty k2 = ConfigurationPropertyMother.create("scm-secure", true, "value"); SCM scmConfig = SCMMother.create("scm-id", "tw-dev", "pluginid", "version", new Configuration(k1, k2)); PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setSCMConfig(scmConfig); material.setName(new CaseInsensitiveString("tw-dev:go-agent")); Modifications modifications = new Modifications(new Modification(null, null, null, new Date(), "revision-123")); EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext(); material.populateEnvironmentContext(environmentVariableContext, new MaterialRevision(material, modifications), null); assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_K1"), is("v1")); assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_SCM_SECURE"), is("value")); assertThat(environmentVariableContext.getPropertyForDisplay("GO_SCM_TW_DEV_GO_AGENT_SCM_SECURE"), is(EnvironmentVariableContext.EnvironmentVariable.MASK_VALUE)); assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_LABEL"), is("revision-123")); }
@Test public void shouldConvertPluggableSCMMaterialToJsonFormatToBeStoredInDb() throws CryptoException { GoCipher cipher = new GoCipher(); String encryptedPassword = cipher.encrypt("password"); ConfigurationProperty secureSCMProperty = new ConfigurationProperty(new ConfigurationKey("secure-key"), null, new EncryptedConfigurationValue(encryptedPassword), cipher); ConfigurationProperty scmProperty = new ConfigurationProperty(new ConfigurationKey("non-secure-key"), new ConfigurationValue("value"), null, cipher); SCM scmConfig = SCMMother.create("scm-id", "scm-name", "plugin-id", "1.0", new Configuration(secureSCMProperty, scmProperty)); PluggableSCMMaterial pluggableSCMMaterial = new PluggableSCMMaterial(); pluggableSCMMaterial.setSCMConfig(scmConfig); String json = JsonHelper.toJsonString(pluggableSCMMaterial); String expected = "{\"scm\":{\"plugin\":{\"id\":\"plugin-id\",\"version\":\"1.0\"},\"config\":[{\"configKey\":{\"name\":\"secure-key\"},\"encryptedConfigValue\":{\"value\":" + new Gson().toJson(encryptedPassword) + "}},{\"configKey\":{\"name\":\"non-secure-key\"},\"configValue\":{\"value\":\"value\"}}]}}"; assertThat(json, is(expected)); assertThat(JsonHelper.fromJson(expected, PluggableSCMMaterial.class), is(pluggableSCMMaterial)); }
@Test public void shouldGetUriForDisplay() { SCMMetadataStore.getInstance().addMetadataFor("some-plugin", new SCMConfigurations(), null); ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "scm-v1"); ConfigurationProperty k2 = ConfigurationPropertyMother.create("k2", false, "scm-v2"); Configuration configuration = new Configuration(k1, k2); SCM scmConfig = SCMMother.create("scm-id", "scm-name", "some-plugin", "version", configuration); PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setSCMConfig(scmConfig); assertThat(material.getUriForDisplay(), is("[k1=scm-v1, k2=scm-v2]")); }