+
接口版本管理
@@ -59,10 +59,10 @@
@@ -100,6 +100,6 @@
-->
- #bodyEnd
-
+ #bodyEnd
+
diff --git a/WebContent/stat/js/util/mock.plugin.js b/WebContent/stat/js/util/mock.plugin.js
index 760fce8..9e84d56 100644
--- a/WebContent/stat/js/util/mock.plugin.js
+++ b/WebContent/stat/js/util/mock.plugin.js
@@ -1,4 +1,3 @@
-
/*! rap.plugin Mar.10th 2014 */
(function() {
var node = null;
@@ -66,9 +65,9 @@
rapUrlConverterJQuery(oOptions);
var oldSuccess = oOptions.success;
oOptions.success = function(data) {
- if (PREFIX == '/mockjs/') {
- data = Mock.mock(data);
- }
+ if (PREFIX == '/mockjs/') {
+ data = Mock.mock(data);
+ }
oldSuccess.apply(this, arguments);
};
} else if(isInWhiteList(url) && !oOptions.RAP_NOT_TRACK) {
@@ -111,46 +110,25 @@
rapUrlConverterKissy(oOptions);
oldSuccess = oOptions.success;
oOptions.success = function(data) {
- if (PREFIX == '/mockjs/') {
- data = Mock.mock(data);
- }
+ if (PREFIX == '/mockjs/') {
+ data = Mock.mock(data);
+ }
oldSuccess.apply(this, arguments);
};
- } else {
- if (!oOptions.RAP_NOT_TRACK) {
- // real data checking
- var oldSuccess = oOptions.success;
- oOptions.success = function() {
- var realData = arguments[0];
- KISSY.IO({
- url : url,
- dataType : 'jsonp',
- jsonp : '_c',
- RAP_NOT_TRACK : true,
- success : function(mockData) {
- var validator = new StructureValidator(realData, mockData);
- var result = validator.getResult();
- var realDataResult = result.left;
- var rapDataResult = result.right;
- var i;
-
- if (realDataResult.length === 0 && rapDataResult.length === 0) {
- console.log('接口结构校验完毕,未发现问题。');
- } else {
- for (i = 0; i < realDataResult.length; i++) {
- validatorResultLog(realDataResult[i]);
- }
- for (i = 0; i < rapDataResult.length; i++) {
- validatorResultLog(rapDataResult[i], true);
- }
- }
- }
- });
- oldSuccess.apply(this,arguments);
-
+ } else if(isInWhiteList(url) && !oOptions.RAP_NOT_TRACK) {
+ var checkerOptions = {url:oOptions.url};
+ rapUrlConverterKissy(checkerOptions);
+ checkerOptions.RAP_NOT_TRACK = true;
+ checkerOptions.success = checkerHandler;
+ // real data checking
+ oldSuccess = oOptions.success;
+ oOptions.success = function() {
+ var realData = arguments[0];
+ checkerOptions.context = {
+ data : realData
};
// perform real data check
- KISSY.IO(checkerOptions);
+ IO(checkerOptions);
oldSuccess.apply(this,arguments);
};
@@ -162,21 +140,7 @@
}, {
requires: ['ajax']
});
-
- function replace(modules) {
- var splited = modules;
- if (KISSY.isString(modules)) {
- splited = modules.split(',');
- }
- var index = -1;
- for (var i = 0, l = splited.length; i < l; i++) {
- var name = KISSY.trim(splited[i]).toLowerCase();
- if (name === 'ajax' || name === 'io') {
- splited[i] = 'rap_io'
- }
- }
- return splited.join(',');
- }
+
KISSY.use = function(modules, callback) {
var args = arguments;
@@ -223,10 +187,10 @@
}
- function checkerHandler(mockData) {
- if (PREFIX == '/mockjs/') {
- mockData = Mock.mock(mockData);
- }
+ function checkerHandler(mockData) {
+ if (PREFIX == '/mockjs/') {
+ mockData = Mock.mock(mockData);
+ }
var realData = this.data;
var validator = new StructureValidator(realData, mockData);
var result = validator.getResult();
@@ -353,7 +317,7 @@
* example: www.baidu.com/a => alibaba-inc.com/mock/106/a
*/
function rapUrlConverterKissy(options) {
- var url = options.url;
+ var url = options.url;
if (!options || typeof options !== 'object') {
throw Error('illegal option object:' + options);
}
@@ -371,7 +335,7 @@
* example: www.baidu.com/a => alibaba-inc.com/mock/106/a
*/
function rapUrlConverterJQuery(options) {
- var url = options.url;
+ var url = options.url;
if (!options || typeof options !== 'object') {
throw Error('illegal option object:' + options);
}
@@ -425,4 +389,4 @@
return PREFIX;
}
};
-})();
+})();
\ No newline at end of file
diff --git a/src/com/taobao/rigel/rap/mock/service/MockMgr.java b/src/com/taobao/rigel/rap/mock/service/MockMgr.java
index e1095a2..460b9a6 100644
--- a/src/com/taobao/rigel/rap/mock/service/MockMgr.java
+++ b/src/com/taobao/rigel/rap/mock/service/MockMgr.java
@@ -9,8 +9,9 @@ public interface MockMgr {
* @param projectId
* @param pattern
* @return JSON String
+ * @throws UnsupportedEncodingException
*/
- public String generateData(int projectId, String pattern);
+ public String generateData(int projectId, String pattern) throws UnsupportedEncodingException;
/**
* modify mock data of parameters based on mockData
diff --git a/src/com/taobao/rigel/rap/mock/service/impl/MockMgrImpl.java b/src/com/taobao/rigel/rap/mock/service/impl/MockMgrImpl.java
index 431e75f..7befdb1 100644
--- a/src/com/taobao/rigel/rap/mock/service/impl/MockMgrImpl.java
+++ b/src/com/taobao/rigel/rap/mock/service/impl/MockMgrImpl.java
@@ -54,8 +54,9 @@ public void setProjectDao(ProjectDao projectDao) {
}
@Override
- public String generateData(int projectId, String pattern) {
+ public String generateData(int projectId, String pattern) throws UnsupportedEncodingException {
_num = 1;
+ String originalPattern = pattern;
System.out.println("pattern before processed:" + pattern);
if (pattern.contains("?")) {
pattern = pattern.substring(0, pattern.indexOf("?"));
@@ -68,7 +69,9 @@ public String generateData(int projectId, String pattern) {
.getMatchedActionList(projectId, pattern);
if (aList.size() == 0)
return "{\"isOk\":false, \"errMsg\":\"no matched action\"}";
- Action action = aList.get(0);
+
+ Action action = actionPick(aList, originalPattern);
+
String desc = action.getDescription();
Set
pList = action.getResponseParameterList();
// load mock data by QA
diff --git a/src/com/taobao/rigel/rap/mock/web/action/MockAction.java b/src/com/taobao/rigel/rap/mock/web/action/MockAction.java
index c18e363..f176e2c 100644
--- a/src/com/taobao/rigel/rap/mock/web/action/MockAction.java
+++ b/src/com/taobao/rigel/rap/mock/web/action/MockAction.java
@@ -134,7 +134,7 @@ public void setPattern(String pattern) {
}
}
- public String createData() {
+ public String createData() throws UnsupportedEncodingException {
String _c = get_c();
if (callback != null && !callback.isEmpty()) {
setContent(callback + "(" + mockMgr.generateData(id, pattern) + ")");