Search in sources :

Example 1 with JsonErrorResponse

use of org.folio.rest.support.JsonErrorResponse in project mod-inventory-storage by folio-org.

the class ItemStorageTest method cannotProvideAdditionalPropertiesInItem.

@Test
public void cannotProvideAdditionalPropertiesInItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID holdingsRecordId = createInstanceAndHolding(mainLibraryLocationId);
    JsonObject requestWithAdditionalProperty = nod(UUID.randomUUID(), holdingsRecordId);
    requestWithAdditionalProperty.put("somethingAdditional", "foo");
    CompletableFuture<JsonErrorResponse> createCompleted = new CompletableFuture<>();
    client.post(itemsStorageUrl(""), requestWithAdditionalProperty, StorageTestSuite.TENANT_ID, ResponseHandler.jsonErrors(createCompleted));
    JsonErrorResponse response = createCompleted.get(5, TimeUnit.SECONDS);
    assertThat(response.getStatusCode(), is(AdditionalHttpStatusCodes.UNPROCESSABLE_ENTITY));
    assertThat(response.getErrors(), hasSoleMessageContaining("Unrecognized field"));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with JsonErrorResponse

use of org.folio.rest.support.JsonErrorResponse in project mod-inventory-storage by folio-org.

the class ItemStorageTest method cannotRemoveItemStatus.

@Test
public void cannotRemoveItemStatus() throws Exception {
    UUID holdingsRecordId = createInstanceAndHolding(mainLibraryLocationId);
    UUID id = UUID.randomUUID();
    JsonObject itemToCreate = smallAngryPlanet(id, holdingsRecordId).put("status", new JsonObject().put("name", "Available"));
    createItem(itemToCreate);
    JsonObject createdItem = getById(id).getJson();
    assertThat(createdItem.getJsonObject("status").getString("name"), is("Available"));
    JsonObject replacement = itemToCreate.copy();
    replacement.remove("status");
    CompletableFuture<JsonErrorResponse> updateCompleted = new CompletableFuture<>();
    client.put(itemsStorageUrl("/" + id), replacement, TENANT_ID, ResponseHandler.jsonErrors(updateCompleted));
    JsonErrorResponse updateResponse = updateCompleted.get(5, TimeUnit.SECONDS);
    assertThat(updateResponse.getStatusCode(), is(422));
    assertThat(updateResponse.getErrors().size(), is(1));
    JsonObject error = updateResponse.getErrors().get(0);
    assertThat(error.getString("message"), anyOf(is("may not be null"), is("must not be null")));
    assertThat(error.getJsonArray("parameters").getJsonObject(0).getString("key"), is("status"));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with JsonErrorResponse

use of org.folio.rest.support.JsonErrorResponse in project mod-inventory-storage by folio-org.

the class ItemStorageTest method cannotProvideAdditionalPropertiesInItemStatus.

@Test
public void cannotProvideAdditionalPropertiesInItemStatus() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID holdingsRecordId = createInstanceAndHolding(mainLibraryLocationId);
    JsonObject requestWithAdditionalProperty = nod(UUID.randomUUID(), holdingsRecordId);
    requestWithAdditionalProperty.put("status", new JsonObject().put("somethingAdditional", "foo"));
    CompletableFuture<JsonErrorResponse> createCompleted = new CompletableFuture<>();
    client.post(itemsStorageUrl(""), requestWithAdditionalProperty, StorageTestSuite.TENANT_ID, ResponseHandler.jsonErrors(createCompleted));
    JsonErrorResponse response = createCompleted.get(5, TimeUnit.SECONDS);
    assertThat(response.getStatusCode(), is(AdditionalHttpStatusCodes.UNPROCESSABLE_ENTITY));
    assertThat(response.getErrors(), hasSoleMessageContaining("Unrecognized field"));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with JsonErrorResponse

use of org.folio.rest.support.JsonErrorResponse in project mod-inventory-storage by folio-org.

the class ItemStorageTest method cannotProvideAdditionalPropertiesInItemLocation.

@Test
public void cannotProvideAdditionalPropertiesInItemLocation() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID holdingsRecordId = createInstanceAndHolding(mainLibraryLocationId);
    JsonObject requestWithAdditionalProperty = nod(UUID.randomUUID(), holdingsRecordId);
    requestWithAdditionalProperty.put("location", new JsonObject().put("somethingAdditional", "foo"));
    CompletableFuture<JsonErrorResponse> createCompleted = new CompletableFuture<>();
    client.post(itemsStorageUrl(""), requestWithAdditionalProperty, StorageTestSuite.TENANT_ID, ResponseHandler.jsonErrors(createCompleted));
    JsonErrorResponse response = createCompleted.get(5, TimeUnit.SECONDS);
    assertThat(response.getStatusCode(), is(AdditionalHttpStatusCodes.UNPROCESSABLE_ENTITY));
    assertThat(response.getErrors(), hasSoleMessageContaining("Unrecognized field"));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with JsonErrorResponse

use of org.folio.rest.support.JsonErrorResponse in project mod-inventory-storage by folio-org.

the class ItemStorageTest method cannotRemoveItemStatusName.

@Test
public void cannotRemoveItemStatusName() throws Exception {
    UUID holdingsRecordId = createInstanceAndHolding(mainLibraryLocationId);
    UUID id = UUID.randomUUID();
    JsonObject itemToCreate = smallAngryPlanet(id, holdingsRecordId).put("status", new JsonObject().put("name", "Available"));
    createItem(itemToCreate);
    JsonObject createdItem = getById(id).getJson();
    assertThat(createdItem.getJsonObject("status").getString("name"), is("Available"));
    JsonObject replacement = itemToCreate.copy();
    replacement.getJsonObject("status").remove("name");
    CompletableFuture<JsonErrorResponse> updateCompleted = new CompletableFuture<>();
    client.put(itemsStorageUrl("/" + id), replacement, TENANT_ID, ResponseHandler.jsonErrors(updateCompleted));
    JsonErrorResponse updateResponse = updateCompleted.get(5, TimeUnit.SECONDS);
    assertThat(updateResponse.getStatusCode(), is(422));
    assertThat(updateResponse.getErrors().size(), is(1));
    JsonObject error = updateResponse.getErrors().get(0);
    assertThat(error.getString("message"), anyOf(is("may not be null"), is("must not be null")));
    assertThat(error.getJsonArray("parameters").getJsonObject(0).getString("key"), is("status.name"));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 JsonErrorResponse (org.folio.rest.support.JsonErrorResponse)7 Test (org.junit.Test)7 UUID (java.util.UUID)5