@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PluggableSCMMaterial that = (PluggableSCMMaterial) o; if (this.getFingerprint() != null ? !this.getFingerprint().equals(that.getFingerprint()) : that.getFingerprint() != null) { return false; } return true; }
@Override protected void appendCriteria(Map<String, Object> parameters) { parameters.put("fingerprint", getFingerprint()); }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (this.getFingerprint() != null ? this.getFingerprint().hashCode() : 0); return result; }
@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 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())); }
@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 shouldSetFingerprintWhenConvertingMaterialInstanceToMaterial() { String fingerprint = "fingerprint"; PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial(); PluggableSCMMaterialInstance materialInstance = new PluggableSCMMaterialInstance(JsonHelper.toJsonString(material), "flyweight"); ReflectionUtil.setField(materialInstance, "fingerprint", fingerprint); materialInstance.setId(1L); PluggableSCMMaterial constructedMaterial = (PluggableSCMMaterial) materialInstance.toOldMaterial(null, null, null); assertThat(constructedMaterial.getFingerprint(), is(fingerprint)); } }
@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"))); }