@Test public void shouldReturnWorkingDirectoryCorrectly() { PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setFolder("dest"); String baseFolder = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath(); String workingFolder = new File(baseFolder, "dest").getAbsolutePath(); assertThat(material.workingDirectory(new File(baseFolder)).getAbsolutePath(), is(workingFolder)); material.setFolder(null); assertThat(material.workingDirectory(new File(baseFolder)).getAbsolutePath(), is(baseFolder)); }
@Test public void shouldTypeForDisplay() { PluggableSCMMaterial material = new PluggableSCMMaterial(); assertThat(material.getTypeForDisplay(), is("SCM")); }
@Test public void shouldReturnTrueForPluggableScmMaterial_supportsDestinationFolder() throws Exception { PluggableSCMMaterial material = new PluggableSCMMaterial(); assertThat(material.supportsDestinationFolder(), is(true)); }
@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 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 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 shouldReturnFalseForIsUsedInFetchArtifact() { PluggableSCMMaterial material = new PluggableSCMMaterial(); assertThat(material.isUsedInFetchArtifact(new PipelineConfig()), is(false)); }
@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 shouldGetPluggableSCMMaterialAgent() { File workingDirectory = new File("/tmp/workingDirectory"); MaterialRevision revision = new MaterialRevision(new PluggableSCMMaterial(), new Modifications()); MaterialAgentFactory factory = new MaterialAgentFactory(null, workingDirectory, null, scmExtension); MaterialAgent agent = factory.createAgent(revision); assertThat(agent instanceof PluggableSCMMaterialAgent, is(true)); assertThat(ReflectionUtil.getField(agent, "scmExtension"), is(scmExtension)); assertThat(ReflectionUtil.getField(agent, "revision"), is(revision)); assertThat(ReflectionUtil.getField(agent, "workingDirectory"), is(workingDirectory)); } }
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 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 shouldGetPluggableSCMMaterial_byFolder() { Materials materials = new Materials(); PluggableSCMMaterial material1 = new PluggableSCMMaterial("scm-id"); material1.setFolder("folder"); Material material2 = new HgMaterial("", "folder"); materials.add(material1); materials.add(material2); assertThat(materials.byFolder("folder"), is(material1)); }
@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 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 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 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]")); }