|
18 | 18 |
|
19 | 19 | import org.codehaus.plexus.util.FileUtils; |
20 | 20 | import org.junit.Before; |
| 21 | +import org.junit.Ignore; |
21 | 22 | import org.junit.Test; |
22 | 23 | import org.mockito.Mockito; |
23 | 24 | import org.springframework.core.io.ClassPathResource; |
@@ -312,6 +313,102 @@ public void testJobNameStartingWithDash() throws Exception { |
312 | 313 | assertStatusManagerIsOk(); |
313 | 314 | } |
314 | 315 |
|
| 316 | + @Test |
| 317 | + @Ignore // Fails with git |
| 318 | + public void testJobNameWithBlanks() throws Exception { |
| 319 | + createSCMMock(); |
| 320 | + sscBusiness.synchronizeAllConfigs(ScmSyncConfigurationPlugin.AVAILABLE_STRATEGIES); |
| 321 | + |
| 322 | + File jobDirectory = new File(getCurrentHudsonRootDirectory(), "jobs/new fake Job/" ); |
| 323 | + File configFile = new File(jobDirectory, "config.xml"); |
| 324 | + jobDirectory.mkdir(); |
| 325 | + FileUtils.copyFile(new ClassPathResource("expected-scm-hierarchies/HudsonExtensionsTest.testAddJobNameWithBlanks/jobs/new fake Job/config.xml").getFile(), configFile); |
| 326 | + |
| 327 | + // Creating fake new job |
| 328 | + Item mockedItem = Mockito.mock(Job.class); |
| 329 | + when(mockedItem.getName()).thenReturn("new fake Job"); |
| 330 | + when(mockedItem.getRootDir()).thenReturn(jobDirectory); |
| 331 | + |
| 332 | + sscItemListener.onCreated(mockedItem); |
| 333 | + |
| 334 | + verifyCurrentScmContentMatchesHierarchy("expected-scm-hierarchies/InitRepositoryTest.shouldSynchronizeHudsonFiles/"); |
| 335 | + |
| 336 | + sscConfigurationSaveableListener.onChange(mockedItem, new XmlFile(configFile)); |
| 337 | + |
| 338 | + verifyCurrentScmContentMatchesHierarchy("expected-scm-hierarchies/HudsonExtensionsTest.testAddJobNameWithBlanks/"); |
| 339 | + |
| 340 | + assertStatusManagerIsOk(); |
| 341 | + |
| 342 | + // Now delete it again |
| 343 | + assertTrue("Config file deletion", configFile.delete()); |
| 344 | + assertTrue("Job dir deletion", jobDirectory.delete()); |
| 345 | + |
| 346 | + sscItemListener.onDeleted(mockedItem); |
| 347 | + |
| 348 | + verifyCurrentScmContentMatchesHierarchy("hudsonRootBaseTemplate/"); |
| 349 | + |
| 350 | + assertStatusManagerIsOk(); |
| 351 | + } |
| 352 | + |
| 353 | + @Test |
| 354 | + @Ignore // Fails with git |
| 355 | + public void testJobRenameWithBlanksAndDash() throws Exception { |
| 356 | + createSCMMock(); |
| 357 | + sscBusiness.synchronizeAllConfigs(ScmSyncConfigurationPlugin.AVAILABLE_STRATEGIES); |
| 358 | + |
| 359 | + File jobDirectory = new File(getCurrentHudsonRootDirectory(), "jobs/-newFakeJob/" ); |
| 360 | + File configFile = new File(jobDirectory, "config.xml"); |
| 361 | + jobDirectory.mkdir(); |
| 362 | + FileUtils.copyFile(new ClassPathResource("expected-scm-hierarchies/HudsonExtensionsTest.testAddJobNameStartingWithDash/jobs/-newFakeJob/config.xml").getFile(), configFile); |
| 363 | + |
| 364 | + // Creating fake new job |
| 365 | + Item mockedItem = Mockito.mock(Job.class); |
| 366 | + when(mockedItem.getName()).thenReturn("-newFakeJob"); |
| 367 | + when(mockedItem.getRootDir()).thenReturn(jobDirectory); |
| 368 | + |
| 369 | + sscItemListener.onCreated(mockedItem); |
| 370 | + |
| 371 | + verifyCurrentScmContentMatchesHierarchy("expected-scm-hierarchies/InitRepositoryTest.shouldSynchronizeHudsonFiles/"); |
| 372 | + |
| 373 | + sscConfigurationSaveableListener.onChange(mockedItem, new XmlFile(configFile)); |
| 374 | + |
| 375 | + verifyCurrentScmContentMatchesHierarchy("expected-scm-hierarchies/HudsonExtensionsTest.testAddJobNameStartingWithDash/"); |
| 376 | + |
| 377 | + assertStatusManagerIsOk(); |
| 378 | + |
| 379 | + // Now fake a rename |
| 380 | + assertTrue("Config file deletion", configFile.delete()); |
| 381 | + assertTrue("Job dir deletion", jobDirectory.delete()); |
| 382 | + jobDirectory = new File(getCurrentHudsonRootDirectory(), "jobs/new fake Job/" ); |
| 383 | + configFile = new File(jobDirectory, "config.xml"); |
| 384 | + jobDirectory.mkdir(); |
| 385 | + FileUtils.copyFile(new ClassPathResource("expected-scm-hierarchies/HudsonExtensionsTest.testAddJobNameWithBlanks/jobs/new fake Job/config.xml").getFile(), configFile); |
| 386 | + |
| 387 | + Item mockedRenamedItem = Mockito.mock(Job.class); |
| 388 | + when(mockedRenamedItem.getName()).thenReturn("new fake Job"); |
| 389 | + when(mockedRenamedItem.getRootDir()).thenReturn(jobDirectory); |
| 390 | + |
| 391 | + sscItemListener.onLocationChanged(mockedRenamedItem, "-newFakeJob", "new fake Job"); |
| 392 | + |
| 393 | + verifyCurrentScmContentMatchesHierarchy("expected-scm-hierarchies/HudsonExtensionsTest.testAddJobNameWithBlanks/"); |
| 394 | + |
| 395 | + assertStatusManagerIsOk(); |
| 396 | + |
| 397 | + // And while we're at it: let's rename it back |
| 398 | + assertTrue("Config file deletion", configFile.delete()); |
| 399 | + assertTrue("Job dir deletion", jobDirectory.delete()); |
| 400 | + jobDirectory = new File(getCurrentHudsonRootDirectory(), "jobs/-newFakeJob/" ); |
| 401 | + configFile = new File(jobDirectory, "config.xml"); |
| 402 | + jobDirectory.mkdir(); |
| 403 | + FileUtils.copyFile(new ClassPathResource("expected-scm-hierarchies/HudsonExtensionsTest.testAddJobNameStartingWithDash/jobs/-newFakeJob/config.xml").getFile(), configFile); |
| 404 | + |
| 405 | + sscItemListener.onLocationChanged(mockedItem, "new fake Job", "-newFakeJob"); |
| 406 | + |
| 407 | + verifyCurrentScmContentMatchesHierarchy("expected-scm-hierarchies/HudsonExtensionsTest.testAddJobNameStartingWithDash/"); |
| 408 | + |
| 409 | + assertStatusManagerIsOk(); |
| 410 | + } |
| 411 | + |
315 | 412 | @Test |
316 | 413 | public void shouldFileWhichHaveToBeInSCM() throws Throwable { |
317 | 414 | // IMPORTANT NOTE : |
|
0 commit comments