Search in sources :

Example 11 with QName

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());
}
Also used : Entry(java.util.Map.Entry) QName(javax.xml.namespace.QName) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode)

Example 12 with QName

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());
}
Also used : QName(javax.xml.namespace.QName) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) ResourceType(com.evolveum.midpoint.prism.foo.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Example 13 with QName

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"));
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) PrismTestUtil.createPolyString(com.evolveum.midpoint.prism.util.PrismTestUtil.createPolyString) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) Test(org.testng.annotations.Test)

Example 14 with QName

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);
}
Also used : QName(javax.xml.namespace.QName) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 15 with QName

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());
}
Also used : QName(javax.xml.namespace.QName) AssignmentType(com.evolveum.midpoint.prism.foo.AssignmentType) UserType(com.evolveum.midpoint.prism.foo.UserType) Test(org.testng.annotations.Test)

Aggregations

QName (javax.xml.namespace.QName)6720 Test (org.junit.Test)1407 URL (java.net.URL)1197 Service (javax.xml.ws.Service)1052 ArrayList (java.util.ArrayList)858 Bus (org.apache.cxf.Bus)486 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)462 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)395 Test (org.testng.annotations.Test)357 HashMap (java.util.HashMap)351 OMElement (org.apache.axiom.om.OMElement)344 Element (org.w3c.dom.Element)312 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)292 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)289 JBossWSTest (org.jboss.wsf.test.JBossWSTest)272 Document (org.w3c.dom.Document)263 List (java.util.List)240 IOException (java.io.IOException)218 InputStream (java.io.InputStream)218 JAXBElement (javax.xml.bind.JAXBElement)218