Search in sources :

Example 1 with JobStatus

use of fr.inria.spirals.repairnator.process.inspectors.JobStatus in project repairnator by Spirals-Team.

the class TestInitRepoToPush method testInitRepoShouldRemoveNotificationInTravisYML.

@Test
public void testInitRepoShouldRemoveNotificationInTravisYML() throws IOException {
    int buildId = 331637757;
    RepairnatorConfig repairnatorConfig = RepairnatorConfig.getInstance();
    repairnatorConfig.setClean(false);
    repairnatorConfig.setPush(true);
    Build build = BuildHelper.getBuildFromId(buildId, null);
    assertThat(build, notNullValue());
    assertThat(buildId, is(build.getId()));
    Path tmpDirPath = Files.createTempDirectory("test_initRepoToPush");
    File tmpDir = tmpDirPath.toFile();
    tmpDir.deleteOnExit();
    BuildToBeInspected toBeInspected = new BuildToBeInspected(build, null, ScannedBuildStatus.ONLY_FAIL, "");
    ProjectInspector inspector = mock(ProjectInspector.class);
    when(inspector.getWorkspace()).thenReturn(tmpDir.getAbsolutePath());
    when(inspector.getRepoLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repo");
    when(inspector.getRepoToPushLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repotopush");
    when(inspector.getBuildToBeInspected()).thenReturn(toBeInspected);
    when(inspector.getBuggyBuild()).thenReturn(build);
    when(inspector.getGitHelper()).thenReturn(new GitHelper());
    JobStatus jobStatus = new JobStatus(tmpDir.getAbsolutePath() + "/repo");
    when(inspector.getJobStatus()).thenReturn(jobStatus);
    CloneRepository cloneStep = new CloneRepository(inspector);
    cloneStep.setNextStep(new CheckoutBuggyBuild(inspector)).setNextStep(new InitRepoToPush(inspector));
    cloneStep.execute();
    assertThat(jobStatus.getPushState(), is(PushState.REPO_INITIALIZED));
    File bak = new File(tmpDir.getAbsolutePath() + "/repotopush/bak.travis.yml");
    File travis = new File(tmpDir.getAbsolutePath() + "/repotopush/.travis.yml");
    assertTrue(bak.exists());
    assertTrue(travis.exists());
    boolean detected = false;
    List<String> lines = Files.readAllLines(travis.toPath());
    for (String l : lines) {
        if (l.contains("notification")) {
            assertTrue(l.trim().startsWith("#"));
            detected = true;
        }
        if (l.contains("script")) {
            assertFalse(l.trim().startsWith("#"));
        }
    }
    assertTrue(detected);
}
Also used : Path(java.nio.file.Path) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) RepairnatorConfig(fr.inria.spirals.repairnator.config.RepairnatorConfig) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CloneRepository(fr.inria.spirals.repairnator.process.step.CloneRepository) Build(fr.inria.jtravis.entities.Build) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) File(java.io.File) Test(org.junit.Test)

Example 2 with JobStatus

use of fr.inria.spirals.repairnator.process.inspectors.JobStatus in project repairnator by Spirals-Team.

the class TestInitRepoToPush method testInitRepoToPushSimpleCase.

