Skip to content

Commit

Permalink
Merge pull request #18 from indexdata/PR-1709-dev
Browse files Browse the repository at this point in the history
PR-1786 Add integration test
  • Loading branch information
JanisSaldabols authored Jun 19, 2024
2 parents 96452f9 + ef72847 commit b60316d
Show file tree
Hide file tree
Showing 10 changed files with 520 additions and 250 deletions.
21 changes: 10 additions & 11 deletions src/main/java/org/folio/ncip/FolioRemoteServiceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,10 @@ public String callApiPost(String uriString, JsonObject body)

}

public String callApiPut(String uriString, JsonObject body) throws Exception{
public void callApiPut(String uriString, JsonObject body) throws Exception{
final String timeoutString = System.getProperty(Constants.SERVICE_MGR_TIMEOUT,Constants.DEFAULT_TIMEOUT);
int timeout = Integer.parseInt(timeoutString);
logger.info("Using timeout: " + timeout);
String stringBody = body.toString();
logger.info("With body: " + stringBody);
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(timeout)
.setSocketTimeout(timeout)
Expand All @@ -205,7 +203,7 @@ public String callApiPut(String uriString, JsonObject body) throws Exception{
HttpUriRequest request = RequestBuilder.put()
.setConfig(config)
.setUri(uriString)
.setEntity(new StringEntity(stringBody, ContentType.APPLICATION_JSON))
.setEntity(new StringEntity(body.toString(), ContentType.APPLICATION_JSON))
.setHeader(Constants.X_OKAPI_TENANT, okapiHeaders.get(Constants.X_OKAPI_TENANT))
.setHeader(Constants.ACCEPT_TEXT, Constants.CONTENT_JSON_AND_PLAIN).setVersion(HttpVersion.HTTP_1_1)
.setHeader(Constants.CONTENT_TYPE_TEXT, Constants.CONTENT_JSON)
Expand All @@ -215,12 +213,10 @@ public String callApiPut(String uriString, JsonObject body) throws Exception{

HttpResponse response;
HttpEntity entity;
String responseString;
int responseCode;
try {
response = client.execute(request);
entity = response.getEntity();
responseString = EntityUtils.toString(entity, "UTF-8");
responseCode = response.getStatusLine().getStatusCode();
}
catch(Exception e) {
Expand All @@ -238,13 +234,15 @@ public String callApiPut(String uriString, JsonObject body) throws Exception{
logger.info(body);
logger.info(uriString);
logger.info(responseCode);
logger.info(responseString);

if (responseCode > 399) {
String responseBody = processErrorResponse(responseString);
throw new Exception(responseBody);
if (entity != null) {
String responseBody = processErrorResponse(EntityUtils.toString(entity, "UTF-8"));
throw new Exception(responseBody);
} else {
throw new Exception("Failed to update record");
}
}
return responseString;
}

public HttpResponse callApiDelete(String uriString) throws Exception, IOException, InterruptedException {
Expand Down Expand Up @@ -960,8 +958,9 @@ public JsonObject cancelRequestItem(String requestId, UserId userId, String agen
requestResponse.put("cancellationReasonId", reasonId);
requestResponse.put("cancellationAdditionalInformation", Constants.REQUEST_CANCEL_ADDITIONAL_INFO);
requestResponse.put("cancelledDate", date);
callApiPut(url, requestResponse);

return new JsonObject(callApiPut(url, requestResponse));
return requestResponse;
}
catch(Exception e) {
logger.error("Exception occurred during cancel request item");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public CancelRequestItemResponseData performService(CancelRequestItemInitiationD
return addProblem(responseData, problem);
}

responseData.setRequestId(requestId);
responseData.setUserId(userId);
return responseData;
}

Expand Down
22 changes: 22 additions & 0 deletions src/test/java/org/folio/ncip/CancelRequestItemTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.folio.ncip;

import io.restassured.response.Response;
import org.junit.Test;

import java.net.MalformedURLException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class CancelRequestItemTest extends TestBase {

private static final String REQUEST_ID = "5fc504cb-9042-4bfe-a54f-287c56cd7a11";
@Test
public void callCancelRequestItem() throws MalformedURLException {
Response response = postData("src/test/resources/mockdata/ncip-cancelRequestItem.xml");
String body = response.getBody().prettyPrint();
System.out.println(body);
assertEquals(200, response.getStatusCode());
assertTrue(body.contains(REQUEST_ID));
}
}
Loading

0 comments on commit b60316d

Please sign in to comment.