Skip to content

Instantly share code, notes, and snippets.

@jeffbowman
Created May 16, 2017 21:41
Show Gist options
  • Save jeffbowman/47be85ba96ab41cdb34e82159f4812c5 to your computer and use it in GitHub Desktop.
Save jeffbowman/47be85ba96ab41cdb34e82159f4812c5 to your computer and use it in GitHub Desktop.
Mule lambda expressions returned in DW
mvn clean test -Dmunit.test="lambda-test-suite.xml" :(
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Mule dataweave Application 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://nexusprod:8080/nexus/content/repositories/releases/org/apache/maven/plugins/maven-install-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/snapshots/org/apache/maven/plugins/maven-install-plugin/maven-metadata.xml
Downloading: http://repository.mulesoft.org/releases/org/apache/maven/plugins/maven-install-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/thirdparty/org/apache/maven/plugins/maven-install-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/thirdpartyss/org/apache/maven/plugins/maven-install-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/snapshots/org/apache/maven/plugins/maven-resources-plugin/maven-metadata.xml
Downloading: http://repository.mulesoft.org/releases/org/apache/maven/plugins/maven-resources-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/releases/org/apache/maven/plugins/maven-resources-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/thirdparty/org/apache/maven/plugins/maven-resources-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/thirdpartyss/org/apache/maven/plugins/maven-resources-plugin/maven-metadata.xml
Downloading: http://repository.mulesoft.org/releases/org/apache/maven/plugins/maven-surefire-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/snapshots/org/apache/maven/plugins/maven-surefire-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/releases/org/apache/maven/plugins/maven-surefire-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/thirdparty/org/apache/maven/plugins/maven-surefire-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/thirdpartyss/org/apache/maven/plugins/maven-surefire-plugin/maven-metadata.xml
Downloaded: http://repository.mulesoft.org/releases/org/apache/maven/plugins/maven-surefire-plugin/maven-metadata.xml (439 B at 277 B/s)
Downloading: http://repository.mulesoft.org/releases/org/apache/maven/plugins/maven-compiler-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/snapshots/org/apache/maven/plugins/maven-compiler-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/releases/org/apache/maven/plugins/maven-compiler-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/thirdparty/org/apache/maven/plugins/maven-compiler-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/thirdpartyss/org/apache/maven/plugins/maven-compiler-plugin/maven-metadata.xml
Downloading: http://repository.mulesoft.org/releases/org/apache/maven/plugins/maven-deploy-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/snapshots/org/apache/maven/plugins/maven-deploy-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/releases/org/apache/maven/plugins/maven-deploy-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/thirdparty/org/apache/maven/plugins/maven-deploy-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/thirdpartyss/org/apache/maven/plugins/maven-deploy-plugin/maven-metadata.xml
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ dataweave ---
[INFO] Deleting /Users/j.bowman/IdeaProjects/mule-dataweave-examples/target
[INFO]
[INFO] --- mule-app-maven-plugin:1.2:attach-test-resources (default-attach-test-resources) @ dataweave ---
[INFO] attaching test resource /Users/j.bowman/IdeaProjects/mule-dataweave-examples/src/main/app
[INFO]
[INFO] --- build-helper-maven-plugin:1.7:add-resource (add-resource) @ dataweave ---
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ dataweave ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] Copying 4 resources
[INFO] skip non existing resourceDirectory /Users/j.bowman/IdeaProjects/mule-dataweave-examples/mappings
[INFO] skip non existing resourceDirectory /Users/j.bowman/IdeaProjects/mule-dataweave-examples/src/main/api
[INFO]
[INFO] --- mule-app-maven-plugin:1.2:filter-resources (default-filter-resources) @ dataweave ---
[INFO]
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ dataweave ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 5 source files to /Users/j.bowman/IdeaProjects/mule-dataweave-examples/target/classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ dataweave ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] Copying 16 resources
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.1:testCompile (default-testCompile) @ dataweave ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ dataweave ---
[INFO]
[INFO] --- munit-maven-plugin:1.3.0:test (test) @ dataweave ---
[INFO] Acquiring dynamic ports...
[INFO] Dynamic port definition [DONE]
[INFO] Mule working directory set to: /Users/j.bowman/IdeaProjects/mule-dataweave-examples/target/.mule
[org.mule.munit.remote.RemoteRunner]Run Started
Coverage port: 52680 resources: dataweave.xml,lambdas.xml
=============================================================
=========== Running lambda-test-suite.xml test ===========
=============================================================
Running lambda-test-suiteTest
ERROR - The test lambda-test-suiteTest finished with an Error.
Exception while executing:
billedByPagesUploaded: flowVars.lambdaFns.billedByPagesUploadedFn(payload.billedByPages),
^
Cannot coerce a :object to a :function.
com.mulesoft.weave.mule.exception.WeaveExecutionException: Exception while executing:
billedByPagesUploaded: flowVars.lambdaFns.billedByPagesUploadedFn(payload.billedByPages),
^
Cannot coerce a :object to a :function.
at lambdasFlow.dw:transform-message{mode=immediate}(lambdas.xml:26)
at lambdasFlow.dw:transform-message{mode=immediate}(lambdas.xml:22)
at lambdasFlow.dw:transform-message{mode=immediate}(lambdas.xml:8)
at lambda-test-suiteTest.mule:flow{id=Flow$$EnhancerByMUNIT$$bb7e3368{lambdasFlow}, initialState=started}(lambdas.xml:6)
at lambda-test-suiteTest.mule:flow-ref{}(lambda-test-suite.xml:22)
at lambda-test-suiteTest.munit:test{id=MunitTestFlow$$EnhancerByMUNIT$$904837f0{lambda-test-suiteTest}, abstract=false, description=My First MUnit Test, initialState=started, ignore=false}(lambda-test-suite.xml:21)
Connected to localhost in port 52680
[org.mule.munit.remote.CoverageManager]accumulating report
[org.mule.munit.remote.CoverageManager]report is not null
===================================================================================
Number of tests run: 1 - Failed: 0 - Errors: 1 - Skipped: 0 - Time elapsed: 1.123ms
===================================================================================
[org.mule.munit.remote.CoverageManager]Calculating application coverage for resources: dataweave.xml,lambdas.xml
[org.mule.munit.remote.RemoteRunner]Done
[INFO] Printing Coverage Report...
[INFO] ===============================================================================
[INFO] MUnit Coverage Summary
[INFO] ===============================================================================
[INFO] * Resources: 2 - Flows: 13 - Message Processors: 72
[INFO] * Application Coverage: 04.17%
[INFO] ====================================================================================
[INFO] MUnit Run Summary
[INFO] ====================================================================================
[INFO] >> lambda-test-suite.xml test result: Tests: 1, Errors: 1, Failures:0, Skipped: 0
[INFO] --- lambda-test-suiteTest <<< ERROR
[INFO]
[INFO] ====================================================================================
[INFO] > Tests: 1
[INFO] > Errors: 1
[INFO] > Failures: 0
[INFO] > Skipped: 0
[INFO] ====================================================================================
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:munit="http://www.mulesoft.org/schema/mule/munit"
xmlns:mock="http://www.mulesoft.org/schema/mule/mock"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/mock http://www.mulesoft.org/schema/mule/mock/current/mule-mock.xsd
http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
">
<munit:config name="lambda-test-suite-munit-config"/>
<mock:config name="lambda-test-suite-mock-config"/>
<spring:beans>
<spring:import resource="classpath:lambdas.xml"/>
</spring:beans>
<munit:test name="lambda-test-suiteTest" description="My First MUnit Test">
<flow-ref name="lambdasFlow"/>
<munit:assert-true condition="#[payload['billedByPagesUploaded']]"/>
<munit:assert-true condition="#[payload['billedByPagesHosted']]"/>
<munit:assert-false condition="#[payload['billedByMBsUploaded']]"/>
<munit:assert-false condition="#[payload['billedByGBsUploaded']]"/>
<munit:assert-false condition="#[payload['billedByMBsHosted']]"/>
<munit:assert-false condition="#[payload['billedByGBsHosted']]"/>
</munit:test>
</mule>
%dw 1.0
%input payload application/json
%output application/java
%var Active = 'Active'
%var Hibernation = 'Hibernation'
%function hibernateOrInContinuation(projectStatus) ( projectStatus == Hibernation ) or ( projectStatus == Active and inContinuation )
---
{
billedByPagesUploadedFn: (billedByPages) -> ( not billedByPagesHosted ) and billedByPages,
billedByMBsUploadedFn: (billedByMBs) -> ( not billedByMBsHosted ) and billedByMBs,
billedByGBsUploadedFn: (billedByGBs) -> ( not billedByGBsHosted ) and billedByGBs,
billedByPagesHostedFn: (projectStatus, billedByPages) -> hibernateOrInContinuation(projectStatus) and billedByPages,
billedByMBsHostedFn: (projectStatus, billedByMBs) -> hibernateOrInContinuation(projectStatus) and billedByMBs,
billedByGBsHostedFn: (projectStatus, billedByGBs) -> hibernateOrInContinuation(projectStatus) and billedByGBs
}
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
xsi:schemaLocation=
"http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<flow name="lambdasFlow">
<description>Example Flow for lambdas</description>
<dw:transform-message>
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
inContinuation: false,
projectStatus: "Hibernation",
billedByPages: true,
billedByMBs: false,
billedByGBs: false
}
]]></dw:set-payload>
</dw:transform-message>
<dw:transform-message>
<dw:set-variable variableName="lambdaFns" resource="lambdas.dwl"/>
</dw:transform-message>
<dw:transform-message>
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
billedByPagesUploaded: flowVars.lambdaFns.billedByPagesUploadedFn(payload.billedByPages),
billedByMBsUploaded: flowVars.lambdaFns.billedByMBsUploadedFn(payload.billedByMBs),
billedByGBsUploaded: flowVars.lambdaFns.billedByGBsUploadedFn(payload.billedByGBs),
billedByPagesHosted: flowVars.lambdaFns.billedByPagesHostedFn(payload.projectStatus, payload.billedByPages),
billedByMBsHosted: flowVars.lambdaFns.billedByMBsHostedFn(payload.projectStatus, payload.billedByMBs),
billedByGBsHosted: flowVars.lambdaFns.billedByGBsHostedFn(payload.projectStatus, payload.billedByGBs)
}
]]></dw:set-payload>
</dw:transform-message>
<logger message="#[message.payload]"/>
</flow>
</mule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment