Search in sources :

Example 1 with Users

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

the class PgUtilIT method deleteByIdForeignKeyViolation400.

@Test
public void deleteByIdForeignKeyViolation400(TestContext testContext) {
    String userId = randomUuid();
    String refId = randomUuid();
    post(testContext, "Folio", userId, 201);
    insertReferencing(testContext, refId, userId);
    PgUtil.deleteById("users", userId, okapiHeaders, vertx.getOrCreateContext(), Users.DeleteUsersByUserIdResponse.class, asyncAssertSuccess(testContext, 400, "is still referenced from table referencing"));
}
Also used : Mockito.anyString(org.mockito.Mockito.anyString) Users(org.folio.rest.jaxrs.model.Users) Test(org.junit.Test)

Example 2 with Users

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

the class PgUtilIT method searchForDataUnoptimizedNoClass.

private UserdataCollection searchForDataUnoptimizedNoClass(String cql, int offset, int limit, TestContext testContext) {
    UserdataCollection userdataCollection = new UserdataCollection();
    Async async = testContext.async();
    PgUtil.get("users", User.class, Object.class, cql, offset, limit, okapiHeaders, vertx.getOrCreateContext(), ResponseImpl.class, testContext.asyncAssertSuccess(response -> {
        if (response.getStatus() != 500) {
            testContext.fail("Expected status 500, got " + response.getStatus() + " " + response.getStatusInfo().getReasonPhrase());
            async.complete();
            return;
        }
        UserdataCollection c = (UserdataCollection) response.getEntity();
        userdataCollection.setTotalRecords(c.getTotalRecords());
        userdataCollection.setUsers(c.getUsers());
        async.complete();
    }));
    async.awaitSuccess(10000);
    return userdataCollection;
}
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) UserdataCollection(org.folio.rest.jaxrs.model.UserdataCollection) Async(io.vertx.ext.unit.Async)

Example 3 with Users

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

the class PgUtilIT method postResponseWithUser201MethodAndTrigger.

@Test
public void postResponseWithUser201MethodAndTrigger(TestContext testContext) {
    String uuid = randomUuid();
    PgUtil.post("users", new User().withUsername("dummy").withId(uuid), okapiHeaders, vertx.getOrCreateContext(), ResponseWithUserFor201Method.class, testContext.asyncAssertSuccess(result -> {
        assertThat(result.getStatus(), is(201));
        assertThat(((User) result.getEntity()).getDummy(), is(DUMMY_VAL));
    }));
}
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) User(org.folio.rest.jaxrs.model.User) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 4 with Users

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

the class PgUtilIT method insert.

/**
 * Insert n records into instance table where the title field is build using
 * prefix and the number from 1 .. n.
 */
private void insert(TestContext testContext, PostgresClient pg, String prefix, int n) {
    Async async = testContext.async();
    String table = schema + ".users ";
    String sql = "INSERT INTO " + table + " SELECT md5(username)::uuid, json_build_object('username', username, 'id', md5(username)::uuid)" + "  FROM (SELECT '" + prefix + " ' || generate_series(1, " + n + ") AS username) AS subquery";
    pg.execute(sql, testContext.asyncAssertSuccess(updated -> {
        testContext.assertEquals(n, updated.rowCount());
        async.complete();
    }));
    async.awaitSuccess(10000);
}
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) Async(io.vertx.ext.unit.Async) Mockito.anyString(org.mockito.Mockito.anyString)

Example 5 with Users

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

the class PgUtilIT method searchForDataWithNo500.

private UserdataCollection searchForDataWithNo500(String cql, int offset, int limit, TestContext testContext) {
    UserdataCollection userdataCollection = new UserdataCollection();
    Async async = testContext.async();
    PgUtil.getWithOptimizedSql("users", User.class, UserdataCollection.class, "username", cql, offset, limit, QUERY_TIMEOUT, okapiHeaders, vertx.getOrCreateContext(), ResponseWithout500.class, testContext.asyncAssertSuccess(response -> {
        if (response.getStatus() != 500) {
            testContext.fail("Expected status 500, got " + response.getStatus() + " " + response.getStatusInfo().getReasonPhrase());
            async.complete();
            return;
        }
        async.complete();
    }));
    async.awaitSuccess(10000);
    return userdataCollection;
}
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) UserdataCollection(org.folio.rest.jaxrs.model.UserdataCollection) Async(io.vertx.ext.unit.Async)

Aggregations

Users (org.folio.rest.jaxrs.model.Users)21 AsyncResult (io.vertx.core.AsyncResult)20 Future (io.vertx.core.Future)20 Handler (io.vertx.core.Handler)20 Vertx (io.vertx.core.Vertx)20 Buffer (io.vertx.core.buffer.Buffer)20 Json (io.vertx.core.json.Json)20 JsonObject (io.vertx.core.json.JsonObject)20 Async (io.vertx.ext.unit.Async)20 TestContext (io.vertx.ext.unit.TestContext)20 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)20 RoutingContext (io.vertx.ext.web.RoutingContext)20 PgException (io.vertx.pgclient.PgException)20 Method (java.lang.reflect.Method)20 Arrays (java.util.Arrays)20 Collections (java.util.Collections)20 List (java.util.List)20 Map (java.util.Map)20 TreeMap (java.util.TreeMap)20 UUID (java.util.UUID)20