Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
dingpei committed Mar 1, 2024
1 parent a776c23 commit 4107845
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
18 changes: 1 addition & 17 deletions jcommon/mockjs/src/main/java/run/mone/mock/MockJsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static String mock(String template) {
template = StringUtils.trimToEmpty(template);

try {
String result = MOCK_JS_ENGINE.eval("JSON.stringify(Mock.mock(" + template + "))").toString();
String result = MOCK_JS_ENGINE.eval("JSON.stringify(" + template + ")").toString();
return result;
} catch (Throwable e) {
log.error("执行Mock.mock错误", e);
Expand Down Expand Up @@ -79,21 +79,5 @@ public static List<String> batchOperation(List<String> res, Supplier<String> sup
}
}

public static String random(String template) {
template = StringUtils.trimToEmpty(template);

try {
String result = MOCK_JS_ENGINE.eval("JSON.stringify(Mock." + template + ")").toString();
return result;
} catch (Throwable e) {
log.error("执行Mock.mock错误", e);
}

return null;
}

public static List<String> batchRandom(String template, int number) {
return batchOperation(new ArrayList<>(), () -> random(template), number);
}

}
20 changes: 10 additions & 10 deletions jcommon/mockjs/src/test/java/run/mone/mock/test/MockTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class MockTest {

@Test
public void mockjsTest() {
String input = "{\n" +
" \"string|1-10\": \"\"\n" +
"}";
String input = "Mock.mock({\n" +
" \"number|1-100.1-10\": 1\n" +
"})";
long begin = System.currentTimeMillis();
String output = MockJsUtils.mock(input);
long costtime = System.currentTimeMillis() - begin;
Expand All @@ -22,9 +22,9 @@ public void mockjsTest() {

@Test
public void mockjsTestBatch() {
String input = "{\n" +
" \"string|1-10\": \"\"\n" +
"}";
String input = "Mock.mock({\n" +
" \"number|1-100.1-10\": 1\n" +
"})";
long begin = System.currentTimeMillis();
List<String> output = MockJsUtils.batchMock(input, 50000);
long costtime = System.currentTimeMillis() - begin;
Expand All @@ -33,18 +33,18 @@ public void mockjsTestBatch() {

@Test
public void mockjsTestRandom() {
String input = "Random.title(3, 5)";
String input = "Mock.Random.title(3, 5)";
long begin = System.currentTimeMillis();
String output = MockJsUtils.random(input);
String output = MockJsUtils.mock(input);
long costtime = System.currentTimeMillis() - begin;
System.out.println(output);
}

@Test
public void mockjsTestRandomBatch() {
String input = "Random.title(3, 5)";
String input = "Mock.Random.title(3, 5)";
long begin = System.currentTimeMillis();
List<String> output = MockJsUtils.batchRandom(input, 9999);
List<String> output = MockJsUtils.batchMock(input, 9999);
long costtime = System.currentTimeMillis() - begin;
System.out.println(output);
}
Expand Down

0 comments on commit 4107845

Please sign in to comment.