@Test public void test910TypeWrongCompat() throws Exception { final String TEST_NAME = "test900TypeWrong"; String fileName = TEST_DIR + "/" + TEST_NAME + ".xml"; QueryType jaxb = toQueryTypeCompat(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()); } }
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); assertEquals("Reparsed query is not as original one (via toString)", q1object.toString(), q2object.toString()); // primitive way of comparing parsed queries assertTrue("Reparsed query is not as original one (via equivalent):\nq1="+q1object+"\nq2="+q2object, q1object.equivalent(q2object)); }
@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 = getPrismContext().queryFor(OrgType.class).isChildOf("333").build(); assertEquals("Parsed query is wrong", expectedQuery.toString(), query.toString()); // primitive way of comparing queries // 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); }
@Test public void testConnectorQuery() throws Exception { displayTestTitle("testConnectorQuery"); SearchFilterType filterType = PrismTestUtil.parseAtomicValue(FILTER_CONNECTOR_BY_TYPE_FILE, SearchFilterType.COMPLEX_TYPE); ObjectQuery query; try { query = getQueryConverter().createObjectQuery(ConnectorType.class, filterType); displayQuery(query); assertNotNull(query); ObjectFilter filter = query.getFilter(); PrismAsserts.assertEqualsFilter(query.getFilter(), ConnectorType.F_CONNECTOR_TYPE, DOMUtil.XSD_STRING, ConnectorType.F_CONNECTOR_TYPE); PrismAsserts.assertEqualsFilterValue((EqualFilter) 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; } }
@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 = getPrismContext().queryFor(ShadowType.class) .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)); assertEquals("Reparsed query is not as original one (via toString)", q1object.toString(), q2object.toString()); // primitive way of comparing parsed queries if (!q1object.equivalent(q2object)) { AssertJUnit.fail("Reparsed query is not as original one (via equivalent):\nq1="+q1object+"\nq2="+q2object); } }
@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, 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, ItemPath.create( 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); }
@Test public void testShadowKindTypeQuery() throws Exception { displayTestTitle("testShadowKindTypeQuery"); SearchFilterType filterType = PrismTestUtil.parseAtomicValue(FILTER_BY_TYPE_FILE, SearchFilterType.COMPLEX_TYPE); ObjectQuery query; try { ObjectFilter kindFilter = getPrismContext().queryFor(ShadowType.class) .item(ShadowType.F_KIND).eq(ShadowKindType.ACCOUNT) .buildFilter(); query = getQueryFactory().createQuery(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; } }
displayQueryType(convertedQueryType); } catch (Exception ex) { LOGGER.error("Error while converting query: {}", ex.getMessage(), ex);