Skip to content

Instantly share code, notes, and snippets.

View stephan-landers's full-sized avatar

stephan-landers

View GitHub Profile
@stephan-landers
stephan-landers / pom.xml
Created August 26, 2019 10:27
Adding JSONAssert dependency
[...]
<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>android-json</artifactId>
[...]
<spring:beans>
[...]
<spring:bean
id="httpRequestExceptionInterceptor"
class="com.ricston.mule.interceptors.HttpRequestExceptionInterceptor">
<spring:property name="lastErrorMessageVarName" value="lastHttpError"/>
</spring:bean>
<aop:config>
<aop:aspect
public class HttpRequestExceptionInterceptor {
/** Flow variable name for transferring the outside event session to inside the enricher */
private static final String OUTSIDE_EVENT_SESSION =
"_HttpRequestExceptionInterceptor_outsideEventSession";
/** Session variable name for the MuleMessage on an exception */
private String lastErrorMessageVarName = "lastHttpError";
public void setLastErrorMessageVarName(final String name) {
this.lastErrorMessageVarName = name;
}
// Replicates the belongs() method used in Mule's SuccessStatusValidator
def belongs(values, value) {
var intValue = Integer.parseInt(value);
var valueParts = values.toString().split(','); //values.split sometimes fails. Strange...
var valuePart;
var limits;
var code;
var lower;
var upper;
var i;
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);
/*
* © 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;
{
"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]"
<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"
@stephan-landers
stephan-landers / MockInterceptor.java
Last active July 9, 2019 11:17
MockInterceptor.java
// [...]
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(); ?
<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>