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];
}
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"));
}));
}
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));
}
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);
}
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));
}
Aggregations