Search in sources :

Example 1 with KbCredentialsPostRequest

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

the class EholdingsKbCredentialsImplTest method shouldReturn422OnPostWhenCredentialsAreInvalid.

@Test
public void shouldReturn422OnPostWhenCredentialsAreInvalid() {
    KbCredentialsPostRequest kbCredentialsPostRequest = new KbCredentialsPostRequest().withData(stubbedCredentials());
    String postBody = Json.encode(kbCredentialsPostRequest);
    mockVerifyFailedCredentialsRequest();
    JsonapiError error = postWithStatus(KB_CREDENTIALS_ENDPOINT, postBody, SC_UNPROCESSABLE_ENTITY, STUB_TOKEN_HEADER).as(JsonapiError.class);
    assertErrorContainsTitle(error, "KB API Credentials are invalid");
}
Also used : JsonapiError(org.folio.rest.jaxrs.model.JsonapiError) Matchers.containsString(org.hamcrest.Matchers.containsString) KbCredentialsPostRequest(org.folio.rest.jaxrs.model.KbCredentialsPostRequest) Test(org.junit.Test)

Example 2 with KbCredentialsPostRequest

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

the class EholdingsKbCredentialsImplTest method shouldReturn422OnPostWhenCredentialsNameIsLongerThen255.

@Test
public void shouldReturn422OnPostWhenCredentialsNameIsLongerThen255() {
    KbCredentials creds = stubbedCredentials();
    creds.getAttributes().setName(Strings.repeat('*', 256));
    KbCredentialsPostRequest kbCredentialsPostRequest = new KbCredentialsPostRequest().withData(creds);
    String postBody = Json.encode(kbCredentialsPostRequest);
    JsonapiError error = postWithStatus(KB_CREDENTIALS_ENDPOINT, postBody, 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) KbCredentialsPostRequest(org.folio.rest.jaxrs.model.KbCredentialsPostRequest) Test(org.junit.Test)

Example 3 with KbCredentialsPostRequest

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

the class EholdingsKbCredentialsImplTest method shouldReturn201OnPostIfCredentialsAreValid.

@Test
public void shouldReturn201OnPostIfCredentialsAreValid() {
    KbCredentialsPostRequest kbCredentialsPostRequest = new KbCredentialsPostRequest().withData(stubbedCredentials());
    String postBody = Json.encode(kbCredentialsPostRequest);
    mockVerifyValidCredentialsRequest();
    KbCredentials actual = postWithStatus(KB_CREDENTIALS_ENDPOINT, postBody, SC_CREATED, STUB_TOKEN_HEADER).as(KbCredentials.class);
    assertNotNull(actual);
    assertNotNull(actual.getId());
    assertNotNull(actual.getType());
    assertEquals(getWiremockUrl(), actual.getAttributes().getUrl());
    assertEquals(STUB_CREDENTIALS_NAME, actual.getAttributes().getName());
    assertEquals(STUB_CUSTOMER_ID, actual.getAttributes().getCustomerId());
    assertEquals(STUB_USERNAME, actual.getMeta().getCreatedByUsername());
    assertEquals(STUB_USER_ID, actual.getMeta().getCreatedByUserId());
    assertNotNull(actual.getMeta().getCreatedDate());
}
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) KbCredentialsPostRequest(org.folio.rest.jaxrs.model.KbCredentialsPostRequest) Test(org.junit.Test)

Example 4 with KbCredentialsPostRequest

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

the class EholdingsKbCredentialsImplTest method shouldReturnStatusNotStartedOnKbCredentialsCreation.

@Test
public void shouldReturnStatusNotStartedOnKbCredentialsCreation() {
    KbCredentialsPostRequest kbCredentialsPostRequest = new KbCredentialsPostRequest().withData(stubbedCredentials());
    String postBody = Json.encode(kbCredentialsPostRequest);
    mockVerifyValidCredentialsRequest();
    KbCredentials actual = postWithStatus(KB_CREDENTIALS_ENDPOINT, postBody, SC_CREATED, STUB_TOKEN_HEADER).as(KbCredentials.class);
    final HoldingsLoadingStatus status = getStatus(actual.getId(), vertx);
    assertEquals(LoadStatusNameEnum.NOT_STARTED, status.getData().getAttributes().getStatus().getName());
    final RetryStatus retryStatus = getRetryStatus(actual.getId(), vertx);
    assertThat(retryStatus, notNullValue());
}
Also used : KbCredentialsTestUtil.saveKbCredentials(org.folio.util.KbCredentialsTestUtil.saveKbCredentials) KbCredentialsTestUtil.getKbCredentials(org.folio.util.KbCredentialsTestUtil.getKbCredentials) KbCredentials(org.folio.rest.jaxrs.model.KbCredentials) HoldingsLoadingStatus(org.folio.rest.jaxrs.model.HoldingsLoadingStatus) Matchers.containsString(org.hamcrest.Matchers.containsString) RetryStatus(org.folio.repository.holdings.status.retry.RetryStatus) HoldingsRetryStatusTestUtil.getRetryStatus(org.folio.util.HoldingsRetryStatusTestUtil.getRetryStatus) KbCredentialsPostRequest(org.folio.rest.jaxrs.model.KbCredentialsPostRequest) Test(org.junit.Test)

Example 5 with KbCredentialsPostRequest

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

the class EholdingsKbCredentialsImplTest method shouldReturn422OnPostWhenCredentialsNameIsEmpty.

@Test
public void shouldReturn422OnPostWhenCredentialsNameIsEmpty() {
    KbCredentials creds = stubbedCredentials();
    creds.getAttributes().setName("");
    KbCredentialsPostRequest kbCredentialsPostRequest = new KbCredentialsPostRequest().withData(creds);
    String postBody = Json.encode(kbCredentialsPostRequest);
    JsonapiError error = postWithStatus(KB_CREDENTIALS_ENDPOINT, postBody, 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) KbCredentialsPostRequest(org.folio.rest.jaxrs.model.KbCredentialsPostRequest) Test(org.junit.Test)

Aggregations

KbCredentialsPostRequest (org.folio.rest.jaxrs.model.KbCredentialsPostRequest)8 Matchers.containsString (org.hamcrest.Matchers.containsString)7 Test (org.junit.Test)7 KbCredentials (org.folio.rest.jaxrs.model.KbCredentials)6 JsonapiError (org.folio.rest.jaxrs.model.JsonapiError)5 KbCredentialsTestUtil.getKbCredentials (org.folio.util.KbCredentialsTestUtil.getKbCredentials)5 KbCredentialsTestUtil.saveKbCredentials (org.folio.util.KbCredentialsTestUtil.saveKbCredentials)5 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