Search in sources :

Example 1 with AssignmentType

use of com.evolveum.midpoint.prism.foo.AssignmentType in project midpoint by Evolveum.

the class TestDelta method testDeltaComplex.

@Test
public void testDeltaComplex() throws Exception {
    System.out.println("\n\n===[ testDeltaComplex ]===\n");
    // GIVEN
    ObjectDelta<UserType> delta = ObjectDelta.createModificationAddProperty(UserType.class, USER_FOO_OID, UserType.F_FULL_NAME, PrismTestUtil.getPrismContext(), PrismTestUtil.createPolyString("Foo Bar"));
    PrismObjectDefinition<UserType> userTypeDefinition = getUserTypeDefinition();
    PrismContainerDefinition<ActivationType> activationDefinition = userTypeDefinition.findContainerDefinition(UserType.F_ACTIVATION);
    PrismContainer<ActivationType> activationContainer = activationDefinition.instantiate();
    PrismPropertyDefinition enabledDef = activationDefinition.findPropertyDefinition(ActivationType.F_ENABLED);
    PrismProperty<Boolean> enabledProperty = enabledDef.instantiate();
    enabledProperty.setRealValue(true);
    activationContainer.add(enabledProperty);
    delta.addModificationDeleteContainer(UserType.F_ACTIVATION, activationContainer.getValue().clone());
    PrismContainerDefinition<AssignmentType> assDef = userTypeDefinition.findContainerDefinition(UserType.F_ASSIGNMENT);
    PrismPropertyDefinition descDef = assDef.findPropertyDefinition(AssignmentType.F_DESCRIPTION);
    PrismContainerValue<AssignmentType> assVal1 = new PrismContainerValue<AssignmentType>(PrismTestUtil.getPrismContext());
    assVal1.setId(111L);
    PrismProperty<String> descProp1 = descDef.instantiate();
    descProp1.setRealValue("desc 1");
    assVal1.add(descProp1);
    PrismContainerValue<AssignmentType> assVal2 = new PrismContainerValue<AssignmentType>(PrismTestUtil.getPrismContext());
    assVal2.setId(222L);
    PrismProperty<String> descProp2 = descDef.instantiate();
    descProp2.setRealValue("desc 2");
    assVal2.add(descProp2);
    delta.addModificationAddContainer(UserType.F_ASSIGNMENT, assVal1, assVal2);
    System.out.println("Delta:");
    System.out.println(delta.debugDump());
    // WHEN, THEN
    PrismInternalTestUtil.assertVisitor(delta, 14);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(UserType.F_FULL_NAME), true, 2);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(UserType.F_ACTIVATION), true, 4);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(UserType.F_ACTIVATION, ActivationType.F_ENABLED), true, 2);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(UserType.F_ASSIGNMENT), true, 7);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), IdItemPathSegment.WILDCARD), true, 6);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(UserType.F_FULL_NAME), false, 1);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(UserType.F_ACTIVATION), false, 1);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(UserType.F_ACTIVATION, ActivationType.F_ENABLED), false, 1);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(UserType.F_ASSIGNMENT), false, 1);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), IdItemPathSegment.WILDCARD), false, 2);
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ActivationType(com.evolveum.midpoint.prism.foo.ActivationType) AssignmentType(com.evolveum.midpoint.prism.foo.AssignmentType) UserType(com.evolveum.midpoint.prism.foo.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 2 with AssignmentType

use of com.evolveum.midpoint.prism.foo.AssignmentType in project midpoint by Evolveum.

the class TestDiff method testContainerValueDiffDesciptionNoPath.

@Test
public void testContainerValueDiffDesciptionNoPath() throws Exception {
    System.out.println("\n\n===[ testContainerValueDiffDesciptionNoPath ]===\n");
    // GIVEN
    PrismObjectDefinition<UserType> userDef = getUserTypeDefinition();
    PrismContainerDefinition<AssignmentType> assignmentContDef = userDef.findContainerDefinition(UserType.F_ASSIGNMENT);
    PrismContainer<AssignmentType> ass1 = assignmentContDef.instantiate();
    PrismContainerValue<AssignmentType> ass1cval = ass1.createNewValue();
    ass1cval.setPropertyRealValue(AssignmentType.F_DESCRIPTION, "blah blah", PrismTestUtil.getPrismContext());
    PrismContainer<AssignmentType> ass2 = assignmentContDef.instantiate();
    PrismContainerValue<AssignmentType> ass2cval = ass2.createNewValue();
    ass2cval.setPropertyRealValue(AssignmentType.F_DESCRIPTION, "chamalalia patlama paprtala", PrismTestUtil.getPrismContext());
    // WHEN
    Collection<? extends ItemDelta> modifications = ass1cval.diff(ass2cval);
    // THEN
    assertNotNull(modifications);
    System.out.println(DebugUtil.debugDump(modifications));
    assertEquals("Unexpected number of midifications", 1, modifications.size());
    PrismAsserts.assertPropertyReplace(modifications, new ItemPath(UserType.F_ASSIGNMENT, AssignmentType.F_DESCRIPTION), "chamalalia patlama paprtala");
    ItemDelta.checkConsistence(modifications);
}
Also used : AssignmentType(com.evolveum.midpoint.prism.foo.AssignmentType) UserType(com.evolveum.midpoint.prism.foo.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 3 with AssignmentType

use of com.evolveum.midpoint.prism.foo.AssignmentType in project midpoint by Evolveum.

the class TestDiff method testContainerDiffModificationsDesciption.

@Test
public void testContainerDiffModificationsDesciption() throws Exception {
    System.out.println("\n\n===[ testContainerDiffModificationsDesciption ]===\n");
    // GIVEN
    PrismObjectDefinition<UserType> userDef = getUserTypeDefinition();
    PrismContainerDefinition<AssignmentType> assignmentContDef = userDef.findContainerDefinition(UserType.F_ASSIGNMENT);
    PrismContainer<AssignmentType> ass1 = assignmentContDef.instantiate();
    PrismContainerValue<AssignmentType> ass1cval = ass1.createNewValue();
    ass1cval.setId(1L);
    ass1cval.setPropertyRealValue(AssignmentType.F_DESCRIPTION, "blah blah", PrismTestUtil.getPrismContext());
    PrismContainer<AssignmentType> ass2 = assignmentContDef.instantiate();
    PrismContainerValue<AssignmentType> ass2cval = ass2.createNewValue();
    ass2cval.setId(1L);
    ass2cval.setPropertyRealValue(AssignmentType.F_DESCRIPTION, "chamalalia patlama paprtala", PrismTestUtil.getPrismContext());
    // WHEN
    Collection<? extends ItemDelta> modifications = ass1.diffModifications(ass2);
    // THEN
    assertNotNull(modifications);
    System.out.println(DebugUtil.debugDump(modifications));
    assertEquals("Unexpected number of midifications", 1, modifications.size());
    PrismAsserts.assertPropertyReplace(modifications, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(1L), new NameItemPathSegment(AssignmentType.F_DESCRIPTION)), "chamalalia patlama paprtala");
    ItemDelta.checkConsistence(modifications);
}
Also used : IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) AssignmentType(com.evolveum.midpoint.prism.foo.AssignmentType) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) UserType(com.evolveum.midpoint.prism.foo.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 4 with AssignmentType

use of com.evolveum.midpoint.prism.foo.AssignmentType in project midpoint by Evolveum.

the class TestPerformance method testPerfContainerNewValue.

/**
     * Construct object with schema. Starts by instantiating a definition and working downwards.
     * All the items in the object should have proper definition.
     */
@Test
public void testPerfContainerNewValue() throws Exception {
    final String TEST_NAME = "testPerfContainerNewValue";
    PrismInternalTestUtil.displayTestTitle(TEST_NAME);
    // GIVEN
    PrismContext ctx = constructInitializedPrismContext();
    PrismObjectDefinition<UserType> userDefinition = getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO, "user"));
    PrismObject<UserType> user = userDefinition.instantiate();
    PrismContainer<AssignmentType> assignmentContainer = user.findOrCreateContainer(UserType.F_ASSIGNMENT);
    PerfRecorder recorderCreateNewValue = new PerfRecorder("createNewValue");
    PerfRecorder recorderFindOrCreateProperty = new PerfRecorder("findOrCreateProperty");
    PerfRecorder recorderSetRealValue = new PerfRecorder("setRealValue");
    // WHEN
    for (int i = 0; i < ITERATIONS; i++) {
        long tsStart = System.nanoTime();
        PrismContainerValue<AssignmentType> newValue = assignmentContainer.createNewValue();
        long ts1 = System.nanoTime();
        PrismProperty<String> descriptionProperty = newValue.findOrCreateProperty(AssignmentType.F_DESCRIPTION);
        long ts2 = System.nanoTime();
        descriptionProperty.setRealValue("ass " + i);
        long tsEnd = System.nanoTime();
        recorderCreateNewValue.record(i, ((double) (ts1 - tsStart)) / 1000000);
        recorderFindOrCreateProperty.record(i, ((double) (ts2 - ts1)) / 1000000);
        recorderSetRealValue.record(i, ((double) (tsEnd - ts2)) / 1000000);
        System.out.println("Run " + i + ": total " + (((double) (tsEnd - tsStart)) / 1000000) + "ms");
    }
    // THEN
    System.out.println(recorderCreateNewValue.dump());
    System.out.println(recorderFindOrCreateProperty.dump());
    System.out.println(recorderCreateNewValue.dump());
    // Do not assert maximum here. The maximum values may jump around
    // quite wildly (e.g. because of garbage collector runs?)
    recorderCreateNewValue.assertAverageBelow(0.05D);
    recorderFindOrCreateProperty.assertAverageBelow(0.1D);
    recorderCreateNewValue.assertAverageBelow(0.05D);
    System.out.println("User:");
    System.out.println(user.debugDump());
}
Also used : QName(javax.xml.namespace.QName) AssignmentType(com.evolveum.midpoint.prism.foo.AssignmentType) UserType(com.evolveum.midpoint.prism.foo.UserType) Test(org.testng.annotations.Test)

