~ubuntu-branches/ubuntu/saucy/jenkins/saucy-proposed

« back to all changes in this revision

Viewing changes to maven-plugin/src/test/java/hudson/maven/reporters/SurefireArchiverUnitTest.java

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-13 12:35:19 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20130813123519-tizgfxcr70trl7r0
Tags: 1.509.2+dfsg-1
* New upstream release (Closes: #706725):
  - d/control: Update versioned BD's:
    * jenkins-executable-war >= 1.28.
    * jenkins-instance-identity >= 1.3.
    * libjenkins-remoting-java >= 2.23.
    * libjenkins-winstone-java >= 0.9.10-jenkins-44.
    * libstapler-java >= 1.207.
    * libjenkins-json-java >= 2.4-jenkins-1.
    * libstapler-adjunct-timeline-java >= 1.4.
    * libstapler-adjunct-codemirror-java >= 1.2.
    * libmaven-hpi-plugin-java >= 1.93.
    * libjenkins-xstream-java >= 1.4.4-jenkins-3.
  - d/maven.rules: Map to older version of animal-sniffer-maven-plugin.
  - Add patch for compatibility with guava >= 0.14.
  - Add patch to exclude asm4 dependency via jnr-posix.
  - Fixes the following security vulnerabilities:
    CVE-2013-2034, CVE-2013-2033, CVE-2013-2034, CVE-2013-1808
* d/patches/*: Switch to using git patch-queue for managing patches.
* De-duplicate jars between libjenkins-java and jenkins-external-job-monitor
  (Closes: #701163):
  - d/control: Add dependency between jenkins-external-job-monitor ->
    libjenkins-java.
  - d/rules: 
    Drop installation of jenkins-core in jenkins-external-job-monitor.
  - d/jenkins-external-job-monitor.{links,install}: Link to jenkins-core
    in /usr/share/java instead of included version.
* Wait longer for jenkins to stop during restarts (Closes: #704848):
  - d/jenkins.init: Re-sync init script from upstream codebase.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package hudson.maven.reporters;
2
2
 
 
3
import static org.junit.Assert.assertEquals;
3
4
import static org.mockito.Mockito.doReturn;
4
5
import static org.mockito.Mockito.mock;
5
6
import static org.mockito.Mockito.spy;
13
14
import hudson.maven.MavenProjectActionBuilder;
14
15
import hudson.maven.MavenReporter;
15
16
import hudson.maven.MojoInfo;
 
17
import hudson.maven.MojoInfoBuilder;
16
18
import hudson.model.BuildListener;
17
19
import hudson.model.Cause;
18
20
import hudson.model.Result;
28
30
import java.util.List;
29
31
 
30
32
import org.apache.commons.io.output.NullOutputStream;
31
 
import org.apache.maven.plugin.MojoExecution;
32
 
import org.apache.maven.plugin.descriptor.MojoDescriptor;
33
 
import org.apache.maven.plugin.descriptor.PluginDescriptor;
34
 
import org.apache.tools.ant.types.FileSet;
35
33
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
36
34
import org.junit.Assert;
37
35
import org.junit.Before;
53
51
    @Before
54
52
    @SuppressWarnings("unchecked")
55
53
    public void before() throws ComponentConfigurationException, URISyntaxException {
56
 
        //suppress(constructor(MavenBuild.class, new Class[0]));
57
 
        
58
54
        this.archiver = new SurefireArchiver();
59
55
        this.build = mock(MavenBuild.class);
60
56
        when(build.getAction(Matchers.any(Class.class))).thenCallRealMethod();
69
65
    }
70
66
 
71
67
    private MojoInfo createMojoInfo() throws ComponentConfigurationException {
72
 
        PluginDescriptor pluginDescriptor = new PluginDescriptor();
73
 
        pluginDescriptor.setGroupId("org.apache.maven.plugins");
74
 
        pluginDescriptor.setArtifactId("maven-surefire-plugin");
75
 
        pluginDescriptor.setVersion("2.9");
76
 
        
77
 
        MojoDescriptor mojoDescriptor = new MojoDescriptor();
78
 
        mojoDescriptor.setPluginDescriptor(pluginDescriptor);
79
 
        mojoDescriptor.setGoal("test");
80
 
        
81
 
        MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
82
 
        MojoInfo info = new MojoInfo(mojoExecution, null, null, null);
 
68
        MojoInfo info = MojoInfoBuilder.mojoBuilder("org.apache.maven.plugins", "maven-surefire-plugin", "test")
 
69
                .version("2.9").build();
83
70
        
84
71
        MojoInfo spy = spy(info);
85
72
        
103
90
    public void testArchiveResults() throws InterruptedException, IOException, URISyntaxException, ComponentConfigurationException {
104
91
        URL resource = SurefireArchiverUnitTest.class.getResource("/surefire-archiver-test2");
105
92
        File reportsDir = new File(resource.toURI().getPath());
 
93
        
106
94
        doReturn(reportsDir).when(this.mojoInfo).getConfigurationValue("reportsDirectory", File.class);
107
95
        touchReportFiles(reportsDir);
108
96
        
130
118
    }
131
119
    
132
120
    @Test
133
 
    public void testAlreadyCheckedFilesAreNotParsedAgain() throws InterruptedException, IOException, URISyntaxException, ComponentConfigurationException {
 
121
    public void testResultsAreNotCountedTwice() throws InterruptedException, IOException, URISyntaxException, ComponentConfigurationException {
134
122
        URL resource = SurefireArchiverUnitTest.class.getResource("/surefire-archiver-test2");
135
123
        File reportsDir = new File(resource.toURI().getPath());
136
124
        doReturn(reportsDir).when(this.mojoInfo).getConfigurationValue("reportsDirectory", File.class);
137
125
        touchReportFiles(reportsDir);
138
126
        
139
 
        FileSet fileSet = this.archiver.getFileSet(reportsDir);
140
 
        Assert.assertEquals(2, fileSet.getDirectoryScanner().getIncludedFilesCount());
 
127
        this.archiver.postExecute(buildProxy, null, this.mojoInfo, new NullBuildListener(), null);
 
128
        SurefireReport action = this.build.getAction(SurefireReport.class);
 
129
        TestResult result = action.getResult();
 
130
        assertEquals(2658, result.getTotalCount());
141
131
        
 
132
        // result count shouldn't increase if mojo is called again
142
133
        this.archiver.postExecute(buildProxy, null, this.mojoInfo, new NullBuildListener(), null);
143
 
 
144
 
        fileSet = this.archiver.getFileSet(reportsDir);
145
 
        Assert.assertEquals(0, fileSet.getDirectoryScanner().getIncludedFilesCount());
 
134
        action = this.build.getAction(SurefireReport.class);
 
135
        result = action.getResult();
 
136
        assertEquals(2658, result.getTotalCount());
146
137
    }
147
138
    
148
139
    @Test
205
196
    private void touchReportFiles(File reportsDir) {
206
197
        File[] files = reportsDir.listFiles();
207
198
        for(File f : files) {
208
 
            f.setLastModified(System.currentTimeMillis());
 
199
            f.setLastModified(this.mojoInfo.getStartTime());
209
200
        }
210
201
    }
211
202