Skip to content

Commit

Permalink
Test: job name with blanks
Browse files Browse the repository at this point in the history
Add two more test cases for adding/deleting/renaming a job with blanks
in the name. Ignored because of maven-scm bug SCM-772.[1]

[1] https://issues.apache.org/jira/browse/SCM-772
  • Loading branch information
tomaswolf committed Jul 4, 2015
1 parent 91897e8 commit f32a1ed
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.codehaus.plexus.util.FileUtils;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.core.io.ClassPathResource;
Expand Down Expand Up @@ -312,6 +313,102 @@ public void testJobNameStartingWithDash() throws Exception {
assertStatusManagerIsOk();
}

@Test
@Ignore // Fails with git
public void testJobNameWithBlanks() throws Exception {
createSCMMock();
sscBusiness.synchronizeAllConfigs(ScmSyncConfigurationPlugin.AVAILABLE_STRATEGIES);

File jobDirectory = new File(getCurrentHudsonRootDirectory(), "jobs/new fake Job/" );
File configFile = new File(jobDirectory, "config.xml");
jobDirectory.mkdir();
FileUtils.copyFile(new ClassPathResource("expected-scm-hierarchies/HudsonExtensionsTest.testAddJobNameWithBlanks/jobs/new fake Job/config.xml").getFile(), configFile);

// Creating fake new job
Item mockedItem = Mockito.mock(Job.class);
when(mockedItem.getName()).thenReturn("new fake Job");
when(mockedItem.getRootDir()).thenReturn(jobDirectory);

sscItemListener.onCreated(mockedItem);

verifyCurrentScmContentMatchesHierarchy("expected-scm-hierarchies/InitRepositoryTest.shouldSynchronizeHudsonFiles/");

sscConfigurationSaveableListener.onChange(mockedItem, new XmlFile(configFile));

verifyCurrentScmContentMatchesHierarchy("expected-scm-hierarchies/HudsonExtensionsTest.testAddJobNameWithBlanks/");

assertStatusManagerIsOk();

// Now delete it again
assertTrue("Config file deletion", configFile.delete());
assertTrue("Job dir deletion", jobDirectory.delete());

sscItemListener.onDeleted(mockedItem);

verifyCurrentScmContentMatchesHierarchy("hudsonRootBaseTemplate/");

assertStatusManagerIsOk();
}

@Test
@Ignore // Fails with git
public void testJobRenameWithBlanksAndDash() throws Exception {
createSCMMock();
sscBusiness.synchronizeAllConfigs(ScmSyncConfigurationPlugin.AVAILABLE_STRATEGIES);

File jobDirectory = new File(getCurrentHudsonRootDirectory(), "jobs/-newFakeJob/" );
File configFile = new File(jobDirectory, "config.xml");
jobDirectory.mkdir();
FileUtils.copyFile(new ClassPathResource("expected-scm-hierarchies/HudsonExtensionsTest.testAddJobNameStartingWithDash/jobs/-newFakeJob/config.xml").getFile(), configFile);

// Creating fake new job
Item mockedItem = Mockito.mock(Job.class);
when(mockedItem.getName()).thenReturn("-newFakeJob");
when(mockedItem.getRootDir()).thenReturn(jobDirectory);

sscItemListener.onCreated(mockedItem);

verifyCurrentScmContentMatchesHierarchy("expected-scm-hierarchies/InitRepositoryTest.shouldSynchronizeHudsonFiles/");

sscConfigurationSaveableListener.onChange(mockedItem, new XmlFile(configFile));

verifyCurrentScmContentMatchesHierarchy("expected-scm-hierarchies/HudsonExtensionsTest.testAddJobNameStartingWithDash/");

assertStatusManagerIsOk();

// Now fake a rename
assertTrue("Config file deletion", configFile.delete());
assertTrue("Job dir deletion", jobDirectory.delete());
jobDirectory = new File(getCurrentHudsonRootDirectory(), "jobs/new fake Job/" );
configFile = new File(jobDirectory, "config.xml");
jobDirectory.mkdir();
FileUtils.copyFile(new ClassPathResource("expected-scm-hierarchies/HudsonExtensionsTest.testAddJobNameWithBlanks/jobs/new fake Job/config.xml").getFile(), configFile);

Item mockedRenamedItem = Mockito.mock(Job.class);
when(mockedRenamedItem.getName()).thenReturn("new fake Job");
when(mockedRenamedItem.getRootDir()).thenReturn(jobDirectory);

sscItemListener.onLocationChanged(mockedRenamedItem, "-newFakeJob", "new fake Job");

verifyCurrentScmContentMatchesHierarchy("expected-scm-hierarchies/HudsonExtensionsTest.testAddJobNameWithBlanks/");

assertStatusManagerIsOk();

// And while we're at it: let's rename it back
assertTrue("Config file deletion", configFile.delete());
assertTrue("Job dir deletion", jobDirectory.delete());
jobDirectory = new File(getCurrentHudsonRootDirectory(), "jobs/-newFakeJob/" );
configFile = new File(jobDirectory, "config.xml");
jobDirectory.mkdir();
FileUtils.copyFile(new ClassPathResource("expected-scm-hierarchies/HudsonExtensionsTest.testAddJobNameStartingWithDash/jobs/-newFakeJob/config.xml").getFile(), configFile);

sscItemListener.onLocationChanged(mockedItem, "new fake Job", "-newFakeJob");

verifyCurrentScmContentMatchesHierarchy("expected-scm-hierarchies/HudsonExtensionsTest.testAddJobNameStartingWithDash/");

assertStatusManagerIsOk();
}

