Search in sources :

Example 6 with Title

use of org.folio.rest.acq.model.Title in project mod-orders by folio-org.

the class TitlesApiTest method testPostTitle.

@Test
void testPostTitle() {
    logger.info("=== Test POST Title (Create Title) ===");
    String poLineId = UUID.randomUUID().toString();
    CompositePoLine poLine = getMinimalContentCompositePoLine().withId(poLineId);
    addMockEntry(PO_LINES_STORAGE, JsonObject.mapFrom(poLine));
    Title postTitleRq = titleJsonReqData.mapTo(Title.class).withPoLineId(poLineId);
    // Positive cases
    // Title id is null initially
    assertThat(postTitleRq.getId(), nullValue());
    Title postTitleRs = verifyPostResponse(TITLES_ENDPOINT, JsonObject.mapFrom(postTitleRq).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID), APPLICATION_JSON, HttpStatus.HTTP_CREATED.toInt()).as(Title.class);
    // Title id not null
    assertThat(postTitleRs.getId(), Matchers.notNullValue());
    // Negative cases
    // Unable to create title test
    int status400 = HttpStatus.HTTP_BAD_REQUEST.toInt();
    verifyPostResponse(TITLES_ENDPOINT, JsonObject.mapFrom(postTitleRq).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID, new Header(X_ECHO_STATUS, String.valueOf(status400))), APPLICATION_JSON, status400);
    // Internal error on mod-orders-storage test
    int status500 = HttpStatus.HTTP_INTERNAL_SERVER_ERROR.toInt();
    verifyPostResponse(TITLES_ENDPOINT, JsonObject.mapFrom(postTitleRq).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID, new Header(X_ECHO_STATUS, String.valueOf(status500))), APPLICATION_JSON, status500);
    addMockEntry(TITLES, JsonObject.mapFrom(postTitleRs));
    Errors errors = verifyPostResponse(TITLES_ENDPOINT, JsonObject.mapFrom(postTitleRq).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID), APPLICATION_JSON, HttpStatus.HTTP_UNPROCESSABLE_ENTITY.toInt()).as(Errors.class);
    assertEquals("titleExist", errors.getErrors().get(0).getCode());
}
Also used : Errors(org.folio.rest.jaxrs.model.Errors) Header(io.restassured.http.Header) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) Title(org.folio.rest.acq.model.Title) Test(org.junit.jupiter.api.Test)

Example 7 with Title

use of org.folio.rest.acq.model.Title in project mod-orders by folio-org.

the class PurchaseOrderLinesApiTest method testGetOrderLineByIdWithTitleNoInstanceId.

@Test
void testGetOrderLineByIdWithTitleNoInstanceId() {
    logger.info("=== Test Get Orderline By Id with title but without instanceId ===");
    addMockEntry(TITLES, new Title().withId(UUID.randomUUID().toString()).withPoLineId(ANOTHER_PO_LINE_ID_FOR_SUCCESS_CASE).withTitle("Title"));
    final CompositePoLine resp = verifySuccessGet(String.format(LINE_BY_ID_PATH, ANOTHER_PO_LINE_ID_FOR_SUCCESS_CASE), CompositePoLine.class);
    logger.info(JsonObject.mapFrom(resp).encodePrettily());
    assertEquals(ANOTHER_PO_LINE_ID_FOR_SUCCESS_CASE, resp.getId());
    assertThat(getPoLineSearches(), hasSize(1));
    assertThat(getTitlesSearches(), hasSize(1));
}
Also used : Title(org.folio.rest.acq.model.Title) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 8 with Title

use of org.folio.rest.acq.model.Title in project mod-orders by folio-org.

the class TitlesApiTest method titleShouldBePopulatedFromPackagePoLine.

