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();
}
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");
}
Aggregations