Search in sources :

Example 81 with QueryType

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;
    }
}
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) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 82 with QueryType

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
}
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 83 with QueryType

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);
    }
}
Also used : File(java.io.File) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) Test(org.testng.annotations.Test)

Example 84 with QueryType

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());
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) File(java.io.File) Test(org.testng.annotations.Test)

Example 85 with QueryType

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());
}
Also used : PagingType(com.evolveum.prism.xml.ns._public.query_3.PagingType) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) 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)33 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 Task (com.evolveum.midpoint.task.api.Task)13 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 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 Holder (javax.xml.ws.Holder)12 GetFeatureType (ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)12