Search in sources :

Example 1 with Publication

use of org.folio.rest.jaxrs.model.Publication in project mod-inventory-storage by folio-org.

the class InstanceStorageTest method canUpdateInstanceWithPublicationPeriod.

@Test
public void canUpdateInstanceWithPublicationPeriod() throws Exception {
    var entity = smallAngryPlanet(UUID.randomUUID()).mapTo(Instance.class).withPublication(Collections.singletonList(new Publication().withDateOfPublication("1997")));
    IndividualResource instance = createInstance(JsonObject.mapFrom(entity));
    entity = instance.getJson().mapTo(Instance.class).withPublication(Collections.singletonList(new Publication().withDateOfPublication("2006")));
    final IndividualResource updateInstance = updateInstance(JsonObject.mapFrom(entity));
    assertEquals(Integer.valueOf(2006), updateInstance.getJson().mapTo(Instance.class).getPublicationPeriod().getStart());
}
Also used : DomainEventAssertions.assertRemoveAllEventForInstance(org.folio.rest.support.matchers.DomainEventAssertions.assertRemoveAllEventForInstance) DomainEventAssertions.assertRemoveEventForInstance(org.folio.rest.support.matchers.DomainEventAssertions.assertRemoveEventForInstance) DomainEventAssertions.assertCreateEventForInstance(org.folio.rest.support.matchers.DomainEventAssertions.assertCreateEventForInstance) Instance(org.folio.rest.jaxrs.model.Instance) DomainEventAssertions.assertUpdateEventForInstance(org.folio.rest.support.matchers.DomainEventAssertions.assertUpdateEventForInstance) Publication(org.folio.rest.jaxrs.model.Publication) IndividualResource(org.folio.rest.support.IndividualResource) Test(org.junit.Test)

Example 2 with Publication

use of org.folio.rest.jaxrs.model.Publication in project mod-inventory-storage by folio-org.

the class PublicationPeriodParserTest method shouldReturnNullPeriodForMultiplePublications.

@Test
@Parameters({ "[19uu], null", "hafniae MCMLXX, null", "null, null" })
public void shouldReturnNullPeriodForMultiplePublications(@Nullable String firstDate, @Nullable String lastDate) {
    var firstPublication = new Publication().withDateOfPublication(firstDate);
    var lastPublication = new Publication().withDateOfPublication(lastDate);
    var publicationPeriod = parsePublicationPeriod(List.of(firstPublication, lastPublication));
    assertThat(publicationPeriod, nullValue());
}
Also used : Publication(org.folio.rest.jaxrs.model.Publication) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 3 with Publication

use of org.folio.rest.jaxrs.model.Publication in project mod-inventory-storage by folio-org.

the class InstanceStorageTest method canCreateAnInstance.

