io.restassured.response.Response.getContentType()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(131)

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

Response.getContentType介绍

暂无

代码示例

代码示例来源:origin: rest-assured/rest-assured

/**
 * Clone an already existing response.
 *
 * @return Builder.
 */
public ResponseBuilder clone(Response response) {
  if (isRestAssuredResponse(response)) {
    final RestAssuredResponseImpl raResponse = raResponse(response);
    restAssuredResponse.setContent(raResponse.getContent());
    restAssuredResponse.setHasExpectations(raResponse.getHasExpectations());
    restAssuredResponse.setDefaultContentType(raResponse.getDefaultContentType());
    restAssuredResponse.setDecoderConfig(raResponse.getDecoderConfig());
    restAssuredResponse.setSessionIdName(raResponse.getSessionIdName());
    restAssuredResponse.setConnectionManager(raResponse.getConnectionManager());
    restAssuredResponse.setConfig(raResponse.getConfig());
    restAssuredResponse.setRpr(raResponse.getRpr());
    restAssuredResponse.setLogRepository(raResponse.getLogRepository());
    restAssuredResponse.setFilterContextProperties(raResponse.getFilterContextProperties());
  } else {
    restAssuredResponse.setContent(response.asInputStream());
  }
  restAssuredResponse.setContentType(response.getContentType());
  restAssuredResponse.setCookies(response.getDetailedCookies());
  restAssuredResponse.setResponseHeaders(response.getHeaders());
  restAssuredResponse.setStatusCode(response.getStatusCode());
  restAssuredResponse.setStatusLine(response.getStatusLine());
  return this;
}

代码示例来源:origin: ctco/cukes

@Override
  public String getContentType(Object o) {
    return ((Response) o).getContentType();
  }
}

代码示例来源:origin: lv.ctco.cukes/cukes-http

@Override
  public String getContentType(Object o) {
    return ((Response) o).getContentType();
  }
}

代码示例来源:origin: guru.nidi.raml/raml-tester

@Override
public String getContentType() {
  return response.getContentType();
}

代码示例来源:origin: nidi3/raml-tester

