Search in sources :

Example 1 with KbCredentials

use of org.folio.rest.jaxrs.model.KbCredentials 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 KbCredentials

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

the class EholdingsKbCredentialsImplTest method shouldReturn200AndKbCredentialsOnGetByUserWhenSingleKbCredentialsPresent.

@Test
public void shouldReturn200AndKbCredentialsOnGetByUserWhenSingleKbCredentialsPresent() {
    saveKbCredentials(STUB_API_URL, STUB_CREDENTIALS_NAME, STUB_API_KEY, STUB_CUSTOMER_ID, vertx);
    KbCredentials actual = getWithStatus(USER_KB_CREDENTIAL_ENDPOINT, SC_OK, STUB_TOKEN_HEADER).as(KbCredentials.class);
    assertEquals(getKbCredentialsNonSecured(vertx).get(0), actual);
}
Also used : KbCredentialsTestUtil.saveKbCredentials(org.folio.util.KbCredentialsTestUtil.saveKbCredentials) KbCredentialsTestUtil.getKbCredentials(org.folio.util.KbCredentialsTestUtil.getKbCredentials) KbCredentials(org.folio.rest.jaxrs.model.KbCredentials) Test(org.junit.Test)

Example 3 with KbCredentials

use of org.folio.rest.jaxrs.model.KbCredentials 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 4 with KbCredentials

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

the class EholdingsKbCredentialsImplTest method shouldReturn204OnDeleteWhenCredentialsAreMissing.

@Test
public void shouldReturn204OnDeleteWhenCredentialsAreMissing() {
    String resourcePath = KB_CREDENTIALS_ENDPOINT + "/11111111-1111-1111-a111-111111111111";
    deleteWithNoContent(resourcePath);
    List<KbCredentials> kbCredentialsInDb = getKbCredentials(vertx);
    assertTrue(kbCredentialsInDb.isEmpty());
}
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) Test(org.junit.Test)

Example 5 with KbCredentials

use of org.folio.rest.jaxrs.model.KbCredentials 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)

Aggregations

KbCredentials (org.folio.rest.jaxrs.model.KbCredentials)26 Test (org.junit.Test)22 KbCredentialsTestUtil.getKbCredentials (org.folio.util.KbCredentialsTestUtil.getKbCredentials)18 KbCredentialsTestUtil.saveKbCredentials (org.folio.util.KbCredentialsTestUtil.saveKbCredentials)18 Matchers.containsString (org.hamcrest.Matchers.containsString)17 KbCredentialsPutRequest (org.folio.rest.jaxrs.model.KbCredentialsPutRequest)9 JsonapiError (org.folio.rest.jaxrs.model.JsonapiError)8 KbCredentialsPostRequest (org.folio.rest.jaxrs.model.KbCredentialsPostRequest)8 DbKbCredentials (org.folio.repository.kbcredentials.DbKbCredentials)7 KbCredentialsDataAttributes (org.folio.rest.jaxrs.model.KbCredentialsDataAttributes)4 KbCredentialsPatchRequest (org.folio.rest.jaxrs.model.KbCredentialsPatchRequest)4 Context (io.vertx.core.Context)3 OffsetDateTime (java.time.OffsetDateTime)3 Collection (java.util.Collection)3 Map (java.util.Map)3 Objects.requireNonNull (java.util.Objects.requireNonNull)3 Optional (java.util.Optional)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)3 BiFunction (java.util.function.BiFunction)3