public static void assertQueriesEquivalent(String message, ObjectQuery expected, ObjectQuery real) { if (!expected.equivalent(real)) { fail(message + ": expected:\n" + expected.debugDump() + "\nreal:\n" + real.debugDump()); } }
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 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); } }