@Test
public void shouldFileWhichHaveToBeInSCM() throws Throwable {
// IMPORTANT NOTE :
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version='1.0' encoding='UTF-8'?>
<hudson>
<version>1.339</version>
<numExecutors>2</numExecutors>
<mode>NORMAL</mode>
<useSecurity>true</useSecurity>
<authorizationStrategy class="hudson.security.FullControlOnceLoggedInAuthorizationStrategy"/>
<securityRealm class="hudson.security.HudsonPrivateSecurityRealm">
<disableSignup>true</disableSignup>
</securityRealm>
<systemMessage>Welcome !</systemMessage>
<jdks />
<clouds/>
<slaves/>
<quietPeriod>5</quietPeriod>
<scmCheckoutRetryCount>0</scmCheckoutRetryCount>
<views>
<hudson.model.AllView>
<owner class="hudson" reference="../../.."/>
<name>All</name>
<filterExecutors>false</filterExecutors>
<filterQueue>false</filterQueue>
</hudson.model.AllView>
</views>
<primaryView>All</primaryView>
<slaveAgentPort>0</slaveAgentPort>
<label></label>
<nodeProperties/>
<globalNodeProperties/>
<disabledAdministrativeMonitors/>
</hudson>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<hudson.tasks.Shell_-DescriptorImpl>
<helpRedirect/>
<shell>/bin/bash</shell>
</hudson.tasks.Shell_-DescriptorImpl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version='1.0' encoding='UTF-8'?>
<maven2-moduleset>
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers class="vector"/>
<concurrentBuild>false</concurrentBuild>
<aggregatorStyleBuild>true</aggregatorStyleBuild>
<incrementalBuild>false</incrementalBuild>
<usePrivateRepository>false</usePrivateRepository>
<ignoreUpstremChanges>false</ignoreUpstremChanges>
<archivingDisabled>false</archivingDisabled>
<reporters/>
<publishers/>
<buildWrappers/>
</maven2-moduleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version='1.0' encoding='UTF-8'?>
<maven2-moduleset>
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>true</disabled>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers class="vector"/>
<concurrentBuild>false</concurrentBuild>
<aggregatorStyleBuild>true</aggregatorStyleBuild>
<incrementalBuild>false</incrementalBuild>
<usePrivateRepository>true</usePrivateRepository>
<ignoreUpstremChanges>false</ignoreUpstremChanges>
<archivingDisabled>false</archivingDisabled>
<reporters/>
<publishers/>
<buildWrappers/>
</maven2-moduleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<hudson.plugins.scm__sync__configuration.ScmSyncConfigurationPlugin version="1">
<scmRepositoryUrl>scm:svn:https://myrepo/synchronizedDirectory/</scmRepositoryUrl>
<scm class="hudson.plugins.scm_sync_configuration.scms.ScmSyncSubversionSCM"/>
</hudson.plugins.scm__sync__configuration.ScmSyncConfigurationPlugin>

0 comments on commit f32a1ed

Please sign in to comment.