Search in sources :

Example 11 with User

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

the class PgUtilIT method post.

/**
 * Post a new user, expect the httpStatus, and a returned User with matching username
 * and matching uuid if uuid was not null.
 * @param uuid  optional
 * @return uuid returned by the POST
 */
private String post(TestContext testContext, String username, String uuid, int httpStatus) {
    Async async = testContext.async();
    String[] returnedUuid = new String[1];
    PgUtil.post("users", new User().withUsername(username).withId(uuid), okapiHeaders, vertx.getOrCreateContext(), ResponseImpl.class, result -> {
        returnedUuid[0] = assertStatusAndUser(testContext, result, httpStatus, username, uuid);
        async.complete();
    });
    async.awaitSuccess();
    return returnedUuid[0];
}
Also used : User(org.folio.rest.jaxrs.model.User) Async(io.vertx.ext.unit.Async) Mockito.anyString(org.mockito.Mockito.anyString)

Example 12 with User

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

the class PgUtilIT method putNonexistingId.

@Test
public void putNonexistingId(TestContext testContext) {
    String uuid = randomUuid();
    PgUtil.put("users", new User().withUsername("Rosamunde"), uuid, okapiHeaders, vertx.getOrCreateContext(), Users.PutUsersByUserIdResponse.class, asyncAssertSuccess(testContext, 404, put -> {
        // make sure that a record with this uuid really hasn't been inserted
        PgUtil.getById("users", User.class, uuid, okapiHeaders, vertx.getOrCreateContext(), Users.GetUsersByUserIdResponse.class, asyncAssertSuccess(testContext, 404, "Not found"));
    }));
}
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) Users(org.folio.rest.jaxrs.model.Users) Test(org.junit.Test)

Example 13 with User

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

the class PgUtilIT method postSync.

@Test
public void postSync(TestContext testContext) {
    String id1 = randomUuid();
    String id2 = randomUuid();
    List<User> entities = Arrays.asList(new User().withId(id1), new User().withId(id2));
    List<User> entities1 = Arrays.asList(new User().withId(id1).withVersion(1), new User().withId(id2).withVersion(1));
    List<User> entities2 = Arrays.asList(new User().withId(id1).withVersion(2), new User().withId(id2).withVersion(2));
    boolean upsert = true;
    boolean noUpsert = false;
    postSync(entities, upsert).onComplete(asyncAssertSuccess(testContext, 201)).compose(x -> getUser(id2)).onComplete(testContext.asyncAssertSuccess(user -> {
        assertThat(user.getMetadata().getCreatedByUserId(), is("okapiUser"));
    })).compose(x -> postSync(entities, upsert)).onComplete(asyncAssertSuccess(testContext, 409)).compose(x -> postSync(entities1, upsert)).onComplete(asyncAssertSuccess(testContext, 201)).compose(x -> postSync(entities1, upsert)).onComplete(asyncAssertSuccess(testContext, 409)).compose(x -> postSync(entities2, noUpsert)).onComplete(asyncAssertSuccess(testContext, 422)).compose(x -> postSync(entities2, upsert)).onComplete(asyncAssertSuccess(testContext, 201));
}
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 14 with User

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

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

the class PgUtilIT method postSync409.

@Test
public void postSync409(TestContext testContext) {
    String uuid = randomUuid();
    post(testContext, "abc", uuid, 201);
    List<User> users = Arrays.asList(new User(), new User().withId(uuid).withUsername("xyz"));
    postSync(users, true).onComplete(result -> assertStatusAndUser(testContext, result, 409, "abc", uuid));
}
Also used : User(org.folio.rest.jaxrs.model.User) Mockito.anyString(org.mockito.Mockito.anyString) 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