use of org.eclipse.wst.xsd.contentmodel.internal.CMDocumentFactoryXSD in project webtools.sourceediting by eclipse.
the class BugFixesTest method testXSITypeVsTypeAttr.
public void testXSITypeVsTypeAttr() {
// See bug 225447, 225819
// Load the XSD file
String XSD_FILE_NAME = "XSITypeTest.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);
// Check and obtain the two global elements (elementA and elementB)
CMNamedNodeMap elements = cmDocument.getElements();
assertEquals(elements.getLength(), 2);
CMElementDeclaration cmElementDeclaration = (CMElementDeclaration) elements.item(0);
CMElementDeclaration cmElementDeclarationA = null;
CMElementDeclaration cmElementDeclarationB = null;
if ("elementA".equals(cmElementDeclaration.getElementName())) {
cmElementDeclarationA = cmElementDeclaration;
cmElementDeclarationB = (CMElementDeclaration) elements.item(1);
} else {
cmElementDeclarationB = cmElementDeclaration;
cmElementDeclarationA = (CMElementDeclaration) elements.item(1);
}
// elementA has a "type" attribute with "X" enumerated value, make sure it appears in the model
CMNamedNodeMap attributesA = cmElementDeclarationA.getAttributes();
assertEquals(attributesA.getLength(), 1);
CMAttributeDeclaration cmAttributeDeclarationA = (CMAttributeDeclaration) attributesA.item(0);
assertEquals("type", cmAttributeDeclarationA.getAttrName());
CMDataType attrTypeA = cmAttributeDeclarationA.getAttrType();
String[] enumeratedValuesA = attrTypeA.getEnumeratedValues();
assertEquals(1, enumeratedValuesA.length);
assertEquals("X", enumeratedValuesA[0]);
// elementB does not have a "type" attribute, make sure the xsi:type appears in the model
CMNamedNodeMap attributesB = cmElementDeclarationB.getAttributes();
assertEquals(attributesB.getLength(), 1);
CMAttributeDeclaration cmAttributeDeclarationB = (CMAttributeDeclaration) attributesB.item(0);
assertEquals("type", cmAttributeDeclarationB.getAttrName());
CMDataType attrTypeB = cmAttributeDeclarationB.getAttrType();
assertEquals("typeNames", attrTypeB.getDataTypeName());
}
use of org.eclipse.wst.xsd.contentmodel.internal.CMDocumentFactoryXSD in project webtools.sourceediting by eclipse.
the class BugFixesTest method testXSIType.
// Add tests here
@SuppressWarnings("unchecked")
public void testXSIType() {
String soapSchemaURI = locateFileUsingCatalog("http://schemas.xmlsoap.org/wsdl/soap/");
CMDocumentFactoryXSD factory = new CMDocumentFactoryXSD();
assertNotNull("Assert factory is not null", factory);
CMDocument cmDocument = factory.createCMDocument(soapSchemaURI);
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 ("binding".equals(element.getElementName())) {
foundDesiredElement = true;
CMNamedNodeMap attributes = element.getAttributes();
// Three attributes: required, transport and style
assertNotNull(attributes);
// If the xsi:type was present, it would be 4 attributes
assertTrue(attributes.getLength() == 3);
CMNode attrNode = null;
attrNode = attributes.getNamedItem("required");
assertNotNull(attrNode);
attrNode = attributes.getNamedItem("transport");
assertNotNull(attrNode);
attrNode = attributes.getNamedItem("style");
assertNotNull(attrNode);
// Should be null!
attrNode = attributes.getNamedItem("type");
assertNull(attrNode);
break;
}
}
// if we didn't even find the binding element, then something terrible went wrong
assertTrue(foundDesiredElement);
}
use of org.eclipse.wst.xsd.contentmodel.internal.CMDocumentFactoryXSD 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));
}
}
Aggregations