Search in sources :

Example 11 with QueryType

use of org.apache.openejb.jee.oejb2.QueryType in project midpoint by Evolveum.

the class TestQueryConvertor method checkQuery.

private void checkQuery(Class<? extends Containerable> objectClass, ObjectQuery q1object, String q2xml) throws Exception {
    // step 1 (serialization of Q1 + comparison)
    displayText("Query 1:");
    displayQuery(q1object);
    QueryType q1jaxb = toQueryType(q1object);
    displayQueryType(q1jaxb);
    String q1xml = toXml(q1jaxb);
    displayQueryXml(q1xml);
    //		XMLAssert.assertXMLEqual("Serialized query is not correct: Expected:\n" + q2xml + "\n\nReal:\n" + q1xml, q2xml, q1xml);
    // step 2 (parsing of Q2 + comparison)
    displayText("Query 2:");
    displayQueryXml(q2xml);
    QueryType q2jaxb = toQueryType(q2xml);
    displayQueryType(q2jaxb);
    ObjectQuery q2object = toObjectQuery(objectClass, q2jaxb);
    // primitive way of comparing parsed queries
    assertEquals("Reparsed query is not as original one (via toString)", q1object.toString(), q2object.toString());
    assertTrue("Reparsed query is not as original one (via equivalent):\nq1=" + q1object + "\nq2=" + q2object, q1object.equivalent(q2object));
}
Also used : QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Example 12 with QueryType

use of org.apache.openejb.jee.oejb2.QueryType in project midpoint by Evolveum.

the class TestQueryConvertor method testAccountQueryCompositeOr.

@Test
public void testAccountQueryCompositeOr() throws Exception {
    displayTestTitle("testAccountQueryCompositeOr");
    SearchFilterType filterType = unmarshalFilter(FILTER_OR_COMPOSITE);
    ObjectQuery query = toObjectQuery(ShadowType.class, filterType);
    displayQuery(query);
    assertNotNull(query);
    ObjectFilter filter = query.getFilter();
    PrismAsserts.assertOrFilter(filter, 4);
    ObjectFilter first = getFilterCondition(filter, 0);
    PrismAsserts.assertEqualsFilter(first, ShadowType.F_INTENT, DOMUtil.XSD_STRING, new ItemPath(ShadowType.F_INTENT));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) first, "some account type");
    ObjectFilter second = getFilterCondition(filter, 1);
    PrismAsserts.assertEqualsFilter(second, fooBlaDefinition, DOMUtil.XSD_STRING, new ItemPath(ShadowType.F_ATTRIBUTES, fooBlaDefinition));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) second, "foo value");
    ObjectFilter third = getFilterCondition(filter, 2);
    PrismAsserts.assertEqualsFilter(third, stringExtensionDefinition, DOMUtil.XSD_STRING, new ItemPath(ShadowType.F_EXTENSION, stringExtensionDefinition));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) third, "uid=test,dc=example,dc=com");
    ObjectFilter forth = getFilterCondition(filter, 3);
    PrismAsserts.assertRefFilter(forth, ShadowType.F_RESOURCE_REF, ObjectReferenceType.COMPLEX_TYPE, new ItemPath(ShadowType.F_RESOURCE_REF));
    assertRefFilterValue((RefFilter) forth, "d0db5be9-cb93-401f-b6c1-86ffffe4cd5e");
    QueryType convertedQueryType = toQueryType(query);
    LOGGER.info(DOMUtil.serializeDOMToString(convertedQueryType.getFilter().getFilterClauseAsElement(getPrismContext())));
// TODO: add some asserts
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 13 with QueryType

use of org.apache.openejb.jee.oejb2.QueryType in project midpoint by Evolveum.

the class TestQueryConvertor method testShadowKindTypeQuery.

