-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7744cf3
commit 02870e1
Showing
8 changed files
with
168 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package api.settings; | ||
|
||
import static api.support.http.InterfaceUrls.circulationSettingsUrl; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import api.support.APITests; | ||
import api.support.builders.CirculationSettingBuilder; | ||
import api.support.http.CqlQuery; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class CirculationSettingsTests extends APITests { | ||
|
||
@Test | ||
void crudOperationsTest() { | ||
// Testing POST method | ||
final var setting = circulationSettingsClient.create(new CirculationSettingBuilder() | ||
.withName("initial-name") | ||
.withValue(new JsonObject().put("initial-key", "initial-value"))); | ||
final var settingId = setting.getId(); | ||
|
||
// Testing GET (individual setting) method | ||
final var settingById = circulationSettingsClient.get(settingId); | ||
assertThat(settingById.getJson().getString("name"), is("initial-name")); | ||
assertThat(settingById.getJson().getJsonObject("value").getString("initial-key"), | ||
is("initial-value")); | ||
|
||
// Testing GET (all) method | ||
final var anotherSetting = circulationSettingsClient.create(new CirculationSettingBuilder() | ||
.withName("another-name") | ||
.withValue(new JsonObject().put("another-key", "another-value"))); | ||
final var allSettings = circulationSettingsClient.getMany(CqlQuery.noQuery()); | ||
assertThat(allSettings.size(), is(2)); | ||
|
||
// Testing DELETE method | ||
circulationSettingsClient.delete(anotherSetting.getId()); | ||
final var allSettingsAfterDeletion = circulationSettingsClient.getMany(CqlQuery.noQuery()); | ||
assertThat(allSettingsAfterDeletion.size(), is(1)); | ||
assertThat(allSettingsAfterDeletion.getFirst().getString("name"), is("initial-name")); | ||
assertThat(allSettingsAfterDeletion.getFirst().getJsonObject("value").getString("initial-key"), | ||
is("initial-value")); | ||
|
||
// Testing PUT method | ||
circulationSettingsClient.replace(settingId, new CirculationSettingBuilder() | ||
.withId(settingId) | ||
.withName("new-name") | ||
.withValue(new JsonObject().put("new-key", "new-value"))); | ||
|
||
final var updatedSetting = circulationSettingsClient.get(settingId); | ||
|
||
assertThat(updatedSetting.getJson().getString("name"), is("new-name")); | ||
assertThat(updatedSetting.getJson().getJsonObject("value").getString("new-key"), | ||
is("new-value")); | ||
} | ||
|
||
@Test | ||
void invalidRequestsTest() { | ||
final var setting = circulationSettingsClient.create(new CirculationSettingBuilder() | ||
.withName("initial-name") | ||
.withValue(new JsonObject().put("initial-key", "initial-value"))); | ||
|
||
// Testing GET with invalid ID | ||
restAssuredClient.get(circulationSettingsUrl("/" + randomId()), 404, | ||
"get-circulation-setting"); | ||
|
||
// Testing DELETE with invalid ID | ||
restAssuredClient.delete(circulationSettingsUrl("/" + randomId()), 204, | ||
"delete-circulation-setting"); | ||
|
||
// Testing PUT with malformed JSON | ||
var putErrors = restAssuredClient.put("{\"invalid-field\": \"invalid-value\"}", | ||
circulationSettingsUrl("/" + randomId()), 422, "put-circulation-setting"); | ||
assertThat(putErrors.getJson().getJsonArray("errors").getJsonObject(0).getString("message"), | ||
is("Circulation setting JSON is malformed")); | ||
|
||
// Testing POST with malformed JSON | ||
var postErrors = restAssuredClient.post("{\"invalid-field\": \"invalid-value\"}", | ||
circulationSettingsUrl(""), 422, "put-circulation-setting"); | ||
assertThat(postErrors.getJson().getJsonArray("errors").getJsonObject(0).getString("message"), | ||
is("Circulation setting JSON is malformed")); | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
src/test/java/api/support/builders/CirculationSettingBuilder.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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package api.support.builders; | ||
|
||
import java.util.UUID; | ||
|
||
import io.vertx.core.json.JsonObject; | ||
import lombok.AllArgsConstructor; | ||
import lombok.NoArgsConstructor; | ||
import lombok.With; | ||
|
||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@With | ||
public class CirculationSettingBuilder extends JsonBuilder implements Builder { | ||
private UUID id = null; | ||
private String name = null; | ||
private JsonObject value = null; | ||
|
||
@Override | ||
public JsonObject create() { | ||
JsonObject circulationSetting = new JsonObject(); | ||
|
||
if (id != null) { | ||
put(circulationSetting, "id", id); | ||
} | ||
if (name != null) { | ||
put(circulationSetting, "name", name); | ||
} | ||
if (value != null) { | ||
put(circulationSetting, "value", value); | ||
} | ||
|
||
return circulationSetting; | ||
} | ||
} |
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