@Test
public void canCreateAnInstance() throws InterruptedException, ExecutionException, TimeoutException {
    UUID id = UUID.randomUUID();
    NatureOfContentTerm journalContentType = createNatureOfContentTerm("journal_test");
    NatureOfContentTerm bookContentType = createNatureOfContentTerm("book_test");
    String[] natureOfContentIds = Stream.of(journalContentType, bookContentType).map(NatureOfContentTerm::getId).toArray(String[]::new);
    var publication = new Publication().withDateOfPublication("2000-2001");
    String adminNote = "Administrative note";
    JsonObject instanceToCreate = smallAngryPlanet(id);
    instanceToCreate.put("natureOfContentTermIds", Arrays.asList(natureOfContentIds));
    instanceToCreate.put("publication", new JsonArray().add(JsonObject.mapFrom(publication)));
    instanceToCreate.put("administrativeNotes", new JsonArray().add(adminNote));
    CompletableFuture<Response> createCompleted = new CompletableFuture<>();
    client.post(instancesStorageUrl(""), instanceToCreate, TENANT_ID, json(createCompleted));
    Response response = createCompleted.get(5, SECONDS);
    assertThat(response.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
    JsonObject instance = response.getJson();
    assertThat(instance.getString("id"), is(id.toString()));
    assertThat(instance.getString("title"), is("Long Way to a Small Angry Planet"));
    assertThat(instance.getBoolean("previouslyHeld"), is(false));
    assertThat(instance.getJsonArray("administrativeNotes").contains(adminNote), is(true));
    JsonArray identifiers = instance.getJsonArray("identifiers");
    assertThat(identifiers.size(), is(1));
    assertThat(identifiers, hasItem(identifierMatches(UUID_ISBN.toString(), "9781473619777")));
    assertThat(instance.getJsonArray("natureOfContentTermIds"), containsInAnyOrder(natureOfContentIds));
    assertThat(instance.getBoolean(DISCOVERY_SUPPRESS), is(false));
    Response getResponse = getById(id);
    assertThat(getResponse.getStatusCode(), is(HTTP_OK));
    JsonObject instanceFromGet = getResponse.getJson();
    assertThat(instanceFromGet.getString("title"), is("Long Way to a Small Angry Planet"));
    JsonArray identifiersFromGet = instanceFromGet.getJsonArray("identifiers");
    assertThat(identifiersFromGet.size(), is(1));
    assertThat(identifiersFromGet, hasItem(identifierMatches(UUID_ISBN.toString(), "9781473619777")));
    List<String> tags = instanceFromGet.getJsonObject("tags").getJsonArray("tagList").getList();
    assertThat(tags.size(), is(1));
    assertThat(tags, hasItem(TAG_VALUE));
    assertThat(instanceFromGet.getJsonArray("natureOfContentTermIds"), containsInAnyOrder(natureOfContentIds));
    assertThat(instanceFromGet.getString(STATUS_UPDATED_DATE_PROPERTY), hasIsoFormat());
    assertThat(instanceFromGet.getBoolean(DISCOVERY_SUPPRESS), is(false));
    assertCreateEventForInstance(instanceFromGet);
    var storedPublicationPeriod = instance.getJsonObject("publicationPeriod").mapTo(PublicationPeriod.class);
    assertThat(storedPublicationPeriod.getStart(), is(2000));
    assertThat(storedPublicationPeriod.getEnd(), is(2001));
}
Also used : NatureOfContentTerm(org.folio.rest.jaxrs.model.NatureOfContentTerm) JsonArray(io.vertx.core.json.JsonArray) JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) InstancesBatchResponse(org.folio.rest.jaxrs.model.InstancesBatchResponse) Response(org.folio.rest.support.Response) CompletableFuture(java.util.concurrent.CompletableFuture) Publication(org.folio.rest.jaxrs.model.Publication) JsonObject(io.vertx.core.json.JsonObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with Publication

use of org.folio.rest.jaxrs.model.Publication in project mod-inventory-storage by folio-org.

the class PublicationPeriodParserTest method shouldReturnNullPeriodForSinglePublication.

@Test
@Parameters({ "[19uu]", "hafniae MCMLXX", "null" })
public void shouldReturnNullPeriodForSinglePublication(@Nullable String dateOfPublication) {
    var publication = new Publication().withDateOfPublication(dateOfPublication);
    var publicationPeriod = parsePublicationPeriod(List.of(publication));
    assertThat(publicationPeriod, nullValue());
}
Also used : Publication(org.folio.rest.jaxrs.model.Publication) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 5 with Publication

use of org.folio.rest.jaxrs.model.Publication in project mod-inventory-storage by folio-org.

the class PublicationPeriodParserTest method shouldParseDateOfPublicationForSinglePublication.

@Test
@Parameters({ "1990, 1990, null", "[1990], 1990, null", "©1990, 1990, null", "[1999?], 1999, null", "Cop 1990, 1990, null", "[2003]\\\\, ©2001, 2003, null", "2001\\\\, 2003, 2001, 2003", "2001- 2003, 2001, 2003", "between 2001 and 2003, 2001, 2003" })
public void shouldParseDateOfPublicationForSinglePublication(@Nullable String dateOfPublication, @Nullable Integer start, @Nullable Integer end) {
    var publication = new Publication().withDateOfPublication(dateOfPublication);
    var publicationPeriod = parsePublicationPeriod(List.of(publication));
    assertThat(publicationPeriod.getStart(), is(start));
    assertThat(publicationPeriod.getEnd(), is(end));
}
Also used : Publication(org.folio.rest.jaxrs.model.Publication) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

Publication (org.folio.rest.jaxrs.model.Publication)6 Test (org.junit.Test)6 Parameters (junitparams.Parameters)4 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Instance (org.folio.rest.jaxrs.model.Instance)1 InstancesBatchResponse (org.folio.rest.jaxrs.model.InstancesBatchResponse)1 NatureOfContentTerm (org.folio.rest.jaxrs.model.NatureOfContentTerm)1 IndividualResource (org.folio.rest.support.IndividualResource)1 JsonErrorResponse (org.folio.rest.support.JsonErrorResponse)1 Response (org.folio.rest.support.Response)1 DomainEventAssertions.assertCreateEventForInstance (org.folio.rest.support.matchers.DomainEventAssertions.assertCreateEventForInstance)1 DomainEventAssertions.assertRemoveAllEventForInstance (org.folio.rest.support.matchers.DomainEventAssertions.assertRemoveAllEventForInstance)1 DomainEventAssertions.assertRemoveEventForInstance (org.folio.rest.support.matchers.DomainEventAssertions.assertRemoveEventForInstance)1 DomainEventAssertions.assertUpdateEventForInstance (org.folio.rest.support.matchers.DomainEventAssertions.assertUpdateEventForInstance)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1