Skip to content

Commit

Permalink
MODINV-1024 422 Unprocessable Content Error while updating Instances …
Browse files Browse the repository at this point in the history
…and Items with electronic access without URI field populated. (#720)

* MODINV-1024 422 Unprocessable Content Error while updating  Instances and Items with electronic access without URI field populated.

* fix test

* fix test

* remove unused import

(cherry picked from commit 9af7ad0)
  • Loading branch information
JavokhirAbdullayev authored and KaterynaSenchenko committed May 9, 2024
1 parent bafc0d9 commit c10914e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
3 changes: 0 additions & 3 deletions src/main/java/org/folio/inventory/support/JsonHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import liquibase.util.StringUtil;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -87,8 +86,6 @@ private static JsonObject handleNullNestedFields(JsonObject itemObject) {
var value = itemObject.getValue(key);
if (value == null) {
keysToRemove.add(key);
} else if (value instanceof String str && StringUtil.isEmpty(str)) {
keysToRemove.add(key);
} else if (value instanceof JsonObject object) {
handleNullNestedFields(object);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void jsonContainsVersion() {
}

@Test
public void jsonWithoutNullOrEmptyValues() {
public void jsonWithoutNullValuesOnly() {
var testValue = "https://test.com";
var electronicAccessKey = "electronicAccess";
var item = new Item(UUID.randomUUID().toString(), null, null,
Expand All @@ -46,7 +46,7 @@ public void jsonWithoutNullOrEmptyValues() {
var emptyElectronicAccessObject = nullElectronicAccessJson.getJsonArray(electronicAccessKey);

assertThat(electronicAccessObject.size(), is(1));
assertThat(electronicAccessObject.getJsonObject(0).fieldNames().size(), is(1));
assertThat(electronicAccessObject.getJsonObject(0).fieldNames().size(), is(2));
assertThat(electronicAccessObject.getJsonObject(0).getValue("uri"), is(testValue));
assertThat(emptyElectronicAccessObject, is(new JsonArray()));
}
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/org/folio/inventory/support/JsonHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public void shouldNotIncludeIfValueIsNull() {
}

@Test
public void shouldNotIncludeNullOeEmptyValues() {
var nutNullString = "notNull";
public void shouldNotIncludeOnlyNullValues() {
var notNullString = "notNull";
var key = "key";
var rootKey = "root";
var arrayKey = "array";
Expand All @@ -64,7 +64,7 @@ public void shouldNotIncludeNullOeEmptyValues() {
var arrayList = new ArrayList<JsonArray>();
var jsonArray = new JsonArray();

nestedValue.put(nutNullString, nutNullString);
nestedValue.put(notNullString, notNullString);
nestedValue.put("null", null);
nestedValue.put("empty", "");
value.put(key, nestedValue);
Expand All @@ -81,12 +81,12 @@ public void shouldNotIncludeNullOeEmptyValues() {
var listResult = representation.getJsonArray(arrayKey);
var arrayListResult = representation.getJsonArray(arrayListKey).getJsonArray(0).getJsonObject(0);
var jsonArrayResult = representation.getJsonArray(jsonArrayKey).getJsonObject(0);
assertThat(objResult.size(), is(1));
assertThat(objResult.getValue(nutNullString), is(nutNullString));
assertThat(arrayListResult.size(), is(1));
assertThat(arrayListResult.getValue(nutNullString), is(nutNullString));
assertThat(jsonArrayResult.size(), is(1));
assertThat(jsonArrayResult.getValue(nutNullString), is(nutNullString));
assertThat(listResult.size(), is(1));
assertThat(objResult.size(), is(2));
assertThat(objResult.getValue(notNullString), is(notNullString));
assertThat(arrayListResult.size(), is(2));
assertThat(arrayListResult.getValue(notNullString), is(notNullString));
assertThat(jsonArrayResult.size(), is(2));
assertThat(jsonArrayResult.getValue(notNullString), is(notNullString));
assertThat(listResult.getList().size(), is(1));
}
}

0 comments on commit c10914e

Please sign in to comment.