Search in sources :

Example 16 with User

use of org.folio.rest.jaxrs.model.User in project raml-module-builder by folio-org.

the class PgUtilIT method responseValueWithExceptionInValueMethod.

@Test
public void responseValueWithExceptionInValueMethod(TestContext testContext) throws Exception {
    Method exceptionMethod = PgUtilIT.class.getMethod("exceptionMethod", Object.class);
    Method respond500 = ResponseImpl.class.getMethod("respond500WithTextPlain", Object.class);
    Future<Response> future = PgUtil.response(new User(), exceptionMethod, respond500);
    assertTrue(future.succeeded());
    Response response = future.result();
    assertThat(response.getStatus(), is(500));
    assertThat(response.getEntity(), is("some runtime exception"));
}
Also used : Response(javax.ws.rs.core.Response) PostUsersResponse(org.folio.rest.jaxrs.model.Users.PostUsersResponse) User(org.folio.rest.jaxrs.model.User) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 17 with User

use of org.folio.rest.jaxrs.model.User in project raml-module-builder by folio-org.

the class PgUtilIT method responseLocation4Nulls.

@Test
public void responseLocation4Nulls(TestContext testContext) {
    Future<Response> future = PgUtil.response(new User(), "localhost", null, null, null, null);
    assertTrue(future.failed());
    assertThat(future.cause(), is(instanceOf(NullPointerException.class)));
}
Also used : Response(javax.ws.rs.core.Response) PostUsersResponse(org.folio.rest.jaxrs.model.Users.PostUsersResponse) User(org.folio.rest.jaxrs.model.User) Test(org.junit.Test)

Example 18 with User

use of org.folio.rest.jaxrs.model.User in project raml-module-builder by folio-org.

the class PgUtilIT method postDuplicateId422.

@Test
public void postDuplicateId422(TestContext testContext) {
    String uuid = randomUuid();
    post(testContext, "Snow-White", uuid, 201);
    PgUtil.post("users", new User().withUsername("Rose-Red").withId(uuid), okapiHeaders, vertx.getOrCreateContext(), ResponseWith422.class, asyncAssertSuccess(testContext, 422, response -> {
        Errors errors = (Errors) response.result().getEntity();
        assertThat(errors.getErrors(), hasSize(1));
        Error error = errors.getErrors().get(0);
        assertThat(error.getMessage(), containsString("id value already exists in table users: " + uuid));
        assertThat(error.getParameters(), hasSize(1));
        assertThat(error.getParameters().get(0).getKey(), is("id"));
        assertThat(error.getParameters().get(0).getValue(), is(uuid));
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) CoreMatchers(org.hamcrest.CoreMatchers) Arrays(java.util.Arrays) XOkapiHeaders(org.folio.okapi.common.XOkapiHeaders) RoutingContext(io.vertx.ext.web.RoutingContext) VertxUtils(org.folio.rest.tools.utils.VertxUtils) Users(org.folio.rest.jaxrs.model.Users) User(org.folio.rest.jaxrs.model.User) Map(java.util.Map) UtilityClassTester(org.folio.okapi.testing.UtilityClassTester) JsonObject(io.vertx.core.json.JsonObject) Method(java.lang.reflect.Method) Errors(org.folio.rest.jaxrs.model.Errors) AfterClass(org.junit.AfterClass) UUID(java.util.UUID) Future(io.vertx.core.Future) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) List(java.util.List) Response(javax.ws.rs.core.Response) Buffer(io.vertx.core.buffer.Buffer) PostUsersResponse(org.folio.rest.jaxrs.model.Users.PostUsersResponse) Mockito.mock(org.mockito.Mockito.mock) PgException(io.vertx.pgclient.PgException) Strictness(org.mockito.quality.Strictness) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) RestVerticle(org.folio.rest.RestVerticle) BeforeClass(org.junit.BeforeClass) PostgresTesterContainer(org.folio.postgres.testing.PostgresTesterContainer) RunWith(org.junit.runner.RunWith) SchemaMaker(org.folio.rest.persist.ddlgen.SchemaMaker) Mockito.timeout(org.mockito.Mockito.timeout) Answer(org.mockito.stubbing.Answer) ResponseDelegate(org.folio.rest.jaxrs.resource.support.ResponseDelegate) Timeout(org.junit.rules.Timeout) Referencing(org.folio.rest.jaxrs.model.Referencing) MockitoJUnit(org.mockito.junit.MockitoJUnit) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AsyncResult(io.vertx.core.AsyncResult) Mockito.anyString(org.mockito.Mockito.anyString) ExpectedException(org.junit.rules.ExpectedException) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Vertx(io.vertx.core.Vertx) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AssertionFailedError(junit.framework.AssertionFailedError) Mockito.when(org.mockito.Mockito.when) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) UserdataCollection(org.folio.rest.jaxrs.model.UserdataCollection) Mockito.verify(org.mockito.Mockito.verify) Error(org.folio.rest.jaxrs.model.Error) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) TreeMap(java.util.TreeMap) MockitoRule(org.mockito.junit.MockitoRule) Handler(io.vertx.core.Handler) Collections(java.util.Collections) Errors(org.folio.rest.jaxrs.model.Errors) User(org.folio.rest.jaxrs.model.User) AssertionFailedError(junit.framework.AssertionFailedError) Error(org.folio.rest.jaxrs.model.Error) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 19 with User

