use of com.evolveum.prism.xml.ns._public.query_3.QueryType in project midpoint by Evolveum.
the class TestQueryConvertor method testTypeFilterQuery.
@Test
public void testTypeFilterQuery() throws Exception {
displayTestTitle("testConnectorQuery");
SearchFilterType filterType = PrismTestUtil.parseAtomicValue(FILTER_BY_TYPE_FILE, SearchFilterType.COMPLEX_TYPE);
ObjectQuery query;
try {
query = QueryJaxbConvertor.createObjectQuery(ConnectorType.class, filterType, getPrismContext());
displayQuery(query);
assertNotNull(query);
ObjectFilter filter = query.getFilter();
assertTrue("filter is not an instance of type filter", filter instanceof TypeFilter);
TypeFilter typeFilter = (TypeFilter) filter;
assertEquals(typeFilter.getType(), UserType.COMPLEX_TYPE);
assertNotNull("filter in type filter must not be null", typeFilter.getFilter());
ItemPath namePath = new ItemPath(UserType.F_NAME);
PrismPropertyDefinition ppd = getUserDefinition().findPropertyDefinition(namePath);
PrismAsserts.assertEqualsFilter(typeFilter.getFilter(), ppd.getName(), ppd.getTypeName(), namePath);
PrismAsserts.assertEqualsFilterValue((EqualFilter) typeFilter.getFilter(), PrismTestUtil.createPolyString("some name identificator"));
// PrismAsserts.assertEqualsFilter(query.getFilter(), ConnectorType.F_CONNECTOR_TYPE, DOMUtil.XSD_STRING,
// new ItemPath(ConnectorType.F_CONNECTOR_TYPE));
// PrismAsserts.assertEqualsFilterValue((EqualsFilter) filter, "org.identityconnectors.ldap.LdapConnector");
QueryType convertedQueryType = toQueryType(query);
displayQueryType(convertedQueryType);
} catch (Exception ex) {
LOGGER.error("Error while converting query: {}", ex.getMessage(), ex);
throw ex;
}
}
use of com.evolveum.prism.xml.ns._public.query_3.QueryType in project midpoint by Evolveum.
the class TestQueryConvertor method testAccountQueryAttributesAndResource.
@Test
public void testAccountQueryAttributesAndResource() throws Exception {
displayTestTitle("testAccountQueryAttributesAndResource");
SearchFilterType filterType = unmarshalFilter(FILTER_ACCOUNT_ATTRIBUTES_RESOURCE_REF_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.assertRefFilter(first, ShadowType.F_RESOURCE_REF, ObjectReferenceType.COMPLEX_TYPE, new ItemPath(ShadowType.F_RESOURCE_REF));
assertRefFilterValue((RefFilter) first, "aae7be60-df56-11df-8608-0002a5d5c51b");
ObjectFilter second = getFilterCondition(filter, 1);
PrismAsserts.assertEqualsFilter(second, ICF_NAME, DOMUtil.XSD_STRING, new ItemPath(ShadowType.F_ATTRIBUTES, ICF_NAME));
PrismAsserts.assertEqualsFilterValue((EqualFilter) second, "uid=jbond,ou=People,dc=example,dc=com");
QueryType convertedQueryType = toQueryType(query);
LOGGER.info(DOMUtil.serializeDOMToString(convertedQueryType.getFilter().getFilterClauseAsElement(getPrismContext())));
// TODO: add some asserts
}
use of com.evolveum.prism.xml.ns._public.query_3.QueryType in project midpoint by Evolveum.
the class TestQueryConvertor method test360Ref.
@Test
public void test360Ref() throws Exception {
final String TEST_NAME = "test360Ref";
displayTestTitle(TEST_NAME);
// we test only parsing here, as there are more serialized forms used here
ObjectQuery q1object = QueryBuilder.queryFor(ShadowType.class, getPrismContext()).item(ShadowType.F_RESOURCE_REF).ref("oid1").or().item(ShadowType.F_RESOURCE_REF).ref("oid2", ResourceType.COMPLEX_TYPE).or().item(ShadowType.F_RESOURCE_REF).ref("oid3").or().item(ShadowType.F_RESOURCE_REF).ref("oid4", ResourceType.COMPLEX_TYPE).build();
q1object.getFilter().checkConsistence(true);
String q2xml = FileUtils.readFileToString(new File(TEST_DIR + "/" + TEST_NAME + ".xml"));
displayQueryXml(q2xml);
QueryType q2jaxb = toQueryType(q2xml);
displayQueryType(q2jaxb);
ObjectQuery q2object = toObjectQuery(ShadowType.class, q2jaxb);
System.out.println("q1object:\n" + q1object.debugDump(1));
System.out.println("q2object:\n" + q2object.debugDump(1));
// primitive way of comparing parsed queries
assertEquals("Reparsed query is not as original one (via toString)", q1object.toString(), q2object.toString());
if (!q1object.equivalent(q2object)) {
AssertJUnit.fail("Reparsed query is not as original one (via equivalent):\nq1=" + q1object + "\nq2=" + q2object);
}
}
use of com.evolveum.prism.xml.ns._public.query_3.QueryType in project midpoint by Evolveum.
the class TestQueryConvertor method test900TypeWrong.
@Test
public void test900TypeWrong() throws Exception {
final String TEST_NAME = "test900TypeWrong";
String fileName = TEST_DIR + "/" + TEST_NAME + ".xml";
QueryType jaxb = toQueryType(FileUtils.readFileToString(new File(fileName)));
displayQueryType(jaxb);
try {
ObjectQuery query = toObjectQuery(ObjectType.class, jaxb);
displayQuery(query);
fail("Unexpected success!");
} catch (SchemaException e) {
System.out.println("Got expected exception: " + e.getMessage());
}
}
use of com.evolveum.prism.xml.ns._public.query_3.QueryType in project midpoint by Evolveum.
the class TestQueryConvertor method testConvertQueryNullFilter.
@Test
public void testConvertQueryNullFilter() throws Exception {
ObjectQuery query = ObjectQuery.createObjectQuery(ObjectPaging.createPaging(0, 10));
QueryType queryType = QueryJaxbConvertor.createQueryType(query, getPrismContext());
assertNotNull(queryType);
assertNull(queryType.getFilter());
PagingType paging = queryType.getPaging();
assertNotNull(paging);
assertEquals(new Integer(0), paging.getOffset());
assertEquals(new Integer(10), paging.getMaxSize());
}
Aggregations