-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/mip 424 #22
Merged
Merged
Feature/mip 424 #22
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
64f8e94
Added onError Scenarios
kkingavio 47ffd9d
updated name of app
kkingavio 604cb0d
Order of rules changes... Fixed that to not require order
kkingavio ea14c78
MIP-424 Created Rule and Test
kkingavio 8c2f1c3
MIP-424 Added violation check
kkingavio 66ae542
MIP-424 Added violation check
kkingavio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...n/groovy/com/avioconsulting/mule/linter/rule/configuration/OnErrorLogExceptionRule.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.avioconsulting.mule.linter.rule.configuration | ||
|
||
import com.avioconsulting.mule.linter.model.Application | ||
import com.avioconsulting.mule.linter.model.Rule | ||
import com.avioconsulting.mule.linter.model.RuleViolation | ||
|
||
class OnErrorLogExceptionRule extends Rule { | ||
|
||
static final String RULE_ID = 'ON_ERROR_LOG_EXCEPTION' | ||
static final String RULE_NAME = 'On Error Enable Log Exception Rule' | ||
static final String RULE_VIOLATION_MESSAGE = 'Log exception enabled is required for ' + | ||
'on-error-continue and on-error-propagate' | ||
private static final List<String> ON_ERROR_COMPONENTS = ['on-error-continue', 'on-error-propagate'] | ||
private static final String ATTRIBUTE_NAME = 'logException' | ||
private static final String ATTRIBUTE_VALUE_CHECK = 'false' | ||
|
||
OnErrorLogExceptionRule() { | ||
this.ruleId = RULE_ID | ||
this.ruleName = RULE_NAME | ||
} | ||
|
||
@Override | ||
List<RuleViolation> execute(Application application) { | ||
List<RuleViolation> violations = [] | ||
application.configurationFiles.each { file -> | ||
ON_ERROR_COMPONENTS.each { | ||
file.findComponents(it, file.MULE_CORE_NAMESPACE).each { comp -> | ||
if (comp.getAttributeValue(ATTRIBUTE_NAME).equalsIgnoreCase(ATTRIBUTE_VALUE_CHECK)) { | ||
violations.add(new RuleViolation(this, file.name, comp.lineNumber, RULE_VIOLATION_MESSAGE)) | ||
} | ||
} | ||
} | ||
} | ||
return violations | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
...oovy/com/avioconsulting/mule/linter/rule/configuration/OnErrorLogExceptionRuleTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package com.avioconsulting.mule.linter.rule.configuration | ||
|
||
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 spock.lang.Specification | ||
|
||
|
||
@SuppressWarnings(['MethodName', 'MethodReturnTypeRequired', 'StaticFieldsBeforeInstanceFields']) | ||
class OnErrorLogExceptionRuleTest extends Specification { | ||
|
||
private final TestApplication testApp = new TestApplication() | ||
private Application app | ||
|
||
def setup() { | ||
testApp.create() | ||
testApp.addPom() | ||
testApp.addConfig() | ||
} | ||
|
||
def cleanup() { | ||
testApp.remove() | ||
} | ||
|
||
def 'Flows are correct'() { | ||
given: | ||
Rule rule = new OnErrorLogExceptionRule() | ||
|
||
when: | ||
app = new Application(testApp.appDir) | ||
List<RuleViolation> violations = rule.execute(app) | ||
|
||
then: | ||
app.configurationFiles.size() == 3 | ||
violations.size() == 0 | ||
} | ||
|
||
def 'on-error-continue and -propagate invalid'() { | ||
given: | ||
Rule rule = new OnErrorLogExceptionRule() | ||
|
||
when: | ||
testApp.addFile('src/main/mule/on-error-logging-exception.xml', BAD_CONFIG) | ||
app = new Application(testApp.appDir) | ||
List<RuleViolation> violations = rule.execute(app) | ||
|
||
then: | ||
app.configurationFiles.size() == 4 | ||
violations.size() == 2 | ||
violations[0].lineNumber == 23 | ||
violations[0].fileName.contains('on-error-logging-exception.xml') | ||
violations[0].message.contains(OnErrorLogExceptionRule.RULE_VIOLATION_MESSAGE) | ||
violations[1].lineNumber == 69 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add check for message here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like-> OnErrorLogExceptionRule.RULE_VIOLATION_MESSAGE |
||
} | ||
|
||
private static final String BAD_CONFIG = '''<?xml version="1.0" encoding="UTF-8"?> | ||
<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" | ||
\t\txmlns="http://www.mulesoft.org/schema/mule/core" | ||
\t\txmlns:doc="http://www.mulesoft.org/schema/mule/documentation" | ||
\t\txmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
\t\txsi:schemaLocation="http://www.mulesoft.org/schema/mule/core | ||
\t\t\thttp://www.mulesoft.org/schema/mule/core/current/mule.xsd | ||
\t\t\thttp://www.mulesoft.org/schema/mule/ee/core | ||
\t\t\thttp://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd"> | ||
\t<sub-flow name="bad-sub-flow"> | ||
\t\t<try doc:name="Try" doc:id="246a02ea-45b3-4796-b41d-a57c0384bf7b" > | ||
\t\t\t<ee:transform doc:name="Simple Transform"> | ||
\t\t\t<ee:message> | ||
\t\t\t\t<ee:set-payload><![CDATA[%dw 2.0 | ||
output application/java | ||
--- | ||
{ | ||
}]]></ee:set-payload> | ||
\t\t\t</ee:message> | ||
\t\t</ee:transform> | ||
\t\t\t<error-handler > | ||
\t\t\t\t<on-error-continue enableNotifications="true" logException="false" | ||
\t\t\t\t\t\tdoc:name="Bad On Error Continue" > | ||
\t\t\t\t\t<logger level="ERROR" doc:name="Log Error" | ||
\t\t\t\t\t\t\tmessage='An Error Occured... Continuing' | ||
\t\t\t\t\t\t\tcategory="com.avioconsulting.mulelinter"/> | ||
\t\t\t\t</on-error-continue> | ||
\t\t\t</error-handler> | ||
\t\t</try> | ||
\t\t<try doc:name="Try" > | ||
\t\t\t<logger level="DEBUG" doc:name="Log End" message="Ending" | ||
\t\t\t\t\tcategory="com.avioconsulting.mulelinter" /> | ||
\t\t\t<error-handler > | ||
\t\t\t\t<on-error-propagate enableNotifications="true" | ||
\t\t\t\t\t\tlogException="true" doc:name="On Error Propagate" | ||
\t\t\t\t\t\tdoc:id="c59d99e4-e679-4f4f-aa10-02541a3428d2" > | ||
\t\t\t\t\t<logger level="ERROR" doc:name="Log Another Error" | ||
\t\t\t\t\t\tmessage='An Error Occured... Propagating' | ||
\t\t\t\t\t\tcategory="com.avioconsulting.mulelinter" /> | ||
\t\t\t\t</on-error-propagate> | ||
\t\t\t</error-handler> | ||
\t\t</try> | ||
\t</sub-flow> | ||
\t<sub-flow name="bad-sub-flow-2"> | ||
\t\t<try doc:name="Try"> | ||
\t\t\t<ee:transform doc:name="Simple Transform"> | ||
\t\t\t<ee:message> | ||
\t\t\t\t<ee:set-payload><![CDATA[%dw 2.0 | ||
output application/java | ||
--- | ||
{ | ||
}]]></ee:set-payload> | ||
\t\t\t</ee:message> | ||
\t\t</ee:transform> | ||
\t\t\t<error-handler > | ||
\t\t\t\t<on-error-continue enableNotifications="true" logException="true" | ||
\t\t\t\t\t\tdoc:name="On Error Continue" doc:id="28755785-b5a0-4403-ae4e-71223ac59a78" > | ||
\t\t\t\t\t<logger level="ERROR" doc:name="Log Error" | ||
\t\t\t\t\t\t\tmessage='An Error Occured... Continuing' | ||
\t\t\t\t\t\t\tcategory="com.avioconsulting.mulelinter"/> | ||
\t\t\t\t</on-error-continue> | ||
\t\t\t</error-handler> | ||
\t\t</try> | ||
\t\t<try doc:name="Try"> | ||
\t\t\t<logger level="DEBUG" doc:name="Log End" message="Ending" | ||
\t\t\t\t\tcategory="com.avioconsulting.mulelinter" /> | ||
\t\t\t<error-handler > | ||
\t\t\t\t<on-error-propagate enableNotifications="true" logException="false" | ||
\t\t\t\t\t\tdoc:name="Bad On Error Propagate" doc:id="dccce6bd-82dd-4223-a0cc-01bbe3f892cf" > | ||
\t\t\t\t\t<logger level="ERROR" doc:name="Log Another Error" | ||
\t\t\t\t\t\tmessage='An Error Occured... Propagating' | ||
\t\t\t\t\t\tcategory="com.avioconsulting.mulelinter" /> | ||
\t\t\t\t</on-error-propagate> | ||
\t\t\t</error-handler> | ||
\t\t</try> | ||
\t</sub-flow> | ||
</mule> | ||
''' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this.