use of javax.xml.namespace.QName in project midpoint by Evolveum.
the class AbstractLexicalProcessorTest method assertUserJackXNodeOrdering.
protected void assertUserJackXNodeOrdering(String message, XNode xnode) {
if (xnode instanceof RootXNode) {
xnode = ((RootXNode) xnode).getSubnode();
}
MapXNode xmap = getAssertXNode(message + ": top", xnode, MapXNode.class);
Set<Entry<QName, XNode>> reTopMapEntrySet = xmap.entrySet();
Iterator<Entry<QName, XNode>> reTopMapEntrySetIter = reTopMapEntrySet.iterator();
Entry<QName, XNode> reTopMapEntry0 = reTopMapEntrySetIter.next();
assertEquals(message + ": Wrong entry 0, the xnodes were shuffled", "oid", reTopMapEntry0.getKey().getLocalPart());
Entry<QName, XNode> reTopMapEntry1 = reTopMapEntrySetIter.next();
assertEquals(message + ": Wrong entry 1, the xnodes were shuffled", "version", reTopMapEntry1.getKey().getLocalPart());
Entry<QName, XNode> reTopMapEntry2 = reTopMapEntrySetIter.next();
assertEquals(message + ": Wrong entry 2, the xnodes were shuffled", UserType.F_NAME, reTopMapEntry2.getKey());
Entry<QName, XNode> reTopMapEntry3 = reTopMapEntrySetIter.next();
assertEquals(message + ": Wrong entry 3, the xnodes were shuffled", UserType.F_DESCRIPTION, reTopMapEntry3.getKey());
}
use of javax.xml.namespace.QName in project midpoint by Evolveum.
the class AbstractLexicalProcessorTest method testParseResourceRoundTrip.
@Test
public void testParseResourceRoundTrip() throws Exception {
final String TEST_NAME = "testParseResourceRoundTrip";
displayTestTitle(TEST_NAME);
// GIVEN
LexicalProcessor<String> lexicalProcessor = createParser();
PrismContext prismContext = PrismTestUtil.getPrismContext();
// WHEN (parse)
RootXNode xnode = lexicalProcessor.read(getFileSource(RESOURCE_RUM_FILE_BASENAME), ParsingContext.createDefault());
PrismObject<ResourceType> resource = prismContext.parserFor(xnode).parse();
// THEN
System.out.println("\nParsed resource:");
System.out.println(resource.debugDump());
assertResourceRum(resource);
// WHEN (re-serialize to XNode)
XNode serializedXNode = prismContext.xnodeSerializer().options(SerializationOptions.createSerializeCompositeObjects()).serialize(resource);
String serializedString = lexicalProcessor.write(serializedXNode, new QName(NS_FOO, "resource"), null);
// THEN
System.out.println("\nXNode after re-serialization:");
System.out.println(serializedXNode.debugDump());
System.out.println("\nRe-serialized string:");
System.out.println(serializedString);
validateResourceSchema(serializedString, prismContext);
// WHEN (re-parse)
RootXNode reparsedXnode = lexicalProcessor.read(new ParserStringSource(serializedString), ParsingContext.createDefault());
PrismObject<ResourceType> reparsedResource = prismContext.parserFor(reparsedXnode).parse();
// THEN
System.out.println("\nXNode after re-parsing:");
System.out.println(reparsedXnode.debugDump());
System.out.println("\nRe-parsed resource:");
System.out.println(reparsedResource.debugDump());
ObjectDelta<ResourceType> diff = DiffUtil.diff(resource, reparsedResource);
System.out.println("\nDiff:");
System.out.println(diff.debugDump());
assertTrue("Re-parsed user does not match: " + diff, diff.isEmpty());
}
use of javax.xml.namespace.QName in project midpoint by Evolveum.
the class TestQueryConvertors method testFilterTypeUserNone.
@Test
public void testFilterTypeUserNone() throws Exception {
displayTestTitle("testFilterTypeUserNone");
SearchFilterType filterType = PrismTestUtil.parseAnyValue(FILTER_TYPE_USER_NONE);
ObjectQuery query = toObjectQuery(UserType.class, filterType);
displayQuery(query);
assertNotNull(query);
ObjectFilter filter = query.getFilter();
assertTrue("Filter is not of TYPE type", filter instanceof TypeFilter);
ObjectFilter subFilter = ((TypeFilter) filter).getFilter();
assertTrue("Filter is not of NONE type", subFilter instanceof NoneFilter);
QueryType convertedQueryType = toQueryType(query);
System.out.println("Re-converted query type");
System.out.println(convertedQueryType.debugDump());
Element filterClauseElement = convertedQueryType.getFilter().getFilterClauseAsElement(getPrismContext());
LOGGER.info(convertedQueryType.getFilter().getFilterClauseXNode().debugDump());
System.out.println("Serialized filter (JAXB->DOM)");
String filterAsString = DOMUtil.serializeDOMToString(filterClauseElement);
System.out.println(filterAsString);
LOGGER.info(filterAsString);
DomAsserts.assertElementQName(filterClauseElement, new QName(PrismConstants.NS_QUERY, "type"));
}
use of javax.xml.namespace.QName in project midpoint by Evolveum.
the class TestPath method testPathRemainder.
@Test
public void testPathRemainder() throws Exception {
System.out.println("\n\n===[ testPathRemainder ]===\n");
// GIVEN
ItemPath pathFoo = new ItemPath(new QName(NS, "foo"));
ItemPath pathBar = new ItemPath(new QName(NS, "bar"));
ItemPath pathFooNull = new ItemPath(new NameItemPathSegment(new QName(NS, "foo")), new IdItemPathSegment());
ItemPath pathFoo123 = new ItemPath(new NameItemPathSegment(new QName(NS, "foo")), new IdItemPathSegment(123L));
ItemPath pathFooBar = new ItemPath(new QName(NS, "foo"), new QName(NS, "bar"));
ItemPath pathFooNullBar = new ItemPath(new NameItemPathSegment(new QName(NS, "foo")), new IdItemPathSegment(), new NameItemPathSegment(new QName(NS, "bar")));
// WHEN
ItemPath remainder1 = pathFooBar.remainder(pathFooNull);
// THEN
assertEquals("Remainder fooBar, fooNull", pathBar, remainder1);
}
use of javax.xml.namespace.QName in project midpoint by Evolveum.
the class TestPerformance method testPerfContainerNewValue.
/**
* Construct object with schema. Starts by instantiating a definition and working downwards.
* All the items in the object should have proper definition.
*/
@Test
public void testPerfContainerNewValue() throws Exception {
final String TEST_NAME = "testPerfContainerNewValue";
PrismInternalTestUtil.displayTestTitle(TEST_NAME);
// GIVEN
PrismContext ctx = constructInitializedPrismContext();
PrismObjectDefinition<UserType> userDefinition = getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO, "user"));
PrismObject<UserType> user = userDefinition.instantiate();
PrismContainer<AssignmentType> assignmentContainer = user.findOrCreateContainer(UserType.F_ASSIGNMENT);
PerfRecorder recorderCreateNewValue = new PerfRecorder("createNewValue");
PerfRecorder recorderFindOrCreateProperty = new PerfRecorder("findOrCreateProperty");
PerfRecorder recorderSetRealValue = new PerfRecorder("setRealValue");
// WHEN
for (int i = 0; i < ITERATIONS; i++) {
long tsStart = System.nanoTime();
PrismContainerValue<AssignmentType> newValue = assignmentContainer.createNewValue();
long ts1 = System.nanoTime();
PrismProperty<String> descriptionProperty = newValue.findOrCreateProperty(AssignmentType.F_DESCRIPTION);
long ts2 = System.nanoTime();
descriptionProperty.setRealValue("ass " + i);
long tsEnd = System.nanoTime();
recorderCreateNewValue.record(i, ((double) (ts1 - tsStart)) / 1000000);
recorderFindOrCreateProperty.record(i, ((double) (ts2 - ts1)) / 1000000);
recorderSetRealValue.record(i, ((double) (tsEnd - ts2)) / 1000000);
System.out.println("Run " + i + ": total " + (((double) (tsEnd - tsStart)) / 1000000) + "ms");
}
// THEN
System.out.println(recorderCreateNewValue.dump());
System.out.println(recorderFindOrCreateProperty.dump());
System.out.println(recorderCreateNewValue.dump());
// Do not assert maximum here. The maximum values may jump around
// quite wildly (e.g. because of garbage collector runs?)
recorderCreateNewValue.assertAverageBelow(0.05D);
recorderFindOrCreateProperty.assertAverageBelow(0.1D);
recorderCreateNewValue.assertAverageBelow(0.05D);
System.out.println("User:");
System.out.println(user.debugDump());
}
Aggregations