forked from folio-org/mod-circulation-storage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into CIRCSTORE-520-vertx-4.5.9
- Loading branch information
Showing
5 changed files
with
169 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 99 additions & 47 deletions
146
src/test/java/org/folio/rest/api/CirculationSettingsAPITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,147 @@ | ||
package org.folio.rest.api; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.junit.MatcherAssert.assertThat; | ||
|
||
import java.net.MalformedURLException; | ||
import java.util.UUID; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
import io.vertx.core.json.JsonObject; | ||
import lombok.SneakyThrows; | ||
import org.folio.rest.support.ApiTests; | ||
import org.folio.rest.support.http.AssertingRecordClient; | ||
import org.folio.rest.support.http.InterfaceUrls; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import io.vertx.core.json.JsonObject; | ||
import java.util.UUID; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.junit.MatcherAssert.assertThat; | ||
|
||
public class CirculationSettingsAPITest extends ApiTests { | ||
private static final String ID_KEY = "id"; | ||
private static final String NAME_KEY = "name"; | ||
private static final String VALUE_KEY = "value"; | ||
private static final String SAMPLE_VALUE = "sample"; | ||
private static final String SAMPLE_KEY = "sample"; | ||
private static final String INITIAL_VALUE = "OK"; | ||
private static final String UPDATED_VALUE = "OK1"; | ||
private static final String TABLE_NAME = "circulation_settings"; | ||
private static final String CIRCULATION_SETTINGS_PROPERTY = "circulation-settings"; | ||
private static final int NOT_FOUND_STATUS = 404; | ||
private static final String REQUEST_PRINT_SETTING = "Enable Request Print"; | ||
|
||
private final AssertingRecordClient circulationSettingsClient = | ||
new AssertingRecordClient( | ||
client, StorageTestSuite.TENANT_ID, InterfaceUrls::circulationSettingsUrl, | ||
"circulation-settings"); | ||
client, StorageTestSuite.TENANT_ID, InterfaceUrls::circulationSettingsUrl, | ||
CIRCULATION_SETTINGS_PROPERTY); | ||
|
||
@Test | ||
public void canCreateAndRetrieveCirculationSettings() throws MalformedURLException, | ||
ExecutionException, InterruptedException, TimeoutException { | ||
@Before | ||
public void beforeEach() { | ||
StorageTestSuite.cleanUpTable(TABLE_NAME); | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
public void updateInsteadCreateWithTheSameName() { | ||
String id = UUID.randomUUID().toString(); | ||
JsonObject circulationSettingsJson = getCirculationSetting(id); | ||
JsonObject circulationSettingsResponse = | ||
circulationSettingsClient.create(circulationSettingsJson).getJson(); | ||
JsonObject circulationSettingsJsonUpdated = getUpdatedSettingsJson(); | ||
circulationSettingsClient.create(circulationSettingsJsonUpdated); | ||
JsonObject circulationSettingsById = circulationSettingsClient.getById(id).getJson(); | ||
|
||
assertThat(circulationSettingsResponse.getString("id"), is(id)); | ||
assertThat(circulationSettingsById.getString("id"), is(id)); | ||
assertThat(circulationSettingsById.getJsonObject("value"), is( | ||
circulationSettingsJson.getJsonObject("value"))); | ||
assertThatCorrectCreation(circulationSettingsResponse, circulationSettingsJson); | ||
assertThat(circulationSettingsClient.getAll().getTotalRecords(), is(1)); | ||
assertThat(getValue(circulationSettingsJsonUpdated), is(getValue(circulationSettingsById))); | ||
} | ||
|
||
@Test | ||
public void canUpdateCirculationSettings() throws MalformedURLException, | ||
ExecutionException, InterruptedException, TimeoutException { | ||
@SneakyThrows | ||
public void canCreateAndRetrieveCirculationSettings() { | ||
String id = UUID.randomUUID().toString(); | ||
JsonObject circulationSettingsJson = getCirculationSetting(id); | ||
JsonObject circulationSettingsResponse = | ||
circulationSettingsClient.create(circulationSettingsJson).getJson(); | ||
JsonObject circulationSettingsById = circulationSettingsClient.getById(id).getJson(); | ||
|
||
assertThat(circulationSettingsResponse.getString(ID_KEY), is(id)); | ||
assertThat(circulationSettingsById.getString(ID_KEY), is(id)); | ||
assertThat(circulationSettingsById.getJsonObject(VALUE_KEY), is( | ||
circulationSettingsJson.getJsonObject(VALUE_KEY))); | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
public void canUpdateCirculationSettings() { | ||
String id = UUID.randomUUID().toString(); | ||
JsonObject circulationSettingsJson = getCirculationSetting(id); | ||
circulationSettingsClient.create(circulationSettingsJson).getJson(); | ||
circulationSettingsClient.attemptPutById( | ||
circulationSettingsJson.put("value", new JsonObject().put("sample", "DONE"))); | ||
circulationSettingsJson.put(VALUE_KEY, new JsonObject().put(SAMPLE_KEY, "DONE"))); | ||
JsonObject updatedCirculationSettings = circulationSettingsClient.getById(id).getJson(); | ||
|
||
assertThat(updatedCirculationSettings.getString("id"), is(id)); | ||
assertThat(updatedCirculationSettings.getJsonObject("value"), is( | ||
circulationSettingsJson.getJsonObject("value"))); | ||
assertThat(updatedCirculationSettings.getString(ID_KEY), is(id)); | ||
assertThat(updatedCirculationSettings.getJsonObject(VALUE_KEY), is( | ||
circulationSettingsJson.getJsonObject(VALUE_KEY))); | ||
} | ||
|
||
@Test | ||
public void canDeleteCirculationSettings() throws MalformedURLException, | ||
ExecutionException, InterruptedException, TimeoutException { | ||
|
||
@SneakyThrows | ||
public void canDeleteCirculationSettings() { | ||
UUID id = UUID.randomUUID(); | ||
circulationSettingsClient.create(getCirculationSetting(id.toString())).getJson(); | ||
circulationSettingsClient.deleteById(id); | ||
var deletedCirculationSettings = circulationSettingsClient.attemptGetById(id); | ||
assertThat(deletedCirculationSettings.getStatusCode(), is(404)); | ||
} | ||
|
||
private JsonObject getCirculationSetting(String id) { | ||
return new JsonObject() | ||
.put("id", id) | ||
.put("name", "sample") | ||
.put("value", new JsonObject().put("sample", "OK")); | ||
assertThat(deletedCirculationSettings.getStatusCode(), is(NOT_FOUND_STATUS)); | ||
} | ||
|
||
@Test | ||
public void canCreateAndRetrieveEnableRequestPrintDetailsSetting() throws MalformedURLException, | ||
ExecutionException, InterruptedException, TimeoutException { | ||
@SneakyThrows | ||
public void canCreateAndRetrieveEnableRequestPrintDetailsSetting() { | ||
String id = UUID.randomUUID().toString(); | ||
JsonObject enableRequestPrintDetailsSettingJson = new JsonObject(); | ||
enableRequestPrintDetailsSettingJson.put("id", id); | ||
enableRequestPrintDetailsSettingJson.put("name", "Enable Request Print"); | ||
enableRequestPrintDetailsSettingJson.put("value", new JsonObject().put("Enable Request Print", true)); | ||
enableRequestPrintDetailsSettingJson.put(ID_KEY, id); | ||
enableRequestPrintDetailsSettingJson.put(NAME_KEY, REQUEST_PRINT_SETTING); | ||
JsonObject enablePrintSettingJson = new JsonObject().put(REQUEST_PRINT_SETTING, true); | ||
enableRequestPrintDetailsSettingJson.put(VALUE_KEY, enablePrintSettingJson); | ||
|
||
JsonObject circulationSettingsResponse = | ||
circulationSettingsClient.create(enableRequestPrintDetailsSettingJson).getJson(); | ||
JsonObject circulationSettingsById = circulationSettingsClient.getById(id).getJson(); | ||
|
||
assertThat(circulationSettingsResponse.getString("id"), is(id)); | ||
assertThat(circulationSettingsResponse.getString("name"), | ||
is(enableRequestPrintDetailsSettingJson.getString("name"))); | ||
assertThat(circulationSettingsById.getString("id"), is(id)); | ||
assertThat(circulationSettingsById.getJsonObject("value"), | ||
is(enableRequestPrintDetailsSettingJson.getJsonObject("value"))); | ||
assertThat(circulationSettingsResponse.getString(ID_KEY), is(id)); | ||
assertThat(circulationSettingsResponse.getString(NAME_KEY), | ||
is(enableRequestPrintDetailsSettingJson.getString(NAME_KEY))); | ||
assertThat(circulationSettingsById.getString(ID_KEY), is(id)); | ||
assertThat(circulationSettingsById.getJsonObject(VALUE_KEY), | ||
is(enableRequestPrintDetailsSettingJson.getJsonObject(VALUE_KEY))); | ||
} | ||
|
||
private static String getValue(JsonObject circulationSettingsById) { | ||
return circulationSettingsById.getJsonObject(VALUE_KEY).getString(SAMPLE_KEY); | ||
} | ||
|
||
private JsonObject getCirculationSetting(String id) { | ||
return new JsonObject() | ||
.put(ID_KEY, id) | ||
.put(NAME_KEY, SAMPLE_VALUE) | ||
.put(VALUE_KEY, new JsonObject().put(SAMPLE_KEY, INITIAL_VALUE)); | ||
} | ||
|
||
private static void assertThatCorrectCreation(JsonObject circulationSettingsResponse, | ||
JsonObject circulationSettingsJson) { | ||
|
||
String actualCreatedId = circulationSettingsResponse.getString(ID_KEY); | ||
String expectedCreatedId = circulationSettingsJson.getString(ID_KEY); | ||
String actualCreatedName = circulationSettingsResponse.getString(NAME_KEY); | ||
String expectedCreatedName = circulationSettingsJson.getString(NAME_KEY); | ||
|
||
assertThat(actualCreatedId, is(expectedCreatedId)); | ||
assertThat(actualCreatedName, is(expectedCreatedName)); | ||
} | ||
|
||
private JsonObject getUpdatedSettingsJson() { | ||
String updatedId = UUID.randomUUID().toString(); | ||
JsonObject circulationSettingsJsonUpdated = getCirculationSetting(updatedId); | ||
JsonObject updatedValue = new JsonObject().put(SAMPLE_KEY, UPDATED_VALUE); | ||
circulationSettingsJsonUpdated.put(VALUE_KEY, updatedValue); | ||
return circulationSettingsJsonUpdated; | ||
} | ||
} | ||
} |