Search in sources :

Example 1 with KbCredentialsPutRequest

use of org.folio.rest.jaxrs.model.KbCredentialsPutRequest in project mod-kb-ebsco-java by folio-org.

the class EholdingsKbCredentialsImplTest method shouldReturn422OnPutWhenCredentialsNameIsEmpty.

@Test
public void shouldReturn422OnPutWhenCredentialsNameIsEmpty() {
    KbCredentials creds = stubbedCredentials();
    creds.getAttributes().setName("");
    KbCredentialsPutRequest kbCredentialsPutRequest = new KbCredentialsPutRequest().withData(creds);
    String putBody = Json.encode(kbCredentialsPutRequest);
    String resourcePath = KB_CREDENTIALS_ENDPOINT + "/11111111-1111-1111-a111-111111111111";
    JsonapiError error = putWithStatus(resourcePath, putBody, SC_UNPROCESSABLE_ENTITY, STUB_TOKEN_HEADER).as(JsonapiError.class);
    assertErrorContainsTitle(error, "Invalid name");
    assertErrorContainsDetail(error, "name must not be empty");
}
Also used : KbCredentialsTestUtil.saveKbCredentials(org.folio.util.KbCredentialsTestUtil.saveKbCredentials) KbCredentialsTestUtil.getKbCredentials(org.folio.util.KbCredentialsTestUtil.getKbCredentials) KbCredentials(org.folio.rest.jaxrs.model.KbCredentials) JsonapiError(org.folio.rest.jaxrs.model.JsonapiError) Matchers.containsString(org.hamcrest.Matchers.containsString) KbCredentialsPutRequest(org.folio.rest.jaxrs.model.KbCredentialsPutRequest) Test(org.junit.Test)

Example 2 with KbCredentialsPutRequest

use of org.folio.rest.jaxrs.model.KbCredentialsPutRequest in project mod-kb-ebsco-java by folio-org.

the class EholdingsKbCredentialsImplTest method shouldReturn400OnPutWhenIdIsInvalid.

@Test
public void shouldReturn400OnPutWhenIdIsInvalid() {
    KbCredentials creds = stubbedCredentials();
    creds.setId(UUID.randomUUID().toString());
    KbCredentialsPutRequest kbCredentialsPutRequest = new KbCredentialsPutRequest().withData(creds);
    String putBody = Json.encode(kbCredentialsPutRequest);
    String resourcePath = KB_CREDENTIALS_ENDPOINT + "/invalid-id";
    JsonapiError error = putWithStatus(resourcePath, putBody, SC_BAD_REQUEST).as(JsonapiError.class);
    assertErrorContainsTitle(error, "'id' parameter is incorrect.");
}
Also used : KbCredentialsTestUtil.saveKbCredentials(org.folio.util.KbCredentialsTestUtil.saveKbCredentials) KbCredentialsTestUtil.getKbCredentials(org.folio.util.KbCredentialsTestUtil.getKbCredentials) KbCredentials(org.folio.rest.jaxrs.model.KbCredentials) JsonapiError(org.folio.rest.jaxrs.model.JsonapiError) Matchers.containsString(org.hamcrest.Matchers.containsString) KbCredentialsPutRequest(org.folio.rest.jaxrs.model.KbCredentialsPutRequest) Test(org.junit.Test)

Example 3 with KbCredentialsPutRequest

use of org.folio.rest.jaxrs.model.KbCredentialsPutRequest in project mod-kb-ebsco-java by folio-org.

the class EholdingsKbCredentialsImplTest method shouldReturn204OnPutIfCredentialsAreValid.

@Test
public void shouldReturn204OnPutIfCredentialsAreValid() {
    String credentialsId = saveKbCredentials(STUB_API_URL, STUB_CREDENTIALS_NAME, STUB_API_KEY, STUB_CUSTOMER_ID, vertx);
    KbCredentials creds = stubbedCredentials();
    creds.getAttributes().withName(STUB_CREDENTIALS_NAME + "updated").withCustomerId(STUB_CUSTOMER_ID + "updated");
    KbCredentialsPutRequest kbCredentialsPutRequest = new KbCredentialsPutRequest().withData(creds);
    String putBody = Json.encode(kbCredentialsPutRequest);
    mockVerifyValidCredentialsRequest();
    String resourcePath = KB_CREDENTIALS_ENDPOINT + "/" + credentialsId;
    putWithNoContent(resourcePath, putBody, STUB_TOKEN_HEADER);
    KbCredentials actual = getKbCredentials(vertx).get(0);
    assertNotNull(actual);
    assertNotNull(actual.getId());
    assertNotNull(actual.getType());
    assertEquals(getWiremockUrl(), actual.getAttributes().getUrl());
    assertEquals(STUB_CREDENTIALS_NAME + "updated", actual.getAttributes().getName());
    assertEquals(STUB_CUSTOMER_ID + "updated", actual.getAttributes().getCustomerId());
    assertEquals(STUB_USERNAME, actual.getMeta().getCreatedByUsername());
    assertEquals(STUB_USER_ID, actual.getMeta().getCreatedByUserId());
    assertNotNull(actual.getMeta().getCreatedDate());
    assertEquals(STUB_USERNAME, actual.getMeta().getUpdatedByUsername());
    assertEquals(STUB_USER_ID, actual.getMeta().getUpdatedByUserId());
    assertNotNull(actual.getMeta().getUpdatedDate());
}
Also used : KbCredentialsTestUtil.saveKbCredentials(org.folio.util.KbCredentialsTestUtil.saveKbCredentials) KbCredentialsTestUtil.getKbCredentials(org.folio.util.KbCredentialsTestUtil.getKbCredentials) KbCredentials(org.folio.rest.jaxrs.model.KbCredentials) Matchers.containsString(org.hamcrest.Matchers.containsString) KbCredentialsPutRequest(org.folio.rest.jaxrs.model.KbCredentialsPutRequest) Test(org.junit.Test)

