Browse Source

Merge pull request 'WIP REPORT-39459 json数据集-传参方式从get改为post-raw,参数的值没有保留' (#1) from Lucian.Chen/finekit:master into master

Reviewed-on: fanruan/finekit#1
master
richie 4 years ago
parent
commit
a9ed1f7448
  1. 32
      src/main/java/com/fanruan/api/cal/ParameterKit.java
  2. 49
      src/test/java/com/fanruan/api/cal/ParameterKitTest.java

32
src/main/java/com/fanruan/api/cal/ParameterKit.java

@ -18,6 +18,7 @@ import com.fr.stable.script.NameSpace;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -144,6 +145,37 @@ public class ParameterKit {
return parameters; return parameters;
} }
/**
* 获得参数并集将新的参数拼接在后面
*
* @param paramTexts sql语句
* @param ps 旧的参数集合
* @return 新参数集合
*/
public static ParameterProvider[] analyzeAndMergeParameters(String[] paramTexts, ParameterProvider[] ps) {
ParameterProvider[] parameters = ParameterKit.analyze4Parameters(paramTexts, false);
if (ArrayKit.isEmpty(parameters) || ArrayKit.isEmpty(ps)) {
return ArrayUtils.addAll(ps, parameters);
}
List<ParameterProvider> psList = ArrayKit.toList(ps);
// 检查ps中是否有parameter,如果没有就加进去
for (ParameterProvider parameter : parameters) {
for (int i = 0; i < ps.length; i ++) {
if (AssistKit.equals(ps[i].getName(), parameter.getName())) {
break;
}
else if (i >= ps.length - 1) {
psList.add(parameter);
}
}
}
return psList.toArray(new ParameterProvider[0]);
}
/** /**
* 从JSON中解析出来参数信息 * 从JSON中解析出来参数信息
* *

49
src/test/java/com/fanruan/api/cal/ParameterKitTest.java

@ -132,6 +132,55 @@ public class ParameterKitTest extends Prepare {
} }
} }
@Test
public void testAnalyzeAndMergeParameters() {
ParameterProvider param1 = ParameterKit.newParameter("test1", "1");
ParameterProvider param2 = ParameterKit.newParameter("test2", "2");
String text1 = "${a}";
String text2 = "${test1}";
ParameterProvider[] parameters1 = ParameterKit.analyzeAndMergeParameters(
new String[]{text1, text2},
new ParameterProvider[] {param1, param2}
);
ParameterProvider[] parameters2 = ParameterKit.analyzeAndMergeParameters(null, null);
ParameterProvider[] parameters3 = ParameterKit.analyzeAndMergeParameters(
null,
new ParameterProvider[] {param1, param2}
);
ParameterProvider[] parameters4 = ParameterKit.analyzeAndMergeParameters(
new String[] {},
new ParameterProvider[] {param1, param2}
);
ParameterProvider[] parameters5 = ParameterKit.analyzeAndMergeParameters(
new String[]{text1, text2},
new ParameterProvider[] {}
);
Assert.assertEquals(parameters1.length, 3);
Assert.assertEquals(parameters1[0], param1);
Assert.assertEquals(parameters1[1], param2);
Assert.assertEquals(parameters1[2].getName(), "a");
Assert.assertEquals(parameters1[2].getValue(), "");
Assert.assertEquals(parameters2.length, 0);
Assert.assertEquals(parameters3.length, 2);
Assert.assertEquals(parameters3[0], param1);
Assert.assertEquals(parameters3[1], param2);
Assert.assertEquals(parameters4.length, 2);
Assert.assertEquals(parameters4[0], param1);
Assert.assertEquals(parameters4[1], param2);
Assert.assertEquals(parameters5.length, 2);
Assert.assertEquals(parameters5[0].getName(), "a");
Assert.assertEquals(parameters5[0].getValue(), "");
Assert.assertEquals(parameters5[1].getName(), "test1");
Assert.assertEquals(parameters5[1].getValue(), "");
}
@Test @Test
public void json2Parameter() { public void json2Parameter() {
String text = "{\"name\":\"p1\", \"type\":\"Formula\", \"value\":\"=1+1\"}"; String text = "{\"name\":\"p1\", \"type\":\"Formula\", \"value\":\"=1+1\"}";

Loading…
Cancel
Save