1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | { "request": { "uri" : "/event" }, "response": { "text": "event" }, "on": { "complete": { "async" : "true", "post" : { "url" : "http://another_site", "content": "content" } } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import org.junit.Test; import java.io.IOException; import com.github.dreamhead.moco.HttpServer; import org.apache.http.client.fluent.Content; import org.apache.http.client.fluent.Request; import com.github.dreamhead.moco.Runnable; import static com.github.dreamhead.moco.Moco.*; import static com.github.dreamhead.moco.Runner.*; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; @Test public void should_response_as_expected() throws Exception { HttpServer server = httpserver(12306); server.response("foo"); running(server, new Runnable() { @Override public void run() throws IOException { Content content = Request.Get("http://localhost:12306").execute().returnContent(); assertThat(content.asString(), is("foo")); } }); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import org.junit.After; import org.junit.Before; import org.junit.Test; import java.io.IOException; import static com.github.dreamhead.moco.Moco.httpserver; import static com.github.dreamhead.moco.Runner.runner; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; public class MocoRunnerTest { private Runner runner; @Before public void setup() { HttpServer server = httpserver(12306); server.response("foo"); runner = runner(server); runner.start(); helper = new MocoTestHelper(); } @After public void tearDown() { runner.stop(); } @Test public void should_response_as_expected() throws IOException { Content content = Request.Get("http://localhost:12306").execute().returnContent(); assertThat(content.asString(), is("foo")); } } |
1 2 3 4 5 6 7 8 9 10 | [ { "env" : "remote", "include": "foo.json", }, { "env" : "local", "include": "bar.json", } ] |
1 | java -jar moco-runner-<version>-standalone.jar start -p 12306 -g env.json -e remote |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |