use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.
the class UtilTest method testIsSimpleTypedParticle.
@Test
public void testIsSimpleTypedParticle() {
boolean isSimpleTypedParticle = Util.isSimpleTypedParticle(null);
assertFalse(isSimpleTypedParticle);
XSDFactory factory = XSDFactory.eINSTANCE;
XSDParticle particle = factory.createXSDParticle();
isSimpleTypedParticle = Util.isSimpleTypedParticle(particle);
assertFalse(isSimpleTypedParticle);
XSDElementDeclaration elementDeclaration = factory.createXSDElementDeclaration();
elementDeclaration.setTypeDefinition(factory.createXSDSimpleTypeDefinition());
particle.setContent(elementDeclaration);
isSimpleTypedParticle = Util.isSimpleTypedParticle(particle);
assertTrue(isSimpleTypedParticle);
XSDModelGroup modelGroup = factory.createXSDModelGroup();
particle.setContent(modelGroup);
isSimpleTypedParticle = Util.isSimpleTypedParticle(particle);
assertFalse(isSimpleTypedParticle);
}
use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.
the class UtilTest method testGetComplexTypeDefinitionChildren.
/**
* Test method for
* {@link com.amalto.workbench.utils.Util#getComplexTypeDefinitionChildren(org.eclipse.xsd.XSDComplexTypeDefinition, boolean)}
* .
*/
@Test
public void testGetComplexTypeDefinitionChildren() throws Exception {
// get test model
XSDSchema xsdSchema = getXSDSchema();
EList<XSDElementDeclaration> elementDeclarations = xsdSchema.getElementDeclarations();
// test
assertEquals(1, elementDeclarations.size());
XSDTypeDefinition typeDefinition = elementDeclarations.get(0).getTypeDefinition();
ArrayList<Object> children = Util.getComplexTypeDefinitionChildren((XSDComplexTypeDefinition) typeDefinition, true);
assertEquals(3, children.size());
children = Util.getComplexTypeDefinitionChildren((XSDComplexTypeDefinition) typeDefinition, false);
assertEquals(1, children.size());
}
use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.
the class UtilTest method testGetChildElements4TypeArg.
@Test
public void testGetChildElements4TypeArg() throws Exception {
EList<XSDElementDeclaration> xsdElementDeclarations = schema.getElementDeclarations();
XSDElementDeclaration conceptEl = null;
for (XSDElementDeclaration el : xsdElementDeclarations) {
if (el.getName().equals("Entity")) {
// $NON-NLS-1$
conceptEl = el;
break;
}
}
assertNotNull(conceptEl);
Map<String, XSDParticle> childElements = Util.getChildElements("", (XSDComplexTypeDefinition) conceptEl.getTypeDefinition(), false, // $NON-NLS-1$
new HashSet<Object>());
assertNotNull(childElements);
assertEquals(7, childElements.size());
}
use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.
the class XSDUtilTest method testIsFirstLevelChild.
@Test
public void testIsFirstLevelChild() throws Exception {
// $NON-NLS-1$
String fileName = "Product_0.1.xsd";
// $NON-NLS-1$
String elementName = "Product";
String xsdString = TestUtil.readTestResource(XSDUtilTest.this.getClass(), fileName);
assertNotNull(xsdString);
XSDSchema xsdSchema = Util.getXSDSchema(xsdString);
XSDElementDeclaration decl = null;
for (XSDElementDeclaration element : xsdSchema.getElementDeclarations()) {
if (element.getName().equals(elementName)) {
decl = element;
}
}
if (decl != null) {
XSDComplexTypeDefinition ctypeDefinition = (XSDComplexTypeDefinition) decl.getTypeDefinition();
XSDComplexTypeContent content = ctypeDefinition.getContent();
if (content instanceof XSDParticle) {
XSDParticle xsdParticle = (XSDParticle) content;
XSDParticleContent particleContent = xsdParticle.getContent();
if (particleContent instanceof XSDModelGroup) {
XSDModelGroup modelGroup = (XSDModelGroup) particleContent;
EList<XSDParticle> contents = modelGroup.getContents();
for (XSDParticle particle : contents) {
assertTrue(XSDUtil.isFirstLevelChild(particle));
if (particle.getTerm() instanceof XSDElementDeclaration) {
XSDElementDeclaration xsdElementDecl = (XSDElementDeclaration) particle.getTerm();
XSDTypeDefinition typeDefinition = xsdElementDecl.getTypeDefinition();
if (typeDefinition instanceof XSDComplexTypeDefinition) {
XSDParticle childPart = (XSDParticle) ((XSDComplexTypeDefinition) typeDefinition).getContent();
XSDModelGroup childModelGroup = (XSDModelGroup) childPart.getContent();
for (XSDParticle childParticle : childModelGroup.getContents()) {
assertFalse(XSDUtil.isFirstLevelChild(childParticle));
}
}
}
}
}
}
}
}
use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.
the class XSDUtilTest method testGetKeyFields.
@Test
public void testGetKeyFields() throws Exception {
XSDFactory factory = XSDFactory.eINSTANCE;
// $NON-NLS-1$
String conceptName = "Product";
// $NON-NLS-1$ //$NON-NLS-2$
String[] fields = { "Id", "code" };
XSDElementDeclaration concept = factory.createXSDElementDeclaration();
concept.setName(conceptName);
XSDIdentityConstraintDefinition ideCDef = factory.createXSDIdentityConstraintDefinition();
XSDXPathDefinition xpathDefinition1 = factory.createXSDXPathDefinition();
xpathDefinition1.setValue(fields[0]);
ideCDef.getFields().add(xpathDefinition1);
concept.getIdentityConstraintDefinitions().add(ideCDef);
List<String> keyFields = XSDUtil.getKeyFields(concept);
assertTrue(keyFields.isEmpty());
//
ideCDef.setName(conceptName);
XSDXPathDefinition xpathDefinition2 = factory.createXSDXPathDefinition();
xpathDefinition2.setValue(fields[1]);
ideCDef.getFields().add(xpathDefinition2);
keyFields = XSDUtil.getKeyFields(concept);
assertTrue(keyFields.size() == 2);
assertTrue(keyFields.contains(fields[0]));
assertTrue(keyFields.contains(fields[1]));
}
Aggregations