????????Response?????????????????HTTP?????????????????

public class Response {
private final int statusCode;
private final String responseBody;

?????????????EndPoint??????????????????????????????????????????????????????????????????????????????·????????????Σ????????????????????????????????????????????????????????Σ????????????EndPoint??????????????????????????????

??????????????

?????????????EndPoint????????????????????????????????????????????????????????????????????????——“???????”?????????????????????????HTTP?????????????????????????????????????????????????????????????????????????/???Э?飬?????????????????HTTP?????ü???????/???????????в????

????Moco?????????????????????????????????????Moco??“???????????????stub??????????????????”????JUnit?????У????????д?????????????HTTP?????????÷?????????12306??????????????????????“foo”??????

MocoHttpServer server = httpserver(12306);
server.reponse("foo");

?????????????????????????????????????Apache Commons HTTP Client????????????????????????????????????????????????running???У???????????????????????

running(server?? new Runnable() {
     @Override
     public void run() throws IOException {
       Content content = Request.Get("http://localhost:12306").execute().returnContent();
       assertThat(content.asString()?? is("foo"));
     }
}

???????????????????????????Moco??????????????????????????????в???????????????????????????Moco?????????????е????????????????????????????????????????????????????????OpenPTK??OpenPTK?????????XML???Э?飬???????????????????????????/openptk-server/login??????????????????????????ó??????????????????????????Moco server??????????

server = httpserver(12306);
server.post(and(

         by(uri("/openptk-server/login"))??
         by("clientid=test_app&clientcred=fake_password"))).response(status(200));

???????????????????????????????÷???λ??localhost:12306????????????????????????

configuration = new IdentityServiceConfiguration();
configuration.setHost("http://localhost:12306");
configuration.setClientId("test_app");
configuration.setClientCredential("fake_password");
xmlEndPoint = new XmlEndPoint(configuration);

??????????????????????????????????XmlEndPoint??????GET????????????????URL?????????????

@Test
public void shouldBeAbleToCarryGetRequest() throws Exception {
  final String expectedResponse = "<message>SUCCESS</message>";
  server.get(by(uri("/get_path"))).response(expectedResponse);
 
  running(server?? new Runnable() {
    @Override
    public void run() {
      XmlEndPointResponse response =
        xmlEndPoint.get("http://localhost:12306/get_path");
      assertThat(response.getStatusCode()?? equalTo(STATUS_SUCCESS));
      assertThat(response.getResponseBody()?? equalTo(expectedResponse));
    }
  });
}

????????????????????????????????????????“??ó????????”????????????????????XmlEndPoint???get?????????????????

@Test(expected = IdentityServiceSystemException.class)
public void shouldRaiseExceptionIfLoginFails() throws Exception {
    configuration.setClientCredential("wrong_password");
 
    running(server?? new Runnable() {
        @Override
        public void run() {
            xmlEndPoint.get("http://localhost:12306/get_path");
        }
    });
}