@Test
public void testInitRepoToPushSimpleCase() throws IOException, GitAPIException, RepairnatorConfigException {
    // surli/failingProject build
    int buildId = 207924136;
    RepairnatorConfig repairnatorConfig = RepairnatorConfig.getInstance();
    repairnatorConfig.setClean(false);
    repairnatorConfig.setPush(true);
    Build build = BuildHelper.getBuildFromId(buildId, null);
    assertThat(build, notNullValue());
    assertThat(buildId, is(build.getId()));
    Path tmpDirPath = Files.createTempDirectory("test_initRepoToPush");
    File tmpDir = tmpDirPath.toFile();
    tmpDir.deleteOnExit();
    BuildToBeInspected toBeInspected = new BuildToBeInspected(build, null, ScannedBuildStatus.ONLY_FAIL, "");
    ProjectInspector inspector = mock(ProjectInspector.class);
    when(inspector.getWorkspace()).thenReturn(tmpDir.getAbsolutePath());
    when(inspector.getRepoLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repo");
    when(inspector.getRepoToPushLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repotopush");
    when(inspector.getBuildToBeInspected()).thenReturn(toBeInspected);
    when(inspector.getBuggyBuild()).thenReturn(build);
    when(inspector.getGitHelper()).thenReturn(new GitHelper());
    JobStatus jobStatus = new JobStatus(tmpDir.getAbsolutePath() + "/repo");
    when(inspector.getJobStatus()).thenReturn(jobStatus);
    CloneRepository cloneStep = new CloneRepository(inspector);
    cloneStep.setNextStep(new CheckoutBuggyBuild(inspector)).setNextStep(new InitRepoToPush(inspector));
    cloneStep.execute();
    assertThat(jobStatus.getPushState(), is(PushState.REPO_INITIALIZED));
    Git gitDir = Git.open(new File(tmpDir, "repotopush"));
    Iterable<RevCommit> logs = gitDir.log().call();
    Iterator<RevCommit> iterator = logs.iterator();
    assertThat(iterator.hasNext(), is(true));
    RevCommit commit = iterator.next();
    assertThat(commit.getShortMessage(), containsString("End of the repairnator process"));
    RevCommit firstCommit = iterator.next();
    assertThat(firstCommit.getShortMessage(), containsString("Bug commit"));
    assertThat(iterator.hasNext(), is(false));
}
Also used : Path(java.nio.file.Path) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) RepairnatorConfig(fr.inria.spirals.repairnator.config.RepairnatorConfig) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CloneRepository(fr.inria.spirals.repairnator.process.step.CloneRepository) Git(org.eclipse.jgit.api.Git) Build(fr.inria.jtravis.entities.Build) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 3 with JobStatus

use of fr.inria.spirals.repairnator.process.inspectors.JobStatus in project repairnator by Spirals-Team.

the class TestMavenFilterTestOutputHandler method testFilterLogWillWork.

@Test
public void testFilterLogWillWork() throws IOException {
    String resourcePath = "./src/test/resources/build-logs/log-test-failures.txt";
    List<String> lines = Files.readAllLines(new File(resourcePath).toPath());
    ProjectInspector inspector = mock(ProjectInspector.class);
    Path tmp = Files.createTempDirectory("test-filter");
    when(inspector.getRepoLocalPath()).thenReturn(tmp.toAbsolutePath().toString());
    JobStatus jobStatus = new JobStatus(tmp.toAbsolutePath().toString());
    when(inspector.getJobStatus()).thenReturn(jobStatus);
    MavenHelper mavenHelper = mock(MavenHelper.class);
    when(mavenHelper.getInspector()).thenReturn(inspector);
    when(mavenHelper.getName()).thenReturn("test");
    MavenFilterTestOutputHandler filterTest = new MavenFilterTestOutputHandler(mavenHelper);
    for (String s : lines) {
        filterTest.consumeLine(s);
    }
    assertTrue(filterTest.isFailingWithTest());
    assertEquals(40, filterTest.getRunningTests());
    assertEquals(0, filterTest.getFailingTests());
    assertEquals(9, filterTest.getErroringTests());
    assertEquals(3, filterTest.getSkippingTests());
}
Also used : Path(java.nio.file.Path) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) MavenHelper(fr.inria.spirals.repairnator.process.maven.MavenHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) File(java.io.File) Test(org.junit.Test)

Example 4 with JobStatus

use of fr.inria.spirals.repairnator.process.inspectors.JobStatus in project repairnator by Spirals-Team.

the class TestMavenFilterTestOutputHandler method testFilterLogWillWork2.

