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());
}
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));
}
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);
}
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);
}
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);
}
Aggregations