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 custom assertion compares JSON with expected data using JSONAssert. | |
*/ | |
public class JSONAssertion implements MunitAssertion { | |
private Object expected; | |
// [...] | |
public JSONAssertion(final Object expected) { | |
super(); |
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
public static final String REGEX_FIND_STRINGS = // also properly handles escaped strings | |
"([^"\\]*(\\.[^"\\]*)*)"|\'([^\'\\]*(\\.[^\'\\]*)*)\'"; | |
public static final String REGEX_FIND_DATES = // matches most common date formats | |
"((?:\\d{4,4}[-/.]\\d\\d[-/.]\\d\\d|\\d\\d[-/.]\\d\\d[-/.]\\d{4,4})[T ]\\d\\d:\\d\\d:\\d\\d(?:\\.\\d{1,3})?(?:Z|[+-]\\d\\d:?\\d\\d)?)"; | |
public static final String REGEX_FIND_JAVA_DATES = // matches default Date.toString() output | |
"((?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d\\d \\d\\d:\\d\\d:\\d\\d [^ ]+ \\d\\d\\d\\d)"; | |
public static final String FIND_JAVA_IDS = // matches Java IDs (replace with "$100000000" to preserve class information) | |
"(?:(\\w+\\[?@)[0123456789abcdef]+)"; |
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
<munit:assert-true | |
condition="#[jsonAssert('sample_data/steps/cart-before-add.json').check(flowVars.cart)]" | |
doc:name="JSONassert cart-before-add.json"/> |
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
<configuration doc:name="Configuration"> | |
<!-- [...] --> | |
<expression-language> | |
<!-- [...] --> | |
<import class="com.ricston.munit.assertion.JSONAssertion"/> | |
<!-- [...] --> | |
def jsonAssert(file) { | |
return new JSONAssertion(getResource(file).asString()); | |
} |
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
<dependency> | |
<groupId>org.skyscreamer</groupId> | |
<artifactId>jsonassert</artifactId> | |
<version>1.5.0</version> | |
<scope>test</scope> | |
<exclusions> | |
<exclusion> | |
<groupId>com.vaadin.external.google</groupId> | |
<artifactId>json-android</artifactId> | |
</exclusion> |
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
// [...] | |
public class MockInterceptor implements MuleContextAware { | |
//[...] | |
public MessageProcessorBehavior aroundGetBetterMatchingBehavior(final ProceedingJoinPoint joinPoint) throws Throwable { | |
if (joinPoint.getTarget() instanceof MessageProcessorManager == false | |
|| joinPoint.getArgs()[0] instanceof MessageProcessorCall == false) { | |
throw new IllegalArgumentException( | |
"MockInterceptor needs signature MessageProcessorManager.getBetterMatchingBehavior(*)"); | |
// or better log and return joinPoint.proceed(); ? |
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
<spring:beans> | |
<!-- [...] --> | |
<spring:bean | |
id="interceptMockAdvice" | |
class="com.ricston.munit.mock.MockInterceptor"> | |
<property name="triggerExpression" value="#[true]"/> | |
</spring:bean> | |
<aop:config> | |
<aop:aspect | |
id="interceptMockAspect" |
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
{ | |
"id": #[flowVars.currentTestId], | |
"name": "item #[flowVars.currentTestId]", | |
"price": 6.9, | |
"_links": { | |
"self": { | |
"href": "http://localhost:8082/api/products/#[flowVars.currentTestId]" | |
}, | |
"product": { | |
"href": "http://localhost:8082/api/products/#[flowVars.currentTestId]" |
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
/* | |
* © 2019 Ricston Ltd is protected under international copyright law. The software in this package | |
* is published under the terms of the Ricston End User Licensing Agreement (EULA), a copy of which | |
* has been included with this distribution in the LICENSE.md file. | |
*/ | |
package com.ricston.munit.mock; | |
import static org.mule.api.transport.PropertyScope.INBOUND; |
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
def isHttpBroken() { | |
return (message.inboundProperties.'http.status' >= 400); // or better | |
} | |
def errorMessage(pmessage, pwhateveryouneed) { | |
if (isHttpBroken()) { // would need to add expected here as well | |
flowVars.errorContainer.message = pmessage; | |
flowVars.errorContainer.httpStatus = message.inboundProperties.'http.status'; | |
flowVars.errorContainer.httpReason = message.inboundProperties.'http.reason'; | |
flowVars.errorContainer.payload = message.payloadAs(java.lang.String); |
OlderNewer