use of org.eclipse.xsd.XSDFactory in project tmdm-studio-se by Talend.
the class UtilMockTest method testAddImport.
@Test
public void testAddImport() {
// 2184
// $NON-NLS-1$
String namespace1 = "http://www.w3.org/XML/1998/namespace1";
// $NON-NLS-1$
String namespace2 = "http://www.w3.org/XML/1998/namespace2";
// $NON-NLS-1$
String namespace3 = "http://www.w3.org/XML/1998/namespace3";
String[] namespaces = { namespace1, namespace2, namespace3 };
// $NON-NLS-1$
String methodToExecute = "addImport";
XSDFactory factory = XSDFactory.eINSTANCE;
XSDSchema xsdschema = factory.createXSDSchema();
List<XSDImport> imports = new ArrayList<XSDImport>();
for (int i = 0; i < 3; i++) {
XSDImport importt = factory.createXSDImport();
importt.setNamespace(namespaces[i]);
imports.add(importt);
}
XSDImport importt = factory.createXSDImport();
// $NON-NLS-1$
importt.setNamespace("");
imports.add(importt);
xsdschema.getContents().add(imports.get(0));
PowerMockito.mockStatic(Util.class);
try {
PowerMockito.when(Util.class, methodToExecute, any(XSDSchema.class), anyListOf(XSDImport.class)).thenCallRealMethod();
Whitebox.invokeMethod(Util.class, methodToExecute, xsdschema, imports);
EList<XSDSchemaContent> contents = xsdschema.getContents();
assertTrue(contents.size() == 3);
assertTrue(contents.contains(imports.get(0)));
assertTrue(contents.contains(imports.get(1)));
assertTrue(contents.contains(imports.get(2)));
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of org.eclipse.xsd.XSDFactory in project tmdm-studio-se by Talend.
the class UtilMockTest method testIsAImporedElement.
@Test
public void testIsAImporedElement() {
XSDFactory factory = XSDFactory.eINSTANCE;
XSDSchema xsdSchema = factory.createXSDSchema();
XSDElementDeclaration elementDeclaration = factory.createXSDElementDeclaration();
XSDComplexTypeDefinition complexTypeDefinition = factory.createXSDComplexTypeDefinition();
complexTypeDefinition.setBaseTypeDefinition(// $NON-NLS-1$
xsdSchema.resolveComplexTypeDefinition(xsdSchema.getSchemaForSchemaNamespace(), "anyType"));
XSDParticle typeParticle = factory.createXSDParticle();
XSDModelGroup modelGroup = factory.createXSDModelGroup();
XSDParticle particle = factory.createXSDParticle();
XSDElementDeclaration pelement = factory.createXSDElementDeclaration();
elementDeclaration.setAnonymousTypeDefinition(complexTypeDefinition);
complexTypeDefinition.setContent(typeParticle);
typeParticle.setContent(modelGroup);
modelGroup.getContents().add(particle);
particle.setContent(pelement);
boolean isAImporedElement = Util.IsAImporedElement(null, xsdSchema);
assertFalse(isAImporedElement);
isAImporedElement = Util.IsAImporedElement(pelement, xsdSchema);
assertFalse(isAImporedElement);
xsdSchema.getContents().add(elementDeclaration);
isAImporedElement = Util.IsAImporedElement(pelement, xsdSchema);
assertFalse(isAImporedElement);
XSDSchema anotherSchema = factory.createXSDSchema();
isAImporedElement = Util.IsAImporedElement(pelement, anotherSchema);
assertFalse(isAImporedElement);
xsdSchema.getReferencingDirectives().add(factory.createXSDImport());
xsdSchema.getReferencingDirectives().add(factory.createXSDInclude());
isAImporedElement = Util.IsAImporedElement(pelement, anotherSchema);
assertTrue(isAImporedElement);
}
use of org.eclipse.xsd.XSDFactory in project tmdm-studio-se by Talend.
the class UtilMockTest method testUpdateReference.
@Test
public void testUpdateReference() {
// $NON-NLS-1$ //$NON-NLS-2$
String oldValue = "oldValue", newValue = "newValue";
// $NON-NLS-1$
String methodToExecute = "updateReference";
// $NON-NLS-1$
String method_private = "updatePrimaryKeyInfo";
XSDFactory factory = XSDFactory.eINSTANCE;
PowerMockito.mockStatic(Util.class);
try {
PowerMockito.when(Util.class, methodToExecute, any(), any(Object[].class), any(Object[].class), anyString(), anyString()).thenCallRealMethod();
Object[] objs = new Object[4];
Object[] allForeignKeyAndInfos = new Object[0];
Util.updateReference(new Object(), objs, allForeignKeyAndInfos, oldValue, newValue);
PowerMockito.verifyStatic(times(0));
Util.updateForeignKeyRelatedInfo(oldValue, newValue, allForeignKeyAndInfos);
Whitebox.invokeMethod(Util.class, method_private, any(XSDElementDeclaration.class), eq(oldValue), eq(newValue));
//
XSDModelGroup xsdModelGroup = factory.createXSDModelGroup();
XSDElementDeclaration xsdEleDecl = mock(XSDElementDeclaration.class);
XSDParticle particle1 = mock(XSDParticle.class);
when(particle1.getTerm()).thenReturn(xsdEleDecl);
XSDElementDeclaration mockDeclaration1 = mock(XSDElementDeclaration.class);
when(mockDeclaration1.isElementDeclarationReference()).thenReturn(true);
when(mockDeclaration1.getResolvedElementDeclaration()).thenReturn(xsdEleDecl);
when(particle1.getContent()).thenReturn(mockDeclaration1);
XSDParticle particle2 = mock(XSDParticle.class);
when(particle2.getTerm()).thenReturn(xsdEleDecl);
when(particle2.getContent()).thenReturn(xsdModelGroup);
XSDParticle particle3 = mock(XSDParticle.class);
when(particle3.getTerm()).thenReturn(xsdModelGroup);
XSDElementDeclaration mockDeclaration3 = mock(XSDElementDeclaration.class);
when(mockDeclaration3.isElementDeclarationReference()).thenReturn(true);
when(mockDeclaration3.getResolvedElementDeclaration()).thenReturn(xsdEleDecl);
when(particle3.getContent()).thenReturn(mockDeclaration3);
XSDParticle particle4 = mock(XSDParticle.class);
when(particle4.getTerm()).thenReturn(xsdModelGroup);
when(particle4.getContent()).thenReturn(xsdModelGroup);
objs[0] = particle1;
objs[1] = particle2;
objs[2] = particle3;
objs[3] = particle4;
Util.updateReference(xsdEleDecl, objs, allForeignKeyAndInfos, oldValue, newValue);
PowerMockito.verifyStatic();
Util.updateForeignKeyRelatedInfo(oldValue, newValue, allForeignKeyAndInfos);
Whitebox.invokeMethod(Util.class, method_private, any(XSDElementDeclaration.class), eq(oldValue), eq(newValue));
verify(particle1).setTerm(xsdEleDecl);
verify(particle1).updateElement();
verify(mockDeclaration1).setResolvedElementDeclaration(xsdEleDecl);
verify(particle2).setTerm(xsdEleDecl);
verify(particle2).updateElement();
verify(mockDeclaration3).setResolvedElementDeclaration(xsdEleDecl);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of org.eclipse.xsd.XSDFactory in project webtools.sourceediting by eclipse.
the class AddXSDAnyElementCommand method createModelGroup.
private void createModelGroup() {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDParticle particle = factory.createXSDParticle();
parent = factory.createXSDModelGroup();
parent.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
particle.setContent(parent);
complexType.setContent(particle);
}
use of org.eclipse.xsd.XSDFactory in project webtools.sourceediting by eclipse.
the class AddXSDElementCommand method createGlobalXSDElementDeclaration.
protected XSDElementDeclaration createGlobalXSDElementDeclaration() {
ensureSchemaElement(xsdSchema);
// $NON-NLS-1$
XSDSimpleTypeDefinition type = xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("string");
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDElementDeclaration element = factory.createXSDElementDeclaration();
element.setName(XSDCommonUIUtils.createUniqueElementName(nameToAdd == null ? "NewElement" : nameToAdd, // $NON-NLS-1$
xsdSchema.getElementDeclarations()));
element.setTypeDefinition(type);
return element;
}
Aggregations