text:
package com.evolveum.midpoint.model.intest.gensync;

import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.model.intest.TestModelServiceContract;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismContainerDefinition;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.path.IdItemPathSegment;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.NameItemPathSegment;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.ObjectPaging;
import com.evolveum.midpoint.prism.query.OrderDirection;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.RelationalValueSearchQuery;
import com.evolveum.midpoint.schema.RelationalValueSearchType;
import com.evolveum.midpoint.schema.ResultHandler;
import com.evolveum.midpoint.schema.RetrieveOption;
import com.evolveum.midpoint.schema.SearchResultList;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.IntegrationTestTools;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.Validator;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.util.exception.TunnelException;
import com.evolveum.midpoint.xml.ns._public.common.api_types_3.ImportOptionsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;

import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.testng.AssertJUnit;
import org.testng.annotations.Test;

import java.io.File;
import java.util.Collection;

import javax.xml.namespace.QName;

import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertTrue;

/**
 * @author semancik
 *
 */
@ContextConfiguration(locations = {"classpath:ctx-model-intest-test-main.xml"})
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestEditSchema extends AbstractGenericSyncTest {

    public static final File LOOKUP_LANGUAGES_REPLACEMENT_FILE = new File(TEST_DIR, "lookup-languages-replacement.xml");

    @Override
    public void initSystem(Task initTask, OperationResult initResult) throws Exception {
        super.initSystem(initTask, initResult);

        setDefaultUserTemplate(USER_TEMPLATE_COMPLEX_OID);
        importObjectFromFile(ROLE_PRISONER_FILE);
        importObjectFromFile(USER_OTIS_FILE);

        rememberSteadyResources();
    }

    @Test
    public void test100LookupLanguagesGet() throws Exception {
		final String TEST_NAME="test100LookupLanguagesGet";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
        PrismObject<LookupTableType> lookup = modelService.getObject(LookupTableType.class, LOOKUP_LANGUAGES_OID, null, task, result);

		// THEN
		TestUtil.displayThen(TEST_NAME);
		result.computeStatus();
		TestUtil.assertSuccess(result);

		IntegrationTestTools.display("Languages", lookup);

		assertEquals("Wrong lang lookup name", LOOKUP_LANGUAGES_NAME, lookup.asObjectable().getName().getOrig());

		PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
		assertNull("Table container sneaked in", tableContainer);

        assertSteadyResources();
    }

    @Test
    public void test102LookupLanguagesGetExclude() throws Exception {
		final String TEST_NAME="test102LookupLanguagesGetExclude";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(LookupTableType.F_ROW,
    			GetOperationOptions.createRetrieve(RetrieveOption.EXCLUDE));

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
        PrismObject<LookupTableType> lookup = modelService.getObject(LookupTableType.class, LOOKUP_LANGUAGES_OID, options, task, result);

		// THEN
		TestUtil.displayThen(TEST_NAME);
		result.computeStatus();
		TestUtil.assertSuccess(result);

		IntegrationTestTools.display("Languages", lookup);

		assertEquals("Wrong lang lookup name", LOOKUP_LANGUAGES_NAME, lookup.asObjectable().getName().getOrig());

		PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
		assertNull("Table container sneaked in", tableContainer);

        assertSteadyResources();
    }

    @Test
    public void test110LookupLanguagesGetAll() throws Exception {
		final String TEST_NAME="test110LookupLanguagesGetAll";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
		PrismObject<LookupTableType> lookup = getLookupTableAll(LOOKUP_LANGUAGES_OID, task, result);

		// THEN
		TestUtil.displayThen(TEST_NAME);
		result.computeStatus();
		TestUtil.assertSuccess(result);
        checkLookupResult(lookup, new String[]{"en_US", "en", "English (US)"},
                new String[]{"en_PR", "en", "English (pirate)"},
                new String[]{"sk_SK", "sk", "Slovak"},
                new String[]{"tr_TR", "tr", "Turkish"});
    }

    @Test
    public void test120LookupLanguagesGetByKeyExact() throws Exception {
        final String TEST_NAME="test120LookupLanguagesGetByKeyExact";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        // WHEN
        TestUtil.displayWhen(TEST_NAME);

        RelationalValueSearchQuery query = new RelationalValueSearchQuery(LookupTableRowType.F_KEY, "sk_SK", RelationalValueSearchType.EXACT);
        Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(LookupTableType.F_ROW,
                GetOperationOptions.createRetrieve(query));
        PrismObject<LookupTableType> lookup = modelService.getObject(LookupTableType.class, LOOKUP_LANGUAGES_OID, options, task, result);

        // THEN
        TestUtil.displayThen(TEST_NAME);
        result.computeStatus();
        TestUtil.assertSuccess(result);
        checkLookupResult(lookup, new String[] { "sk_SK", "sk", "Slovak" });
    }

    @Test
    public void test121LookupLanguagesGetByKeyStartingWith() throws Exception {
        final String TEST_NAME="test121LookupLanguagesGetByKeyStartingWith";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        // WHEN
        TestUtil.displayWhen(TEST_NAME);

        RelationalValueSearchQuery query = new RelationalValueSearchQuery(LookupTableRowType.F_KEY, "e", RelationalValueSearchType.STARTS_WITH);
        Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(LookupTableType.F_ROW,
                GetOperationOptions.createRetrieve(query));
        PrismObject<LookupTableType> lookup = modelService.getObject(LookupTableType.class, LOOKUP_LANGUAGES_OID, options, task, result);

        // THEN
        TestUtil.displayThen(TEST_NAME);
        result.computeStatus();
        TestUtil.assertSuccess(result);
        checkLookupResult(lookup, new String[]{"en_US", "en", "English (US)"},
                new String[]{"en_PR", "en", "English (pirate)"});
    }

    @Test
    public void test122LookupLanguagesGetByKeyContaining() throws Exception {
        final String TEST_NAME="test122LookupLanguagesGetByKeyContaining";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        // WHEN
        TestUtil.displayWhen(TEST_NAME);

        RelationalValueSearchQuery query = new RelationalValueSearchQuery(LookupTableRowType.F_KEY, "r", RelationalValueSearchType.SUBSTRING);
        Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(LookupTableType.F_ROW,
                GetOperationOptions.createRetrieve(query));
        PrismObject<LookupTableType> lookup = modelService.getObject(LookupTableType.class, LOOKUP_LANGUAGES_OID, options, task, result);

        // THEN
        TestUtil.displayThen(TEST_NAME);
        result.computeStatus();
        TestUtil.assertSuccess(result);
        checkLookupResult(lookup, new String[]{"tr_TR", "tr", "Turkish"});
    }

    @Test
    public void test123LookupLanguagesGetByKeyContainingWithPaging() throws Exception {
        final String TEST_NAME="test123LookupLanguagesGetByKeyContainingWithPaging";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        // WHEN
        TestUtil.displayWhen(TEST_NAME);

        ObjectPaging paging = ObjectPaging.createPaging(2, 1, LookupTableRowType.F_KEY, OrderDirection.ASCENDING);
        RelationalValueSearchQuery query = new RelationalValueSearchQuery(LookupTableRowType.F_KEY, "_", RelationalValueSearchType.SUBSTRING, paging);
        Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(LookupTableType.F_ROW,
                GetOperationOptions.createRetrieve(query));
        PrismObject<LookupTableType> lookup = modelService.getObject(LookupTableType.class, LOOKUP_LANGUAGES_OID, options, task, result);

        // THEN
        TestUtil.displayThen(TEST_NAME);
        result.computeStatus();
        TestUtil.assertSuccess(result);
        checkLookupResult(lookup, new String[] { "sk_SK", "sk", "Slovak" });
    }

    @Test
    public void test124LookupLanguagesGetByKeyContainingReturningNothing() throws Exception {
        final String TEST_NAME="test124LookupLanguagesGetByKeyContainingReturningNothing";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        // WHEN
        TestUtil.displayWhen(TEST_NAME);

        RelationalValueSearchQuery query = new RelationalValueSearchQuery(LookupTableRowType.F_KEY, "xyz", RelationalValueSearchType.SUBSTRING);
        Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(LookupTableType.F_ROW,
                GetOperationOptions.createRetrieve(query));
        PrismObject<LookupTableType> lookup = modelService.getObject(LookupTableType.class, LOOKUP_LANGUAGES_OID, options, task, result);

        // THEN
        TestUtil.displayThen(TEST_NAME);
        result.computeStatus();
        TestUtil.assertSuccess(result);
        IntegrationTestTools.display("Languages", lookup);

        assertEquals("Wrong lang lookup name", LOOKUP_LANGUAGES_NAME, lookup.asObjectable().getName().getOrig());

        PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
        assertTrue("Unexpected content in tableContainer", tableContainer == null || tableContainer.size() == 0);

        assertSteadyResources();
    }

    @Test
    public void test130LookupLanguagesGetByValueExact() throws Exception {
        final String TEST_NAME="test130LookupLanguagesGetByValueExact";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        // WHEN
        TestUtil.displayWhen(TEST_NAME);

        RelationalValueSearchQuery query = new RelationalValueSearchQuery(LookupTableRowType.F_VALUE, "sk", RelationalValueSearchType.EXACT);
        Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(LookupTableType.F_ROW,
                GetOperationOptions.createRetrieve(query));
        PrismObject<LookupTableType> lookup = modelService.getObject(LookupTableType.class, LOOKUP_LANGUAGES_OID, options, task, result);

        // THEN
        TestUtil.displayThen(TEST_NAME);
        result.computeStatus();
        TestUtil.assertSuccess(result);
        checkLookupResult(lookup, new String[] { "sk_SK", "sk", "Slovak" });
    }

    /**
     * Disabled because it's not clear how to treat polystrings in searches.
     *
     */
    @Test
    public void test131LookupLanguagesGetByLabelStartingWith() throws Exception {
        final String TEST_NAME="test131LookupLanguagesGetByLabelStartingWith";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        // WHEN
        TestUtil.displayWhen(TEST_NAME);

        String fragment = "Eng";
        // TODO or fragment = new PolyStringType(new PolyString("Eng", "eng")) ?
        RelationalValueSearchQuery query = new RelationalValueSearchQuery(LookupTableRowType.F_LABEL, fragment, RelationalValueSearchType.STARTS_WITH);
        Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(LookupTableType.F_ROW,
                GetOperationOptions.createRetrieve(query));
        PrismObject<LookupTableType> lookup = modelService.getObject(LookupTableType.class, LOOKUP_LANGUAGES_OID, options, task, result);

        // THEN
        TestUtil.displayThen(TEST_NAME);
        result.computeStatus();
        TestUtil.assertSuccess(result);
        checkLookupResult(lookup, new String[]{"en_US", "en", "English (US)"},
                new String[]{"en_PR", "en", "English (pirate)"});
    }

    @Test
    public void test133LookupLanguagesGetByValueContainingWithPaging() throws Exception {
        final String TEST_NAME="test123LookupLanguagesGetByKeyContainingWithPaging";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        // WHEN
        TestUtil.displayWhen(TEST_NAME);

        ObjectPaging paging = ObjectPaging.createPaging(0, 1, LookupTableRowType.F_LABEL, OrderDirection.DESCENDING); // using sorting key other than the one used in search
        RelationalValueSearchQuery query = new RelationalValueSearchQuery(LookupTableRowType.F_VALUE, "n", RelationalValueSearchType.SUBSTRING, paging);
        Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(LookupTableType.F_ROW,
                GetOperationOptions.createRetrieve(query));
        PrismObject<LookupTableType> lookup = modelService.getObject(LookupTableType.class, LOOKUP_LANGUAGES_OID, options, task, result);

        // THEN
        TestUtil.displayThen(TEST_NAME);
        result.computeStatus();
        TestUtil.assertSuccess(result);
        checkLookupResult(lookup, new String[] { "en_US", "en", "English (US)" });
    }

    /**
     * This test is disabled because id-based searching is not available yet (and it's unclear if it would be eventually necessary).
     */
    @Test(enabled = false)
    public void test140LookupLanguagesGetByIdExisting() throws Exception {
        final String TEST_NAME="test140LookupLanguagesGetByIdExisting";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        // WHEN
        TestUtil.displayWhen(TEST_NAME);

        Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(
                new ItemPath(
                        new NameItemPathSegment(LookupTableType.F_ROW),
                        new IdItemPathSegment(1L)),
                GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
        PrismObject<LookupTableType> lookup = modelService.getObject(LookupTableType.class, LOOKUP_LANGUAGES_OID, options, task, result);

        // THEN
        TestUtil.displayThen(TEST_NAME);
        result.computeStatus();
        TestUtil.assertSuccess(result);
        checkLookupResult(lookup, new String[] { "en_US", "en", "English (US)" });
    }

    private void checkLookupResult(PrismObject<LookupTableType> lookup, String[]... tuples) {
        IntegrationTestTools.display("Languages", lookup);

        assertEquals("Wrong lang lookup name", LOOKUP_LANGUAGES_NAME, lookup.asObjectable().getName().getOrig());

        PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
        assertNotNull("Table container missing", tableContainer);
        assertEquals("Unexpected table container size", tuples.length, tableContainer.size());

        for (String[] tuple : tuples) {
            assertLookupRow(tableContainer, tuple[0], tuple[1], tuple[2]);
        }
        assertSteadyResources();
    }

    @Test
    public void test150LookupLanguagesAddRowFull() throws Exception {
		final String TEST_NAME="test150LookupLanguagesAddRow";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        LookupTableRowType row = new LookupTableRowType();
        row.setKey("gi_GI");
        row.setValue("gi");
        row.setLabel(PrismTestUtil.createPolyStringType("Gibberish"));
        ObjectDelta<LookupTableType> delta = ObjectDelta.createModificationAddContainer(LookupTableType.class,
        		LOOKUP_LANGUAGES_OID, LookupTableType.F_ROW, prismContext, row);

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
		modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);

		// THEN
		TestUtil.displayThen(TEST_NAME);
		result.computeStatus();
		TestUtil.assertSuccess(result);

		PrismObject<LookupTableType> lookup = getLookupTableAll(LOOKUP_LANGUAGES_OID, task, result);

		result.computeStatus();
		TestUtil.assertSuccess(result);

		IntegrationTestTools.display("Languages", lookup);

		assertEquals("Wrong lang lookup name", LOOKUP_LANGUAGES_NAME, lookup.asObjectable().getName().getOrig());

		PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
		assertNotNull("Table container missing", tableContainer);
		assertEquals("Unexpected table container size", 5, tableContainer.size());

		assertLookupRow(tableContainer, "en_US", "en", "English (US)");
		assertLookupRow(tableContainer, "en_PR", "en", "English (pirate)");
		assertLookupRow(tableContainer, "sk_SK", "sk", "Slovak");
		assertLookupRow(tableContainer, "tr_TR", "tr", "Turkish");

		assertLookupRow(tableContainer, "gi_GI", "gi", "Gibberish");

        assertSteadyResources();
    }

    @Test
    public void test152LookupLanguagesAddRowKeyLabel() throws Exception {
		final String TEST_NAME="test152LookupLanguagesAddRowKeyLabel";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        LookupTableRowType row = new LookupTableRowType();
        row.setKey("gi_GO");
        row.setLabel(PrismTestUtil.createPolyStringType("Gobbledygook"));
        ObjectDelta<LookupTableType> delta = ObjectDelta.createModificationAddContainer(LookupTableType.class,
        		LOOKUP_LANGUAGES_OID, LookupTableType.F_ROW, prismContext, row);

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
		modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);

		// THEN
		TestUtil.displayThen(TEST_NAME);
		result.computeStatus();
		TestUtil.assertSuccess(result);

		PrismObject<LookupTableType> lookup = getLookupTableAll(LOOKUP_LANGUAGES_OID, task, result);

		result.computeStatus();
		TestUtil.assertSuccess(result);

		IntegrationTestTools.display("Languages", lookup);

		assertEquals("Wrong lang lookup name", LOOKUP_LANGUAGES_NAME, lookup.asObjectable().getName().getOrig());

		PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
		assertNotNull("Table container missing", tableContainer);
		assertEquals("Unexpected table container size", 6, tableContainer.size());

		assertLookupRow(tableContainer, "en_US", "en", "English (US)");
		assertLookupRow(tableContainer, "en_PR", "en", "English (pirate)");
		assertLookupRow(tableContainer, "sk_SK", "sk", "Slovak");
		assertLookupRow(tableContainer, "tr_TR", "tr", "Turkish");
		assertLookupRow(tableContainer, "gi_GI", "gi", "Gibberish");

		assertLookupRow(tableContainer, "gi_GO", null, "Gobbledygook");

        assertSteadyResources();
    }

    @Test
    public void test154LookupLanguagesAddRowKeyValue() throws Exception {
		final String TEST_NAME="test154LookupLanguagesAddRowKeyValue";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        LookupTableRowType row = new LookupTableRowType();
        row.setKey("gi_HU");
        row.setValue("gi");
        ObjectDelta<LookupTableType> delta = ObjectDelta.createModificationAddContainer(LookupTableType.class,
        		LOOKUP_LANGUAGES_OID, LookupTableType.F_ROW, prismContext, row);

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
		modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);

		// THEN
		TestUtil.displayThen(TEST_NAME);
		result.computeStatus();
		TestUtil.assertSuccess(result);

		PrismObject<LookupTableType> lookup = getLookupTableAll(LOOKUP_LANGUAGES_OID, task, result);

		result.computeStatus();
		TestUtil.assertSuccess(result);

		IntegrationTestTools.display("Languages", lookup);

		assertEquals("Wrong lang lookup name", LOOKUP_LANGUAGES_NAME, lookup.asObjectable().getName().getOrig());

		PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
		assertNotNull("Table container missing", tableContainer);
		assertEquals("Unexpected table container size", 7, tableContainer.size());

		assertLookupRow(tableContainer, "en_US", "en", "English (US)");
		assertLookupRow(tableContainer, "en_PR", "en", "English (pirate)");
		assertLookupRow(tableContainer, "sk_SK", "sk", "Slovak");
		assertLookupRow(tableContainer, "tr_TR", "tr", "Turkish");
		assertLookupRow(tableContainer, "gi_GI", "gi", "Gibberish");
		assertLookupRow(tableContainer, "gi_GO", null, "Gobbledygook");

		assertLookupRow(tableContainer, "gi_HU", "gi", null);

        assertSteadyResources();
    }

    @Test
    public void test156LookupLanguagesAddRowExistingKey() throws Exception {
		final String TEST_NAME="test156LookupLanguagesAddRowExistingKey";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        LookupTableRowType row = new LookupTableRowType();
        row.setKey("gi_HU");
        row.setValue("gi");
        row.setLabel(PrismTestUtil.createPolyStringType("Humbug"));
        ObjectDelta<LookupTableType> delta = ObjectDelta.createModificationAddContainer(LookupTableType.class,
        		LOOKUP_LANGUAGES_OID, LookupTableType.F_ROW, prismContext, row);

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
        boolean exception = false;
        try {
            modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);
        } catch (ObjectAlreadyExistsException ex) {
            exception = true;
        }
        AssertJUnit.assertTrue(exception);

		// THEN
		TestUtil.displayThen(TEST_NAME);
		result.computeStatus();
		TestUtil.assertFailure(result);

        task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        result = task.getResult();
		PrismObject<LookupTableType> lookup = getLookupTableAll(LOOKUP_LANGUAGES_OID, task, result);

		result.computeStatus();
		TestUtil.assertSuccess(result);

		IntegrationTestTools.display("Languages", lookup);

		assertEquals("Wrong lang lookup name", LOOKUP_LANGUAGES_NAME, lookup.asObjectable().getName().getOrig());

		PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
		assertNotNull("Table container missing", tableContainer);
		assertEquals("Unexpected table container size", 7, tableContainer.size());

		assertLookupRow(tableContainer, "en_US", "en", "English (US)");
		assertLookupRow(tableContainer, "en_PR", "en", "English (pirate)");
		assertLookupRow(tableContainer, "sk_SK", "sk", "Slovak");
		assertLookupRow(tableContainer, "tr_TR", "tr", "Turkish");
		assertLookupRow(tableContainer, "gi_GI", "gi", "Gibberish");
		assertLookupRow(tableContainer, "gi_GO", null, "Gobbledygook");

		assertLookupRow(tableContainer, "gi_HU", "gi", null);

        assertSteadyResources();
    }

    /**
     * disabled because we can't delete container based on it's properties. It's against prism containers
     * identification concepts - prism container is identified by object OID and container ID attribute.
     *
     * @throws Exception
     */
    @Test(enabled = false)
    public void test162LookupLanguagesDeleteRowFullNoId() throws Exception {
		final String TEST_NAME="test162LookupLanguagesDeleteRowFullNoId";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        LookupTableRowType row = new LookupTableRowType();
        row.setKey("sk_SK");
        row.setValue("sk");
        row.setLabel(PrismTestUtil.createPolyStringType("Slovak"));
        ObjectDelta<LookupTableType> delta = ObjectDelta.createModificationDeleteContainer(LookupTableType.class,
        		LOOKUP_LANGUAGES_OID, LookupTableType.F_ROW, prismContext, row);

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
		modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);

		// THEN
		TestUtil.displayThen(TEST_NAME);
		result.computeStatus();
		TestUtil.assertSuccess(result);

		PrismObject<LookupTableType> lookup = getLookupTableAll(LOOKUP_LANGUAGES_OID, task, result);

		result.computeStatus();
		TestUtil.assertSuccess(result);

		IntegrationTestTools.display("Languages", lookup);

		assertEquals("Wrong lang lookup name", LOOKUP_LANGUAGES_NAME, lookup.asObjectable().getName().getOrig());

		PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
		assertNotNull("Table container missing", tableContainer);
		assertEquals("Unexpected table container size", 6, tableContainer.size());

		assertLookupRow(tableContainer, "en_US", "en", "English (US)");
		assertLookupRow(tableContainer, "en_PR", "en", "English (pirate)");
		assertLookupRow(tableContainer, "tr_TR", "tr", "Turkish");
		assertLookupRow(tableContainer, "gi_GI", "gi", "Gibberish");
		assertLookupRow(tableContainer, "gi_GO", null, "Gobbledygook");
		assertLookupRow(tableContainer, "gi_HU", "gi", "Humbug");

        assertSteadyResources();
    }

    @Test
    public void test164LookupLanguagesDeleteRowFullId() throws Exception {
		final String TEST_NAME="test164LookupLanguagesDeleteRowFullId";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        LookupTableRowType row = new LookupTableRowType();
        row.setKey("en_US");
        row.setValue("en");
        row.setLabel(PrismTestUtil.createPolyStringType("English (US)"));
        row.setId(1L);
        ObjectDelta<LookupTableType> delta = ObjectDelta.createModificationDeleteContainer(LookupTableType.class,
        		LOOKUP_LANGUAGES_OID, LookupTableType.F_ROW, prismContext, row);

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
		modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);

		// THEN
		TestUtil.displayThen(TEST_NAME);
		result.computeStatus();
		TestUtil.assertSuccess(result);

		PrismObject<LookupTableType> lookup = getLookupTableAll(LOOKUP_LANGUAGES_OID, task, result);

		result.computeStatus();
		TestUtil.assertSuccess(result);

		IntegrationTestTools.display("Languages", lookup);

		assertEquals("Wrong lang lookup name", LOOKUP_LANGUAGES_NAME, lookup.asObjectable().getName().getOrig());

		PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
		assertNotNull("Table container missing", tableContainer);
		assertEquals("Unexpected table container size", 6, tableContainer.size());

		assertLookupRow(tableContainer, "en_PR", "en", "English (pirate)");
		assertLookupRow(tableContainer, "tr_TR", "tr", "Turkish");
		assertLookupRow(tableContainer, "gi_GI", "gi", "Gibberish");
		assertLookupRow(tableContainer, "gi_GO", null, "Gobbledygook");
		assertLookupRow(tableContainer, "gi_HU", "gi", null);
        assertLookupRow(tableContainer, "sk_SK", "sk", "Slovak");

        assertSteadyResources();
    }

    @Test
    public void test166LookupLanguagesDeleteRowIdOnly() throws Exception {
		final String TEST_NAME="test166LookupLanguagesDeleteRowIdOnly";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        LookupTableRowType row = new LookupTableRowType();
        row.setId(3L);
        ObjectDelta<LookupTableType> delta = ObjectDelta.createModificationDeleteContainer(LookupTableType.class,
        		LOOKUP_LANGUAGES_OID, LookupTableType.F_ROW, prismContext, row);

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
		modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);

		// THEN
		TestUtil.displayThen(TEST_NAME);
		result.computeStatus();
		TestUtil.assertSuccess(result);

		PrismObject<LookupTableType> lookup = getLookupTableAll(LOOKUP_LANGUAGES_OID, task, result);

		result.computeStatus();
		TestUtil.assertSuccess(result);

		IntegrationTestTools.display("Languages", lookup);

		assertEquals("Wrong lang lookup name", LOOKUP_LANGUAGES_NAME, lookup.asObjectable().getName().getOrig());

		PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
		assertNotNull("Table container missing", tableContainer);
		assertEquals("Unexpected table container size", 5, tableContainer.size());

		assertLookupRow(tableContainer, "en_PR", "en", "English (pirate)");
		assertLookupRow(tableContainer, "gi_GI", "gi", "Gibberish");
		assertLookupRow(tableContainer, "gi_GO", null, "Gobbledygook");
		assertLookupRow(tableContainer, "gi_HU", "gi", null);
        assertLookupRow(tableContainer, "tr_TR", "tr", "Turkish");

        assertSteadyResources();
    }

    /**
     * disabled because we can't delete container based on it's properties. It's against prism containers
     * identification concepts - prism container is identified by object OID and container ID attribute.
     *
     * @throws Exception
     */
    @Test(enabled = false)
    public void test168LookupLanguagesDeleteRowByKey() throws Exception {
		final String TEST_NAME="test168LookupLanguagesDeleteRowByKey";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        LookupTableRowType row = new LookupTableRowType();
        row.setKey("gi_GI");
        ObjectDelta<LookupTableType> delta = ObjectDelta.createModificationDeleteContainer(LookupTableType.class,
        		LOOKUP_LANGUAGES_OID, LookupTableType.F_ROW, prismContext, row);

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
		modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);

		// THEN
		TestUtil.displayThen(TEST_NAME);
		result.computeStatus();
		TestUtil.assertSuccess(result);

		PrismObject<LookupTableType> lookup = getLookupTableAll(LOOKUP_LANGUAGES_OID, task, result);

		result.computeStatus();
		TestUtil.assertSuccess(result);

		IntegrationTestTools.display("Languages", lookup);

		assertEquals("Wrong lang lookup name", LOOKUP_LANGUAGES_NAME, lookup.asObjectable().getName().getOrig());

		PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
		assertNotNull("Table container missing", tableContainer);
		assertEquals("Unexpected table container size", 3, tableContainer.size());

		assertLookupRow(tableContainer, "en_PR", "en", "English (pirate)");
		assertLookupRow(tableContainer, "gi_GO", null, "Gobbledygook");
		assertLookupRow(tableContainer, "gi_HU", "gi", "Humbug");

        assertSteadyResources();
    }

    @Test
    public void test170LookupLanguagesReplaceRows() throws Exception {
		final String TEST_NAME="test170LookupLanguagesReplaceRows";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        LookupTableRowType row1 = new LookupTableRowType();
        row1.setKey("ja_JA");
        row1.setValue("ja");
        row1.setLabel(PrismTestUtil.createPolyStringType("Jabber"));

        LookupTableRowType row2 = new LookupTableRowType();
        row2.setKey("ja_MJ");
        row2.setValue("ja");
        row2.setLabel(PrismTestUtil.createPolyStringType("Mumbojumbo"));

        LookupTableRowType row3 = new LookupTableRowType();
        row3.setKey("en_PR");       // existing key
        row3.setValue("en1");
        row3.setLabel(PrismTestUtil.createPolyStringType("English (pirate1)"));

        ObjectDelta<LookupTableType> delta = ObjectDelta.createModificationReplaceContainer(LookupTableType.class,
        		LOOKUP_LANGUAGES_OID, LookupTableType.F_ROW, prismContext, row1, row2, row3);

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
		modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);

		// THEN
		TestUtil.displayThen(TEST_NAME);
		result.computeStatus();
		TestUtil.assertSuccess(result);

		PrismObject<LookupTableType> lookup = getLookupTableAll(LOOKUP_LANGUAGES_OID, task, result);

		result.computeStatus();
		TestUtil.assertSuccess(result);

		IntegrationTestTools.display("Languages", lookup);

		assertEquals("Wrong lang lookup name", LOOKUP_LANGUAGES_NAME, lookup.asObjectable().getName().getOrig());

		PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
		assertNotNull("Table container missing", tableContainer);
		assertEquals("Unexpected table container size", 3, tableContainer.size());

		assertLookupRow(tableContainer, "ja_JA", "ja", "Jabber");
		assertLookupRow(tableContainer, "ja_MJ", "ja", "Mumbojumbo");
        assertLookupRow(tableContainer, "en_PR", "en1", "English (pirate1)");

        assertSteadyResources();
    }

    @Test
    public void test180LookupLanguagesReplaceObject() throws Exception {
        final String TEST_NAME="test180LookupLanguagesReplaceObject";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        PrismObject<LookupTableType> replacement = PrismTestUtil.parseObject(LOOKUP_LANGUAGES_REPLACEMENT_FILE);
        ObjectDelta<LookupTableType> delta = ObjectDelta.createAddDelta(replacement);

        // WHEN
        TestUtil.displayWhen(TEST_NAME);
        ModelExecuteOptions options = ModelExecuteOptions.createOverwrite();
        options.setRaw(true);
        modelService.executeChanges(MiscSchemaUtil.createCollection(delta), options, task, result);

        // THEN
        TestUtil.displayThen(TEST_NAME);
        result.computeStatus();
        TestUtil.assertSuccess(result);

        PrismObject<LookupTableType> lookup = getLookupTableAll(LOOKUP_LANGUAGES_OID, task, result);

        result.computeStatus();
        TestUtil.assertSuccess(result);

        IntegrationTestTools.display("Languages", lookup);

        assertEquals("Wrong lang lookup name", "Languages Replaced", lookup.asObjectable().getName().getOrig());

        PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
        assertNotNull("Table container missing", tableContainer);
        assertEquals("Unexpected table container size", 1, tableContainer.size());

        assertLookupRow(tableContainer, "fr_FR", "fr", "Français");
        assertSteadyResources();
    }

    @Test
    public void test182LookupLanguagesReimport() throws Exception {
        final String TEST_NAME="test182LookupLanguagesReimport";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        ImportOptionsType options = new ImportOptionsType();
        options.setOverwrite(true);
        options.setKeepOid(true);

        // WHEN
        TestUtil.displayWhen(TEST_NAME);
		modelService.importObjectsFromFile(LOOKUP_LANGUAGES_FILE, options, task, result);

        // THEN
        TestUtil.displayThen(TEST_NAME);
        result.computeStatus();
        TestUtil.assertSuccess(result);

        PrismObject<LookupTableType> lookup = getLookupTableAll(LOOKUP_LANGUAGES_OID, task, result);

        result.computeStatus();
        TestUtil.assertSuccess(result);

        IntegrationTestTools.display("Languages", lookup);

        assertEquals("Wrong lang lookup name", "Languages", lookup.asObjectable().getName().getOrig());

        checkLookupResult(lookup, new String[]{"en_US", "en", "English (US)"},
                new String[]{"en_PR", "en", "English (pirate)"},
                new String[]{"sk_SK", "sk", "Slovak"},
                new String[]{"tr_TR", "tr", "Turkish"});

        assertSteadyResources();
    }

    private void assertLookupRow(PrismContainer<LookupTableRowType> tableContainer, String key, String value,
			String label) {
		for (PrismContainerValue<LookupTableRowType> row: tableContainer.getValues()) {
			LookupTableRowType rowType = row.asContainerable();
			if (key.equals(rowType.getKey())) {
				assertEquals("Wrong value for key "+key, value, rowType.getValue());
				if (label == null) {
					assertNull("Unexpected label for key "+key+": "+rowType.getLabel(), rowType.getLabel());
				} else {
					assertEquals("Wrong label for key "+key, PrismTestUtil.createPolyStringType(label), rowType.getLabel());
				}
				return;
			}
		}
		AssertJUnit.fail("Row with key '"+key+"' was not found in lookup table");
	}

	private PrismObject<LookupTableType> getLookupTableAll(String oid, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException {
    	Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(LookupTableType.F_ROW,
    			GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
		return modelService.getObject(LookupTableType.class, oid, options, task, result);
    }

    @Test
    public void test200EditSchemaUser() throws Exception {
		final String TEST_NAME="test200EditSchemaUser";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        PrismObjectDefinition<UserType> userDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);
        PrismObject<UserType> user = userDef.instantiate();

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
        PrismObjectDefinition<UserType> editDef = getEditObjectDefinition(user);

		// THEN
		TestUtil.displayThen(TEST_NAME);

		PrismPropertyDefinition<PolyString> additionalNameDef = editDef.findPropertyDefinition(UserType.F_ADDITIONAL_NAME);
		assertNotNull("No definition for additionalName in user", additionalNameDef);
		assertEquals("Wrong additionalName displayName", "Middle Name", additionalNameDef.getDisplayName());
		assertTrue("additionalName not readable", additionalNameDef.canRead());

		PrismPropertyDefinition<String> costCenterDef = editDef.findPropertyDefinition(UserType.F_COST_CENTER);
		assertNotNull("No definition for costCenter in user", costCenterDef);
		assertEquals("Wrong costCenter displayOrder", (Integer)123, costCenterDef.getDisplayOrder());
		assertTrue("costCenter not readable", costCenterDef.canRead());

		PrismPropertyDefinition<String> preferredLanguageDef = editDef.findPropertyDefinition(UserType.F_PREFERRED_LANGUAGE);
		assertNotNull("No definition for preferredLanguage in user", preferredLanguageDef);
		assertEquals("Wrong preferredLanguage displayName", "Language", preferredLanguageDef.getDisplayName());
		assertTrue("preferredLanguage not readable", preferredLanguageDef.canRead());
		PrismReferenceValue valueEnumerationRef = preferredLanguageDef.getValueEnumerationRef();
		assertNotNull("No valueEnumerationRef for preferredLanguage", valueEnumerationRef);
		assertEquals("Wrong valueEnumerationRef OID for preferredLanguage", LOOKUP_LANGUAGES_OID, valueEnumerationRef.getOid());

		PrismContainerDefinition<CredentialsType> credentialsDef = editDef.findContainerDefinition(UserType.F_CREDENTIALS);
		assertNotNull("No definition for credentials in user", credentialsDef);
		assertTrue("Credentials not readable", credentialsDef.canRead());

		ItemPath passwdValPath = new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE);
		PrismPropertyDefinition<ProtectedStringType> passwdValDef = editDef.findPropertyDefinition(passwdValPath);
		assertNotNull("No definition for "+passwdValPath+" in user", passwdValDef);
		assertTrue("Password not readable", passwdValDef.canRead());

        assertSteadyResources();
    }

    @Test
    public void test210UserDefinition() throws Exception {
		final String TEST_NAME="test210UserDefinition";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
        PrismObject<UserType> user = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);

		// THEN
		TestUtil.displayThen(TEST_NAME);
		result.computeStatus();
		TestUtil.assertSuccess(result);

		assertPropertyValues(user, UserType.F_ADDITIONAL_NAME, new Validator<PrismPropertyDefinition<PolyString>>() {
			@Override
			public void validate(PrismPropertyDefinition<PolyString> propDef, String name) throws Exception {
				assertNotNull("No definition for additionalName in user", propDef);
				assertEquals("Wrong additionalName displayName", "Middle Name", propDef.getDisplayName());
				assertTrue("additionalName not readable", propDef.canRead());
			}
		}, PrismTestUtil.createPolyString("Jackie"));

		assertPropertyValues(user, UserType.F_COST_CENTER, new Validator<PrismPropertyDefinition<String>>() {
			@Override
			public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
				assertNotNull("No definition for costCenter in user", propDef);
				assertEquals("Wrong costCenter displayOrder", (Integer)123, propDef.getDisplayOrder());
				assertTrue("costCenter not readable", propDef.canRead());
			}
		});

		assertPropertyValues(user, UserType.F_PREFERRED_LANGUAGE, new Validator<PrismPropertyDefinition<String>>() {
			@Override
			public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
				assertNotNull("No definition for preferredLanguage in user", propDef);
				assertEquals("Wrong preferredLanguage displayName", "Language", propDef.getDisplayName());
				assertTrue("preferredLanguage not readable", propDef.canRead());
				PrismReferenceValue valueEnumerationRef = propDef.getValueEnumerationRef();
				assertNotNull("No valueEnumerationRef for preferredLanguage", valueEnumerationRef);
				assertEquals("Wrong valueEnumerationRef OID for preferredLanguage", LOOKUP_LANGUAGES_OID, valueEnumerationRef.getOid());
			}
		});

		assertContainer(user, UserType.F_CREDENTIALS, new Validator<PrismContainerDefinition<CredentialsType>>() {
			@Override
			public void validate(PrismContainerDefinition<CredentialsType> credentialsDef, String name)
					throws Exception {
				assertNotNull("No definition for credentials in user", credentialsDef);
				assertTrue("Credentials not readable", credentialsDef.canRead());
			}

		}, true);

		assertProperty(user, new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE),
			new Validator<PrismPropertyDefinition<String>>() {
				@Override
				public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
					assertTrue("Password not readable", propDef.canRead());
				}
			});

        assertSteadyResources();
    }

    /**
     * Check that the user definition in schema registry was not ruined
     * @throws Exception
     */
    @Test
    public void test211SchemaRegistryUntouched() throws Exception {
		final String TEST_NAME="test211SchemaRegistryUntouched";
        TestUtil.displayTestTile(this, TEST_NAME);

        assertUntouchedUserDefinition();
        assertSteadyResources();
    }

    /**
     * Modify jack, see if the schema still applies.
     */
    @Test
    public void test213ModifiedUserJack() throws Exception {
		final String TEST_NAME="test213ModifiedUserJack";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        modifyObjectReplaceProperty(UserType.class, USER_JACK_OID, UserType.F_PREFERRED_LANGUAGE, task, result, "en_PR");

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
        PrismObject<UserType> user = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);

		// THEN
		TestUtil.displayThen(TEST_NAME);
		result.computeStatus();
		TestUtil.assertSuccess(result);

		assertPropertyValues(user, UserType.F_ADDITIONAL_NAME, new Validator<PrismPropertyDefinition<PolyString>>() {
			@Override
			public void validate(PrismPropertyDefinition<PolyString> propDef, String name) throws Exception {
				assertNotNull("No definition for additionalName in user", propDef);
				assertEquals("Wrong additionalName displayName", "Middle Name", propDef.getDisplayName());
				assertTrue("additionalName not readable", propDef.canRead());
			}
		}, PrismTestUtil.createPolyString("Jackie"));

		assertPropertyValues(user, UserType.F_COST_CENTER, new Validator<PrismPropertyDefinition<String>>() {
			@Override
			public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
				assertNotNull("No definition for costCenter in user", propDef);
				assertEquals("Wrong costCenter displayOrder", (Integer)123, propDef.getDisplayOrder());
				assertTrue("costCenter not readable", propDef.canRead());
			}
		},"G001"); // This is set by user template

		assertPropertyValues(user, UserType.F_PREFERRED_LANGUAGE, new Validator<PrismPropertyDefinition<String>>() {
			@Override
			public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
				assertNotNull("No definition for preferredLanguage in user", propDef);
				assertEquals("Wrong preferredLanguage displayName", "Language", propDef.getDisplayName());
				assertTrue("preferredLanguage not readable", propDef.canRead());
				PrismReferenceValue valueEnumerationRef = propDef.getValueEnumerationRef();
				assertNotNull("No valueEnumerationRef for preferredLanguage", valueEnumerationRef);
				assertEquals("Wrong valueEnumerationRef OID for preferredLanguage", LOOKUP_LANGUAGES_OID, valueEnumerationRef.getOid());
			}
		}, "en_PR");

		assertContainer(user, UserType.F_CREDENTIALS, new Validator<PrismContainerDefinition<CredentialsType>>() {
			@Override
			public void validate(PrismContainerDefinition<CredentialsType> credentialsDef, String name)
					throws Exception {
				assertNotNull("No definition for credentials in user", credentialsDef);
				assertTrue("Credentials not readable", credentialsDef.canRead());
			}

		}, true);

		assertProperty(user, new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE),
			new Validator<PrismPropertyDefinition<String>>() {
				@Override
				public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
					assertTrue("Password not readable", propDef.canRead());
				}
			});

		assertUntouchedUserDefinition();
        assertSteadyResources();
    }

	@Test
    public void test250EditSchemaRole() throws Exception {
		final String TEST_NAME="test250EditSchemaRole";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        PrismObjectDefinition<RoleType> roleDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(RoleType.class);
        PrismObject<RoleType> role = roleDef.instantiate();

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
        PrismObjectDefinition<RoleType> editDef = getEditObjectDefinition(role);

		// THEN
		TestUtil.displayThen(TEST_NAME);

		// TODO
		PrismPropertyDefinition requestableDef = editDef.findPropertyDefinition(RoleType.F_REQUESTABLE);
		assertNotNull("No definition for requestable in role", requestableDef);
		assertEquals("Wrong requestable displayName", "Can request", requestableDef.getDisplayName());

        assertSteadyResources();
    }

    @Test
    public void test300RoleTypes() throws Exception {
		final String TEST_NAME="test300RoleTypes";
        TestUtil.displayTestTile(this, TEST_NAME);

        assertRoleTypes(getUser(USER_JACK_OID), "application","system","it");
    }

    /**
     * Login as Otis. Otis has a restricted authorizations. Check that schema is presented accordingly to
     * these limitations.
     */
    @Test
    public void test800OtisEditSchemaUser() throws Exception {
		final String TEST_NAME="test800OtisEditSchemaUser";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        login(USER_OTIS_USERNAME);

        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

        PrismObjectDefinition<UserType> userDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);
        PrismObject<UserType> user = userDef.instantiate();

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
        PrismObjectDefinition<UserType> editDef = getEditObjectDefinition(user);
        IntegrationTestTools.display("Otis edit schema", editDef);

		// THEN
		TestUtil.displayThen(TEST_NAME);

		PrismPropertyDefinition<PolyString> nameDef = editDef.findPropertyDefinition(UserType.F_NAME);
		assertNotNull("No definition for name in user", nameDef);
		assertEquals("Wrong name displayName", "Name", nameDef.getDisplayName());
		assertTrue("name not readable", nameDef.canRead());
		assertTrue("name is creatable", !nameDef.canAdd());
		assertTrue("name is modifiable", !nameDef.canModify());

		PrismPropertyDefinition<PolyString> additionalNameDef = editDef.findPropertyDefinition(UserType.F_ADDITIONAL_NAME);
		assertNotNull("No definition for additionalName in user", additionalNameDef);
		assertEquals("Wrong additionalName displayName", "Middle Name", additionalNameDef.getDisplayName());
		assertTrue("additionalName is readable", !additionalNameDef.canRead());
		assertTrue("additionalName is creatable", !additionalNameDef.canAdd());
		assertTrue("additionalName not modifiable", additionalNameDef.canModify());

		PrismPropertyDefinition<String> costCenterDef = editDef.findPropertyDefinition(UserType.F_COST_CENTER);
		assertNotNull("No definition for costCenter in user", costCenterDef);
		assertEquals("Wrong costCenter displayOrder", (Integer)123, costCenterDef.getDisplayOrder());
		assertTrue("costCenter is readable", !costCenterDef.canRead());
		assertTrue("costCenter is creatable", !costCenterDef.canAdd());
		assertTrue("costCenter is modifiable", !costCenterDef.canModify());

		PrismPropertyDefinition<String> preferredLanguageDef = editDef.findPropertyDefinition(UserType.F_PREFERRED_LANGUAGE);
		assertNotNull("No definition for preferredLanguage in user", preferredLanguageDef);
		assertEquals("Wrong preferredLanguage displayName", "Language", preferredLanguageDef.getDisplayName());
		PrismReferenceValue valueEnumerationRef = preferredLanguageDef.getValueEnumerationRef();
		assertNotNull("No valueEnumerationRef for preferredLanguage", valueEnumerationRef);
		assertEquals("Wrong valueEnumerationRef OID for preferredLanguage", LOOKUP_LANGUAGES_OID, valueEnumerationRef.getOid());
		assertTrue("preferredLanguage is readable", !preferredLanguageDef.canRead());
		assertTrue("preferredLanguage is creatable", !preferredLanguageDef.canAdd());
		assertTrue("preferredLanguage is modifiable", !preferredLanguageDef.canModify());

		PrismContainerDefinition<CredentialsType> credentialsDef = editDef.findContainerDefinition(UserType.F_CREDENTIALS);
		assertNotNull("No definition for credentials in user", credentialsDef);
		assertTrue("Credentials is readable", !credentialsDef.canRead());
		assertTrue("Credentials is creatable", !credentialsDef.canAdd());
		assertTrue("Credentials is modifiable", !credentialsDef.canModify());

		ItemPath passwdValPath = new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE);
		PrismPropertyDefinition<ProtectedStringType> passwdValDef = editDef.findPropertyDefinition(passwdValPath);
		assertNotNull("No definition for "+passwdValPath+" in user", passwdValDef);
		assertTrue("Password is readable", !passwdValDef.canRead());
		assertTrue("Password is creatable", !passwdValDef.canAdd());
		assertTrue("Password is modifiable", !passwdValDef.canModify());

		assertUntouchedUserDefinition();
        assertSteadyResources();
    }

    @Test
    public void test810OtisGetJack() throws Exception {
		final String TEST_NAME="test810OtisGetJack";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        login(USER_OTIS_USERNAME);

        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
        PrismObject<UserType> user = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);

		// THEN
		TestUtil.displayThen(TEST_NAME);
		result.computeStatus();
		TestUtil.assertSuccess(result);

		assertPropertyValues(user, UserType.F_NAME, new Validator<PrismPropertyDefinition<PolyString>>() {
			@Override
			public void validate(PrismPropertyDefinition<PolyString> propDef, String name) throws Exception {
				assertNotNull("No definition for name in user", propDef);
				assertEquals("Wrong name displayName", "Name", propDef.getDisplayName());
				assertTrue(name+" not readable", propDef.canRead());
				assertTrue(name+" is creatable", !propDef.canAdd());
				assertTrue(name+" is modifiable", !propDef.canModify());
			}
		}, PrismTestUtil.createPolyString("jack"));

		assertPropertyValues(user, UserType.F_DESCRIPTION, new Validator<PrismPropertyDefinition<String>>() {
			@Override
			public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
				assertNotNull("No definition for description in user", propDef);
				assertEquals("Wrong description displayName", "Comment", propDef.getDisplayName());
				assertTrue(name+" not readable", propDef.canRead());
				assertTrue(name+" is creatable", !propDef.canAdd());
				assertTrue(name+" not modifiable", propDef.canModify());
			}
		}, "Where's the rum?");

		assertPropertyValues(user, UserType.F_ADDITIONAL_NAME, new Validator<PrismPropertyDefinition<PolyString>>() {
			@Override
			public void validate(PrismPropertyDefinition<PolyString> propDef, String name) throws Exception {
				assertNotNull("No definition for additionalName in user", propDef);
				assertEquals("Wrong additionalName displayName", "Middle Name", propDef.getDisplayName());
				assertTrue(name+" is readable", !propDef.canRead());
				assertTrue(name+" is creatable", !propDef.canAdd());
				assertTrue(name+" not modifiable", propDef.canModify());
			}
		});

		assertPropertyValues(user, UserType.F_COST_CENTER, new Validator<PrismPropertyDefinition<String>>() {
			@Override
			public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
				assertNotNull("No definition for costCenter in user", propDef);
				assertEquals("Wrong costCenter displayOrder", (Integer)123, propDef.getDisplayOrder());
				assertTrue(name+" is readable", !propDef.canRead());
				assertTrue(name+" is creatable", !propDef.canAdd());
				assertTrue(name+" is modifiable", !propDef.canModify());
			}
		});

		assertPropertyValues(user, UserType.F_PREFERRED_LANGUAGE, new Validator<PrismPropertyDefinition<String>>() {
			@Override
			public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
				assertNotNull("No definition for preferredLanguage in user", propDef);
				assertEquals("Wrong preferredLanguage displayName", "Language", propDef.getDisplayName());
				PrismReferenceValue valueEnumerationRef = propDef.getValueEnumerationRef();
				assertNotNull("No valueEnumerationRef for preferredLanguage", valueEnumerationRef);
				assertEquals("Wrong valueEnumerationRef OID for preferredLanguage", LOOKUP_LANGUAGES_OID, valueEnumerationRef.getOid());
				assertTrue(name+" is readable", !propDef.canRead());
				assertTrue(name+" is creatable", !propDef.canAdd());
				assertTrue(name+" is modifiable", !propDef.canModify());
			}
		});

		PrismAsserts.assertNoItem(user, UserType.F_CREDENTIALS);

		assertUntouchedUserDefinition();
        assertSteadyResources();
    }

    @Test
    public void test820OtisSearchUsers() throws Exception {
		final String TEST_NAME="test820OtisSearchUsers";
        TestUtil.displayTestTile(this, TEST_NAME);

        // GIVEN
        login(USER_OTIS_USERNAME);

        Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();

		// WHEN
        TestUtil.displayWhen(TEST_NAME);
		SearchResultList<PrismObject<UserType>> users = modelService.searchObjects(UserType.class, null, null, task, result);

		// THEN
		TestUtil.displayThen(TEST_NAME);
		result.computeStatus();
		TestUtil.assertSuccess(result);

		assertEquals("Unexepected number of users found", 6, users.size());

		for (final PrismObject<UserType> user: users) {
			assertProperty(user, UserType.F_NAME, new Validator<PrismPropertyDefinition<PolyString>>() {
				@Override
				public void validate(PrismPropertyDefinition<PolyString> propDef, String name) throws Exception {
					assertNotNull("No definition for name in user", propDef);
					assertEquals("Wrong name displayName", "Name", propDef.getDisplayName());
					assertTrue(name+" of "+user+" not readable", propDef.canRead());
					assertTrue(name+" of "+user+" is creatable", !propDef.canAdd());
					assertTrue(name+" of "+user+" is modifiable", !propDef.canModify());
				}
			});
			assertProperty(user, UserType.F_ADDITIONAL_NAME, new Validator<PrismPropertyDefinition<PolyString>>() {
				@Override
				public void validate(PrismPropertyDefinition<PolyString> propDef, String name) throws Exception {
					assertNotNull("No definition for additionalName in user", propDef);
					assertEquals("Wrong additionalName displayName", "Middle Name", propDef.getDisplayName());
					assertTrue(name+" of "+user+" is readable", !propDef.canRead());
					assertTrue(name+" of "+user+" is creatable", !propDef.canAdd());
					assertTrue(name+" of "+user+" not modifiable", propDef.canModify());
				}
			});
			assertProperty(user, UserType.F_COST_CENTER, new Validator<PrismPropertyDefinition<String>>() {
				@Override
				public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
					assertNotNull("No definition for costCenter in user", propDef);
					assertEquals("Wrong costCenter displayOrder", (Integer)123, propDef.getDisplayOrder());
					assertTrue(name+" of "+user+" is readable", !propDef.canRead());
					assertTrue(name+" of "+user+" is creatable", !propDef.canAdd());
					assertTrue(name+" of "+user+" is modifiable", !propDef.canModify());
				}
			});

			assertProperty(user, UserType.F_PREFERRED_LANGUAGE, new Validator<PrismPropertyDefinition<String>>() {
				@Override
				public void validate(PrismPropertyDefinition<String> propDef, String name) throws Exception {
					assertNotNull("No definition for preferredLanguage in user", propDef);
					assertEquals("Wrong preferredLanguage displayName", "Language", propDef.getDisplayName());
					PrismReferenceValue valueEnumerationRef = propDef.getValueEnumerationRef();
					assertNotNull("No valueEnumerationRef for preferredLanguage", valueEnumerationRef);
					assertEquals("Wrong valueEnumerationRef OID for preferredLanguage", LOOKUP_LANGUAGES_OID, valueEnumerationRef.getOid());
					assertTrue(name+" of "+user+" is readable", !propDef.canRead());
					assertTrue(name+" of "+user+" is creatable", !propDef.canAdd());
					assertTrue(name+" of "+user+" is modifiable", !propDef.canModify());
				}
			});

			PrismAsserts.assertNoItem(user, UserType.F_CREDENTIALS);

			assertUntouchedUserDefinition();
		}

    }

    private <O extends ObjectType, T> void assertPropertyValues(PrismObject<O> object, QName propName,
			Validator<PrismPropertyDefinition<T>> validator, T... expectedValues) throws Exception {
    	assertPropertyValues(object, new ItemPath(propName), validator, expectedValues);
    }

    private <O extends ObjectType, T> void assertProperty(PrismObject<O> object, ItemPath path,
			Validator<PrismPropertyDefinition<T>> validator) throws Exception {
    	assertPropertyValues(object, path, validator, (T[])null);
    }

    private <O extends ObjectType, T> void assertProperty(PrismObject<O> object, QName propname,
			Validator<PrismPropertyDefinition<T>> validator) throws Exception {
    	assertPropertyValues(object, new ItemPath(propname), validator, (T[])null);
    }

    private <O extends ObjectType, T> void assertPropertyValues(PrismObject<O> object, ItemPath path,
			Validator<PrismPropertyDefinition<T>> validator, T... expectedValues) throws Exception {
		PrismProperty<T> prop = object.findProperty(path);
		if (expectedValues == null) {
			if (prop != null) {
				PrismPropertyDefinition<T> propDef = prop.getDefinition();
				assertNotNull("No definition in property "+path, propDef);
				try {
					validator.validate(propDef, path.toString()+" (propDef) ");
				} catch (Exception | Error e) {
					IntegrationTestTools.display("Wrong definition", propDef);
					throw e;
				}
			}
		} else if (expectedValues.length == 0) {
			assertNull("Unexpected property "+path+" in "+object+": "+prop, prop);
		} else {
			assertNotNull("No property "+path+" in "+object, prop);
			PrismAsserts.assertPropertyValue(prop, expectedValues);
			PrismPropertyDefinition<T> propDef = prop.getDefinition();
			assertNotNull("No definition in property "+path, propDef);
			try {
				validator.validate(propDef, path.toString()+" (propDef) ");
			} catch (Exception | Error e) {
				IntegrationTestTools.display("Wrong definition", propDef);
				throw e;
			}
		}

		PrismPropertyDefinition<T> objPropDef = object.getDefinition().findPropertyDefinition(path);
		assertNotNull("No definition of property "+path+" in object "+object, objPropDef);
		try {
			validator.validate(objPropDef, path.toString()+" (objectDef) ");
		} catch (Exception | Error e) {
			IntegrationTestTools.display("Wrong definition", objPropDef);
			throw e;
		}

	}

    private <O extends ObjectType, C extends Containerable> void assertContainer(PrismObject<O> object, QName contName,
			Validator<PrismContainerDefinition<C>> validator, boolean valueExpected) throws Exception {
		PrismContainer<C> container = object.findContainer(contName);
		if (valueExpected) {
			assertNotNull("No container "+contName+" in "+object, container);
			PrismContainerDefinition<C> contDef = container.getDefinition();
			assertNotNull("No definition in container "+contName, contDef);
			validator.validate(contDef, contName.toString());
		} else {
			assertNull("Unexpected container "+contName+" in "+object+": "+container, container);
		}

		PrismContainerDefinition<C> objContDef = object.getDefinition().findContainerDefinition(contName);
		assertNotNull("No definition of container "+contName+" in object "+object, objContDef);
		validator.validate(objContDef, contName.toString());
	}

    private void assertUntouchedUserDefinition() {
        // WHEN
        PrismObjectDefinition<UserType> userDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);

		// THEN

        PrismPropertyDefinition<PolyString> descriptionDef = userDefinition.findPropertyDefinition(UserType.F_DESCRIPTION);
		assertNotNull("No definition for description in user", descriptionDef);
		assertEquals("Wrong description displayName", "Description", descriptionDef.getDisplayName());
		assertTrue("description not readable", descriptionDef.canRead());
		assertTrue("description not creatable", descriptionDef.canAdd());
		assertTrue("description not modifiable", descriptionDef.canModify());

        PrismPropertyDefinition<PolyString> additionalNameDef = userDefinition.findPropertyDefinition(UserType.F_ADDITIONAL_NAME);
		assertNotNull("No definition for additionalName in user", additionalNameDef);
		assertEquals("Wrong additionalName displayName", "Additional Name", additionalNameDef.getDisplayName());
		assertTrue("additionalName not readable", additionalNameDef.canRead());
		assertTrue("additionalName not creatable", additionalNameDef.canAdd());
		assertTrue("additionalName not modifiable", additionalNameDef.canModify());

		PrismPropertyDefinition<String> costCenterDef = userDefinition.findPropertyDefinition(UserType.F_COST_CENTER);
		assertNotNull("No definition for costCenter in user", costCenterDef);
		assertEquals("Wrong costCenter displayOrder", (Integer)420, costCenterDef.getDisplayOrder());
		assertTrue("costCenter not readable", costCenterDef.canRead());
		assertTrue("costCenter not creatable", costCenterDef.canAdd());
		assertTrue("costCenter not modifiable", costCenterDef.canModify());

		PrismPropertyDefinition<String> preferredLanguageDef = userDefinition.findPropertyDefinition(UserType.F_PREFERRED_LANGUAGE);
		assertNotNull("No definition for preferredLanguage in user", preferredLanguageDef);
		assertEquals("Wrong preferredLanguage displayName", "Preferred Language", preferredLanguageDef.getDisplayName());
		assertTrue("preferredLanguage not readable", preferredLanguageDef.canRead());
		assertTrue("preferredLanguage not creatable", preferredLanguageDef.canAdd());
		assertTrue("preferredLanguage not modifiable", preferredLanguageDef.canModify());
		PrismReferenceValue valueEnumerationRef = preferredLanguageDef.getValueEnumerationRef();
		assertNull("valueEnumerationRef for preferredLanguage sneaked in", valueEnumerationRef);

		PrismContainerDefinition<CredentialsType> credentialsDef = userDefinition.findContainerDefinition(UserType.F_CREDENTIALS);
		assertNotNull("No definition for credentials in user", credentialsDef);
		assertTrue("Credentials not readable", credentialsDef.canRead());
		assertTrue("Credentials not creatable", credentialsDef.canAdd());
		assertTrue("Credentials not modifiable", credentialsDef.canModify());

		ItemPath passwdValPath = new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE);
		PrismPropertyDefinition<ProtectedStringType> passwdValDef = userDefinition.findPropertyDefinition(passwdValPath);
		assertNotNull("No definition for "+passwdValPath+" in user", passwdValDef);
		assertTrue("Password not readable", passwdValDef.canRead());
		assertTrue("Password not creatable", passwdValDef.canAdd());
		assertTrue("Password not modifiable", passwdValDef.canModify());

    }
}


