Skip to content

Commit

Permalink
[EDGEPATRON-133]-Added PUT endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
SinghAdes committed Jun 24, 2024
1 parent 2b947db commit 3cea6b9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
13 changes: 3 additions & 10 deletions src/main/java/org/folio/edge/patron/utils/PatronOkapiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,9 @@ public void put(String url, String tenant, String payload, MultiMap headers, Han
logger.info("PUT '{}' tenant: {} token: {}", () -> url, () -> tenant, () -> request.headers()
.get(X_OKAPI_TOKEN));
request.timeout(reqTimeout);
if (payload.isEmpty()) {
logger.info("put:: Payload is empty");
request.send()
.onSuccess(responseHandler)
.onFailure(exceptionHandler);
} else {
request.sendBuffer(Buffer.buffer(payload))
.onSuccess(responseHandler)
.onFailure(exceptionHandler);
}
request.sendBuffer(Buffer.buffer(payload))
.onSuccess(responseHandler)
.onFailure(exceptionHandler);
}
}

18 changes: 18 additions & 0 deletions src/test/java/org/folio/edge/patron/MainVerticleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,24 @@ public void testPutExternalLCPatron(TestContext context) throws Exception {
.response();
}

@Test
public void testPutExternalLCPatronWithEmptyBody(TestContext context) throws Exception {
logger.info("=== Test put external patron ===");

int expectedStatusCode = 500;
RestAssured
.with()
.body(new JsonObject())
.contentType(APPLICATION_JSON)
.put(
String.format("/patron/account/%s/by-email/%s?apikey=%s", UUID.randomUUID(), "TestMail", apiKey))
.then()
.statusCode(expectedStatusCode)
.header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON)
.extract()
.response();
}

@Test
public void testPlaceInstanceHoldInstanceNotFound(TestContext context) throws Exception {
logger.info("=== Test place instance hold w/ instance not found ===");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,17 @@ public void getExtPatronAccountHandler(RoutingContext ctx) {

public void putExtPatronAccountHandler(RoutingContext ctx) {
String token = ctx.request().getHeader(X_OKAPI_TOKEN);

String body = ctx.request().body().toString();
if (token == null || !token.equals(MOCK_TOKEN)) {
ctx.response()
.setStatusCode(403)
.putHeader(HttpHeaders.CONTENT_TYPE, TEXT_PLAIN)
.end("Access requires permission: patron.account.put");
} else {
} else if (body.isEmpty()) {
ctx.response()
.putHeader(HttpHeaders.CONTENT_TYPE, TEXT_PLAIN)
.end("No Body");
} else {
ctx.response()
.setStatusCode(204)
.putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON)
Expand Down

0 comments on commit 3cea6b9

Please sign in to comment.