use of kong.unirest.RequestBodyEntity in project dependency-track-maven-plugin by pmckeown.
the class BomClient method uploadBom.
/**
* Upload a BOM to the Dependency-Track server. The BOM is processed asynchronously after the upload is completed
* and the response returned. The response contains a token that can be used later to query if the bom that the
* token relates to has been completely processed.
*
* @param bom the request object containing the project details and the Base64 encoded bom.xml
* @return a response containing a token to later determine if processing the supplied BOM is completed
*/
Response<UploadBomResponse> uploadBom(UploadBomRequest bom) {
RequestBodyEntity requestBodyEntity = Unirest.put(commonConfig.getDependencyTrackBaseUrl() + V1_BOM).header(CONTENT_TYPE, "application/json").header("X-Api-Key", commonConfig.getApiKey()).body(bom);
HttpResponse<UploadBomResponse> httpResponse = requestBodyEntity.asObject(new GenericType<UploadBomResponse>() {
});
Optional<UploadBomResponse> body;
if (httpResponse.isSuccess()) {
body = Optional.of(httpResponse.getBody());
} else {
body = Optional.empty();
}
return new Response<>(httpResponse.getStatus(), httpResponse.getStatusText(), httpResponse.isSuccess(), body);
}
use of kong.unirest.RequestBodyEntity in project jbang-catalog by quintesse.
the class Util method apiPost.
HttpResponse<JsonNode> apiPost(String api, Object body) {
String url = getApiUrl(api);
logApiRequest("POST", api, body);
RequestBodyEntity req = Unirest.post(url).body(body);
if (activeServer.user != null && activeServer.password != null) {
req.basicAuth(activeServer.user, activeServer.password);
}
HttpResponse<JsonNode> res = req.asJson();
logApiResult(res);
return res;
}
use of kong.unirest.RequestBodyEntity in project seleniumRobot by bhecquet.
the class ConnectorsTest method preparePostRequest.
private HttpRequest preparePostRequest(String serverUrl, String responseType, HttpRequestWithBody postRequest, HttpResponse<String> response, HttpResponse<JsonNode> jsonResponse) {
RequestBodyEntity requestBodyEntity = mock(RequestBodyEntity.class);
MultipartBody requestMultipartBody = mock(MultipartBody.class);
when(postRequest.socketTimeout(anyInt())).thenReturn(postRequest);
when(postRequest.field(anyString(), anyString())).thenReturn(requestMultipartBody);
when(postRequest.field(anyString(), anyInt())).thenReturn(requestMultipartBody);
when(postRequest.field(anyString(), anyLong())).thenReturn(requestMultipartBody);
when(postRequest.field(anyString(), anyDouble())).thenReturn(requestMultipartBody);
when(postRequest.field(anyString(), any(File.class))).thenReturn(requestMultipartBody);
when(postRequest.basicAuth(anyString(), anyString())).thenReturn(postRequest);
when(postRequest.headerReplace(anyString(), anyString())).thenReturn(postRequest);
when(postRequest.queryString(anyString(), anyString())).thenReturn(postRequest);
when(postRequest.queryString(anyString(), anyInt())).thenReturn(postRequest);
when(postRequest.queryString(anyString(), anyBoolean())).thenReturn(postRequest);
when(postRequest.queryString(anyString(), any(SessionId.class))).thenReturn(postRequest);
when(postRequest.header(anyString(), anyString())).thenReturn(postRequest);
when(requestMultipartBody.field(anyString(), anyString())).thenReturn(requestMultipartBody);
when(requestMultipartBody.field(anyString(), any(File.class))).thenReturn(requestMultipartBody);
when(requestMultipartBody.asString()).thenReturn(response);
doReturn(response).when(postRequest).asString();
when(postRequest.getUrl()).thenReturn(serverUrl);
when(postRequest.body(any(JSONObject.class))).thenReturn(requestBodyEntity);
when(postRequest.body(any(byte[].class))).thenReturn(requestBodyEntity);
when(postRequest.asJson()).thenReturn(jsonResponse);
when(requestBodyEntity.asJson()).thenReturn(jsonResponse);
when(requestBodyEntity.asString()).thenReturn(response);
when(requestMultipartBody.getUrl()).thenReturn(serverUrl);
when(requestMultipartBody.asJson()).thenReturn(jsonResponse);
if ("request".equals(responseType)) {
return postRequest;
} else if ("body".equals(responseType)) {
return requestMultipartBody;
} else if ("requestBodyEntity".equals(responseType)) {
return requestBodyEntity;
} else {
return null;
}
}
use of kong.unirest.RequestBodyEntity in project seleniumRobot by bhecquet.
the class TestCampaign method testCreateCampaignWithError.
@Test(groups = { "ut" }, expectedExceptions = ScenarioException.class)
public void testCreateCampaignWithError() {
RequestBodyEntity postRequest = (RequestBodyEntity) createServerMock("POST", "/campaigns", 200, "{}", "requestBodyEntity");
when(postRequest.asJson()).thenThrow(UnirestException.class);
CampaignFolder campaignFolder = new CampaignFolder("http://localhost:8080/api/rest/latest/campaign-folders/7", 7, "folder", project, null);
Campaign.create(project, "myCampaign", campaignFolder);
}
use of kong.unirest.RequestBodyEntity in project seleniumRobot by bhecquet.
the class TestIteration method testCreateIterationWithError.
@Test(groups = { "ut" }, expectedExceptions = ScenarioException.class)
public void testCreateIterationWithError() {
RequestBodyEntity postRequest = (RequestBodyEntity) createServerMock("POST", "/campaigns/2/iterations", 200, "{}", "requestBodyEntity");
when(postRequest.asJson()).thenThrow(UnirestException.class);
Campaign campaign = new Campaign("http://localhost:8080/api/rest/latest/campaigns/2", 2, "campaign");
Iteration.create(campaign, "new iteration");
}
Aggregations