@Override
public String getContentType() {
  return response.getContentType();
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testGetBinaryDataForFileVariable() {
 String filename = "test.txt";
 byte[] byteContent = "test".getBytes();
 String encoding = "UTF-8";
 FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(ContentType.TEXT.toString()).encoding(encoding).create();
 HistoricVariableInstance variableInstanceMock = MockProvider.mockHistoricVariableInstance().typedValue(variableValue).build();
 when(variableInstanceQueryMock.variableId(variableInstanceMock.getId())).thenReturn(variableInstanceQueryMock);
 when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock);
 when(variableInstanceQueryMock.singleResult()).thenReturn(variableInstanceMock);
 Response response = given().pathParam("id", MockProvider.EXAMPLE_VARIABLE_INSTANCE_ID)
 .then().expect()
  .statusCode(Status.OK.getStatusCode())
 .and()
  .body(is(equalTo(new String(byteContent))))
  .header("Content-Disposition", "attachment; filename="+filename)
 .when().get(VARIABLE_INSTANCE_BINARY_DATA_URL);
 //due to some problems with wildfly we gotta check this separately
 String contentType = response.getContentType();
 assertThat(contentType, is(either(CoreMatchers.<Object>equalTo(ContentType.TEXT.toString() + "; charset=UTF-8")).or(CoreMatchers.<Object>equalTo(ContentType.TEXT.toString() + ";charset=UTF-8"))));
 verify(variableInstanceQueryMock, never()).disableBinaryFetching();
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testBinaryDataForFileVariable() {
 String filename = "test.txt";
 byte[] byteContent = "test".getBytes();
 String encoding = "UTF-8";
 FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(ContentType.TEXT.toString()).encoding(encoding).create();
 MockHistoricVariableUpdateBuilder builder = MockProvider.mockHistoricVariableUpdate();
 HistoricVariableUpdate detailMock = builder
   .typedValue(variableValue)
   .build();
 when(historicDetailQueryMock.detailId(detailMock.getId())).thenReturn(historicDetailQueryMock);
 when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock);
 when(historicDetailQueryMock.singleResult()).thenReturn(detailMock);
 Response response = given().pathParam("id", MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_ID)
 .then().expect()
  .statusCode(Status.OK.getStatusCode())
  . body(is(equalTo(new String(byteContent))))
  .and()
   .header("Content-Disposition", "attachment; filename="+filename)
 .when().get(VARIABLE_INSTANCE_BINARY_DATA_URL);
 //due to some problems with wildfly we gotta check this separately
 String contentType = response.getContentType();
 assertThat(contentType, is(either(CoreMatchers.<Object>equalTo(ContentType.TEXT.toString() + "; charset=UTF-8")).or(CoreMatchers.<Object>equalTo(ContentType.TEXT.toString() + ";charset=UTF-8"))));
 verify(historicDetailQueryMock, never()).disableBinaryFetching();
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testGetBinaryDataForFileVariable() {
 String filename = "test.txt";
 byte[] byteContent = "test".getBytes();
 String encoding = "UTF-8";
 FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(ContentType.TEXT.toString()).encoding(encoding).create();
 MockVariableInstanceBuilder builder = MockProvider.mockVariableInstance();
 VariableInstance variableInstanceMock =
   builder
    .typedValue(variableValue)
    .build();
 when(variableInstanceQueryMock.variableId(variableInstanceMock.getId())).thenReturn(variableInstanceQueryMock);
 when(variableInstanceQueryMock.disableBinaryFetching()).thenReturn(variableInstanceQueryMock);
 when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock);
 when(variableInstanceQueryMock.singleResult()).thenReturn(variableInstanceMock);
 Response response = given().pathParam("id", MockProvider.EXAMPLE_VARIABLE_INSTANCE_ID)
 .then().expect().statusCode(Status.OK.getStatusCode())
 .and()
  .header("Content-Disposition", "attachment; filename="+filename)
 .and()
  .body(is(equalTo(new String(byteContent))))
 .when().get(VARIABLE_INSTANCE_BINARY_DATA_URL);
 //due to some problems with wildfly we gotta check this separately
 String contentType = response.getContentType();
 assertThat(contentType, is(either(CoreMatchers.<Object>equalTo(ContentType.TEXT.toString() + "; charset=UTF-8")).or(CoreMatchers.<Object>equalTo(ContentType.TEXT.toString() + ";charset=UTF-8"))));
}

代码示例来源:origin: lv.ctco.cukes/cukes-http

@Override
protected boolean matchesSafely(Integer statusCode, Description description) {
  description.appendText(format("was \"%d\"", statusCode));
  if (appendBody) {
    final String body = response.body().asString();
    final int size = body.length();
    if (response.getContentType().equals("application/octet-stream")) {
      description.appendText(" with body <binary>");
    } else if (maxSize != null && size > maxSize) {
      description.appendText(" with body <exceeding max size to show>");
    } else {
      description.appendText(format(" with body:\n\"\"\"\n%s\n\"\"\"", body));
    }
  }
  return expectedStatusCode.equals(statusCode);
}

代码示例来源:origin: ctco/cukes

@Override
protected boolean matchesSafely(Integer statusCode, Description description) {
  description.appendText(format("was \"%d\"", statusCode));
  if (appendBody) {
    final String body = response.body().asString();
    final int size = body.length();
    if (response.getContentType().equals("application/octet-stream")) {
      description.appendText(" with body <binary>");
    } else if (maxSize != null && size > maxSize) {
      description.appendText(" with body <exceeding max size to show>");
    } else {
      description.appendText(format(" with body:\n\"\"\"\n%s\n\"\"\"", body));
    }
  }
  return expectedStatusCode.equals(statusCode);
}

相关文章