use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class ModifyTest method test030ModifyUserOnNonExistingAccountTest.
// MID-3483
@Test(enabled = false)
public void test030ModifyUserOnNonExistingAccountTest() throws Exception {
final String TEST_NAME = "test030ModifyUserOnNonExistingAccountTest";
TestUtil.displayTestTile(TEST_NAME);
OperationResult result = new OperationResult("MODIFY");
//add user
File userFile = new File(TEST_DIR, "modify-user.xml");
PrismObject<UserType> user = prismContext.parseObject(userFile);
user.setOid(null);
user.asObjectable().setName(new PolyStringType("non-existing-account-user"));
String oid = repositoryService.addObject(user, null, result);
PrismObject<UserType> userOld = repositoryService.getObject(UserType.class, oid, null, result);
ObjectModificationType modification = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, "change-add-non-existing.xml"), ObjectModificationType.COMPLEX_TYPE);
Collection<? extends ItemDelta> deltas = DeltaConvertor.toModifications(modification, UserType.class, prismContext);
repositoryService.modifyObject(UserType.class, oid, deltas, getModifyOptions(), result);
PropertyDelta.applyTo(deltas, userOld);
PrismObject<UserType> userNew = repositoryService.getObject(UserType.class, oid, null, result);
ObjectDelta<UserType> delta = userOld.diff(userNew);
LOGGER.debug("Modify diff \n{}", delta.debugDump(3));
AssertJUnit.assertTrue("Modify was unsuccessful, diff size: " + delta.getModifications().size(), delta.isEmpty());
AssertJUnit.assertTrue("User is not equivalent.", userOld.equivalent(userNew));
}
use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class EncodingTest method repositorySelfTestUser.
private void repositorySelfTestUser(OperationResult testResult) throws SchemaException {
OperationResult result = testResult.createSubresult("user");
PrismObject<UserType> user = getObjectDefinition(UserType.class).instantiate();
UserType userType = user.asObjectable();
String name = generateRandomName();
PolyStringType namePolyStringType = toPolyStringType(name);
userType.setName(namePolyStringType);
result.addContext("name", name);
userType.setDescription(POLICIJA);
userType.setFullName(toPolyStringType(USER_FULL_NAME));
userType.setGivenName(toPolyStringType(USER_GIVEN_NAME));
userType.setFamilyName(toPolyStringType(USER_FAMILY_NAME));
userType.setTitle(toPolyStringType(INSANE_NATIONAL_STRING));
userType.getEmployeeType().add(USER_EMPLOYEE_TYPE[0]);
userType.getEmployeeType().add(USER_EMPLOYEE_TYPE[1]);
userType.getOrganization().add(toPolyStringType(USER_ORGANIZATION[0]));
userType.getOrganization().add(toPolyStringType(USER_ORGANIZATION[1]));
String oid;
try {
oid = repositoryService.addObject(user, null, result);
} catch (Exception e) {
result.recordFatalError(e);
return;
}
try {
OperationResult subresult = result.createSubresult(result.getOperation() + ".getObject");
PrismObject<UserType> userRetrieved;
try {
userRetrieved = repositoryService.getObject(UserType.class, oid, null, subresult);
} catch (Exception e) {
result.recordFatalError(e);
return;
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Self-test:user getObject:\n{}", userRetrieved.debugDump());
}
checkUser(userRetrieved, name, subresult);
subresult.recordSuccessIfUnknown();
OperationResult subresult1 = result.createSubresult(result.getOperation() + ".searchObjects.fullName");
try {
ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext).item(UserType.F_FULL_NAME).eq(toPolyString(USER_FULL_NAME)).matchingNorm().build();
subresult1.addParam("query", query);
List<PrismObject<UserType>> foundObjects = repositoryService.searchObjects(UserType.class, query, null, subresult1);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Self-test:user searchObjects:\n{}", DebugUtil.debugDump(foundObjects));
}
assertSingleSearchResult("user", foundObjects, subresult1);
userRetrieved = foundObjects.iterator().next();
checkUser(userRetrieved, name, subresult1);
subresult1.recordSuccessIfUnknown();
} catch (Exception e) {
subresult1.recordFatalError(e);
return;
}
} finally {
// try {
// repositoryService.deleteObject(UserType.class, oid, testResult);
// } catch (ObjectNotFoundException e) {
// result.recordFatalError(e);
// return;
// } catch (RuntimeException e) {
// result.recordFatalError(e);
// return;
// }
result.computeStatus();
}
}
use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class EncodingTest method toPolyStringType.
private PolyStringType toPolyStringType(String orig) {
PolyStringType polyStringType = new PolyStringType();
polyStringType.setOrig(orig);
return polyStringType;
}
use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class ConcurrencyTest method concurrencyUniversal.
private void concurrencyUniversal(String name, long duration, long waitStep, ModifierThread[] modifierThreads, Checker checker) throws Exception {
Session session = getFactory().openSession();
session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
System.out.println(">>>>" + connection.getTransactionIsolation());
}
});
session.close();
final File file = new File("src/test/resources/concurrency/user.xml");
PrismObject<UserType> user = prismContext.parseObject(file);
user.asObjectable().setName(new PolyStringType(name));
OperationResult result = new OperationResult("Concurrency Test");
String oid = repositoryService.addObject(user, null, result);
LOGGER.info("*** Object added: " + oid + " ***");
LOGGER.info("*** Starting modifier threads ***");
for (ModifierThread mt : modifierThreads) {
mt.setOid(oid);
mt.start();
}
LOGGER.info("*** Waiting " + duration + " ms ***");
long startTime = System.currentTimeMillis();
int readIteration = 1;
main: while (System.currentTimeMillis() - startTime < duration) {
if (checker != null) {
checker.check(readIteration, oid);
}
if (waitStep > 0L) {
Thread.sleep(waitStep);
}
for (ModifierThread mt : modifierThreads) {
if (!mt.isAlive()) {
LOGGER.error("At least one of threads died prematurely, finishing waiting.");
break main;
}
}
readIteration++;
}
for (ModifierThread mt : modifierThreads) {
// stop the threads
mt.stop = true;
System.out.println("Thread " + mt.id + " has done " + (mt.counter - 1) + " iterations");
LOGGER.info("Thread " + mt.id + " has done " + (mt.counter - 1) + " iterations");
}
// we do not have to wait for the threads to be stopped, just examine their results
// give the threads a chance to finish (before repo will be shut down)
Thread.sleep(1000);
for (ModifierThread mt : modifierThreads) {
LOGGER.info("Modifier thread " + mt.id + " finished with an exception: ", mt.threadResult);
}
for (ModifierThread mt : modifierThreads) {
if (mt.threadResult != null) {
throw new AssertionError("Modifier thread " + mt.id + " finished with an exception: " + mt.threadResult, mt.threadResult);
}
}
}
use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class AddGetObjectTest method testIterationToken.
private String testIterationToken(String token) throws Exception {
PrismObjectDefinition accDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ShadowType.class);
PrismObject<ShadowType> shadow = accDef.instantiate();
ShadowType shadowType = shadow.asObjectable();
shadowType.setName(new PolyStringType("testIterationToken"));
shadowType.setIterationToken(token);
OperationResult result = new OperationResult("sync desc test");
final String oid = repositoryService.addObject(shadowType.asPrismObject(), null, result);
shadow = repositoryService.getObject(ShadowType.class, oid, null, result);
shadowType = shadow.asObjectable();
token = shadowType.getIterationToken();
repositoryService.deleteObject(ShadowType.class, oid, result);
return token;
}
Aggregations