use of com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser in project midpoint by Evolveum.
the class SqaleRepoSmokeTest method test900WorkingWithPgArraysJsonbAndBytea.
// region low-level tests
/**
* This tests our type mapper/converter classes and related column mapping.
*/
@Test
public void test900WorkingWithPgArraysJsonbAndBytea() {
QUser u = aliasFor(QUser.class);
MUser user = new MUser();
String userName = "user" + getTestNumber();
setName(user, userName);
user.policySituations = new Integer[] { 1, 2 };
user.subtypes = new String[] { "subtype1", "subtype2" };
// more whitespaces/lines
user.ext = new Jsonb("{\"key\" : \"value\",\n\"number\": 47} ");
user.photo = new byte[] { 0, 1, 0, 1 };
try (JdbcSession jdbcSession = startTransaction()) {
jdbcSession.newInsert(u).populate(user).execute();
jdbcSession.commit();
}
MUser row = selectOne(u, u.nameNorm.eq(userName));
assertThat(row.policySituations).contains(1, 2);
assertThat(row.subtypes).contains("subtype1", "subtype2");
// normalized
assertThat(row.ext.value).isEqualTo("{\"key\": \"value\", \"number\": 47}");
// byte[] is used for fullObject, there is no chance to miss a problem with it
assertThat(row.photo).hasSize(4);
// setting NULLs
try (JdbcSession jdbcSession = startTransaction()) {
jdbcSession.newUpdate(u).setNull(u.policySituations).set(u.subtypes, // this should do the same
(String[]) null).setNull(u.ext).setNull(u.photo).where(u.oid.eq(row.oid)).execute();
jdbcSession.commit();
}
row = selectOne(u, u.nameNorm.eq(userName));
assertThat(row.policySituations).isNull();
assertThat(row.subtypes).isNull();
assertThat(row.ext).isNull();
// but we never set fullObject to null, so this is a good test for doing so with byte[]
assertThat(row.photo).isNull();
}
use of com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser in project midpoint by Evolveum.
the class SqaleRepoSearchIterativeTest method test125SearchIterativeWithCustomOrdering.
@Test
public void test125SearchIterativeWithCustomOrdering() throws Exception {
OperationResult operationResult = createOperationResult();
SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
pm.clearGlobalPerformanceInformation();
given("query with custom ordering");
ObjectQuery query = prismContext.queryFor(UserType.class).asc(UserType.F_COST_CENTER).maxSize(// see the limit below
47).build();
when("calling search iterative");
SearchResultMetadata metadata = searchObjectsIterative(query, operationResult);
then("result metadata is not null and reports partial result (because of the break)");
assertThatOperationResult(operationResult).isSuccess();
assertThat(metadata).isNotNull();
assertThat(metadata.getApproxNumberOfAllResults()).isEqualTo(testHandler.getCounter());
// everything was processed
assertThat(metadata.isPartialResults()).isFalse();
and("search operations were called");
assertOperationRecordedCount(REPO_OP_PREFIX + RepositoryService.OP_SEARCH_OBJECTS_ITERATIVE, 1);
assertTypicalPageOperationCount(metadata);
and("all objects were processed in proper order");
QUser u = aliasFor(QUser.class);
try (JdbcSession jdbcSession = startReadOnlyTransaction()) {
List<String> result = jdbcSession.newQuery().from(u).orderBy(u.costCenter.asc(), u.oid.asc()).select(u.employeeNumber).limit(// must match the maxSize above
47).fetch();
for (int i = 1; i < result.size(); i++) {
// order matches
assertThat(result.get(i)).isEqualTo(getTestNumber() + "-" + i);
}
}
}
use of com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser in project midpoint by Evolveum.
the class SqaleRepoSearchIterativeTest method test115SearchIterativeWithBreakingConditionCheckingOidOrdering.
@Test
public void test115SearchIterativeWithBreakingConditionCheckingOidOrdering() throws Exception {
OperationResult operationResult = createOperationResult();
SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
pm.clearGlobalPerformanceInformation();
String midOid = "80000000-0000-0000-0000-000000000000";
given("condition that breaks iterative search based on UUID");
testHandler.setStoppingPredicate(u -> u.getOid().compareTo(midOid) >= 0);
when("calling search iterative with null query");
SearchResultMetadata metadata = searchObjectsIterative(null, operationResult);
then("result metadata is not null and reports partial result (because of the break)");
assertThat(metadata).isNotNull();
assertThat(metadata.getApproxNumberOfAllResults()).isEqualTo(testHandler.getCounter());
// extremely likely with enough items
assertThat(metadata.isPartialResults()).isTrue();
and("search operations were called");
assertOperationRecordedCount(REPO_OP_PREFIX + RepositoryService.OP_SEARCH_OBJECTS_ITERATIVE, 1);
assertTypicalPageOperationCount(metadata);
and("all objects up to specified UUID were processed");
QUser u = aliasFor(QUser.class);
assertThat(testHandler.getCounter()).isEqualTo(count(u, u.oid.lt(UUID.fromString(midOid))) + 1);
}
use of com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser in project midpoint by Evolveum.
the class SqaleRepoAddDeleteObjectTest method test110AddWithoutOidIgnoresOverwriteOption.
@Test
public void test110AddWithoutOidIgnoresOverwriteOption() throws ObjectAlreadyExistsException, SchemaException {
OperationResult result = createOperationResult();
given("user with a name but without OID");
String userName = "user" + getTestNumber();
UserType userType = new UserType(prismContext).name(userName);
when("adding it to the repository with overwrite option");
repositoryService.addObject(userType.asPrismObject(), createOverwrite(), result);
then("operation is successful and user row for it is created, overwrite is meaningless");
assertThatOperationResult(result).isSuccess();
QUser u = aliasFor(QUser.class);
List<MUser> users = select(u, u.nameOrig.eq(userName));
assertThat(users).hasSize(1);
assertThat(users.get(0).oid).isNotNull();
}
use of com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser in project midpoint by Evolveum.
the class SqaleRepoAddDeleteObjectTest method test120AddUserWithProvidedOidWorksOk.
@Test
public void test120AddUserWithProvidedOidWorksOk() throws ObjectAlreadyExistsException, SchemaException {
OperationResult result = createOperationResult();
given("user with provided OID");
UUID providedOid = UUID.randomUUID();
String userName = "user" + getTestNumber();
UserType userType = new UserType(prismContext).oid(providedOid.toString()).name(userName);
when("adding it to the repository");
repositoryService.addObject(userType.asPrismObject(), null, result);
then("operation is successful and user row with provided OID is created");
assertThatOperationResult(result).isSuccess();
QUser u = aliasFor(QUser.class);
List<MUser> users = select(u, u.nameOrig.eq(userName));
assertThat(users).hasSize(1);
MUser mUser = users.get(0);
assertThat(mUser.oid).isEqualTo(providedOid);
assertThat(mUser.version).isEqualTo(SqaleRepositoryService.INITIAL_VERSION_NUMBER);
}
Aggregations