Search in sources :

Example 41 with MapXNode

use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.

the class TestJaxbConstruction method testUserConstructionBeforeAdopt.

@Test
public void testUserConstructionBeforeAdopt() throws Exception {
    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    UserType userType = new UserType();
    userType.setFullName(new PolyStringType("Čučoriedka"));
    userType.setDescription("blah blah");
    ExtensionType extension = new ExtensionType();
    userType.setExtension(extension);
    AssignmentType assignmentType = new AssignmentType();
    userType.getAssignment().add(assignmentType);
    // Assignment
    ExtensionType assignmentExtension = new ExtensionType();
    assignmentType.setExtension(assignmentExtension);
    // accountRef/account
    ObjectReferenceType accountRefType = new ObjectReferenceType();
    accountRefType.setOid(USER_ACCOUNT_REF_1_OID);
    MapXNode filterElement = createFilter();
    SearchFilterType filter = new SearchFilterType();
    filter.setFilterClauseXNode(filterElement);
    accountRefType.setFilter(filter);
    userType.getLinkRef().add(accountRefType);
    ShadowType accountShadowType = new ShadowType();
    prismContext.adopt(accountShadowType);
    accountShadowType.setOid(USER_ACCOUNT_REF_1_OID);
    ObjectReferenceType accountRef1 = new ObjectReferenceType();
    accountRef1.asReferenceValue().setObject(accountShadowType.asPrismObject());
    userType.getLinkRef().add(accountRef1);
    ObjectReferenceType accountRef2 = new ObjectReferenceType();
    accountRef2.setOid(USER_ACCOUNT_REF_2_OID);
    userType.getLinkRef().add(accountRef2);
    // WHEN
    prismContext.adopt(userType);
    // THEN
    PrismObject<UserType> user = userType.asPrismObject();
    assertNotNull("No object definition after adopt", user.getDefinition());
    SchemaTestUtil.assertUserDefinition(user.getDefinition());
    // fullName: PolyString
    PrismProperty<PolyString> fullNameProperty = user.findProperty(UserType.F_FULL_NAME);
    user.checkConsistence();
    user.assertDefinitions();
    PolyString fullName = fullNameProperty.getRealValue();
    assertEquals("Wrong fullName orig", "Čučoriedka", fullName.getOrig());
    assertEquals("Wrong fullName norm", "cucoriedka", fullName.getNorm());
    PrismProperty<String> descriptionProperty = user.findProperty(UserType.F_DESCRIPTION);
    assertEquals("Wrong description value", "blah blah", descriptionProperty.getRealValue());
    PrismContainer<Containerable> extensionContainer = user.findContainer(GenericObjectType.F_EXTENSION);
    checkExtension(extensionContainer, "user extension");
    checkExtension(extension, "user extension");
    PrismReference accountRef = user.findReference(UserType.F_LINK_REF);
    assertEquals("Wrong accountRef values", 2, accountRef.getValues().size());
    PrismAsserts.assertReferenceValues(accountRef, USER_ACCOUNT_REF_1_OID, USER_ACCOUNT_REF_2_OID);
    PrismReferenceValue accountRefVal0 = accountRef.getAnyValue();
    SearchFilterType prismFilter = accountRefVal0.getFilter();
    assertNotNull("Filter have not passed", prismFilter);
    // assertTrue("Wrong filter in reference " , prismFilter instanceof EqualsFilter);
    // assertEquals("Difference filter", filterElement, prismFilter);
    assertAccountRefs(userType, USER_ACCOUNT_REF_1_OID, USER_ACCOUNT_REF_2_OID);
    user.assertDefinitions();
    user.checkConsistence();
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) PrismTestUtil.getPrismContext(com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Example 42 with MapXNode

use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.

the class TestQueryConverter method testAccountFilter.

@Test
public void testAccountFilter() throws Exception {
    SearchFilterType filterType = unmarshalFilter(FILTER_ACCOUNT_FILE);
    ObjectQuery query = toObjectQuery(ShadowType.class, filterType);
    displayQuery(query);
    assertNotNull(query);
    ObjectFilter filter = query.getFilter();
    PrismAsserts.assertAndFilter(filter, 2);
    ObjectFilter first = getFilterCondition(filter, 0);
    PrismAsserts.assertEqualsFilter(first, ShadowType.F_TAG, PrimitiveType.XSD_STRING, ShadowType.F_TAG);
    PrismAsserts.assertEqualsFilterValue((EqualFilter) first, "abc");
    ObjectFilter second = getFilterCondition(filter, 1);
    PrismAsserts.assertEqualsFilter(second, ShadowType.F_NAME, PolyStringType.COMPLEX_TYPE, ShadowType.F_NAME);
    PrismAsserts.assertEqualsFilterValue((EqualFilter) second, createPolyString("someName"));
    QueryType convertedQueryType = toQueryType(query);
    System.out.println("Re-converted query type");
    System.out.println(convertedQueryType.debugDump());
    SearchFilterType convertedFilterType = convertedQueryType.getFilter();
    MapXNode xFilter = convertedFilterType.serializeToXNode(getPrismContext());
    PrismAsserts.assertSize(xFilter, 1);
    PrismAsserts.assertSubnode(xFilter, AndFilter.ELEMENT_NAME, MapXNode.class);
    MapXNode xandmap = (MapXNode) xFilter.get(AndFilter.ELEMENT_NAME);
    PrismAsserts.assertSize(xandmap, 1);
    PrismAsserts.assertSubnode(xandmap, EqualFilter.ELEMENT_NAME, ListXNode.class);
    ListXNode xequalsList = (ListXNode) xandmap.get(EqualFilter.ELEMENT_NAME);
    PrismAsserts.assertSize(xequalsList, 2);
// Element filterClauseElement = convertedFilterType.getFilterClauseAsElement(getPrismContext());
// System.out.println("Serialized filter (JAXB->DOM)");
// System.out.println(DOMUtil.serializeDOMToString(filterClauseElement));
// 
// DomAsserts.assertElementQName(filterClauseElement, AndFilter.ELEMENT_NAME);
// DomAsserts.assertSubElements(filterClauseElement, 2);
// 
// Element firstSubelement = DOMUtil.getChildElement(filterClauseElement, 0);
// DomAsserts.assertElementQName(firstSubelement, EqualFilter.ELEMENT_NAME);
// Element firstValueElement = DOMUtil.getChildElement(firstSubelement, PrismConstants.Q_VALUE);
// DomAsserts.assertTextContent(firstValueElement, "abc");
// 
// Element secondSubelement = DOMUtil.getChildElement(filterClauseElement, 1);
// DomAsserts.assertElementQName(secondSubelement, EqualFilter.ELEMENT_NAME);
// Element secondValueElement = DOMUtil.getChildElement(secondSubelement, PrismConstants.Q_VALUE);
// DomAsserts.assertTextContent(secondValueElement, "someName");
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) Test(org.testng.annotations.Test) AbstractUnitTest(com.evolveum.midpoint.tools.testng.AbstractUnitTest)

Aggregations

MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)42 QName (javax.xml.namespace.QName)24 RootXNode (com.evolveum.midpoint.prism.xnode.RootXNode)21 XNode (com.evolveum.midpoint.prism.xnode.XNode)18 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)15 ListXNode (com.evolveum.midpoint.prism.xnode.ListXNode)13 Test (org.testng.annotations.Test)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)9 SchemaXNode (com.evolveum.midpoint.prism.xnode.SchemaXNode)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)7 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)7 Element (org.w3c.dom.Element)6 PrismContext (com.evolveum.midpoint.prism.PrismContext)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)4 Protector (com.evolveum.midpoint.prism.crypto.Protector)3 EncryptedDataType (com.evolveum.prism.xml.ns._public.types_3.EncryptedDataType)3 NotNull (org.jetbrains.annotations.NotNull)3 TestProtector (com.evolveum.midpoint.prism.crypto.TestProtector)2