Example 4 with KbCredentialsPutRequest

use of org.folio.rest.jaxrs.model.KbCredentialsPutRequest in project mod-kb-ebsco-java by folio-org.

the class EholdingsKbCredentialsImplTest method shouldReturn422OnPutWhenCredentialsWithProvidedCustIdAndUrlAlreadyExist.

@Test
public void shouldReturn422OnPutWhenCredentialsWithProvidedCustIdAndUrlAlreadyExist() {
    saveKbCredentials(getWiremockUrl(), STUB_CREDENTIALS_NAME, STUB_API_KEY, STUB_CUSTOMER_ID, vertx);
    String credentialsId = saveKbCredentials(getWiremockUrl(), STUB_CREDENTIALS_NAME + "2", STUB_API_KEY, OTHER_CUST_ID, vertx);
    KbCredentials creds = stubbedCredentials();
    creds.getAttributes().setName(STUB_CREDENTIALS_NAME + "2");
    KbCredentialsPutRequest kbCredentialsPutRequest = new KbCredentialsPutRequest().withData(creds);
    String putBody = Json.encode(kbCredentialsPutRequest);
    mockVerifyValidCredentialsRequest();
    String resourcePath = KB_CREDENTIALS_ENDPOINT + "/" + credentialsId;
    JsonapiError error = putWithStatus(resourcePath, putBody, SC_UNPROCESSABLE_ENTITY, STUB_TOKEN_HEADER).as(JsonapiError.class);
    assertErrorContainsTitle(error, "Duplicate credentials");
    assertErrorContainsDetail(error, String.format("Credentials with customer id '%s' and url '%s' already exist", STUB_CUSTOMER_ID, getWiremockUrl()));
}
Also used : KbCredentialsTestUtil.saveKbCredentials(org.folio.util.KbCredentialsTestUtil.saveKbCredentials) KbCredentialsTestUtil.getKbCredentials(org.folio.util.KbCredentialsTestUtil.getKbCredentials) KbCredentials(org.folio.rest.jaxrs.model.KbCredentials) JsonapiError(org.folio.rest.jaxrs.model.JsonapiError) Matchers.containsString(org.hamcrest.Matchers.containsString) KbCredentialsPutRequest(org.folio.rest.jaxrs.model.KbCredentialsPutRequest) Test(org.junit.Test)

Example 5 with KbCredentialsPutRequest

use of org.folio.rest.jaxrs.model.KbCredentialsPutRequest in project mod-kb-ebsco-java by folio-org.

the class EholdingsKbCredentialsImplTest method shouldReturn422OnPutWhenCredentialsNameIsLongerThen255.

@Test
public void shouldReturn422OnPutWhenCredentialsNameIsLongerThen255() {
    KbCredentials creds = stubbedCredentials();
    creds.getAttributes().setName(Strings.repeat('*', 256));
    KbCredentialsPutRequest kbCredentialsPutRequest = new KbCredentialsPutRequest().withData(creds);
    String putBody = Json.encode(kbCredentialsPutRequest);
    String resourcePath = KB_CREDENTIALS_ENDPOINT + "/11111111-1111-1111-a111-111111111111";
    JsonapiError error = putWithStatus(resourcePath, putBody, SC_UNPROCESSABLE_ENTITY, STUB_TOKEN_HEADER).as(JsonapiError.class);
    assertErrorContainsTitle(error, "Invalid name");
    assertErrorContainsDetail(error, "name is too long (maximum is 255 characters)");
}
Also used : KbCredentialsTestUtil.saveKbCredentials(org.folio.util.KbCredentialsTestUtil.saveKbCredentials) KbCredentialsTestUtil.getKbCredentials(org.folio.util.KbCredentialsTestUtil.getKbCredentials) KbCredentials(org.folio.rest.jaxrs.model.KbCredentials) JsonapiError(org.folio.rest.jaxrs.model.JsonapiError) Matchers.containsString(org.hamcrest.Matchers.containsString) KbCredentialsPutRequest(org.folio.rest.jaxrs.model.KbCredentialsPutRequest) Test(org.junit.Test)

Aggregations

KbCredentialsPutRequest (org.folio.rest.jaxrs.model.KbCredentialsPutRequest)9 Matchers.containsString (org.hamcrest.Matchers.containsString)8 Test (org.junit.Test)8 JsonapiError (org.folio.rest.jaxrs.model.JsonapiError)7 KbCredentials (org.folio.rest.jaxrs.model.KbCredentials)7 KbCredentialsTestUtil.getKbCredentials (org.folio.util.KbCredentialsTestUtil.getKbCredentials)6 KbCredentialsTestUtil.saveKbCredentials (org.folio.util.KbCredentialsTestUtil.saveKbCredentials)6 Context (io.vertx.core.Context)1 OffsetDateTime (java.time.OffsetDateTime)1 Collection (java.util.Collection)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 StringUtils.defaultIfBlank (org.apache.commons.lang3.StringUtils.defaultIfBlank)1 RowSetUtils.fromUUID (org.folio.db.RowSetUtils.fromUUID)1 RowSetUtils.toUUID (org.folio.db.RowSetUtils.toUUID)1