You know it's time for a pair of truly wireless earbuds when headphones cords start getting on your nerves! Plus, you won't have to worry about the headphone jack wearing out!
The xFyro xS2 earbuds have zero cords and come with a beautifully made charging dock/case with a USB out port that doubles as a mini 850 mAh power bank.
The xS2 charging case exterior is made of leather like material with gold accents around the edges where the earbuds get inserted.
The xS2 charging case charges both earbuds at the same time and acts as a carrying case. When placing the earbuds in the charging case, you want to press the home button on each earpiece to turn them off as they will not turn off automatically.
Inside the xS2 charging case you will also see metal prongs which are designed to make contact with the earbuds.
The housing of the earbuds also integrate strong magnets which hold the earbuds in and prevent them from falling out. The magnets also help to pull the earbuds tight enough so the earbuds make proper connection with the prongs when charging.
The xS2 charging case itself fully charges in 60 minutes so when the charging case is charged, the blinking blue light becomes solid blue.
Battery life is between 2 hours (at 100% volume) and 5 hours (at 45% volume). The xS2 earbuds take 2.5 hours to fully charge and hold charge pretty well so they can be on a standby for a good five days.
The xS2 come with two earbuds clearly labeled L & R and they work in stereo mode so you can hear sound from both earpieces simultaneously from the same device.
The xFyro xS2 earbuds supports multi-point Bluetooth connection too, which means you can have each earbud connected to two separate devices at one time which is an extremely useful feature to have as you can use the xS2 earbuds as a rider to rider motorcycle communication device.
When motorcycling with a backseat rider, the passenger can pair one of the earpieces with their phone so you can talk to them. The earbuds also don't protrude too far out so you can still fit a helmet comfortably.
Being able to connect each earbud individually also means that you can use the earbuds separately to listen to music so when battery runs out on one earbud you can swap it with the other earpiece (effectively doubling the battery life).
While each individual earbud can only be connected to one device at a time and you cannot skip tracks nor control the volume or activate Siri, you can play/pause music as well as accept/reject calls (single press the home button during an incoming call) and redial the last number (double press the home button).
As far as the voice calling feature, you can connect either the right or the left earbud individually so the voice calling feature can be heard on either earbud but only through the earbud that is connected as the primary earbud.
You can change the primary earbud by going to the Bluetooth settings of your phone and select "Forget" to unpair the current earbud. Then, pair the other earbud that you want to use as the primary earbud.
The xFyro xS2 earbuds are rated IP67 like the iPhone 7 so you can technically swim with the xFyro xS2 earbuds. The xFyro xS2 can be submerged under water up to 1 meter deep for up to 30 minutes. The Bluetooth signal range without obstacles is 10 meters and around 7 meters without line of sight.
Unlike other true wireless earbuds, the xFyro xS2 earbuds have a more simplified pairing process which makes connecting the xS2 earbuds to a smartphone easier. All you do is turn Bluetooth on on your phone and power on both earpieces and wait to hear the "pairing" voice prompt and for the LEDs to flash red and blue.
When you see S2 listed twice under the Bluetooth device list of your phone, click on each one to complete the pairing process and that's it. Both earpieces will sync audio to one another automatically. The entire pairing process takes less than 30 seconds which is nice.
As far as fitment, the xS2 earbuds stay pretty well embedded in your ear canal and you get three different size of eartip choices to help fitment. The music sound quality is pretty good with adequate amount of bass, while the microphone sound quality is loud and clear.