Example 5 with AssignmentType

use of com.evolveum.midpoint.prism.foo.AssignmentType in project midpoint by Evolveum.

the class TestFind method testFindAssignment.

@Test
public void testFindAssignment() throws SchemaException, SAXException, IOException {
    final String TEST_NAME = "testFindAssignment";
    System.out.println("===[ " + TEST_NAME + " ]===");
    // GIVEN
    ItemPath path = new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT));
    // WHEN
    PrismContainer<AssignmentType> container = findUserContainer(path);
    // THEN
    PrismContainerValue<AssignmentType> value2 = container.getValue(USER_ASSIGNMENT_2_ID);
    assertEquals("Wrong value2 description (path=" + path + ")", "Assignment 2", value2.findProperty(AssignmentType.F_DESCRIPTION).getRealValue());
}
Also used : AssignmentType(com.evolveum.midpoint.prism.foo.AssignmentType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Aggregations

AssignmentType (com.evolveum.midpoint.prism.foo.AssignmentType)8 UserType (com.evolveum.midpoint.prism.foo.UserType)7 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 Test (org.testng.annotations.Test)7 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)6 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 ActivationType (com.evolveum.midpoint.prism.foo.ActivationType)3 QName (javax.xml.namespace.QName)2 AccountConstructionType (com.evolveum.midpoint.prism.foo.AccountConstructionType)1 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1