org.mockserver.model.HttpRequest.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(77)

本文整理了Java中org.mockserver.model.HttpRequest.<init>()方法的一些代码示例,展示了HttpRequest.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.<init>()方法的具体详情如下:
包路径:org.mockserver.model.HttpRequest
类名称:HttpRequest
方法名:<init>

HttpRequest.<init>介绍

暂无

代码示例

代码示例来源:origin: jamesdbloom/mockserver

public static HttpRequest request() {
  return new HttpRequest();
}

代码示例来源:origin: jamesdbloom/mockserver

public static HttpRequest request(String path) {
  return new HttpRequest().withPath(path);
}

代码示例来源:origin: jamesdbloom/mockserver

public HttpRequest mapHttpServletRequestToMockServerRequest(HttpServletRequest httpServletRequest) {
  HttpRequest request = new HttpRequest();
  setMethod(request, httpServletRequest);
  setPath(request, httpServletRequest);
  setQueryString(request, httpServletRequest);
  setBody(request, httpServletRequest);
  setHeaders(request, httpServletRequest);
  setCookies(request, httpServletRequest);
  request.withKeepAlive(isKeepAlive(httpServletRequest));
  request.withSecure(httpServletRequest.isSecure());
  return request;
}

代码示例来源:origin: jamesdbloom/mockserver

public HttpRequest buildObject() {
  return new HttpRequest()
    .withMethod(method)
    .withPath(path)
    .withQueryStringParameters(queryStringParameters)
    .withBody((body != null ? Not.not(body.buildObject(), body.getNot()) : null))
    .withHeaders(headers)
    .withCookies(cookies)
    .withSecure(secure)
    .withKeepAlive(keepAlive);
}

代码示例来源:origin: jamesdbloom/mockserver

public HttpRequest decode(FullHttpRequest fullHttpRequest) {
  HttpRequest httpRequest = new HttpRequest();
  if (fullHttpRequest != null) {
    setMethod(httpRequest, fullHttpRequest);
    setPath(httpRequest, fullHttpRequest);
    setQueryString(httpRequest, new QueryStringDecoder(fullHttpRequest.uri()));
    setHeaders(httpRequest, fullHttpRequest);
    setCookies(httpRequest, fullHttpRequest);
    setBody(httpRequest, fullHttpRequest);
    httpRequest.withKeepAlive(isKeepAlive(fullHttpRequest));
    httpRequest.withSecure(isSecure);
  }
  return httpRequest;
}

代码示例来源:origin: org.mock-server/mockserver-core

public static HttpRequest request() {
  return new HttpRequest();
}

代码示例来源:origin: org.mock-server/mockserver-core

public static HttpRequest request(String path) {
  return new HttpRequest().withPath(path);
}

代码示例来源:origin: RoboZonky/robozonky

@BeforeEach
void emptyExports() {
  server.when(new HttpRequest()).respond(new HttpResponse().withBody("")); // just return something to be downloaded
  final Response response = mock(Response.class);
  when(response.getStatus()).thenReturn(302);
  when(response.getHeaderString(any())).thenReturn("http://" + serverUrl + "/file");
  doReturn(response).when(zonky).downloadWalletExport();
  doReturn(response).when(zonky).downloadInvestmentsExport();
}

代码示例来源:origin: RoboZonky/robozonky

@BeforeEach
void emptyExports() {
  server.when(new HttpRequest()).respond(new HttpResponse()); // just return something to be downloaded
  final Response response = mock(Response.class);
  when(response.getStatus()).thenReturn(302);
  when(response.getHeaderString(any())).thenReturn("http://" + serverUrl + "/file");
  doReturn(response).when(zonky).downloadWalletExport();
  doReturn(response).when(zonky).downloadInvestmentsExport();
}

代码示例来源:origin: org.mock-server/mockserver-core

public HttpRequest mapHttpServletRequestToMockServerRequest(HttpServletRequest httpServletRequest) {
  HttpRequest request = new HttpRequest();
  setMethod(request, httpServletRequest);
  setPath(request, httpServletRequest);
  setQueryString(request, httpServletRequest);
  setBody(request, httpServletRequest);
  setHeaders(request, httpServletRequest);
  setCookies(request, httpServletRequest);
  request.withKeepAlive(isKeepAlive(httpServletRequest));
  request.withSecure(httpServletRequest.isSecure());
  return request;
}

代码示例来源:origin: org.mock-server/mockserver-core

