Search in sources :

Example 1 with XSDElementDeclarationAdapter

use of org.eclipse.wst.xsd.contentmodel.internal.XSDImpl.XSDElementDeclarationAdapter in project webtools.sourceediting by eclipse.

the class BugFixesTest method testXSDTypeWhitespaceFacets.

// @SuppressWarnings("unchecked")
// public void testStackOverflow()
// {
// String namespaceURI = "http://www.w3.org/TR/voicexml20/vxml.xsd";
// String vxmlSchemaURI = locateFileUsingCatalog(namespaceURI);
// 
// // See bug 206138
// 
// // Two ways to test this.
// // First way. Call findTypesDerivedFrom from XSDImpl.
// 
// assertNotNull("unable to locate file for " + namespaceURI, vxmlSchemaURI);
// assertTrue("unable to locate file for " + namespaceURI, vxmlSchemaURI.length() > 0);
// XSDSchema xsdSchema = XSDImpl.buildXSDModel(vxmlSchemaURI);
// assertNotNull("failed to build model for " + vxmlSchemaURI,xsdSchema);
// boolean foundDesiredType = false;
// for (Iterator<XSDTypeDefinition> types = xsdSchema.getTypeDefinitions().iterator(); types.hasNext(); )
// {
// XSDTypeDefinition type = types.next();
// if (type instanceof XSDComplexTypeDefinition)
// {
// XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) type;
// if ("basic.event.handler".equals(complexType.getName()))
// {
// foundDesiredType = true;
// List<XSDTypeDefinition> list = XSDImpl.findTypesDerivedFrom(complexType);
// int size = list.size();
// // assertTrue(size == 1);  // if we got something back, then great, there was no out of stack error
// assertTrue("no types found in XSD", size >= 0);
// // Because of bug 203048, there is a change in behaviour to redefined types.
// // The complex type named speaker is no longer circular.   In terms of this junit, the value returned is not relevant
// // since we just want some length back (i.e. there was no crash from a stack overflow).
// break;
// }
// }
// }
// assertTrue("type \"basic.event.handler\" not found in XSD", foundDesiredType);  // if we didn't even find the complex type, then something terrible went wrong
// 
// // Second way to test via content model
// 
// CMDocumentFactoryXSD factory = new CMDocumentFactoryXSD();
// assertNotNull("Assert factory is not null", factory);
// 
// CMDocument cmDocument = factory.createCMDocument(vxmlSchemaURI);
// assertNotNull("Assert CMDocument is not null", cmDocument);
// 
// CMNamedNodeMap elements = cmDocument.getElements();
// 
// boolean foundDesiredElement = false;
// for (Iterator<CMElementDeclaration> i = elements.iterator(); i.hasNext(); )
// {
// CMElementDeclaration element = i.next();
// if ("noinput".equals(element.getElementName()))
// {
// CMNamedNodeMap attributes = element.getAttributes();
// assertNotNull(attributes);
// // assertTrue(attributes.getLength() == 3);  // if we got something back, then great, there was no out of stack error
// // Because of bug 203048, there is a change in behaviour to redefined types.
// // The complex type named speaker is no longer circular.   In terms of this junit, the value returned is not relevant
// // since we just want some length back (i.e. there was no crash from a stack overflow).
// assertTrue(attributes.getLength() >= 0);
// foundDesiredElement = true;
// break;
// }
// }
// assertTrue("element \"noinput\"r not found in XSD", foundDesiredElement);  // if we didn't even find the noinput element, then something terrible went wrong
// }
public void testXSDTypeWhitespaceFacets() {
    // Bug [194698] - Test that the correct whitespace facets are applied to the types
    String XSD_FILE_NAME = "XSDWhitespace.xsd";
    String fileURI = FILE_PROTOCOL + PLUGIN_ABSOLUTE_PATH + SAMPLES_DIR + XSD_FILE_NAME;
    CMDocumentFactoryXSD factory = new CMDocumentFactoryXSD();
    assertNotNull("Assert factory is not null", factory);
    CMDocument cmDocument = factory.createCMDocument(fileURI);
    assertNotNull("Assert CMDocument is not null", cmDocument);
    CMElementDeclaration elemDecl = (CMElementDeclaration) cmDocument.getElements().item(0);
    assertEquals("test", elemDecl.getNodeName());
    assertTrue(elemDecl.getContent() instanceof XSDModelGroupAdapter);
    XSDModelGroupAdapter group = (XSDModelGroupAdapter) elemDecl.getContent();
    CMNodeList list = group.getChildNodes();
    XSDElementDeclarationAdapter adapter = null;
    String nodeName = null, expected = null;
    CMDataType type = null;
    // Iterate over the child nodes of the element, examining the whitespace facets */
    for (int i = 0; i < list.getLength(); i++) {
        adapter = (XSDElementDeclarationAdapter) list.item(i);
        nodeName = adapter.getNodeName();
        assertNotNull(nodeName);
        assertTrue(nodeName.contains("-"));
        type = adapter.getDataType();
        assertNotNull(type);
        expected = nodeName.substring(nodeName.indexOf('-') + 1);
        assertEquals(expected, type.getProperty(XSDImpl.PROPERTY_WHITESPACE_FACET));
    }
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) XSDModelGroupAdapter(org.eclipse.wst.xsd.contentmodel.internal.XSDImpl.XSDModelGroupAdapter) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.contentmodel.internal.XSDImpl.XSDElementDeclarationAdapter) CMDocumentFactoryXSD(org.eclipse.wst.xsd.contentmodel.internal.CMDocumentFactoryXSD) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)

Aggregations

CMDataType (org.eclipse.wst.xml.core.internal.contentmodel.CMDataType)1 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)1 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)1 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)1 CMDocumentFactoryXSD (org.eclipse.wst.xsd.contentmodel.internal.CMDocumentFactoryXSD)1 XSDElementDeclarationAdapter (org.eclipse.wst.xsd.contentmodel.internal.XSDImpl.XSDElementDeclarationAdapter)1 XSDModelGroupAdapter (org.eclipse.wst.xsd.contentmodel.internal.XSDImpl.XSDModelGroupAdapter)1