use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList 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));
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList in project webtools.sourceediting by eclipse.
the class BugFixesTest method testGlobalAttr3Documentation.
private void testGlobalAttr3Documentation(CMNamedNodeMap attributes) {
CMAttributeDeclaration attribute = (CMAttributeDeclaration) attributes.getNamedItem("globalAttr3");
assertNotNull("Missing globalAttr1 attribute.");
CMNodeList documentation = (CMNodeList) attribute.getProperty("documentation");
if (documentation.getLength() == 0) {
fail("Unable to find documentation for globalAttr3");
}
assertEquals("Wrong number of documentation annotations.", 1, documentation.getLength());
assertEquals("Incorrect annotation for globalAttr3:", "PASS! Documentation for resolved attribute ref when the attribute ref has an annotation but does not have documentation", ((DocumentationImpl) documentation.item(0)).getValue().trim());
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList in project webtools.sourceediting by eclipse.
the class ModelQueryTester method testDTDLoadFromSystemID_2.
/**
* A short test to ensure that a DTD, the XHTML 1.0 Transitional one, can
* be loaded from a system reference.
*
* Note: May require a functioning network connection for the references
* to be resolved properly.
* @throws IOException
*/
public void testDTDLoadFromSystemID_2() throws IOException {
if (testShippedDTDLookup) {
URL installationPath = Platform.getBundle(JSPUITestsPlugin.ID).getEntry("/");
String diskLocation = null;
diskLocation = FileLocator.resolve(installationPath).toExternalForm();
assertTrue("failed to resolve plugin install path", diskLocation != null);
setUpXML();
String content = "<?xml version=\"1.0\"?><!DOCTYPE html SYSTEM " + diskLocation + "testfiles/XHTML/xhtml1-transitional.dtd\"" + "><html></html>";
fModel.getStructuredDocument().set(content);
CMDocumentManager documentManagaer = fModelQuery.getCMDocumentManager();
documentManagaer.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, false);
documentManagaer.setPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD, true);
// see defect 282429
CMElementDeclaration htmlDecl = (CMElementDeclaration) fModelQuery.getCMNode((Node) fModel.getIndexedRegion(content.length() - 2));
assertTrue("xhtml1-transitional.dtd not loaded", htmlDecl != null);
// HTML's children are within a group
CMContent contents = htmlDecl.getContent();
assertTrue("content type is not a group", contents.getNodeType() == CMNode.GROUP);
CMGroup group = (CMGroup) contents;
int operator = group.getOperator();
CMNodeList childList = group.getChildNodes();
int max = contents.getMaxOccur();
int min = contents.getMinOccur();
// the group should be allowed once, with a sequence whose first
// entry
// is the declaration for HEAD
assertTrue("occurrance of group", min == 1 && max == 1);
assertTrue("relationship in group", operator == CMGroup.SEQUENCE);
assertTrue("content descriptor type, position 0", contents.getNodeType() == CMNode.GROUP);
assertTrue("child order (HEAD first)", childList.item(0).getNodeName().equals(HTML40Namespace.ElementName.HEAD.toLowerCase()));
assertTrue("child order (BODY second)", childList.item(1).getNodeName().equals(HTML40Namespace.ElementName.BODY.toLowerCase()));
}
}
Aggregations