public HttpRequest buildObject() {
  return new HttpRequest()
    .withMethod(method)
    .withPath(path)
    .withQueryStringParameters(queryStringParameters)
    .withBody((body != null ? Not.not(body.buildObject(), body.getNot()) : null))
    .withHeaders(headers)
    .withCookies(cookies)
    .withSecure(secure)
    .withKeepAlive(keepAlive);
}

代码示例来源:origin: org.mock-server/mockserver-core

public HttpRequest decode(FullHttpRequest fullHttpRequest) {
  HttpRequest httpRequest = new HttpRequest();
  if (fullHttpRequest != null) {
    setMethod(httpRequest, fullHttpRequest);
    setPath(httpRequest, fullHttpRequest);
    setQueryString(httpRequest, new QueryStringDecoder(fullHttpRequest.uri()));
    setHeaders(httpRequest, fullHttpRequest);
    setCookies(httpRequest, fullHttpRequest);
    setBody(httpRequest, fullHttpRequest);
    httpRequest.withKeepAlive(isKeepAlive(fullHttpRequest));
    httpRequest.withSecure(isSecure);
  }
  return httpRequest;
}

代码示例来源:origin: tus/tus-java-client

@Test
public void testMissingUploadOffsetHeader() throws Exception {
  byte[] content = "hello world".getBytes();
  mockServer.when(new HttpRequest()
      .withPath("/files/missingHeader"))
      .respond(new HttpResponse()
          .withStatusCode(204)
          .withHeader("Tus-Resumable", TusClient.TUS_VERSION));
  TusClient client = new TusClient();
  URL uploadUrl = new URL(mockServerURL + "/missingHeader");
  TusInputStream input = new TusInputStream(new ByteArrayInputStream(content));
  TusUploader uploader = new TusUploader(client, uploadUrl, input, 0);
  boolean exceptionThrown = false;
  try {
    assertEquals(11, uploader.uploadChunk());
    uploader.finish();
  } catch(ProtocolException e) {
    assertTrue(e.getMessage().contains("no or invalid Upload-Offset header"));
    exceptionThrown = true;
  } finally {
    assertTrue(exceptionThrown);
  }
}

代码示例来源:origin: tus/tus-java-client

@Test
  public void testUnmatchingUploadOffsetHeader() throws Exception {
    byte[] content = "hello world".getBytes();

    mockServer.when(new HttpRequest()
        .withPath("/files/unmatchingHeader"))
        .respond(new HttpResponse()
            .withStatusCode(204)
            .withHeader("Tus-Resumable", TusClient.TUS_VERSION)
            .withHeader("Upload-Offset", "44"));

    TusClient client = new TusClient();
    URL uploadUrl = new URL(mockServerURL + "/unmatchingHeader");
    TusInputStream input = new TusInputStream(new ByteArrayInputStream(content));

    TusUploader uploader = new TusUploader(client, uploadUrl, input, 0);

    boolean exceptionThrown = false;
    try {
      assertEquals(11, uploader.uploadChunk());
      uploader.finish();
    } catch(ProtocolException e) {
      assertTrue(e.getMessage().contains("different Upload-Offset value (44) than expected (11)"));
      exceptionThrown = true;
    } finally {
      assertTrue(exceptionThrown);
    }
  }
}

代码示例来源:origin: tus/tus-java-client

@Test
public void testCreateUpload() throws IOException, ProtocolException {
  mockServer.when(new HttpRequest()
      .withMethod("POST")
      .withPath("/files")
      .withHeader("Tus-Resumable", TusClient.TUS_VERSION)
      .withHeader("Upload-Metadata", "foo aGVsbG8=,bar d29ybGQ=")
      .withHeader("Upload-Length", "10"))
      .respond(new HttpResponse()
          .withStatusCode(201)
          .withHeader("Tus-Resumable", TusClient.TUS_VERSION)
          .withHeader("Location", mockServerURL + "/foo"));
  Map<String, String> metadata = new LinkedHashMap<String, String>();
  metadata.put("foo", "hello");
  metadata.put("bar", "world");
  TusClient client = new TusClient();
  client.setUploadCreationURL(mockServerURL);
  TusUpload upload = new TusUpload();
  upload.setSize(10);
  upload.setInputStream(new ByteArrayInputStream(new byte[10]));
  upload.setMetadata(metadata);
  TusUploader uploader = client.createUpload(upload);
  assertEquals(uploader.getUploadURL(), new URL(mockServerURL + "/foo"));
}