use of org.folio.rest.jaxrs.model.User in project raml-module-builder by folio-org.

the class PgUtilIT method put.

@Test
public void put(TestContext testContext) {
    String uuid = randomUuid();
    post(testContext, "Pippilotta", uuid, 201);
    getUser(uuid).compose(user -> PgUtil.put("users", user.withUsername("Momo").withId(randomUuid()), uuid, okapiHeaders, vertx.getOrCreateContext(), Users.PutUsersByUserIdResponse.class)).onComplete(asyncAssertSuccess(testContext, 204, put -> assertGetById(testContext, uuid, "Momo")));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) CoreMatchers(org.hamcrest.CoreMatchers) Arrays(java.util.Arrays) XOkapiHeaders(org.folio.okapi.common.XOkapiHeaders) RoutingContext(io.vertx.ext.web.RoutingContext) VertxUtils(org.folio.rest.tools.utils.VertxUtils) Users(org.folio.rest.jaxrs.model.Users) User(org.folio.rest.jaxrs.model.User) Map(java.util.Map) UtilityClassTester(org.folio.okapi.testing.UtilityClassTester) JsonObject(io.vertx.core.json.JsonObject) Method(java.lang.reflect.Method) Errors(org.folio.rest.jaxrs.model.Errors) AfterClass(org.junit.AfterClass) UUID(java.util.UUID) Future(io.vertx.core.Future) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) List(java.util.List) Response(javax.ws.rs.core.Response) Buffer(io.vertx.core.buffer.Buffer) PostUsersResponse(org.folio.rest.jaxrs.model.Users.PostUsersResponse) Mockito.mock(org.mockito.Mockito.mock) PgException(io.vertx.pgclient.PgException) Strictness(org.mockito.quality.Strictness) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) RestVerticle(org.folio.rest.RestVerticle) BeforeClass(org.junit.BeforeClass) PostgresTesterContainer(org.folio.postgres.testing.PostgresTesterContainer) RunWith(org.junit.runner.RunWith) SchemaMaker(org.folio.rest.persist.ddlgen.SchemaMaker) Mockito.timeout(org.mockito.Mockito.timeout) Answer(org.mockito.stubbing.Answer) ResponseDelegate(org.folio.rest.jaxrs.resource.support.ResponseDelegate) Timeout(org.junit.rules.Timeout) Referencing(org.folio.rest.jaxrs.model.Referencing) MockitoJUnit(org.mockito.junit.MockitoJUnit) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AsyncResult(io.vertx.core.AsyncResult) Mockito.anyString(org.mockito.Mockito.anyString) ExpectedException(org.junit.rules.ExpectedException) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Vertx(io.vertx.core.Vertx) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AssertionFailedError(junit.framework.AssertionFailedError) Mockito.when(org.mockito.Mockito.when) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) UserdataCollection(org.folio.rest.jaxrs.model.UserdataCollection) Mockito.verify(org.mockito.Mockito.verify) Error(org.folio.rest.jaxrs.model.Error) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) TreeMap(java.util.TreeMap) MockitoRule(org.mockito.junit.MockitoRule) Handler(io.vertx.core.Handler) Collections(java.util.Collections) Mockito.anyString(org.mockito.Mockito.anyString) Users(org.folio.rest.jaxrs.model.Users) Test(org.junit.Test)

Example 20 with User

use of org.folio.rest.jaxrs.model.User in project raml-module-builder by folio-org.

the class PgUtilIT method putDuplicateUuid.

@Test
public void putDuplicateUuid(TestContext testContext) {
    String uuid = randomUuid();
    execute(testContext, "INSERT INTO " + schema + ".duplicateid VALUES " + "('" + uuid + "', '{}')," + "('" + uuid + "', '{}')");
    PgUtil.put("duplicateid", new User(), uuid, okapiHeaders, vertx.getOrCreateContext(), Users.PutUsersByUserIdResponse.class, asyncAssertSuccess(testContext, 500, "Updated 2 records in duplicateid for id: " + uuid));
}
Also used : User(org.folio.rest.jaxrs.model.User) Mockito.anyString(org.mockito.Mockito.anyString) Users(org.folio.rest.jaxrs.model.Users) Test(org.junit.Test)

Aggregations

User (org.folio.rest.jaxrs.model.User)20 Test (org.junit.Test)17 Response (javax.ws.rs.core.Response)13 PostUsersResponse (org.folio.rest.jaxrs.model.Users.PostUsersResponse)13 Method (java.lang.reflect.Method)11 Mockito.anyString (org.mockito.Mockito.anyString)11 JsonObject (io.vertx.core.json.JsonObject)8 Async (io.vertx.ext.unit.Async)8 UserdataCollection (org.folio.rest.jaxrs.model.UserdataCollection)8 Users (org.folio.rest.jaxrs.model.Users)8 AsyncResult (io.vertx.core.AsyncResult)7 Future (io.vertx.core.Future)7 Handler (io.vertx.core.Handler)7 Vertx (io.vertx.core.Vertx)7 Buffer (io.vertx.core.buffer.Buffer)7 Json (io.vertx.core.json.Json)7 TestContext (io.vertx.ext.unit.TestContext)7 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)7 RoutingContext (io.vertx.ext.web.RoutingContext)7 PgException (io.vertx.pgclient.PgException)7