text:
Lipoprotein (a) and Diabetes
Elevated lipoprotein(a) (Lp(a)) level is a major determinant of the presence and severity of CAD (coronary artery disease) and cerebrovascular disease (CVD), and PAD (peripheral arterial disease) among patients with diabetes regardless of ethnicity.1-13
Elevated Lp(a) level is a strong independent predictor of subclinical atherosclerosis (silent heart disease) as measured by coronary artery calcification score (Heart Scan) or carotid intimal medial thickness.1, 3, 14, 15
Lp(a) is an independent determinant of aortic stiffness in elderly patients with diabetes.16
Lp(a) was associated inversely with risk of type 2 diabetes independently of risk factors, in contrast to prior findings of positive associations of Lp(a) with cardiovascular risk.17
Lp(a) levels correlate inversely with insulin levels in Type 2 diabetic patients.18 Insulin-requiring type II diabetic patients have high levels of Lp(a).19 Lp(a) may be one of the cardiovascular risk factors in type 2 diabetic patients with longer duration of diabetes.18, 20 Conversely, diabetic patients with a high Lp(a) often end up requiring insulin earlier than those without elevated Lp(a).
Lipoprotein(a) levels are inversely correlated with triglyceride levels in people with and without diabetes.7
Elevated Lp(a) level is associated with various complications including microalbuminuria, nephropathy retinopathy, amputations, heart attack, stroke, and death among patients with diabetes.21-24
Diabetes and Lp(a) increase severity of atherosclerosis and CAD and those with both conditions have extremely severe atherosclerosis. A high prevalence of this combination is a major contributor to the malignant heart disease among young Asian Indians.25
1. Qasim AN, Martin SS, Mehta NN, et al. Lipoprotein(a) is strongly associated with coronary artery calcification in type-2 diabetic women. Int J Cardiol. Mar 18 2010.
2. Mohan V, Deepa R, Haranath SP, et al. Lipoprotein(a) is an independent risk factor for coronary artery disease in NIDDM patients in South India. Diabetes Care. Nov 1998;21(11):1819-1823.
3. Velmurugan K, Deepa R, Ravikumar R, et al. Relationship of lipoprotein(a) with intimal medial thickness of the carotid artery in Type 2 diabetic patients in south India. Diabet Med. Jun 2003;20(6):455-461.
4. Gazzaruso C, Garzaniti A, Falcone C, Geroldi D, Finardi G, Fratino P. Association of lipoprotein(a) levels and apolipoprotein(a) phenotypes with coronary artery disease in Type 2 diabetic patients and in non- diabetic subjects. Diabet Med. 2001;18(7):589-594.
5. Ruiz J, Thillet J, Huby T, et al. Association of elevated lipoprotein(a) levels and coronary heart disease in NIDDM patients. Relationship with apolipoprotein(a) phenotypes. Diabetologia. 1994;37(6):585-591.
6. Rasouli M, Mohseni Kiasari A. Interactions of lipoprotein(a) with diabetes mellitus, apolipoprotein B and cholesterol enhance the prognostic values for coronary artery disease. Clin Chem Lab Med. 2008;46(5):667-673.
7. Albahrani A, Alkindi M, Marks E, Alyahyaee S, Shenkin A. Lipoprotein(a): an independent risk factor for ischemic heart disease that is dependent on triglycerides in subjects with type 2 diabetes mellitus. Lipids Health Dis. 2007;6:26.
8. Ben Hamda K, Masmoudi AS, Mandhouj O, et al. [Lipoprotein (a) and ischemic heart diseases in patients with type 2 diabetes]. Arch Inst Pasteur Tunis. 2002;79(1-4):27-33.
9. Koschinsky ML, Marcovina SM. The relationship between lipoprotein(a) and the complications of diabetes mellitus. Acta Diabetol. Jun 2003;40(2):65-76.
10. Murase T, Okubo M, Amemiya-Kudo M, Ebara T, Mori Y. Impact of elevated serum lipoprotein (a) concentrations on the risk of coronary heart disease in patients with type 2 diabetes mellitus. Metabolism. Jun 2008;57(6):791-795.
11. Gazzaruso C, Bruno R, Pujia A, et al. Lipoprotein(a), apolipoprotein(a) polymorphism and coronary atherosclerosis severity in type 2 diabetic patients. Int J Cardiol. Jun 13 2005.
12. Gazzaruso C, Bruno R, Pujia A, et al. Lipoprotein(a), apolipoprotein(a) polymorphism and coronary atherosclerosis severity in type 2 diabetic patients. Int J Cardiol. Apr 14 2006;108(3):354-358.
13. Miyao M, Araki A, Hattori A, et al. [Lipoprotein(a) as a risk factor for cardiovascular disease in elderly patients with diabetes]. Nippon Ronen Igakkai Zasshi. 1997;34(3):185-191.
14. GazzarusoC, Garzaniti A, Giordanetti S, Falcone C, Fratino P. Silent coronary artery disease in type 2 diabetes mellitus: the role of Lipoprotein(a), homocysteine and apo(a) polymorphism. Cardiovasc Diabetol. Nov 22 2002;1:5.
15. Gazzaruso C, Garzaniti A, Giordanetti S, et al. Assessment of asymptomatic coronary artery disease in apparently uncomplicated type 2 diabetic patients: a role for lipoprotein(a) and apolipoprotein(a) polymorphism. Diabetes Care. 2002;25(8):1418-1424.
16. Wakabayashi I, Masuda H. Lipoprotein (a) as a determinant of arterial stiffness in elderly patients with type 2 diabetes mellitus. Clin Chim Acta. May 17 2006.
17. Mora S., Kamstrup PR, Rifai N, Nordestgaard BG, Buring JE, Ridker PM. Lipoprotein(a) and risk of type 2 diabetes. Clin Chem. Aug 2010;56(8):1252-1260.
18. Habib SS, Aslam M, Shah SF, Naveed AK. Lipoprotein (a) is associated with basal insulin levels in patients with type 2 Diabetes Mellitus. Arq Bras Cardiol. Jul 2009;93(1):28-33.
19. Heller FR, Jamart J, Honore P, et al. Serum lipoprotein(a) in patients with diabetes mellitus. Diabetes Care. May 1993;16(5):819-823.
20. Morishita E, Asakura H, Jokaji H, et al. Hypercoagulability and high lipoprotein(a) levels in patients with type II diabetes mellitus. Atherosclerosis. Feb 1996;120(1-2):7-14.
21. Heesen BJ, Wolffenbuttel BH, Leurs PB, et al. Lipoprotein(a) levels in relation to diabetic complications in patients with non-insulin-dependent diabetes. Eur J Clin Invest. 1993;23(9):580-584.
22. Maca T, Mlekusch W, Doweik L, et al. Influence and interaction of diabetes and lipoprotein (a) serum levels on mortality of patients with peripheral artery disease. Eur J Clin Invest. Mar 2007;37(3):180-186.
23. Tarkun I, Cetinarslan B, Canturk Z. Lipoprotein(a) concentrations in patients with type 2 diabetes mellitus without cardiovascular disease: relationship to metabolic parameters and diabetic complications. Nutr Metab Cardiovasc Dis. Jun 2002;12(3):127-131.
24. Song KH, Ko SH, Kim HW, et al. Prospective study of lipoprotein(a) as a risk factor for deteriorating renal function in type 2 diabetic patients with overt proteinuria. Diabetes Care. Jul 2005;28(7):1718-1723.

