Search in sources :

Example 81 with QueryType

use of net.opengis.cat.csw.v_2_0_2.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 82 with QueryType

use of net.opengis.cat.csw.v_2_0_2.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 83 with QueryType

use of net.opengis.cat.csw.v_2_0_2.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 84 with QueryType

use of net.opengis.cat.csw.v_2_0_2.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)

Example 85 with QueryType

use of net.opengis.cat.csw.v_2_0_2.QueryType in project midpoint by Evolveum.

the class TestParseTask method testSerializeTask.

@Test
public static void testSerializeTask() throws Exception {
    ObjectQuery query = QueryBuilder.queryFor(ShadowType.class, getPrismContext()).item(ShadowType.F_KIND).eq(ShadowKindType.ACCOUNT).build();
    QueryType queryType = QueryJaxbConvertor.createQueryType(query, getPrismContext());
    PrismPropertyDefinition queryDef = new PrismPropertyDefinitionImpl(SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY, QueryType.COMPLEX_TYPE, getPrismContext());
    PrismProperty<QueryType> queryProp = queryDef.instantiate();
    queryProp.setRealValue(queryType);
    TaskType taskType = getPrismContext().createObject(TaskType.class).asObjectable();
    taskType.setExtension(new ExtensionType(getPrismContext()));
    taskType.getExtension().asPrismContainerValue().add(queryProp);
    taskType.setName(PolyStringType.fromOrig("Test task"));
    String xml = getPrismContext().xmlSerializer().serialize(taskType.asPrismObject());
    System.out.println("Task serialized:\n" + xml);
    PrismObject<TaskType> taskParsed = getPrismContext().parserFor(xml).parse();
    String xmlSerializedAgain = getPrismContext().xmlSerializer().serialize(taskParsed);
    System.out.println("Task serialized again:\n" + xmlSerializedAgain);
}
Also used : ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) 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)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