RestAssured Post call with nested object throws an error “java.lang.AssertionError: 1 expectation failed. Expected status code <200> but was <500>.”

隐身守侯 提交于 2019-12-25 00:57:07

问题


@Test
public void testPost() throws URISyntaxException {
    DbConnectionProperties sourceDB = new DbConnectionProperties("SourceDBName", "SourceDBDriver", "SourceDBUrl", "SourceDBUserName", "SourceDBPassword");
    DbConnectionProperties destinationDB = new DbConnectionProperties("DestinationDBName", "DestinationDBDriver", "DestinationDBUrl", "DestinationDBUserName", "DestinationDBPassword");
    Streams streamsAvailablity = new Streams(1, 1, 1, 1);

    AgencyRequest agencyRequest = new AgencyRequest();
    agencyRequest.setConnectorId(1);
    agencyRequest.setJobConfig("/usr/local/workspace/test.config.xml");
    agencyRequest.setConnectorName("/usr/local/workspace/test.kjb");
    agencyRequest.setRequestId(1);
    agencyRequest.setTenantId(1);
    agencyRequest.setTenantName("Test Tenant");
    agencyRequest.setTimeZone("UTC");
    agencyRequest.setSourceDB(sourceDB);
    agencyRequest.setDestinationDB(destinationDB);
    agencyRequest.setIntervalBatchUnit("d");
    agencyRequest.setIntervalBatch(0);
    agencyRequest.setIntervalReloadUnit("d");
    agencyRequest.setIntervalReload(0);
    agencyRequest.setMustUseBatch(1);
    agencyRequest.setStreamsAvailablity(streamsAvailablity);

    String json = new Gson().toJson(agencyRequest);
    System.out.println(json);
    System.out.println(uri + "/" + ResourceConstants.JOB_CONFIG);
    given().
    accept(ContentType.JSON).
    contentType(ContentType.JSON).
    body(json).
    post(new URI(uri + "/" + ResourceConstants.JOB_CONFIG)).
    then().
    assertThat().
    statusCode(HttpStatus.OK_200);
}

When i pass the json body with nested objects, it throws me an internal error "Status code 500" It succeed if I pass a json string without a nested object

来源:https://stackoverflow.com/questions/48388415/restassured-post-call-with-nested-object-throws-an-error-java-lang-assertionerr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!