2018-01-30 14:33:28 +02:00
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.rules.RuleChain
|
2018-02-05 17:02:59 +02:00
|
|
|
import org.junit.Ignore
|
2018-01-30 14:33:28 +02:00
|
|
|
|
|
|
|
import com.lesfurets.jenkins.unit.BasePipelineTest
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals
|
|
|
|
import static org.junit.Assert.assertTrue
|
|
|
|
|
2018-02-01 14:17:17 +02:00
|
|
|
import util.Rules
|
2018-01-30 14:33:28 +02:00
|
|
|
|
2018-02-02 15:50:26 +02:00
|
|
|
class ChecksPublishResultsTest extends BasePipelineTest {
|
2018-01-30 14:33:28 +02:00
|
|
|
Map publisherStepOptions
|
2018-01-30 16:26:54 +02:00
|
|
|
List archiveStepPatterns
|
2018-01-30 14:33:28 +02:00
|
|
|
|
|
|
|
@Rule
|
2018-02-06 10:53:27 +02:00
|
|
|
public RuleChain ruleChain = Rules.getCommonRules(this)
|
2018-01-30 14:33:28 +02:00
|
|
|
|
2018-02-08 17:38:55 +02:00
|
|
|
def checksPublishResultsScript
|
2018-01-30 14:33:28 +02:00
|
|
|
|
|
|
|
@Before
|
|
|
|
void init() {
|
|
|
|
publisherStepOptions = [:]
|
2018-01-30 16:26:54 +02:00
|
|
|
archiveStepPatterns = []
|
2018-01-30 14:33:28 +02:00
|
|
|
// prepare checkResultsPublish step
|
2018-02-08 17:38:55 +02:00
|
|
|
checksPublishResultsScript = loadScript("checksPublishResults.groovy").checksPublishResults
|
2018-01-30 14:33:28 +02:00
|
|
|
// add handler for generic step call
|
|
|
|
helper.registerAllowedMethod("step", [Map.class], {
|
|
|
|
parameters -> publisherStepOptions[parameters.$class] = parameters
|
|
|
|
})
|
2018-01-30 16:26:54 +02:00
|
|
|
helper.registerAllowedMethod("archiveArtifacts", [Map.class], {
|
|
|
|
parameters -> archiveStepPatterns.push(parameters.artifacts)
|
|
|
|
})
|
2018-01-30 14:33:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testPublishWithDefaultSettings() throws Exception {
|
2018-02-08 17:38:55 +02:00
|
|
|
checksPublishResultsScript.call()
|
2018-01-30 16:26:54 +02:00
|
|
|
|
|
|
|
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
|
|
|
|
// ensure nothing else is published
|
|
|
|
assertTrue("WarningsPublisher options not empty", publisherStepOptions['WarningsPublisher'] == null)
|
|
|
|
assertTrue("PmdPublisher options not empty", publisherStepOptions['PmdPublisher'] == null)
|
|
|
|
assertTrue("DryPublisher options not empty", publisherStepOptions['DryPublisher'] == null)
|
|
|
|
assertTrue("FindBugsPublisher options not empty", publisherStepOptions['FindBugsPublisher'] == null)
|
|
|
|
assertTrue("CheckStylePublisher options not empty", publisherStepOptions['CheckStylePublisher'] == null)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testPublishForJavaWithDefaultSettings() throws Exception {
|
2018-02-08 17:38:55 +02:00
|
|
|
checksPublishResultsScript.call(pmd: true, cpd: true, findbugs: true, checkstyle: true)
|
2018-01-30 16:26:54 +02:00
|
|
|
|
|
|
|
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
|
|
|
|
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
|
|
|
|
assertTrue("DryPublisher options not set", publisherStepOptions['DryPublisher'] != null)
|
|
|
|
assertTrue("FindBugsPublisher options not set", publisherStepOptions['FindBugsPublisher'] != null)
|
|
|
|
assertTrue("CheckStylePublisher options not set", publisherStepOptions['CheckStylePublisher'] != null)
|
|
|
|
// ensure default patterns are set
|
|
|
|
assertEquals("PmdPublisher default pattern not set", '**/target/pmd.xml', publisherStepOptions['PmdPublisher']['pattern'])
|
|
|
|
assertEquals("DryPublisher default pattern not set", '**/target/cpd.xml', publisherStepOptions['DryPublisher']['pattern'])
|
|
|
|
assertEquals("FindBugsPublisher default pattern not set", '**/target/findbugsXml.xml, **/target/findbugs.xml', publisherStepOptions['FindBugsPublisher']['pattern'])
|
|
|
|
assertEquals("CheckStylePublisher default pattern not set", '**/target/checkstyle-result.xml', publisherStepOptions['CheckStylePublisher']['pattern'])
|
|
|
|
// ensure nothing else is published
|
|
|
|
assertTrue("WarningsPublisher options not empty", publisherStepOptions['WarningsPublisher'] == null)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testPublishForJavaScriptWithDefaultSettings() throws Exception {
|
2018-02-08 17:38:55 +02:00
|
|
|
checksPublishResultsScript.call(eslint: true)
|
2018-01-30 16:26:54 +02:00
|
|
|
|
|
|
|
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
|
|
|
|
assertTrue("WarningsPublisher options not set", publisherStepOptions['WarningsPublisher'] != null)
|
|
|
|
assertTrue("WarningsPublisher parser configuration number not correct", publisherStepOptions['WarningsPublisher']['parserConfigurations'].size() == 1)
|
|
|
|
// ensure correct parser is set set
|
|
|
|
assertEquals("ESLint parser not correct", 'JSLint', publisherStepOptions['WarningsPublisher']['parserConfigurations'][0]['parserName'])
|
|
|
|
// ensure default patterns are set
|
|
|
|
assertEquals("ESLint default pattern not set", '**/eslint.xml', publisherStepOptions['WarningsPublisher']['parserConfigurations'][0]['pattern'])
|
|
|
|
// ensure nothing else is published
|
|
|
|
assertTrue("PmdPublisher options not empty", publisherStepOptions['PmdPublisher'] == null)
|
|
|
|
assertTrue("DryPublisher options not empty", publisherStepOptions['DryPublisher'] == null)
|
|
|
|
assertTrue("FindBugsPublisher options not empty", publisherStepOptions['FindBugsPublisher'] == null)
|
|
|
|
assertTrue("CheckStylePublisher options not empty", publisherStepOptions['CheckStylePublisher'] == null)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testPublishForPythonWithDefaultSettings() throws Exception {
|
2018-02-08 17:38:55 +02:00
|
|
|
checksPublishResultsScript.call(pylint: true)
|
2018-01-30 16:26:54 +02:00
|
|
|
|
|
|
|
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
|
|
|
|
assertTrue("WarningsPublisher options not set", publisherStepOptions['WarningsPublisher'] != null)
|
|
|
|
assertTrue("WarningsPublisher parser configuration number not correct", publisherStepOptions['WarningsPublisher']['parserConfigurations'].size() == 1)
|
|
|
|
assertEquals('PyLint', publisherStepOptions['WarningsPublisher']['parserConfigurations'][0]['parserName'])
|
|
|
|
// ensure correct parser is set set
|
|
|
|
assertEquals("PyLint parser not correct", 'PyLint', publisherStepOptions['WarningsPublisher']['parserConfigurations'][0]['parserName'])
|
|
|
|
// ensure default patterns are set
|
|
|
|
assertEquals("PyLint default pattern not set", '**/pylint.log', publisherStepOptions['WarningsPublisher']['parserConfigurations'][0]['pattern'])
|
|
|
|
// ensure nothing else is published
|
|
|
|
assertTrue("PmdPublisher options not empty", publisherStepOptions['PmdPublisher'] == null)
|
|
|
|
assertTrue("DryPublisher options not empty", publisherStepOptions['DryPublisher'] == null)
|
|
|
|
assertTrue("FindBugsPublisher options not empty", publisherStepOptions['FindBugsPublisher'] == null)
|
|
|
|
assertTrue("CheckStylePublisher options not empty", publisherStepOptions['CheckStylePublisher'] == null)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testPublishNothing() throws Exception {
|
2018-02-08 17:38:55 +02:00
|
|
|
checksPublishResultsScript.call(aggregation: false)
|
2018-01-30 16:26:54 +02:00
|
|
|
|
|
|
|
// ensure nothing is published
|
|
|
|
assertTrue("AnalysisPublisher options not empty", publisherStepOptions['AnalysisPublisher'] == null)
|
|
|
|
assertTrue("WarningsPublisher options not empty", publisherStepOptions['WarningsPublisher'] == null)
|
|
|
|
assertTrue("PmdPublisher options not empty", publisherStepOptions['PmdPublisher'] == null)
|
|
|
|
assertTrue("DryPublisher options not empty", publisherStepOptions['DryPublisher'] == null)
|
|
|
|
assertTrue("FindBugsPublisher options not empty", publisherStepOptions['FindBugsPublisher'] == null)
|
|
|
|
assertTrue("CheckStylePublisher options not empty", publisherStepOptions['CheckStylePublisher'] == null)
|
|
|
|
}
|
|
|
|
|
2018-02-05 14:48:39 +02:00
|
|
|
@Test
|
|
|
|
void testPublishNothingExplicitFalse() throws Exception {
|
2018-02-08 17:38:55 +02:00
|
|
|
checksPublishResultsScript.call(pmd: false)
|
2018-02-05 14:48:39 +02:00
|
|
|
|
|
|
|
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
|
|
|
|
// ensure nothing else is published
|
2018-02-08 11:50:11 +02:00
|
|
|
assertTrue("PmdPublisher options not empty", publisherStepOptions['PmdPublisher'] == null)
|
2018-02-05 14:48:39 +02:00
|
|
|
assertTrue("DryPublisher options not empty", publisherStepOptions['DryPublisher'] == null)
|
|
|
|
assertTrue("FindBugsPublisher options not empty", publisherStepOptions['FindBugsPublisher'] == null)
|
|
|
|
assertTrue("CheckStylePublisher options not empty", publisherStepOptions['CheckStylePublisher'] == null)
|
|
|
|
assertTrue("WarningsPublisher options not empty", publisherStepOptions['WarningsPublisher'] == null)
|
|
|
|
}
|
|
|
|
|
2018-02-08 11:50:11 +02:00
|
|
|
@Test
|
|
|
|
void testPublishNothingImplicitTrue() throws Exception {
|
2018-02-08 17:38:55 +02:00
|
|
|
checksPublishResultsScript.call(pmd: [:])
|
2018-02-08 11:50:11 +02:00
|
|
|
|
|
|
|
// ensure pmd is not published
|
|
|
|
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testPublishNothingExplicitActiveFalse() throws Exception {
|
2018-02-08 17:38:55 +02:00
|
|
|
checksPublishResultsScript.call(pmd: [active: false])
|
2018-02-08 11:50:11 +02:00
|
|
|
|
|
|
|
// ensure pmd is not published
|
|
|
|
assertTrue("PmdPublisher options not empty", publisherStepOptions['PmdPublisher'] == null)
|
|
|
|
}
|
|
|
|
|
2018-02-05 14:48:39 +02:00
|
|
|
@Test
|
|
|
|
void testPublishWithChangedStepDefaultSettings() throws Exception {
|
|
|
|
// pmd has been set to active: true in step configuration
|
2018-02-08 17:38:55 +02:00
|
|
|
checksPublishResultsScript.call(script: [commonPipelineEnvironment: [
|
2018-02-05 17:02:59 +02:00
|
|
|
configuration: [steps: [checksPublishResults: [pmd: [active: true]]]]
|
|
|
|
]])
|
2018-02-05 14:48:39 +02:00
|
|
|
|
|
|
|
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
|
|
|
|
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
|
|
|
|
// ensure nothing else is published
|
|
|
|
assertTrue("DryPublisher options not empty", publisherStepOptions['DryPublisher'] == null)
|
|
|
|
assertTrue("FindBugsPublisher options not empty", publisherStepOptions['FindBugsPublisher'] == null)
|
|
|
|
assertTrue("CheckStylePublisher options not empty", publisherStepOptions['CheckStylePublisher'] == null)
|
|
|
|
assertTrue("WarningsPublisher options not empty", publisherStepOptions['WarningsPublisher'] == null)
|
|
|
|
}
|
|
|
|
|
2018-01-30 16:26:54 +02:00
|
|
|
@Test
|
|
|
|
void testPublishWithCustomPattern() throws Exception {
|
2018-02-08 17:38:55 +02:00
|
|
|
checksPublishResultsScript.call(eslint: [pattern: 'my-fancy-file.ext'], pmd: [pattern: 'this-is-not-a-patter.xml'])
|
2018-01-30 16:26:54 +02:00
|
|
|
|
|
|
|
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
|
|
|
|
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
|
|
|
|
assertTrue("WarningsPublisher options not set", publisherStepOptions['WarningsPublisher'] != null)
|
|
|
|
assertTrue("WarningsPublisher parser configuration number not correct", publisherStepOptions['WarningsPublisher']['parserConfigurations'].size() == 1)
|
|
|
|
// ensure custom patterns are set
|
|
|
|
assertEquals("PmdPublisher custom pattern not set", 'this-is-not-a-patter.xml', publisherStepOptions['PmdPublisher']['pattern'])
|
|
|
|
assertEquals("ESLint custom pattern not set", 'my-fancy-file.ext', publisherStepOptions['WarningsPublisher']['parserConfigurations'][0]['pattern'])
|
|
|
|
// ensure nothing else is published
|
|
|
|
assertTrue("DryPublisher options not empty", publisherStepOptions['DryPublisher'] == null)
|
|
|
|
assertTrue("FindBugsPublisher options not empty", publisherStepOptions['FindBugsPublisher'] == null)
|
|
|
|
assertTrue("CheckStylePublisher options not empty", publisherStepOptions['CheckStylePublisher'] == null)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testPublishWithArchive() throws Exception {
|
2018-02-08 17:38:55 +02:00
|
|
|
checksPublishResultsScript.call(archive: true, eslint: true, pmd: true, cpd: true, findbugs: true, checkstyle: true)
|
2018-01-30 16:26:54 +02:00
|
|
|
|
|
|
|
assertTrue("ArchivePatterns number not correct", archiveStepPatterns.size() == 5)
|
|
|
|
assertTrue("ArchivePatterns contains no PMD pattern", archiveStepPatterns.contains('**/target/pmd.xml'))
|
|
|
|
assertTrue("ArchivePatterns contains no CPD pattern", archiveStepPatterns.contains('**/target/cpd.xml'))
|
|
|
|
assertTrue("ArchivePatterns contains no FindBugs pattern", archiveStepPatterns.contains('**/target/findbugsXml.xml, **/target/findbugs.xml'))
|
|
|
|
assertTrue("ArchivePatterns contains no CheckStyle pattern", archiveStepPatterns.contains('**/target/checkstyle-result.xml'))
|
|
|
|
assertTrue("ArchivePatterns contains no ESLint pattern", archiveStepPatterns.contains('**/eslint.xml'))
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testPublishWithPartialArchive() throws Exception {
|
2018-02-08 17:38:55 +02:00
|
|
|
checksPublishResultsScript.call(archive: true, eslint: [archive: false], pmd: true, cpd: true, findbugs: true, checkstyle: true)
|
2018-01-30 16:26:54 +02:00
|
|
|
|
|
|
|
assertTrue("ArchivePatterns number not correct", archiveStepPatterns.size() == 4)
|
|
|
|
assertTrue("ArchivePatterns contains no PMD pattern", archiveStepPatterns.contains('**/target/pmd.xml'))
|
|
|
|
assertTrue("ArchivePatterns contains no CPD pattern", archiveStepPatterns.contains('**/target/cpd.xml'))
|
|
|
|
assertTrue("ArchivePatterns contains no FindBugs pattern", archiveStepPatterns.contains('**/target/findbugsXml.xml, **/target/findbugs.xml'))
|
|
|
|
assertTrue("ArchivePatterns contains no CheckStyle pattern", archiveStepPatterns.contains('**/target/checkstyle-result.xml'))
|
|
|
|
// ensure no ESLint pattern is contained
|
|
|
|
assertTrue("ArchivePatterns contains ESLint pattern", !archiveStepPatterns.contains('**/eslint.xml'))
|
|
|
|
}
|
|
|
|
|
2018-02-08 11:43:06 +02:00
|
|
|
@Test
|
|
|
|
void testPublishWithDefaultThresholds() throws Exception {
|
2018-02-08 17:38:55 +02:00
|
|
|
checksPublishResultsScript.call(pmd: true)
|
2018-02-08 11:43:06 +02:00
|
|
|
|
|
|
|
assertTrue("AnalysisPublisher options not set",
|
|
|
|
publisherStepOptions['AnalysisPublisher'] != null)
|
|
|
|
assertTrue("PmdPublisher options not set",
|
|
|
|
publisherStepOptions['PmdPublisher'] != null)
|
|
|
|
assertEquals("AnalysisPublisher thresholds configuration for failedTotalHigh not correct",
|
2018-02-09 13:15:26 +02:00
|
|
|
'0', publisherStepOptions['AnalysisPublisher']['failedTotalHigh'])
|
2018-02-08 11:43:06 +02:00
|
|
|
assertEquals("PmdPublisher thresholds configuration for failedTotalHigh not correct",
|
2018-02-09 13:15:26 +02:00
|
|
|
'0', publisherStepOptions['PmdPublisher']['failedTotalHigh'])
|
2018-02-08 11:43:06 +02:00
|
|
|
// ensure other values are empty
|
|
|
|
assertEquals("AnalysisPublisher thresholds configuration for failedTotalNormal is set",
|
|
|
|
null, publisherStepOptions['AnalysisPublisher']['failedTotalNormal'])
|
|
|
|
assertEquals("AnalysisPublisher thresholds configuration for failedTotalLow is set",
|
|
|
|
null, publisherStepOptions['AnalysisPublisher']['failedTotalLow'])
|
|
|
|
assertEquals("AnalysisPublisher thresholds configuration for failedTotalAll is set",
|
|
|
|
null, publisherStepOptions['AnalysisPublisher']['failedTotalAll'])
|
|
|
|
assertEquals("AnalysisPublisher thresholds configuration for unstableTotalHigh not correct",
|
|
|
|
null, publisherStepOptions['AnalysisPublisher']['unstableTotalHigh'])
|
|
|
|
assertEquals("AnalysisPublisher thresholds configuration for unstableTotalNormal is set",
|
|
|
|
null, publisherStepOptions['AnalysisPublisher']['unstableTotalNormal'])
|
|
|
|
assertEquals("AnalysisPublisher thresholds configuration for unstableTotalLow is set",
|
|
|
|
null, publisherStepOptions['AnalysisPublisher']['unstableTotalLow'])
|
|
|
|
assertEquals("AnalysisPublisher thresholds configuration for unstableTotalAll is set",
|
|
|
|
null, publisherStepOptions['AnalysisPublisher']['unstableTotalAll'])
|
|
|
|
// ensure nothing else is published
|
|
|
|
assertTrue("DryPublisher options not empty", publisherStepOptions['DryPublisher'] == null)
|
|
|
|
assertTrue("FindBugsPublisher options not empty", publisherStepOptions['FindBugsPublisher'] == null)
|
|
|
|
assertTrue("CheckStylePublisher options not empty", publisherStepOptions['CheckStylePublisher'] == null)
|
|
|
|
assertTrue("WarningsPublisher options not empty", publisherStepOptions['WarningsPublisher'] == null)
|
|
|
|
}
|
|
|
|
|
2018-01-30 16:26:54 +02:00
|
|
|
@Test
|
|
|
|
void testPublishWithThresholds() throws Exception {
|
2018-02-09 13:15:26 +02:00
|
|
|
checksPublishResultsScript.call(aggregation: [thresholds: [fail: [high: '10']]], pmd: true)
|
2018-01-30 16:26:54 +02:00
|
|
|
|
|
|
|
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
|
|
|
|
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
|
2018-02-08 11:43:06 +02:00
|
|
|
assertEquals("AnalysisPublisher thresholds configuration for failedTotalHigh not correct",
|
2018-02-09 13:15:26 +02:00
|
|
|
'10', publisherStepOptions['AnalysisPublisher']['failedTotalHigh'])
|
2018-01-30 16:26:54 +02:00
|
|
|
// ensure other values are empty
|
2018-02-08 11:43:06 +02:00
|
|
|
assertEquals("AnalysisPublisher thresholds configuration for failedTotalNormal is set",
|
|
|
|
null, publisherStepOptions['AnalysisPublisher']['failedTotalNormal'])
|
|
|
|
assertEquals("AnalysisPublisher thresholds configuration for failedTotalLow is set",
|
|
|
|
null, publisherStepOptions['AnalysisPublisher']['failedTotalLow'])
|
|
|
|
assertEquals("AnalysisPublisher thresholds configuration for failedTotalAll is set",
|
|
|
|
null, publisherStepOptions['AnalysisPublisher']['failedTotalAll'])
|
|
|
|
assertEquals("AnalysisPublisher thresholds configuration for unstableTotalHigh not correct",
|
|
|
|
null, publisherStepOptions['AnalysisPublisher']['unstableTotalHigh'])
|
|
|
|
assertEquals("AnalysisPublisher thresholds configuration for unstableTotalNormal is set",
|
|
|
|
null, publisherStepOptions['AnalysisPublisher']['unstableTotalNormal'])
|
|
|
|
assertEquals("AnalysisPublisher thresholds configuration for unstableTotalLow is set",
|
|
|
|
null, publisherStepOptions['AnalysisPublisher']['unstableTotalLow'])
|
|
|
|
assertEquals("AnalysisPublisher thresholds configuration for unstableTotalAll is set",
|
|
|
|
null, publisherStepOptions['AnalysisPublisher']['unstableTotalAll'])
|
2018-01-30 14:33:28 +02:00
|
|
|
// ensure nothing else is published
|
2018-01-30 16:26:54 +02:00
|
|
|
assertTrue("DryPublisher options not empty", publisherStepOptions['DryPublisher'] == null)
|
|
|
|
assertTrue("FindBugsPublisher options not empty", publisherStepOptions['FindBugsPublisher'] == null)
|
|
|
|
assertTrue("CheckStylePublisher options not empty", publisherStepOptions['CheckStylePublisher'] == null)
|
|
|
|
assertTrue("WarningsPublisher options not empty", publisherStepOptions['WarningsPublisher'] == null)
|
2018-01-30 14:33:28 +02:00
|
|
|
}
|
|
|
|
}
|