@Test
public void testFilterLogWillWork2() throws IOException {
    String resourcePath = "./src/test/resources/build-logs/log-test-druidio.txt";
    List<String> lines = Files.readAllLines(new File(resourcePath).toPath());
    ProjectInspector inspector = mock(ProjectInspector.class);
    Path tmp = Files.createTempDirectory("test-filter");
    when(inspector.getRepoLocalPath()).thenReturn(tmp.toAbsolutePath().toString());
    JobStatus jobStatus = new JobStatus(tmp.toAbsolutePath().toString());
    when(inspector.getJobStatus()).thenReturn(jobStatus);
    MavenHelper mavenHelper = mock(MavenHelper.class);
    when(mavenHelper.getInspector()).thenReturn(inspector);
    when(mavenHelper.getName()).thenReturn("test");
    MavenFilterTestOutputHandler filterTest = new MavenFilterTestOutputHandler(mavenHelper);
    for (String s : lines) {
        filterTest.consumeLine(s);
    }
    assertFalse(filterTest.isFailingWithTest());
    assertEquals(77351 * 2, filterTest.getRunningTests());
    assertEquals(0, filterTest.getFailingTests());
    assertEquals(0, filterTest.getErroringTests());
    assertEquals((52 + 6 + 1) * 2, filterTest.getSkippingTests());
}
Also used : Path(java.nio.file.Path) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) MavenHelper(fr.inria.spirals.repairnator.process.maven.MavenHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) File(java.io.File) Test(org.junit.Test)

Example 5 with JobStatus

use of fr.inria.spirals.repairnator.process.inspectors.JobStatus in project repairnator by Spirals-Team.

the class TestAbstractStep method testSetPropertiesWillGivePropertiesToOtherSteps.

@Test
public void testSetPropertiesWillGivePropertiesToOtherSteps() {
    ProjectInspector mockInspector = mock(ProjectInspector.class);
    JobStatus jobStatus = new JobStatus("");
    when(mockInspector.getJobStatus()).thenReturn(jobStatus);
    AbstractStep step1 = new AbstractStepNop(mockInspector);
    AbstractStep step2 = new AbstractStepNop(mockInspector);
    AbstractStep step3 = new AbstractStepNop(mockInspector);
    Properties properties = new Properties();
    properties.setProperty("testvalue", "toto");
    properties.setProperty("anotherone", "foo");
    step1.setNextStep(step2).setNextStep(step3);
    step1.setProperties(properties);
    assertThat(step3.getProperties(), is(properties));
}
Also used : JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

JobStatus (fr.inria.spirals.repairnator.process.inspectors.JobStatus)48 ProjectInspector (fr.inria.spirals.repairnator.process.inspectors.ProjectInspector)39 Test (org.junit.Test)38 Build (fr.inria.jtravis.entities.Build)37 BuildToBeInspected (fr.inria.spirals.repairnator.BuildToBeInspected)35 File (java.io.File)34 Path (java.nio.file.Path)33 GitHelper (fr.inria.spirals.repairnator.process.git.GitHelper)30 CheckoutBuggyBuild (fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild)22 CloneRepository (fr.inria.spirals.repairnator.process.step.CloneRepository)10 CheckoutPatchedBuild (fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutPatchedBuild)8 Git (org.eclipse.jgit.api.Git)7 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 GatherTestInformation (fr.inria.spirals.repairnator.process.step.gatherinfo.GatherTestInformation)5 ArrayList (java.util.ArrayList)5 JsonObject (com.google.gson.JsonObject)4 RepairnatorConfig (fr.inria.spirals.repairnator.config.RepairnatorConfig)4 BuildShouldFail (fr.inria.spirals.repairnator.process.step.gatherinfo.BuildShouldFail)4 Date (java.util.Date)4 ScannedBuildStatus (fr.inria.spirals.repairnator.states.ScannedBuildStatus)3