代码示例来源:origin: tus/tus-java-client

@Test
public void testBeginOrResumeUploadFromURL() throws IOException, ProtocolException {
  mockServer.when(new HttpRequest()
      .withMethod("HEAD")
      .withPath("/files/fooFromURL")
      .withHeader("Tus-Resumable", TusClient.TUS_VERSION))
      .respond(new HttpResponse()
          .withStatusCode(204)
          .withHeader("Tus-Resumable", TusClient.TUS_VERSION)
          .withHeader("Upload-Offset", "3"));
  TusClient client = new TusClient();
  URL uploadURL = new URL(mockServerURL.toString() + "/fooFromURL");
  TusUpload upload = new TusUpload();
  upload.setSize(10);
  upload.setInputStream(new ByteArrayInputStream(new byte[10]));
  TusUploader uploader = client.beginOrResumeUploadFromURL(upload, uploadURL);
  assertEquals(uploader.getUploadURL(), uploadURL);
  assertEquals(uploader.getOffset(), 3);
}

代码示例来源:origin: tus/tus-java-client

mockServer.when(new HttpRequest()
    .withMethod("POST")
    .withPath("/filesRedirect")
        .withHeader("Location", mockServerURL + "Redirected/"));
mockServer.when(new HttpRequest()
    .withMethod("POST")
    .withPath("/filesRedirected/")

代码示例来源:origin: tus/tus-java-client

@Test
public void testResumeUpload() throws ResumingNotEnabledException, FingerprintNotFoundException, IOException, ProtocolException {
  mockServer.when(new HttpRequest()
      .withMethod("HEAD")
      .withPath("/files/foo")
      .withHeader("Tus-Resumable", TusClient.TUS_VERSION))
      .respond(new HttpResponse()
          .withStatusCode(204)
          .withHeader("Tus-Resumable", TusClient.TUS_VERSION)
          .withHeader("Upload-Offset", "3"));
  TusClient client = new TusClient();
  client.setUploadCreationURL(mockServerURL);
  client.enableResuming(new TestResumeUploadStore());
  TusUpload upload = new TusUpload();
  upload.setSize(10);
  upload.setInputStream(new ByteArrayInputStream(new byte[10]));
  upload.setFingerprint("test-fingerprint");
  TusUploader uploader = client.resumeUpload(upload);
  assertEquals(uploader.getUploadURL(), new URL(mockServerURL.toString() + "/foo"));
  assertEquals(uploader.getOffset(), 3);
}

代码示例来源:origin: tus/tus-java-client

@Test
public void testResumeOrCreateUpload() throws IOException, ProtocolException {
  mockServer.when(new HttpRequest()
      .withMethod("POST")
      .withPath("/files")
      .withHeader("Tus-Resumable", TusClient.TUS_VERSION)
      .withHeader("Upload-Length", "10"))
      .respond(new HttpResponse()
          .withStatusCode(201)
          .withHeader("Tus-Resumable", TusClient.TUS_VERSION)
          .withHeader("Location", mockServerURL + "/foo"));
  TusClient client = new TusClient();
  client.setUploadCreationURL(mockServerURL);
  TusUpload upload = new TusUpload();
  upload.setSize(10);
  upload.setInputStream(new ByteArrayInputStream(new byte[10]));
  TusUploader uploader = client.resumeOrCreateUpload(upload);
  assertEquals(uploader.getUploadURL(), new URL(mockServerURL + "/foo"));
}

代码示例来源:origin: tus/tus-java-client

@Test
public void testCreateUploadWithMissingLocationHeader() throws IOException, Exception {
  mockServer.when(new HttpRequest()
      .withMethod("POST")
      .withPath("/files")
      .withHeader("Tus-Resumable", TusClient.TUS_VERSION)
      .withHeader("Upload-Length", "10"))
      .respond(new HttpResponse()
          .withStatusCode(201)
          .withHeader("Tus-Resumable", TusClient.TUS_VERSION));
  TusClient client = new TusClient();
  client.setUploadCreationURL(mockServerURL);
  TusUpload upload = new TusUpload();
  upload.setSize(10);
  upload.setInputStream(new ByteArrayInputStream(new byte[10]));
  try {
    TusUploader uploader = client.createUpload(upload);
    throw new Exception("unreachable code reached");
  } catch(ProtocolException e) {
    assertEquals(e.getMessage(), "missing upload URL in response for creating upload");
  }
}

相关文章