Search in sources :

Example 36 with PolyStringType

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));
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Test(org.testng.annotations.Test)

Example 37 with PolyStringType

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();
    }
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) PrismObject(com.evolveum.midpoint.prism.PrismObject) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RandomString(com.evolveum.midpoint.util.RandomString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SchemaException(com.evolveum.midpoint.util.exception.SchemaException)

Example 38 with PolyStringType

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;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType)

Example 39 with 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);
        }
    }
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SQLException(java.sql.SQLException) Connection(java.sql.Connection) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Work(org.hibernate.jdbc.Work) File(java.io.File) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Session(org.hibernate.Session)

Example 40 with PolyStringType

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;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)94 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)28 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)26 Test (org.testng.annotations.Test)23 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)20 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)14 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)12 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)12 QName (javax.xml.namespace.QName)11 Task (com.evolveum.midpoint.task.api.Task)10 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)10 File (java.io.File)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)9 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 ArrayList (java.util.ArrayList)7 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)5 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)4 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4