@Test
public void testShadowKindTypeQuery() throws Exception {
    displayTestTitle("testShadowKindTypeQuery");
    SearchFilterType filterType = PrismTestUtil.parseAtomicValue(FILTER_BY_TYPE_FILE, SearchFilterType.COMPLEX_TYPE);
    ObjectQuery query;
    try {
        ObjectFilter kindFilter = QueryBuilder.queryFor(ShadowType.class, getPrismContext()).item(ShadowType.F_KIND).eq(ShadowKindType.ACCOUNT).buildFilter();
        query = ObjectQuery.createObjectQuery(kindFilter);
        assertNotNull(query);
        ObjectFilter filter = query.getFilter();
        assertTrue("filter is not an instance of type filter", filter instanceof EqualFilter);
        EqualFilter typeFilter = (EqualFilter) filter;
        assertEquals(typeFilter.getSingleValue().getRealValue(), ShadowKindType.ACCOUNT);
        QueryType convertedQueryType = toQueryType(query);
        toObjectQuery(ShadowType.class, convertedQueryType);
        displayQueryType(convertedQueryType);
    } catch (Exception ex) {
        LOGGER.error("Error while converting query: {}", ex.getMessage(), ex);
        throw ex;
    }
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) Test(org.testng.annotations.Test)

Example 14 with QueryType

use of org.apache.openejb.jee.oejb2.QueryType in project midpoint by Evolveum.

the class TestQueryConvertor method test430OrgFilterDefaultScope.

@Test
public void test430OrgFilterDefaultScope() throws Exception {
    final String TEST_NAME = "test430OrgFilterDefaultScope";
    displayTestTitle(TEST_NAME);
    // default scope is SUBTREE
    String queryXml = "<?xml version='1.0'?><query><filter><org>\n" + "        <orgRef>\n" + "            <oid>333</oid>\n" + "        </orgRef>\n" + "    </org></filter></query>";
    QueryType queryJaxb = toQueryType(queryXml);
    displayQueryType(queryJaxb);
    ObjectQuery query = toObjectQuery(OrgType.class, queryJaxb);
    displayQuery(query);
    ObjectQuery expectedQuery = QueryBuilder.queryFor(OrgType.class, getPrismContext()).isChildOf("333").build();
    // primitive way of comparing queries
    assertEquals("Parsed query is wrong", expectedQuery.toString(), query.toString());
    // now reserialize the parsed query and compare with XML - the XML contains explicit scope=SUBTREE (as this is set when parsing original queryXml)
    checkQueryRoundtripFile(OrgType.class, query, TEST_NAME);
}
Also used : QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) Test(org.testng.annotations.Test)

Example 15 with QueryType

use of org.apache.openejb.jee.oejb2.QueryType in project midpoint by Evolveum.

the class TestQueryConvertor method testGenericQuery.

@Test
public void testGenericQuery() throws Exception {
    displayTestTitle("testGenericQuery");
    SearchFilterType queryType = unmarshalFilter(FILTER_AND_GENERIC_FILE);
    ObjectQuery query = toObjectQuery(GenericObjectType.class, queryType);
    displayQuery(query);
    // check parent filter
    assertNotNull(query);
    ObjectFilter filter = query.getFilter();
    PrismAsserts.assertAndFilter(filter, 2);
    // check first condition
    ObjectFilter first = getFilterCondition(filter, 0);
    PrismAsserts.assertEqualsFilter(first, GenericObjectType.F_NAME, PolyStringType.COMPLEX_TYPE, new ItemPath(GenericObjectType.F_NAME));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) first, createPolyString("generic object"));
    // check second condition
    ObjectFilter second = getFilterCondition(filter, 1);
    PrismAsserts.assertEqualsFilter(second, intExtensionDefinition, DOMUtil.XSD_INT, new ItemPath(ObjectType.F_EXTENSION, new QName(NS_EXTENSION, "intType")));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) second, 123);
    QueryType convertedQueryType = toQueryType(query);
    assertNotNull("Re-serialized query is null ", convertedQueryType);
    assertNotNull("Filter in re-serialized query must not be null.", convertedQueryType.getFilter());
    displayQueryType(convertedQueryType);
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Aggregations

QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)57 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)41 Test (org.junit.Test)40 QueryImpl (ddf.catalog.operation.impl.QueryImpl)37 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)36 QName (javax.xml.namespace.QName)34 Test (org.testng.annotations.Test)32 JAXBElement (javax.xml.bind.JAXBElement)27 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)24 ArrayList (java.util.ArrayList)24 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)20 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)17 Matchers.anyString (org.mockito.Matchers.anyString)14 ObjectListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType)13 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)12 Task (com.evolveum.midpoint.task.api.Task)12 Holder (javax.xml.ws.Holder)12 GetFeatureType (ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)12 QueryType (ogc.schema.opengis.wfs.v_1_0_0.QueryType)12