@Test
void titleShouldBePopulatedFromPackagePoLine() {
    String packagePoLineId = UUID.randomUUID().toString();
    String packageTitleName = "test title name";
    String packageTestNumber = "test number";
    Date packageExpectedDate = new Date();
    String packageNote = "test note";
    CompositePoLine packagePoLine = getMinimalContentCompositePoLine().withId(packagePoLineId).withTitleOrPackage(packageTitleName).withPoLineNumber(packageTestNumber).withPhysical(new Physical().withExpectedReceiptDate(packageExpectedDate)).withDetails(new Details().withReceivingNote(packageNote)).withIsPackage(true);
    Title titleWithPackagePoLineRQ = titleJsonReqData.mapTo(Title.class).withPoLineId(packagePoLineId);
    addMockEntry(PO_LINES_STORAGE, JsonObject.mapFrom(packagePoLine));
    Title titleWithPackagePoLineRS = verifyPostResponse(TITLES_ENDPOINT, JsonObject.mapFrom(titleWithPackagePoLineRQ).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID), APPLICATION_JSON, HttpStatus.HTTP_CREATED.toInt()).as(Title.class);
    assertEquals(titleWithPackagePoLineRS.getPackageName(), packageTitleName);
    assertEquals(titleWithPackagePoLineRS.getExpectedReceiptDate(), packageExpectedDate);
    assertEquals(titleWithPackagePoLineRS.getPoLineNumber(), packageTestNumber);
    assertEquals(titleWithPackagePoLineRS.getReceivingNote(), packageNote);
}
Also used : Physical(org.folio.rest.jaxrs.model.Physical) Details(org.folio.rest.jaxrs.model.Details) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) Title(org.folio.rest.acq.model.Title) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 9 with Title

use of org.folio.rest.acq.model.Title in project mod-orders by folio-org.

the class MockServer method getTitlesByPoLineIds.

private JsonObject getTitlesByPoLineIds(List<String> poLineIds) {
    Supplier<List<Title>> getFromFile = () -> {
        try {
            return new JsonObject(getMockData(TITLES_PATH)).mapTo(TitleCollection.class).getTitles();
        } catch (IOException e) {
            return Collections.emptyList();
        }
    };
    List<Title> titles = getMockEntries(TITLES, Title.class).orElseGet(getFromFile);
    if (!poLineIds.isEmpty()) {
        titles.removeIf(item -> !poLineIds.contains(item.getPoLineId()));
    }
    Object record = new TitleCollection().withTitles(titles).withTotalRecords(titles.size());
    return JsonObject.mapFrom(record);
}
Also used : JsonObject(io.vertx.core.json.JsonObject) Title(org.folio.rest.acq.model.Title) TestUtils.getTitle(org.folio.TestUtils.getTitle) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) JsonObject(io.vertx.core.json.JsonObject) IOException(java.io.IOException) TitleCollection(org.folio.rest.acq.model.TitleCollection)

Example 10 with Title

use of org.folio.rest.acq.model.Title in project mod-orders by folio-org.

the class MockServer method handlePostPOLine.

private void handlePostPOLine(RoutingContext ctx) {
    logger.info("got poLine: " + ctx.getBodyAsString());
    JsonObject body = ctx.getBodyAsJson();
    org.folio.rest.acq.model.PoLine pol = body.mapTo(org.folio.rest.acq.model.PoLine.class);
    if (pol.getId() == null) {
        pol.setId(UUID.randomUUID().toString());
    }
    if (ID_FOR_INTERNAL_SERVER_ERROR.equals(pol.getPurchaseOrderId())) {
        ctx.response().setStatusCode(500).putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON).end();
    } else {
        if (!pol.getIsPackage() && getMockEntries(TITLES, Title.class).orElseGet(Collections::emptyList).isEmpty()) {
            addMockEntry(TITLES, new Title().withId(UUID.randomUUID().toString()).withPoLineId(pol.getId()).withTitle(pol.getTitleOrPackage()));
        }
        ctx.response().setStatusCode(201).putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON).end(JsonObject.mapFrom(pol).encodePrettily());
    }
    addServerRqRsData(HttpMethod.POST, PO_LINES_STORAGE, body);
    addServerRqRsData(HttpMethod.SEARCH, PO_LINES_STORAGE, body);
}
Also used : JsonObject(io.vertx.core.json.JsonObject) Title(org.folio.rest.acq.model.Title) TestUtils.getTitle(org.folio.TestUtils.getTitle) org.folio.rest.jaxrs.model(org.folio.rest.jaxrs.model) Collections(java.util.Collections)

Aggregations

Title (org.folio.rest.acq.model.Title)15 Test (org.junit.jupiter.api.Test)11 TestUtils.getMinimalContentCompositePoLine (org.folio.TestUtils.getMinimalContentCompositePoLine)9 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 JsonObject (io.vertx.core.json.JsonObject)4 TestUtils.getTitle (org.folio.TestUtils.getTitle)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Transaction (org.folio.rest.acq.model.finance.Transaction)3 Header (io.restassured.http.Header)2 Collections (java.util.Collections)2 Date (java.util.Date)2 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)2 HashBasedTable (com.google.common.collect.HashBasedTable)1 Lists (com.google.common.collect.Lists)1 Table (com.google.common.collect.Table)1 Vertx (io.vertx.core.Vertx)1