我的流有一个Choice,然后是Dataweave转换。 流的输入是json。 当声明时,选择有这个:
<when expression="#[payload.resultSet1.size() >= 1]">
流程运作良好:
<flow name="test1">
<db:stored-procedure doc:name="MyStoredProc"></db:stored-procedure>
<choice doc:name="data found?">
<when expression="#[payload.resultSet1.size() >= 1]">
<dw:transform-message doc:name="CreateResponse">
<dw:set-payload resource="classpath:/dataweave/someDataweave.dwl" />
</dw:transform-message>
</when>
<otherwise>
<logger message="False: payload:#[payload]" level="INFO" doc:name="Log-False"/>
</otherwise>
</choice>
</flow>
现在我正在尝试为它创建一个Munit测试。为了让选择起作用,我不得不玩一些数据。 现在选择有效,但现在dataweave转换引发异常,因为它说json数据缺少引号。 蒙特:
<munit:test name="test1-tryit" description="Test">
<mock:when messageProcessor=".*:.*" doc:name="Mock MyStoredProcResults">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['MyStoredProc']"/>
</mock:with-attributes>
<mock:then-return payload="#[flowVars.jsonStoredProcResponse]" mimeType="text/json"/>
</mock:when>
<set-payload value="#[getResource('myTestData.json').asStream()]" doc:name="GetStoredProcResponse" mimeType="application/json"/>
<json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object"/>
<set-variable variableName="jsonStoredProcResponse" value="#[payload]" doc:name="jsonStoredProcResponse" />
<flow-ref name="test1" doc:name="Flow-ref to test1 flow" />
myTestData.json文件中的数据如下所示: {“resultSet1”:[{“field1”:“123”}]}
不确定如何解决此问题并使选择和转换都能正常工作。
感谢。
答案 0 :(得分:0)
public class VersionChecker extends AsyncTask<String, String, String> {
String newVersion;
Context context;
public VersionChecker(Context context) {
this.context = context;
}
@Override
protected String doInBackground(String... params) {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://play.google.com/store/apps/details?id=" + context.getPackageName() + "&hl=en")
.build();
try {
Response response = client.newCall(request).execute();
result = response.body().string();
if(result!=null && result.contains("softwareVersion")){
String parts[] = result.split("softwareVersion");
result= parts[1].substring(
parts[1].indexOf('>') + 1, parts[1].indexOf('<')
).trim();
}else {
result=CommonUtilities.getAppVersionName(context);
}
} catch (Exception ex) {
result=CommonUtilities.getAppVersionName(context);
ex.printStackTrace();
}
return result;
}}