use of com.googlecode.junit.ext.RunIf in project gocd by gocd.
the class ScriptRunnerTest method shouldBeAbleToSpecifyEncoding.
@Test
@RunIf(value = OSChecker.class, arguments = OSChecker.LINUX)
public void shouldBeAbleToSpecifyEncoding() throws CheckedCommandLineException {
String chrisWasHere = "司徒空在此";
CommandLine command = CommandLine.createCommandLine("echo").withArg(chrisWasHere).withEncoding("UTF-8");
InMemoryConsumer output = new InMemoryConsumer();
ExecScript script = new ExecScript("FOO");
command.runScript(script, output, new EnvironmentVariableContext(), null);
assertThat(output.toString(), containsString(chrisWasHere));
}
use of com.googlecode.junit.ext.RunIf in project gocd by gocd.
the class GitMaterialTest method shouldThrowExceptionWhenWorkingDirectoryIsNotGitRepoAndItsUnableToDeleteIt.
@Test
@RunIf(value = EnhancedOSChecker.class, arguments = { EnhancedOSChecker.WINDOWS })
public void shouldThrowExceptionWhenWorkingDirectoryIsNotGitRepoAndItsUnableToDeleteIt() throws Exception {
File fileToBeLocked = new File(workingDir, "file");
RandomAccessFile lockedFile = new RandomAccessFile(fileToBeLocked, "rw");
FileLock lock = lockedFile.getChannel().lock();
try {
git.latestModification(workingDir, new TestSubprocessExecutionContext());
fail("Should have failed to check modifications since the file is locked and cannot be removed.");
} catch (Exception e) {
assertEquals(e.getMessage().trim(), "Failed to delete directory: " + workingDir.getAbsolutePath().trim());
assertEquals(true, fileToBeLocked.exists());
} finally {
lock.release();
}
}
use of com.googlecode.junit.ext.RunIf in project gocd by gocd.
the class BackupServiceH2IntegrationTest method shouldPerformDbBackupProperly.
@Test
@RunIf(value = DatabaseChecker.class, arguments = { DatabaseChecker.H2 })
public void shouldPerformDbBackupProperly() throws SQLException, IOException {
Pipeline expectedPipeline = saveAPipeline();
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
backupService.startBackup(admin, result);
assertThat(result.isSuccessful(), is(true));
assertThat(result.message(localizer), is("Backup completed successfully."));
String location = temporaryFolder.newFolder().getAbsolutePath();
Restore.execute(dbZip(), location, "cruise", false);
BasicDataSource source = constructTestDataSource(new File(location));
ResultSet resultSet = source.getConnection().prepareStatement("select * from pipelines where id = " + expectedPipeline.getId()).executeQuery();
int size = 0;
while (resultSet.next()) {
assertThat(resultSet.getString("name"), is(expectedPipeline.getName()));
size++;
}
assertThat(size, is(1));
}
use of com.googlecode.junit.ext.RunIf in project gocd by gocd.
the class BackupServiceH2IntegrationTest method shouldCreateTheBackupUnderArtifactRepository.
@Test
@RunIf(value = DatabaseChecker.class, arguments = { DatabaseChecker.H2 })
public void shouldCreateTheBackupUnderArtifactRepository() {
TimeProvider timeProvider = mock(TimeProvider.class);
DateTime now = new DateTime();
when(timeProvider.currentDateTime()).thenReturn(now);
assertThat(backupsDirectory.exists(), is(false));
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
BackupService service = new BackupService(dataSource, artifactsDirHolder, goConfigService, timeProvider, backupInfoRepository, systemEnvironment, serverVersion, configRepository, databaseStrategy);
service.initialize();
service.startBackup(admin, result);
assertThat(result.isSuccessful(), is(true));
assertThat(backupsDirectory.exists(), is(true));
assertThat(backupsDirectory.isDirectory(), is(true));
File backup = new File(backupsDirectory, BackupService.BACKUP + now.toString("YYYYMMdd-HHmmss"));
assertThat(backup.exists(), is(true));
assertThat(new File(backup, "db.zip").exists(), is(true));
assertEquals(new ServerBackup(backup.getAbsolutePath(), now.toDate(), admin.getUsername().toString()), backupInfoRepository.lastBackup());
}
use of com.googlecode.junit.ext.RunIf in project gocd by gocd.
the class CommandRepositoryDirectoryWalkerTest method shouldUpdateServerHealthServiceIfACommandSnippetXMLIsUnReadableAndRemoveItOnceItsReadable.
@Test
@RunIf(value = EnhancedOSChecker.class, arguments = { DO_NOT_RUN_ON, WINDOWS })
public void shouldUpdateServerHealthServiceIfACommandSnippetXMLIsUnReadableAndRemoveItOnceItsReadable() throws IOException {
File dirWithUnreadableFile = temporaryFolder.newFolder("dirWithUnreadableFile");
File unreadableFile = new File(dirWithUnreadableFile, "unreadable.xml");
FileUtils.copyFile(xmlFile, unreadableFile);
unreadableFile.setReadable(false);
walker.getAllCommandSnippets(dirWithUnreadableFile.getPath());
verify(serverHealthService).update(serverHealthWarningMessageWhichContains("Failed to access command snippet XML file located in Go Server Directory at " + unreadableFile.getPath() + ". Go does not have sufficient permissions to access it."));
unreadableFile.setReadable(true);
walker.getAllCommandSnippets(dirWithUnreadableFile.getPath());
verify(serverHealthService, times(2)).update(serverHealthMessageWhichSaysItsOk());
verifyNoMoreInteractions(serverHealthService);
}
Aggregations