Search in sources :

Example 6 with UserdataCollection

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

the class PgUtilIT method searchForDataUnoptimizedNo500.

private UserdataCollection searchForDataUnoptimizedNo500(String cql, int offset, int limit, TestContext testContext) {
    UserdataCollection userdataCollection = new UserdataCollection();
    Async async = testContext.async();
    PgUtil.get("users", User.class, UserdataCollection.class, cql, offset, limit, okapiHeaders, vertx.getOrCreateContext(), ResponseWithout500.class, testContext.asyncAssertSuccess(response -> {
        if (response.getStatus() != 400) {
            testContext.fail("Expected status 400, 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 7 with UserdataCollection

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

the class PgUtilIT method canGetWithUnOptimizedSql.

@Test
public void canGetWithUnOptimizedSql(TestContext testContext) {
    PostgresClient pg = PostgresClient.getInstance(vertx, "testtenant");
    setUpUserDBForTest(testContext, pg);
    // unoptimized sql case
    UserdataCollection c = searchForDataUnoptimized("username=*", 0, 9, testContext);
    int val = c.getUsers().size();
    assertThat(val, is(9));
    // estimation
    assertThat(c.getTotalRecords(), is(greaterThanOrEqualTo(9)));
    // limit=9
    c = searchForDataUnoptimized("username=foo sortBy username", 0, 9, testContext);
    val = c.getUsers().size();
    assertThat(val, is(9));
    // estimation
    assertThat(c.getTotalRecords(), is(greaterThanOrEqualTo(9)));
    // limit=5
    c = searchForDataUnoptimized("username=foo sortBy username", 0, 5, testContext);
    assertThat(c.getUsers().size(), is(5));
    // limit=0
    c = searchForDataUnoptimized("username=foo sortBy username", 0, 0, testContext);
    assertThat(c.getUsers().size(), is(0));
    // estimation
    assertThat(c.getTotalRecords(), is(greaterThanOrEqualTo(1)));
    // offset=6, limit=3
    c = searchForDataUnoptimized("username=foo sortBy username", 6, 3, testContext);
    assertThat(c.getUsers().size(), is(3));
    // offset=1, limit=8
    c = searchForDataUnoptimized("username=foo sortBy username", 1, 8, testContext);
    assertThat(c.getUsers().size(), is(8));
    // "b foo", offset=1, limit=20
    c = searchForDataUnoptimized("username=b sortBy username/sort.ascending", 1, 4, testContext);
    assertThat(c.getUsers().size(), is(4));
    // sort.descending, offset=1, limit=3
    c = searchForDataUnoptimized("username=foo sortBy username/sort.descending", 1, 3, testContext);
    assertThat(c.getUsers().size(), is(3));
    // sort.descending, offset=6, limit=3
    c = searchForDataUnoptimized("username=foo sortBy username/sort.descending", 6, 3, testContext);
    assertThat(c.getUsers().size(), is(3));
    exception.expect(ClassCastException.class);
    searchForDataUnoptimizedNoClass("username=foo sortBy username/sort.descending", 6, 3, testContext);
    searchForDataUnoptimizedNo500("username=foo sortBy username/sort.descending", 6, 3, testContext);
}
Also used : UserdataCollection(org.folio.rest.jaxrs.model.UserdataCollection) Test(org.junit.Test)

Example 8 with UserdataCollection

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

the class PgUtilIT method canGetWithOptimizedSql.

@Test
public void canGetWithOptimizedSql(TestContext testContext) {
    PostgresClient pg = PostgresClient.getInstance(vertx, "testtenant");
    setUpUserDBForTest(testContext, pg);
    // unoptimized sql case
    UserdataCollection c = searchForData("username=*", 0, 9, testContext);
    int val = c.getUsers().size();
    assertThat(val, is(9));
    // estimation
    assertThat(c.getTotalRecords(), is(greaterThanOrEqualTo(9)));
    // limit=9
    c = searchForData("username=foo sortBy username", 0, 9, testContext);
    val = c.getUsers().size();
    assertThat(val, is(9));
    // estimation
    assertThat(c.getTotalRecords(), is(greaterThanOrEqualTo(9)));
    for (int i = 0; i < 5; i++) {
        User user = c.getUsers().get(i);
        assertThat(user.getUsername(), is("b foo " + (i + 1)));
    }
    for (int i = 0; i < 3; i++) {
        User user = c.getUsers().get(5 + i);
        assertThat(user.getUsername(), is("d foo " + (i + 1)));
    }
    // limit=5
    c = searchForData("username=foo sortBy username", 0, 5, testContext);
    assertThat(c.getUsers().size(), is(5));
    for (int i = 0; i < 5; i++) {
        User user = c.getUsers().get(i);
        assertThat(user.getUsername(), is("b foo " + (i + 1)));
    }
    // limit=0
    c = searchForData("username=foo sortBy username", 0, 0, testContext);
    assertThat(c.getUsers().size(), is(0));
    // estimation
    assertThat(c.getTotalRecords(), is(greaterThanOrEqualTo(1)));
    // offset=99, limit=0
    c = searchForData("username=foo sortBy username", 99, 0, testContext);
    assertThat(c.getUsers().size(), is(0));
    // estimation
    assertThat(c.getTotalRecords(), is(greaterThanOrEqualTo(1)));
    // offset=6, limit=3
    c = searchForData("username=foo sortBy username", 6, 3, testContext);
    assertThat(c.getUsers().size(), is(3));
    for (int i = 0; i < 3; i++) {
        User user = c.getUsers().get(i);
        assertThat(user.getUsername(), is("d foo " + (1 + i + 1)));
    }
    // offset=1, limit=8
    c = searchForData("username=foo sortBy username", 1, 8, testContext);
    assertThat(c.getUsers().size(), is(8));
    for (int i = 0; i < 4; i++) {
        User user = c.getUsers().get(i);
        assertThat(user.getUsername(), is("b foo " + (1 + i + 1)));
    }
    for (int i = 0; i < 4; i++) {
        User user = c.getUsers().get(4 + i);
        assertThat(user.getUsername(), is("d foo " + (i + 1)));
    }
    // "b foo", offset=1, limit=20
    c = searchForData("username=b sortBy username/sort.ascending", 1, 20, testContext);
    assertThat(c.getUsers().size(), is(4));
    for (int i = 0; i < 4; i++) {
        User user = c.getUsers().get(i);
        assertThat(user.getUsername(), is("b foo " + (1 + i + 1)));
    }
    // sort.descending, offset=1, limit=3
    c = searchForData("username=foo sortBy username/sort.descending", 1, 3, testContext);
    assertThat(c.getUsers().size(), is(3));
    for (int i = 0; i < 3; i++) {
        User user = c.getUsers().get(i);
        assertThat(user.getUsername(), is("d foo " + (4 - i)));
    }
    // sort.descending, offset=6, limit=3
    c = searchForData("username=foo sortBy username/sort.descending", 6, 3, testContext);
    assertThat(c.getUsers().size(), is(3));
    for (int i = 0; i < 3; i++) {
        User user = c.getUsers().get(i);
        assertThat(user.getUsername(), is("b foo " + (4 - i)));
    }
    searchForData("username=foo sortBy username&%$sort.descending", 6, 3, testContext);
    exception.expect(NullPointerException.class);
    searchForDataNullHeadersExpectFailure("username=foo sortBy username/sort.descending", 6, 3, testContext);
    searchForDataNoClass("username=foo sortBy username/sort.descending", 6, 3, testContext);
}
Also used : User(org.folio.rest.jaxrs.model.User) UserdataCollection(org.folio.rest.jaxrs.model.UserdataCollection) Test(org.junit.Test)

Example 9 with UserdataCollection

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

the class PgUtilIT method searchForDataWithNo400.

private UserdataCollection searchForDataWithNo400(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(), ResponseWithout400.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)

Example 10 with UserdataCollection

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

the class PgUtilIT method searchForDataNoClass.

private UserdataCollection searchForDataNoClass(String cql, int offset, int limit, TestContext testContext) {
    UserdataCollection userdataCollection = new UserdataCollection();
    Async async = testContext.async();
    PgUtil.getWithOptimizedSql("users", User.class, Object.class, "username", cql, offset, limit, QUERY_TIMEOUT, 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;
        }
        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

UserdataCollection (org.folio.rest.jaxrs.model.UserdataCollection)10 Test (org.junit.Test)10 User (org.folio.rest.jaxrs.model.User)9 Async (io.vertx.ext.unit.Async)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 JsonObject (io.vertx.core.json.JsonObject)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 Method (java.lang.reflect.Method)7 Arrays (java.util.Arrays)7 Collections (java.util.Collections)7 List (java.util.List)7 Map (java.util.Map)7