redpajama_set_name: RedPajamaCommonCrawl


Sunfiber dissolves crystal clear in water. You can add it to most foods and beverages without changing their taste, aroma or texture.
Sunfiber delivers clinically substantiated health benefits and qualifies as a dietary fiber under the FDA's new, stringent definition.
Sunfiber is Non-GMO Project Verified, Low FODMAP Certified**, 100% gluten free, low calorie, Kosher, HALAL and suitable for vegan/vegetarian diets.
Your poop is a window into your health. This guide illustrates the seven common poop shapes. Know what's normal, what's not and how Sunfiber may help you become regular.


For all those who are looking to venture into forex trade, one thing is for sure that currency trade is a highly volatile business that can be unpredictable at time. This unpredictability can mar your trading prospects in stock exchange in case you are not equipped with professional information about stock exchange and its proceedings. For all those who wish to learn the ropes of forex trade, it is essential to get the best information about forex trading system so as to be well versed with currency trading and maximize the profits. For amateurs and as well as professionals, Connection2Forex is an online trading portal that provides quality forex alerts trading signals to impart genuine currency trading strategy. At Connection2Forex, one gets the best day trading signals without intraday monitor. With Connection2Forex, one hardly requires to install any software.
To provide the best forex trading strategy, Connection2Forex provides two groups of currency pairs such as USD/EUR and USD/GBP for days and at night one gets Jpy/GBP and Jpy/USD. This helps both the European and Asian economic regions. In case you are looking for accurate market analysis and prediction, Connection2Forex has a non conventional program that helps in providing the latest and update news so as to maximize the profit and reducing the risk that is often involved with investments. Forex signal offer safest levels so as to keep you at safe from market volatility. Connection2Forex is based on genuine mechanical trading algorithms where both price action and volatility are combined so as to give the best result.
As a day time trading system, Connection2Forex opens and closes on the same day while trading on both long and short position. As an online portal, Connection2Forex helps you in availing the accurate market details and making the best of investments without losing investments. Connection2Forex helps you in learning the changing trends of stock market and learning forex signal trade in an easy way. So, in case you are planning to check out some serious forex trading tips, Connection2Forex provides the best currency trading tips and techniques that will help you in minimizing your losses and providing high cash gains. Whine investing in the stock exchange make sure you are dealing with risk funds where the loss will not have any adverse effect on your finances. For more information about Connection2Forex, log on to www.Connection2forex.com and avail the best investment strategies at stock exchange. Tags-: forex trading strategy, forex, forex strategy system, forex signal, forex alerts, currency trading, Forex trading signal.