Search in sources :

Example 21 with RequestPreference

use of org.folio.rest.jaxrs.model.RequestPreference in project mod-user-import by folio-org.

the class UserImportAPITest method testImportWithUserPreferenceDeliveryIsFalseAndAddressTypeSpecified.

@Test
public void testImportWithUserPreferenceDeliveryIsFalseAndAddressTypeSpecified() throws IOException {
    mock.setMockJsonContent("mock_user_creation_with_new_preference.json");
    List<User> users = new ArrayList<>();
    User user = generateUser("1234567", "Amy", "Cabble", null);
    user.setRequestPreference(new RequestPreference().withHoldShelf(RequestPreference.HoldShelf.TRUE).withDelivery(false).withDefaultServicePointId("59646a99-4074-4ee5-bfd4-86f3fc7717da").withDefaultDeliveryAddressTypeId("71628bf4-1962-4dff-a8f2-11108ab532cc"));
    users.add(user);
    UserdataimportCollection collection = new UserdataimportCollection().withUsers(users).withTotalRecords(1);
    given().header(TENANT_HEADER).header(TOKEN_HEADER).header(new Header(XOkapiHeaders.URL, getOkapiUrl())).header(JSON_CONTENT_TYPE_HEADER).body(collection).post(USER_IMPORT).then().body(MESSAGE, equalTo(UserImportAPIConstants.USERS_WERE_IMPORTED_SUCCESSFULLY)).body(TOTAL_RECORDS, equalTo(1)).body(CREATED_RECORDS, equalTo(0)).body(UPDATED_RECORDS, equalTo(0)).body(FAILED_RECORDS, equalTo(1)).body(FAILED_USERS + "[0]." + EXTERNAL_SYSTEM_ID, equalTo(users.get(0).getExternalSystemId())).body(FAILED_USERS + "[0]." + USERNAME, equalTo(users.get(0).getUsername())).body(FAILED_USERS + "[0]." + USER_ERROR_MESSAGE, containsString(UserImportAPIConstants.FAILED_USER_PREFERENCE_VALIDATION + "defaultDeliveryAddressTypeId must be not specified")).statusCode(200);
}
Also used : RequestPreference(org.folio.rest.jaxrs.model.RequestPreference) TestUtils.generateUser(org.folio.TestUtils.generateUser) User(org.folio.rest.jaxrs.model.User) Header(io.restassured.http.Header) ArrayList(java.util.ArrayList) UserdataimportCollection(org.folio.rest.jaxrs.model.UserdataimportCollection) Test(org.junit.Test)

Example 22 with RequestPreference

use of org.folio.rest.jaxrs.model.RequestPreference in project mod-user-import by folio-org.

the class UserImportAPITest method testImportWithUserPreferenceDeliveryIsTrueAndInvalidAddressType.

@Test
public void testImportWithUserPreferenceDeliveryIsTrueAndInvalidAddressType() throws IOException {
    mock.setMockJsonContent("mock_user_creation_with_new_preference.json");
    List<User> users = new ArrayList<>();
    User user = generateUser("1234567", "Amy", "Cabble", null);
    user.setRequestPreference(new RequestPreference().withHoldShelf(RequestPreference.HoldShelf.TRUE).withDelivery(true).withDefaultServicePointId("59646a99-4074-4ee5-bfd4-86f3fc7717z").withDefaultDeliveryAddressTypeId("Returns").withFulfillment(RequestPreference.Fulfillment.DELIVERY));
    users.add(user);
    UserdataimportCollection collection = new UserdataimportCollection().withUsers(users).withTotalRecords(1);
    given().header(TENANT_HEADER).header(TOKEN_HEADER).header(new Header(XOkapiHeaders.URL, getOkapiUrl())).header(JSON_CONTENT_TYPE_HEADER).body(collection).post(USER_IMPORT).then().body("errors.parameters", hasSize(1)).statusCode(422);
}
Also used : RequestPreference(org.folio.rest.jaxrs.model.RequestPreference) TestUtils.generateUser(org.folio.TestUtils.generateUser) User(org.folio.rest.jaxrs.model.User) Header(io.restassured.http.Header) ArrayList(java.util.ArrayList) UserdataimportCollection(org.folio.rest.jaxrs.model.UserdataimportCollection) Test(org.junit.Test)

Example 23 with RequestPreference

use of org.folio.rest.jaxrs.model.RequestPreference in project mod-user-import by folio-org.

the class UserImportAPITest method testImportWithUserUpdateAndWrongPreferenceAddressType.

