diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/Application.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/Application.groovy index d4153802..2d28d949 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/Application.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/Application.groovy @@ -1,5 +1,7 @@ package com.avioconsulting.mule.linter.model +import com.avioconsulting.mule.linter.model.pom.PomFile + class Application { static final String APPLICATION_DOES_NOT_EXIST = 'Application directory does not exists: ' diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/ConfigurationFile.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/ConfigurationFile.groovy index c1638db8..afea1757 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/ConfigurationFile.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/ConfigurationFile.groovy @@ -1,5 +1,6 @@ package com.avioconsulting.mule.linter.model +import com.avioconsulting.mule.linter.parser.MuleXmlParser import groovy.xml.slurpersupport.GPathResult import groovy.xml.slurpersupport.Node diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/MuleComponent.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/MuleComponent.groovy index 8669492a..329fd5b1 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/MuleComponent.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/MuleComponent.groovy @@ -1,5 +1,7 @@ package com.avioconsulting.mule.linter.model +import com.avioconsulting.mule.linter.parser.MuleXmlParser + class MuleComponent { private final String componentName diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/pom/MunitMavenPlugin.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/pom/MunitMavenPlugin.groovy new file mode 100644 index 00000000..6bb7cb8b --- /dev/null +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/pom/MunitMavenPlugin.groovy @@ -0,0 +1,66 @@ +package com.avioconsulting.mule.linter.model.pom + +import com.avioconsulting.mule.linter.parser.MuleXmlParser +import groovy.xml.slurpersupport.GPathResult + +/** + * Example munit-maven-plugin + * + * + * com.mulesoft.munit.tools + * munit-maven-plugin + * ${munit.version} + * + * + * test + * test + * + * test + * coverage-report + * + * + * + * + * MULE_EE + * ${app.runtime} + * + * true + * true + * 80 + * 80 + * 80 + * + * nextep-salesforce-sapi.xml + * global-config.xml + * error-handler.xml + * + * + * console + * html + * + * + * + * + */ +class MunitMavenPlugin extends PomPlugin { + + static final String GROUP_ID = 'com.mulesoft.munit.tools' + static final String ARTIFACT_ID = 'munit-maven-plugin' + + MunitMavenPlugin(GPathResult pluginXml, PomFile pomFile) { + super(pluginXml, pomFile) + } + + List getIgnoreFiles() { + List ignoreFiles = [] + pluginXml.configuration.coverage.ignoreFiles.ignoreFile.each { + ignoreFiles.add(it.text()) + } + return ignoreFiles + } + + Integer getIgnoreFilesLineNo() { + MuleXmlParser.getNodeLineNumber(pluginXml.configuration.coverage.ignoreFiles) + } + +} diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/PomProperty.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/pom/PomElement.groovy similarity index 86% rename from src/main/groovy/com/avioconsulting/mule/linter/model/PomProperty.groovy rename to src/main/groovy/com/avioconsulting/mule/linter/model/pom/PomElement.groovy index 8f0ee878..9f90893f 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/PomProperty.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/pom/PomElement.groovy @@ -1,6 +1,6 @@ -package com.avioconsulting.mule.linter.model +package com.avioconsulting.mule.linter.model.pom -class PomProperty { +class PomElement { private String name private String value diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/PomFile.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/pom/PomFile.groovy similarity index 62% rename from src/main/groovy/com/avioconsulting/mule/linter/model/PomFile.groovy rename to src/main/groovy/com/avioconsulting/mule/linter/model/pom/PomFile.groovy index a392940e..e3250c01 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/PomFile.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/pom/PomFile.groovy @@ -1,5 +1,7 @@ -package com.avioconsulting.mule.linter.model +package com.avioconsulting.mule.linter.model.pom +import com.avioconsulting.mule.linter.model.ProjectFile +import com.avioconsulting.mule.linter.parser.MuleXmlParser import groovy.xml.slurpersupport.GPathResult class PomFile extends ProjectFile { @@ -42,13 +44,13 @@ class PomFile extends ProjectFile { return file.absolutePath } - PomProperty getPomProperty(String propertyName) throws IllegalArgumentException { + PomElement getPomProperty(String propertyName) throws IllegalArgumentException { GPathResult p = pomProperties[propertyName] as GPathResult if (p == null) { throw new IllegalArgumentException('Property doesn\'t exist') } - PomProperty prop = new PomProperty() + PomElement prop = new PomElement() prop.name = propertyName prop.value = p.text() prop.lineNo = parser.getNodeLineNumber(p) @@ -59,6 +61,23 @@ class PomFile extends ProjectFile { return parser.getNodeLineNumber(pomProperties) } + PomPlugin getPlugin(String groupId, String artifactId) { + PomPlugin plugin + GPathResult pluginPath = pomXml.build.plugins.plugin.find { + it.groupId == groupId && it.artifactId == artifactId + } as GPathResult + + if (pluginPath != null && pluginPath.size() > 0) { + plugin = new PomPlugin(pluginPath, this) + } + return plugin + } + + MunitMavenPlugin getMunitPlugin() { + PomPlugin pp = getPlugin(MunitMavenPlugin.GROUP_ID, MunitMavenPlugin.ARTIFACT_ID) + return pp == null ? null : new MunitMavenPlugin(pp.pluginXml, this) + } + private GPathResult getPomProperties() { return pomXml[PROPERTIES] as GPathResult } diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/pom/PomPlugin.groovy b/src/main/groovy/com/avioconsulting/mule/linter/model/pom/PomPlugin.groovy new file mode 100644 index 00000000..9ae31e6d --- /dev/null +++ b/src/main/groovy/com/avioconsulting/mule/linter/model/pom/PomPlugin.groovy @@ -0,0 +1,54 @@ +package com.avioconsulting.mule.linter.model.pom + +import com.avioconsulting.mule.linter.parser.MuleXmlParser +import groovy.xml.slurpersupport.GPathResult + +class PomPlugin { + + String groupId + String artifactId + String version + Integer lineNo + PomFile pomFile + GPathResult pluginXml + + PomPlugin(GPathResult pluginXml, PomFile pomFile) { + this.pluginXml = pluginXml + this.groupId = pluginXml.groupId as String + this.artifactId = pluginXml.artifactId as String + this.lineNo = MuleXmlParser.getNodeLineNumber(pluginXml) + this.pomFile = pomFile + this.version = isExpression(pluginXml.version as String) ? + resolveExpression(pluginXml.version as String) : pluginXml.version + } + + PomElement getConfigProperty(String propertyName) { + PomElement pElement = null + pluginXml.configuration.depthFirst().each { + if (it.name() == propertyName) { + pElement = new PomElement() + pElement.name = propertyName + pElement.value = it.text() + pElement.lineNo = MuleXmlParser.getNodeLineNumber(it) + } + } + return pElement + } + + private Boolean isExpression(String expression) { + expression.startsWith('${') + } + + private String variableName(String expression) { + expression.takeAfter('${').takeBefore('}') + } + + private String resolveExpression(String expression) { + try { + return pomFile.getPomProperty(variableName(expression)).value + } catch (IllegalArgumentException iae) { + return null + } + } + +} diff --git a/src/main/groovy/com/avioconsulting/mule/linter/model/MuleXmlParser.groovy b/src/main/groovy/com/avioconsulting/mule/linter/parser/MuleXmlParser.groovy similarity index 89% rename from src/main/groovy/com/avioconsulting/mule/linter/model/MuleXmlParser.groovy rename to src/main/groovy/com/avioconsulting/mule/linter/parser/MuleXmlParser.groovy index fdf3bf0c..4abe8573 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/model/MuleXmlParser.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/parser/MuleXmlParser.groovy @@ -1,4 +1,4 @@ -package com.avioconsulting.mule.linter.model +package com.avioconsulting.mule.linter.parser import groovy.xml.XmlSlurper import groovy.xml.slurpersupport.GPathResult @@ -34,7 +34,8 @@ class MuleXmlParser extends XmlSlurper { super.startElement(uri, localName, qName, newAttrs) } - Integer getNodeLineNumber(GPathResult node) { + @SuppressWarnings('StaticMethodsBeforeInstanceMethods') + static Integer getNodeLineNumber(GPathResult node) { return Integer.valueOf(String.valueOf(node["@${START_LINE_NO_NAMESPACE_PREFIX}:${START_LINE_NO_ATTRIBUTE}"])) } diff --git a/src/main/groovy/com/avioconsulting/mule/linter/rule/cicd/JenkinsFileExistsRule.groovy b/src/main/groovy/com/avioconsulting/mule/linter/rule/cicd/JenkinsFileExistsRule.groovy index 635918f0..0ab28a35 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/rule/cicd/JenkinsFileExistsRule.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/rule/cicd/JenkinsFileExistsRule.groovy @@ -2,7 +2,6 @@ package com.avioconsulting.mule.linter.rule.cicd import com.avioconsulting.mule.linter.model.Application import com.avioconsulting.mule.linter.model.JenkinsFile -import com.avioconsulting.mule.linter.model.PomFile import com.avioconsulting.mule.linter.model.Rule import com.avioconsulting.mule.linter.model.RuleViolation diff --git a/src/main/groovy/com/avioconsulting/mule/linter/rule/pom/MunitMavenPluginAttributesRule.groovy b/src/main/groovy/com/avioconsulting/mule/linter/rule/pom/MunitMavenPluginAttributesRule.groovy new file mode 100644 index 00000000..d02cecd7 --- /dev/null +++ b/src/main/groovy/com/avioconsulting/mule/linter/rule/pom/MunitMavenPluginAttributesRule.groovy @@ -0,0 +1,71 @@ +package com.avioconsulting.mule.linter.rule.pom + +import com.avioconsulting.mule.linter.model.Application +import com.avioconsulting.mule.linter.model.Rule +import com.avioconsulting.mule.linter.model.RuleViolation +import com.avioconsulting.mule.linter.model.pom.MunitMavenPlugin +import com.avioconsulting.mule.linter.model.pom.PomElement +import com.avioconsulting.mule.linter.model.pom.PomFile + +class MunitMavenPluginAttributesRule extends Rule { + + static final String RULE_ID = 'MUNIT_MAVEN_PLUGIN_ATTRIBUTES' + static final String RULE_NAME = 'Munit Maven plugins attribute values' + static final String RULE_MESSAGE = 'Munit Maven plugin has incorrect or missing configuration coverage value ' + static final String RULE_MESSAGE_MISSING = 'Munit Maven plugin is missing element ' + static final Map COVERAGE_DEFAULTS = ['runCoverage':'true', + 'failBuild':'true', + 'requiredApplicationCoverage':'80', + 'requiredResourceCoverage':'80', + 'requiredFlowCoverage':'80'] + private static final String IGNORE_FILES = 'ignoreFiles' + Map coverageAttributeMap + List ignoreFiles = [] + + MunitMavenPluginAttributesRule() { + this([:], true, []) + } + + MunitMavenPluginAttributesRule(List ignoreFiles) { + this([:], true, ignoreFiles) + } + + MunitMavenPluginAttributesRule(Map coverageAttributeMap, + Boolean includeDefaults) { + this(coverageAttributeMap, includeDefaults, []) + } + + MunitMavenPluginAttributesRule(Map coverageAttributeMap, + Boolean includeDefaults, List ignoreFiles) { + this.ruleId = RULE_ID + this.ruleName = RULE_NAME + this.coverageAttributeMap = includeDefaults ? COVERAGE_DEFAULTS + coverageAttributeMap : coverageAttributeMap + this.ignoreFiles = ignoreFiles + } + + @Override + List execute(Application application) { + List violations = [] + MunitMavenPlugin plugin = application.pomFile.munitPlugin + if (plugin != null) { + coverageAttributeMap.each { key, val -> + PomElement pe = plugin.getConfigProperty(key) + if (pe?.value != val) { + violations.add(new RuleViolation(this, PomFile.POM_XML, + pe == null ? plugin.lineNo : pe.lineNo, RULE_MESSAGE + key + '|' + val)) + } + } + if (ignoreFiles.size() > 0) { + List diff = ignoreFiles - plugin.getIgnoreFiles() + diff.each { + violations.add(new RuleViolation(this, PomFile.POM_XML, + plugin.getIgnoreFilesLineNo(), RULE_MESSAGE_MISSING + 'ignoreFile|' + it )) + } + } + } else { + violations.add(new RuleViolation(this, PomFile.POM_XML, 0, 'Missing munit-maven-plugin')) + } + return violations + } + +} diff --git a/src/main/groovy/com/avioconsulting/mule/linter/rule/pom/PomExistsRule.groovy b/src/main/groovy/com/avioconsulting/mule/linter/rule/pom/PomExistsRule.groovy index d1558e8f..87d53636 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/rule/pom/PomExistsRule.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/rule/pom/PomExistsRule.groovy @@ -1,7 +1,7 @@ package com.avioconsulting.mule.linter.rule.pom import com.avioconsulting.mule.linter.model.Application -import com.avioconsulting.mule.linter.model.PomFile +import com.avioconsulting.mule.linter.model.pom.PomFile import com.avioconsulting.mule.linter.model.Rule import com.avioconsulting.mule.linter.model.RuleViolation diff --git a/src/main/groovy/com/avioconsulting/mule/linter/rule/pom/PomPropertyValueRule.groovy b/src/main/groovy/com/avioconsulting/mule/linter/rule/pom/PomPropertyValueRule.groovy index 3fa55619..d2d3cd27 100644 --- a/src/main/groovy/com/avioconsulting/mule/linter/rule/pom/PomPropertyValueRule.groovy +++ b/src/main/groovy/com/avioconsulting/mule/linter/rule/pom/PomPropertyValueRule.groovy @@ -1,7 +1,7 @@ package com.avioconsulting.mule.linter.rule.pom import com.avioconsulting.mule.linter.model.Application -import com.avioconsulting.mule.linter.model.PomProperty +import com.avioconsulting.mule.linter.model.pom.PomElement import com.avioconsulting.mule.linter.model.Rule import com.avioconsulting.mule.linter.model.RuleViolation @@ -33,7 +33,7 @@ class PomPropertyValueRule extends Rule { List violations = [] try { - PomProperty pomProperty = app.pomFile.getPomProperty(propertyName) + PomElement pomProperty = app.pomFile.getPomProperty(propertyName) if (!pomProperty.value.equalsIgnoreCase(propertyValue)) { violations.add(new RuleViolation(this, app.pomFile.path, pomProperty.lineNo, pomProperty.name + RULE_VIOLATION_MESSAGE)) diff --git a/src/test/groovy/com/avioconsulting/mule/linter/TestApplication.groovy b/src/test/groovy/com/avioconsulting/mule/linter/TestApplication.groovy index 3b9f8427..bdebfa66 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/TestApplication.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/TestApplication.groovy @@ -2,10 +2,10 @@ package com.avioconsulting.mule.linter import com.avioconsulting.mule.linter.model.JenkinsFile import com.avioconsulting.mule.linter.model.MuleArtifact -import com.avioconsulting.mule.linter.model.PomFile +import com.avioconsulting.mule.linter.model.pom.PomFile import com.avioconsulting.mule.linter.model.GitIgnoreFile -@SuppressWarnings('StaticFieldsBeforeInstanceFields') +@SuppressWarnings(['StaticFieldsBeforeInstanceFields', 'BuilderMethodWithSideEffects', 'FactoryMethodName']) class TestApplication { static final String SAMPLE_APP_NAME = 'SampleMuleApp' @@ -21,7 +21,7 @@ class TestApplication { TestApplication() { } - void create() { + void initialize() { appDir = File.createTempDir() buildDirectoryStructure() println 'Created temporary app: ' + appDir.path @@ -138,4 +138,5 @@ out/''' ''' private static final String MULE_CONFIG_END = ''' ''' + } diff --git a/src/test/groovy/com/avioconsulting/mule/linter/cicd/JenkinsFileExistsRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/cicd/JenkinsFileExistsRuleTest.groovy index 9495ae4d..a9f76cbc 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/cicd/JenkinsFileExistsRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/cicd/JenkinsFileExistsRuleTest.groovy @@ -14,7 +14,7 @@ class JenkinsFileExistsRuleTest extends Specification { private Application app def setup() { - testApp.create() + testApp.initialize() testApp.addJenkinsfile() } diff --git a/src/test/groovy/com/avioconsulting/mule/linter/model/MuleXmlParserTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/model/MuleXmlParserTest.groovy index cd1da0c5..364df540 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/model/MuleXmlParserTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/model/MuleXmlParserTest.groovy @@ -1,5 +1,6 @@ package com.avioconsulting.mule.linter.model +import com.avioconsulting.mule.linter.parser.MuleXmlParser import groovy.xml.slurpersupport.GPathResult import spock.lang.Specification diff --git a/src/test/groovy/com/avioconsulting/mule/linter/model/PomPluginTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/model/PomPluginTest.groovy new file mode 100644 index 00000000..af8b9107 --- /dev/null +++ b/src/test/groovy/com/avioconsulting/mule/linter/model/PomPluginTest.groovy @@ -0,0 +1,85 @@ +package com.avioconsulting.mule.linter.model + +import com.avioconsulting.mule.linter.TestApplication +import com.avioconsulting.mule.linter.model.pom.PomFile +import com.avioconsulting.mule.linter.model.pom.PomPlugin +import spock.lang.Specification + +@SuppressWarnings(['MethodName', 'MethodReturnTypeRequired', 'StaticFieldsBeforeInstanceFields']) +class PomPluginTest extends Specification { + + private final TestApplication testApp = new TestApplication() + private Application app + + def setup() { + testApp.initialize() + testApp.addFile(PomFile.POM_XML, PLUGINS_POM) + } + + def cleanup() { + testApp.remove() + } + + def 'Find Plugin and check Values'() { + given: + Application app = new Application(testApp.appDir) + + when: + PomPlugin pp = app.pomFile.getPlugin('com.mulesoft.munit.tools', 'munit-maven-plugin') + + then: + pp.artifactId == 'munit-maven-plugin' + pp.groupId == 'com.mulesoft.munit.tools' + pp.version == '2.2.1' + pp.lineNo == 25 + pp.getConfigProperty('requiredResourceCoverage').value == '85' + pp.getConfigProperty('failBuild').lineNo == 32 + } + + static final String PLUGINS_POM = ''' + +\t4.0.0 +\tcom.avioconsulting.mulelinter +\tsample-mule-app +\t1.0.0 +\tmule-application +\tsample-mule-app-sys-api +\t +\t\tUTF-8 +\t\t4.2.1 +\t\t3.3.5 +\t\t2.2.1 +\t +\t +\t\t +\t\t\t +\t\t\t\tcom.avioconsulting.mulelinter +\t\t\t\tbest-linter-ever +\t\t\t\t${app.runtime} +\t\t\t +\t\t\t +\t\t\t\tcom.mulesoft.munit.tools +\t\t\t\tmunit-maven-plugin +\t\t\t\t${munit.version} +\t\t\t\t +\t\t\t\t\t +\t\t\t\t\t\tfalse +\t\t\t\t\t\tfalse +\t\t\t\t\t\t87 +\t\t\t\t\t\t85 +\t\t\t\t\t\t86 +\t\t\t\t\t\t +\t\t\t\t\t\t\tglobal-config.xml +\t\t\t\t\t\t\terror-handler.xml +\t\t\t\t\t\t +\t\t\t\t\t +\t\t\t\t +\t\t\t +\t\t +\t +''' + +} diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/ConfigFileNamingRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/ConfigFileNamingRuleTest.groovy index 3bc968dc..70bfad48 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/ConfigFileNamingRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/ConfigFileNamingRuleTest.groovy @@ -13,7 +13,7 @@ class ConfigFileNamingRuleTest extends Specification { private Application app def setup() { - testApp.create() + testApp.initialize() testApp.addPom() testApp.addConfig() testApp.buildConfigContent('camelCase.xml', '') diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/FlowSubflowNamingRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/FlowSubflowNamingRuleTest.groovy index c8f8d5c8..939b5eaf 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/FlowSubflowNamingRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/FlowSubflowNamingRuleTest.groovy @@ -15,7 +15,7 @@ class FlowSubflowNamingRuleTest extends Specification { private Application app def setup() { - testApp.create() + testApp.initialize() testApp.addPom() testApp.buildConfigContent('no-naming-standards.xml', FLOWS) diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigNoFlowsRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigNoFlowsRuleTest.groovy index 9a37d05c..3fd1c7c7 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigNoFlowsRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigNoFlowsRuleTest.groovy @@ -6,20 +6,20 @@ import com.avioconsulting.mule.linter.model.Rule import com.avioconsulting.mule.linter.model.RuleViolation import spock.lang.Specification +@SuppressWarnings(['MethodName', 'MethodReturnTypeRequired', 'StaticFieldsBeforeInstanceFields']) class GlobalConfigNoFlowsRuleTest extends Specification { private final TestApplication testApp = new TestApplication() private Application app def setup() { - testApp.create() + testApp.initialize() testApp.addPom() testApp.addConfig() app = new Application(testApp.appDir) } - @SuppressWarnings(['MethodName', 'MethodReturnTypeRequired']) def 'No flow subflow in global configuration file'() { given: Rule rule = new GlobalConfigNoFlowsRule('global-config.xml') @@ -33,7 +33,6 @@ class GlobalConfigNoFlowsRuleTest extends Specification { violations.size() == 0 } - @SuppressWarnings(['MethodName', 'MethodReturnTypeRequired']) def 'flow subflow in global configuration file'() { given: Rule rule = new GlobalConfigNoFlowsRule('global-config.xml') @@ -49,7 +48,6 @@ class GlobalConfigNoFlowsRuleTest extends Specification { violations[0].lineNumber == 14 } - @SuppressWarnings(['MethodName', 'MethodReturnTypeRequired']) def 'Missing global configuration file'() { given: Rule rule = new GlobalConfigNoFlowsRule() diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigRuleTest.groovy index 9e8e7a2d..6747b98a 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/GlobalConfigRuleTest.groovy @@ -14,7 +14,7 @@ class GlobalConfigRuleTest extends Specification { private Application app def setup() { - testApp.create() + testApp.initialize() testApp.addPom() testApp.addConfig() } diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/LoggerAttributesRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/LoggerAttributesRuleTest.groovy index c271fc4b..a6f58922 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/LoggerAttributesRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/LoggerAttributesRuleTest.groovy @@ -13,7 +13,7 @@ class LoggerAttributesRuleTest extends Specification { private Application app def setup() { - testApp.create() + testApp.initialize() testApp.addPom() testApp.addConfig() } diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/LoggerCategoryExistsRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/LoggerCategoryExistsRuleTest.groovy index aa40ddd2..13341d1f 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/LoggerCategoryExistsRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/LoggerCategoryExistsRuleTest.groovy @@ -13,7 +13,7 @@ class LoggerCategoryExistsRuleTest extends Specification { private Application app def setup() { - testApp.create() + testApp.initialize() testApp.addPom() testApp.addConfig() } diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/LoggerMessageExistsRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/LoggerMessageExistsRuleTest.groovy index d1d972ab..2794bfb5 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/LoggerMessageExistsRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/LoggerMessageExistsRuleTest.groovy @@ -13,7 +13,7 @@ class LoggerMessageExistsRuleTest extends Specification { private Application app def setup() { - testApp.create() + testApp.initialize() testApp.addPom() testApp.addConfig() } diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/OnErrorLogExceptionRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/OnErrorLogExceptionRuleTest.groovy index 77cda290..f2ae373f 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/OnErrorLogExceptionRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/configuration/OnErrorLogExceptionRuleTest.groovy @@ -14,7 +14,7 @@ class OnErrorLogExceptionRuleTest extends Specification { private Application app def setup() { - testApp.create() + testApp.initialize() testApp.addPom() testApp.addConfig() } diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/muleartifact/MuleArtifactHasSecurePropertiesRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/muleartifact/MuleArtifactHasSecurePropertiesRuleTest.groovy index 3d8ea53f..d66e7908 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/muleartifact/MuleArtifactHasSecurePropertiesRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/muleartifact/MuleArtifactHasSecurePropertiesRuleTest.groovy @@ -14,7 +14,7 @@ class MuleArtifactHasSecurePropertiesRuleTest extends Specification { private final TestApplication testApp = new TestApplication() def setup() { - testApp.create() + testApp.initialize() testApp.addMuleArtifact() app = new Application(testApp.appDir) } diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/MuleMavenPluginVersionRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/MuleMavenPluginVersionRuleTest.groovy index be373eb1..8fcca4b9 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/MuleMavenPluginVersionRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/MuleMavenPluginVersionRuleTest.groovy @@ -12,7 +12,7 @@ class MuleMavenPluginVersionRuleTest extends Specification { private final TestApplication testApp = new TestApplication() def setup() { - testApp.create() + testApp.initialize() testApp.addPom() } diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/MuleRuntimeVersionRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/MuleRuntimeVersionRuleTest.groovy index 972de4e5..70c2ba7d 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/MuleRuntimeVersionRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/MuleRuntimeVersionRuleTest.groovy @@ -12,7 +12,7 @@ class MuleRuntimeVersionRuleTest extends Specification { private final TestApplication testApp = new TestApplication() def setup() { - testApp.create() + testApp.initialize() testApp.addPom() } diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/MunitMavenPluginAttributesRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/MunitMavenPluginAttributesRuleTest.groovy new file mode 100644 index 00000000..fed4090b --- /dev/null +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/MunitMavenPluginAttributesRuleTest.groovy @@ -0,0 +1,157 @@ +package com.avioconsulting.mule.linter.rule.pom + +import com.avioconsulting.mule.linter.TestApplication +import com.avioconsulting.mule.linter.model.Application +import com.avioconsulting.mule.linter.model.Rule +import com.avioconsulting.mule.linter.model.RuleViolation +import com.avioconsulting.mule.linter.model.pom.PomFile +import spock.lang.Specification + +@SuppressWarnings(['MethodName', 'MethodReturnTypeRequired', 'StaticFieldsBeforeInstanceFields']) +class MunitMavenPluginAttributesRuleTest extends Specification { + + private final TestApplication testApp = new TestApplication() + + def setup() { + testApp.initialize() + } + + def cleanup() { + testApp.remove() + } + + def 'Missing Munit Maven Plugin Check'() { + given: + testApp.addFile(PomFile.POM_XML, MISSING_PLUGINS_POM) + Application app = new Application(testApp.appDir) + + when: + Rule rule = new MunitMavenPluginAttributesRule() + List violations = rule.execute(app) + + then: + violations.size() == 1 + violations[0].fileName == PomFile.POM_XML + violations[0].lineNumber == 0 + } + + def 'Correct Munit Maven Plugin Check'() { + given: + testApp.addPom() + Application app = new Application(testApp.appDir) + + when: + Rule rule = new MunitMavenPluginAttributesRule() + List violations = rule.execute(app) + + then: + violations.size() == 0 + } + + def 'Custom with Defaults Munit Maven Plugin Check'() { + given: + testApp.addPom() + Application app = new Application(testApp.appDir) + + when: + Map coverageAttributes = ['sillyproperty':'incorrect'] + Rule rule = new MunitMavenPluginAttributesRule(coverageAttributes, true) + List violations = rule.execute(app) + + then: + violations.size() == 1 + violations[0].lineNumber == 52 + violations[0].message.endsWith('sillyproperty|incorrect') + } + + def 'Check ignoreFiles - Missing one'() { + given: + testApp.addPom() + Application app = new Application(testApp.appDir) + + when: + Rule rule = new MunitMavenPluginAttributesRule(['error-handler.xml', 'global-config.xml', 'something-else.xml']) + List violations = rule.execute(app) + + then: + violations.size() == 1 + violations[0].lineNumber == 73 + violations[0].message.endsWith('ignoreFile|something-else.xml') + } + def 'Very wrong Munit Maven Plugin'() { + given: + testApp.addFile(PomFile.POM_XML, WRONG_PLUGINS_POM) + Application app = new Application(testApp.appDir) + + when: + Rule rule = new MunitMavenPluginAttributesRule() + List violations = rule.execute(app) + + then: + violations.size() == 5 + violations[0].fileName == PomFile.POM_XML + violations[0].rule.ruleName == MunitMavenPluginAttributesRule.RULE_NAME + violations[0].message.endsWith('runCoverage|true') + violations[0].lineNumber == 26 + violations[1].message.endsWith('failBuild|true') + violations[1].lineNumber == 27 + violations[2].message.endsWith('requiredApplicationCoverage|80') + violations[3].message.endsWith('requiredResourceCoverage|80') + violations[4].message.endsWith('requiredFlowCoverage|80') + } + + private static final String MISSING_PLUGINS_POM = ''' + +\t4.0.0 +\tcom.avioconsulting.mulelinter +\tsample-mule-app +\t1.0.0 +\tmule-application +\tsample-mule-app-sys-api + +''' + private static final String WRONG_PLUGINS_POM = ''' + +\t4.0.0 +\tcom.avioconsulting.mulelinter +\tsample-mule-app +\t1.0.0 +\tmule-application +\tsample-mule-app-sys-api +\t +\t\tUTF-8 +\t\t4.2.1 +\t\t3.3.5 +\t\t2.2.1 +\t +\t +\t\t +\t\t\t +\t\t\t\tcom.mulesoft.munit.tools +\t\t\t\tmunit-maven-plugin +\t\t\t\t${munit.version} +\t\t\t\t +\t\t\t\t\t +\t\t\t\t\t\tfalse +\t\t\t\t\t\tfalse +\t\t\t\t\t\t87 +\t\t\t\t\t\t85 +\t\t\t\t\t\t86 +\t\t\t\t\t\t +\t\t\t\t\t\t\tglobal-config.xml +\t\t\t\t\t\t\terror-handler.xml +\t\t\t\t\t\t +\t\t\t\t\t +\t\t\t\t +\t\t\t +\t\t +\t +''' + +} diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/MunitVersionRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/MunitVersionRuleTest.groovy index 23bfc262..662ca730 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/MunitVersionRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/MunitVersionRuleTest.groovy @@ -1,7 +1,7 @@ package com.avioconsulting.mule.linter.rule.pom import com.avioconsulting.mule.linter.model.Application -import com.avioconsulting.mule.linter.model.PomFile +import com.avioconsulting.mule.linter.model.pom.PomFile import com.avioconsulting.mule.linter.model.Rule import com.avioconsulting.mule.linter.model.RuleViolation import com.avioconsulting.mule.linter.TestApplication @@ -13,7 +13,7 @@ class MunitVersionRuleTest extends Specification { private final TestApplication testApp = new TestApplication() def setup() { - testApp.create() + testApp.initialize() } def cleanup() { @@ -62,8 +62,8 @@ class MunitVersionRuleTest extends Specification { } private static final String INVALID_POM = ''' - 4.0.0 com.avioconsulting.mulelinter diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/PomExistsRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/PomExistsRuleTest.groovy index 82203718..33de5f15 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/PomExistsRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/PomExistsRuleTest.groovy @@ -13,7 +13,7 @@ class PomExistsRuleTest extends Specification { private Application app def setup() { - testApp.create() + testApp.initialize() } def cleanup() { diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/PomPropertyValueRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/PomPropertyValueRuleTest.groovy index 4fcaf521..cdf064a0 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/PomPropertyValueRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/pom/PomPropertyValueRuleTest.groovy @@ -13,7 +13,7 @@ class PomPropertyValueRuleTest extends Specification { private Application app def setup() { - testApp.create() + testApp.initialize() testApp.addPom() app = new Application(testApp.appDir) diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/property/PropertyFileNamingRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/property/PropertyFileNamingRuleTest.groovy index 8222b367..e0b228b3 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/property/PropertyFileNamingRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/property/PropertyFileNamingRuleTest.groovy @@ -14,7 +14,7 @@ class PropertyFileNamingRuleTest extends Specification { private final TestApplication testApp = new TestApplication() def setup() { - testApp.create() + testApp.initialize() testApp.addPom() } diff --git a/src/test/groovy/com/avioconsulting/mule/linter/rule/property/PropertyFilePropertyCountRuleTest.groovy b/src/test/groovy/com/avioconsulting/mule/linter/rule/property/PropertyFilePropertyCountRuleTest.groovy index 1c69ce8f..8a500882 100644 --- a/src/test/groovy/com/avioconsulting/mule/linter/rule/property/PropertyFilePropertyCountRuleTest.groovy +++ b/src/test/groovy/com/avioconsulting/mule/linter/rule/property/PropertyFilePropertyCountRuleTest.groovy @@ -14,7 +14,7 @@ class PropertyFilePropertyCountRuleTest extends Specification { private final TestApplication testApp = new TestApplication() def setup() { - testApp.create() + testApp.initialize() testApp.addPom() testApp.addPropertyFiles(['dev.properties', 'test.properties', diff --git a/src/test/resources/SampleMuleApp/pom.xml b/src/test/resources/SampleMuleApp/pom.xml index bc665147..d6f0a405 100644 --- a/src/test/resources/SampleMuleApp/pom.xml +++ b/src/test/resources/SampleMuleApp/pom.xml @@ -49,7 +49,7 @@ - + com.mulesoft.munit.tools munit-maven-plugin ${munit.version} @@ -66,12 +66,14 @@ true - false - - console - html - json - + true + 80 + 80 + 80 + + global-config.xml + error-handler.xml +