-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(specification-storage): implement endpoints to manage field defi…
…nitions Closes: MRSPECS-6
- Loading branch information
Showing
5 changed files
with
109 additions
and
65 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
60 changes: 0 additions & 60 deletions
60
...s-server/src/main/java/org/folio/rspec/exception/IllegalSpecificationChangeException.java
This file was deleted.
Oops, something went wrong.
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
97 changes: 97 additions & 0 deletions
97
...rd-specifications-server/src/test/java/org/folio/api/SpecificationStorageFieldsApiIT.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,97 @@ | ||
package org.folio.api; | ||
|
||
import static org.folio.support.ApiEndpoints.fieldPath; | ||
import static org.folio.support.ApiEndpoints.specificationFieldsPath; | ||
import static org.folio.support.TestConstants.BIBLIOGRAPHIC_SPECIFICATION_ID; | ||
import static org.hamcrest.Matchers.hasEntry; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import com.jayway.jsonpath.JsonPath; | ||
import java.io.UnsupportedEncodingException; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import org.folio.rspec.domain.dto.SpecificationFieldChangeDto; | ||
import org.folio.rspec.exception.ResourceNotFoundException; | ||
import org.folio.spring.testing.type.IntegrationTest; | ||
import org.folio.support.IntegrationTestBase; | ||
import org.folio.support.TestConstants; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@IntegrationTest | ||
class SpecificationStorageFieldsApiIT extends IntegrationTestBase { | ||
|
||
@BeforeAll | ||
static void beforeAll() { | ||
setUpTenant(); | ||
} | ||
|
||
@Test | ||
void deleteField_shouldReturn204AndDeleteLocalField() throws Exception { | ||
var createdFieldId = createLocalField(getLocalFieldDto()); | ||
|
||
doDelete(fieldPath(createdFieldId)); | ||
|
||
doGet(specificationFieldsPath(BIBLIOGRAPHIC_SPECIFICATION_ID)) | ||
.andExpect(jsonPath("$.fields.[*].id", not(hasItem(createdFieldId)))); | ||
} | ||
|
||
@Test | ||
void deleteField_shouldReturn404WhenFieldNotExist() throws Exception { | ||
var notExistId = UUID.randomUUID(); | ||
tryDelete(fieldPath(notExistId)) | ||
.andExpect(status().isNotFound()) | ||
.andExpect(exceptionMatch(ResourceNotFoundException.class)) | ||
.andExpect(errorMessageMatch(is("field definition with ID [%s] was not found".formatted(notExistId)))); | ||
} | ||
|
||
@Test | ||
void updateField_shouldReturn201AndUpdateLocalField() throws Exception { | ||
var localTestField = getLocalFieldDto(); | ||
var createdFieldId = createLocalField(localTestField); | ||
|
||
localTestField.setDeprecated(true); | ||
localTestField.setUrl("http://www.viverra.com"); | ||
|
||
doPut(fieldPath(createdFieldId), localTestField); | ||
|
||
doGet(specificationFieldsPath(BIBLIOGRAPHIC_SPECIFICATION_ID)) | ||
.andExpect(jsonPath("$.fields.[*]", hasItem(Matchers.<Map<String, Object>>allOf( | ||
hasEntry("id", createdFieldId), | ||
hasEntry("deprecated", true), | ||
hasEntry("url", "http://www.viverra.com") | ||
)))); | ||
} | ||
|
||
@Test | ||
void updateField_shouldReturn404WhenFieldNotExist() throws Exception { | ||
var notExistId = UUID.randomUUID(); | ||
tryPut(fieldPath(notExistId), getLocalFieldDto()) | ||
.andExpect(status().isNotFound()) | ||
.andExpect(exceptionMatch(ResourceNotFoundException.class)) | ||
.andExpect(errorMessageMatch(is("field definition with ID [%s] was not found".formatted(notExistId)))); | ||
} | ||
|
||
private SpecificationFieldChangeDto getLocalFieldDto() { | ||
return new SpecificationFieldChangeDto() | ||
.tag("998") | ||
.required(true) | ||
.deprecated(false) | ||
.required(false) | ||
.label("Local Test Field"); | ||
} | ||
|
||
private String createLocalField(SpecificationFieldChangeDto localTestField) throws UnsupportedEncodingException { | ||
return JsonPath.read( | ||
doPost(specificationFieldsPath(TestConstants.BIBLIOGRAPHIC_SPECIFICATION_ID), localTestField) | ||
.andReturn() | ||
.getResponse().getContentAsString(), | ||
"$.id").toString(); | ||
} | ||
|
||
} |
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