@Test
public void testImportWithUserUpdateAndWrongPreferenceAddressType() throws IOException {
    mock.setMockJsonContent("mock_user_update_with_preference_update.json");
    List<User> users = new ArrayList<>();
    User user = generateUser("89101112", "User", "Update", "58512926-9a29-483b-b801-d36aced855d3");
    Address address = new Address().withAddressLine1("Test first line").withCity("Test city").withRegion("Test region").withPostalCode("12345").withAddressTypeId("Returns").withPrimaryAddress(Boolean.FALSE);
    List<Address> addresses = new ArrayList<>();
    addresses.add(address);
    user.getPersonal().setAddresses(addresses);
    user.setRequestPreference(new RequestPreference().withHoldShelf(RequestPreference.HoldShelf.TRUE).withDelivery(true).withDefaultServicePointId("59646a99-4074-4ee5-bfd4-86f3fc7717da").withDefaultDeliveryAddressTypeId("Claim").withFulfillment(RequestPreference.Fulfillment.DELIVERY));
    users.add(user);
    UserdataimportCollection collection = new UserdataimportCollection().withUsers(users).withTotalRecords(1);
    given().header(TENANT_HEADER).header(TOKEN_HEADER).header(new Header(XOkapiHeaders.URL, getOkapiUrl())).header(JSON_CONTENT_TYPE_HEADER).body(collection).post(USER_IMPORT).then().body(FAILED_USERS + "[0]." + EXTERNAL_SYSTEM_ID, equalTo(users.get(0).getExternalSystemId())).body(FAILED_USERS + "[0]." + USERNAME, equalTo(users.get(0).getUsername())).body(FAILED_USERS + "[0]." + USER_ERROR_MESSAGE, containsString(UserImportAPIConstants.FAILED_USER_PREFERENCE_VALIDATION + "Provided defaultDeliveryAddressTypeId value does not exist in user addresses collection")).statusCode(200);
}
Also used : RequestPreference(org.folio.rest.jaxrs.model.RequestPreference) TestUtils.generateUser(org.folio.TestUtils.generateUser) User(org.folio.rest.jaxrs.model.User) Address(org.folio.rest.jaxrs.model.Address) Header(io.restassured.http.Header) ArrayList(java.util.ArrayList) UserdataimportCollection(org.folio.rest.jaxrs.model.UserdataimportCollection) Test(org.junit.Test)

Example 24 with RequestPreference

use of org.folio.rest.jaxrs.model.RequestPreference in project mod-user-import by folio-org.

the class UserImportAPITest method testImportWithUserUpdateAndExistingPreferenceUpdate.

@Test
public void testImportWithUserUpdateAndExistingPreferenceUpdate() throws IOException {
    mock.setMockJsonContent("mock_user_update_with_preference_update.json");
    List<User> users = new ArrayList<>();
    User user = generateUser("89101112", "User", "Update", "58512926-9a29-483b-b801-d36aced855d3");
    Address address = new Address().withAddressLine1("Test first line").withCity("Test city").withRegion("Test region").withPostalCode("12345").withAddressTypeId("Returns").withPrimaryAddress(Boolean.FALSE);
    List<Address> addresses = new ArrayList<>();
    addresses.add(address);
    user.getPersonal().setAddresses(addresses);
    user.setRequestPreference(new RequestPreference().withHoldShelf(RequestPreference.HoldShelf.TRUE).withDelivery(true).withDefaultServicePointId("59646a99-4074-4ee5-bfd4-86f3fc7717da").withDefaultDeliveryAddressTypeId("Returns").withFulfillment(RequestPreference.Fulfillment.DELIVERY));
    users.add(user);
    UserdataimportCollection collection = new UserdataimportCollection().withUsers(users).withTotalRecords(1);
    given().header(TENANT_HEADER).header(TOKEN_HEADER).header(new Header(XOkapiHeaders.URL, getOkapiUrl())).header(JSON_CONTENT_TYPE_HEADER).body(collection).post(USER_IMPORT).then().body(MESSAGE, equalTo(UserImportAPIConstants.USERS_WERE_IMPORTED_SUCCESSFULLY)).body(TOTAL_RECORDS, equalTo(1)).body(CREATED_RECORDS, equalTo(0)).body(UPDATED_RECORDS, equalTo(1)).body(FAILED_RECORDS, equalTo(0)).body(FAILED_USERS, hasSize(0)).statusCode(200);
}
Also used : RequestPreference(org.folio.rest.jaxrs.model.RequestPreference) TestUtils.generateUser(org.folio.TestUtils.generateUser) User(org.folio.rest.jaxrs.model.User) Address(org.folio.rest.jaxrs.model.Address) Header(io.restassured.http.Header) ArrayList(java.util.ArrayList) UserdataimportCollection(org.folio.rest.jaxrs.model.UserdataimportCollection) Test(org.junit.Test)

Aggregations

RequestPreference (org.folio.rest.jaxrs.model.RequestPreference)24 Test (org.junit.Test)20 User (org.folio.rest.jaxrs.model.User)12 Header (io.restassured.http.Header)11 ArrayList (java.util.ArrayList)11 TestUtils.generateUser (org.folio.TestUtils.generateUser)11 UserdataimportCollection (org.folio.rest.jaxrs.model.UserdataimportCollection)11 JsonResponse (org.folio.rest.support.JsonResponse)9 Address (org.folio.rest.jaxrs.model.Address)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 RequestPreferences (org.folio.rest.jaxrs.model.RequestPreferences)2 JsonObject (io.vertx.core.json.JsonObject)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 List (java.util.List)1 UUID (java.util.UUID)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1