Search in sources :

Example 11 with RunIf

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));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Example 12 with RunIf

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();
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) FileLock(java.nio.channels.FileLock) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) IOException(java.io.IOException) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Example 13 with RunIf

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ResultSet(java.sql.ResultSet) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) File(java.io.File) Pipeline(com.thoughtworks.go.domain.Pipeline) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Example 14 with RunIf

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());
}
Also used : ServerBackup(com.thoughtworks.go.server.domain.ServerBackup) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TimeProvider(com.thoughtworks.go.util.TimeProvider) File(java.io.File) DateTime(org.joda.time.DateTime) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Example 15 with RunIf

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);
}
Also used : File(java.io.File) RunIf(com.googlecode.junit.ext.RunIf)

Aggregations

RunIf (com.googlecode.junit.ext.RunIf)17 Test (org.junit.Test)15 File (java.io.File)7 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 JavaSysMon (com.jezhumble.javasysmon.JavaSysMon)2 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2 OsProcess (com.jezhumble.javasysmon.OsProcess)1 ProcessVisitor (com.jezhumble.javasysmon.ProcessVisitor)1 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)1 BuildCommand (com.thoughtworks.go.domain.BuildCommand)1 Pipeline (com.thoughtworks.go.domain.Pipeline)1 RunIfConfigs (com.thoughtworks.go.domain.RunIfConfigs)1 ServerBackup (com.thoughtworks.go.server.domain.ServerBackup)1 LogFixture (com.thoughtworks.go.util.LogFixture)1 TimeProvider (com.thoughtworks.go.util.TimeProvider)1 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1