use of org.eclipse.xsd.XSDModelGroup in project tmdm-studio-se by Talend.
the class UtilMockTest method buildXSDParticleWithChildren.
private XSDParticle buildXSDParticleWithChildren(int childrenNumb, String[] childrenNames) {
XSDParticle xsdParticle = XSDFactory.eINSTANCE.createXSDParticle();
XSDModelGroup xsdModelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
xsdParticle.setTerm(xsdModelGroup);
for (int i = 0; i < childrenNumb && i < childrenNames.length; i++) {
XSDParticle xsdParticle_child = XSDFactory.eINSTANCE.createXSDParticle();
XSDElementDeclaration xsdElementDeclaration_child = XSDFactory.eINSTANCE.createXSDElementDeclaration();
xsdElementDeclaration_child.setName(childrenNames[i]);
xsdParticle_child.setTerm(xsdElementDeclaration_child);
xsdModelGroup.getContents().add(xsdParticle_child);
}
return xsdParticle;
}
use of org.eclipse.xsd.XSDModelGroup in project tmdm-studio-se by Talend.
the class UtilMockTest method testUpdateReferenceToXSDTypeDefinition.
@Test
public void testUpdateReferenceToXSDTypeDefinition() {
// $NON-NLS-1$
String method_getall = "getAllObject";
// $NON-NLS-1$
String method_updateref = "updateReferenceToXSDTypeDefinition";
PowerMockito.mockStatic(Util.class);
try {
PowerMockito.when(Util.class, method_updateref, any(), any(XSDTypeDefinition.class), any(IStructuredContentProvider.class)).thenCallRealMethod();
Object[] allNodes = {};
XSDFactory factory = XSDFactory.eINSTANCE;
XSDTypeDefinition[] newTypes = { factory.createXSDComplexTypeDefinition(), factory.createXSDSimpleTypeDefinition() };
for (XSDTypeDefinition newType : newTypes) {
//
//
XSDElementDeclaration mockElementDecl = mock(XSDElementDeclaration.class);
when(mockElementDecl.getTypeDefinition()).thenReturn(newType);
//
//
XSDParticle xsdParticle1 = mock(XSDParticle.class);
XSDElementDeclaration mockElementDec2 = mock(XSDElementDeclaration.class);
when(mockElementDec2.getTypeDefinition()).thenReturn(newType);
when(xsdParticle1.getTerm()).thenReturn(mockElementDec2);
//
//
XSDParticle xsdParticle2 = mock(XSDParticle.class);
XSDParticle particle_c1 = mock(XSDParticle.class);
XSDElementDeclaration mockElementDec_c1 = mock(XSDElementDeclaration.class);
when(mockElementDec_c1.getTypeDefinition()).thenReturn(newType);
when(particle_c1.getContent()).thenReturn(mockElementDec_c1);
XSDParticle particle_c2 = mock(XSDParticle.class);
XSDElementDeclaration mockElementDec_c2 = mock(XSDElementDeclaration.class);
when(mockElementDec_c2.getTypeDefinition()).thenReturn(newType);
when(particle_c2.getContent()).thenReturn(mockElementDec_c2);
XSDParticle particle_c3 = mock(XSDParticle.class);
XSDElementDeclaration mockElementDec_c3 = mock(XSDElementDeclaration.class);
when(mockElementDec_c3.getTypeDefinition()).thenReturn(factory.createXSDComplexTypeDefinition());
when(particle_c3.getContent()).thenReturn(mockElementDec_c3);
XSDModelGroup xsdModelGroup = mock(XSDModelGroup.class);
EList<XSDParticle> elist = new BasicEList<XSDParticle>();
elist.add(particle_c1);
elist.add(particle_c2);
elist.add(particle_c3);
when(xsdModelGroup.getContents()).thenReturn(elist);
when(xsdParticle2.getTerm()).thenReturn(xsdModelGroup);
allNodes = new Object[] { mockElementDecl, xsdParticle1, xsdParticle2 };
//
PowerMockito.when(Util.class, method_getall, any(), anyList(), any(IStructuredContentProvider.class)).thenReturn(allNodes);
Util.updateReferenceToXSDTypeDefinition(new Object(), newType, mock(IStructuredContentProvider.class));
Mockito.verify(mockElementDecl).setTypeDefinition(newType);
Mockito.verify(mockElementDec2).setTypeDefinition(newType);
Mockito.verify(mockElementDec_c1).setTypeDefinition(newType);
Mockito.verify(mockElementDec_c2).setTypeDefinition(newType);
if (newType instanceof XSDComplexTypeDefinition) {
PowerMockito.verifyStatic();
Util.updateChildrenReferenceToComplexType((XSDComplexTypeDefinition) newType);
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of org.eclipse.xsd.XSDModelGroup in project tmdm-studio-se by Talend.
the class UtilMockTest method testFindOutAllSonElements.
@Test
public void testFindOutAllSonElements() {
XSDFactory factory = XSDFactory.eINSTANCE;
Set<XSDConcreteComponent> complexTypes = new HashSet<XSDConcreteComponent>();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String[] targetNameSpaces = { "http://www.w3.org/2001/XMLSchema", "", "" };
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String[] names = { "p1", "p2", "p3" };
XSDTypeDefinition[] types = { factory.createXSDSimpleTypeDefinition(), factory.createXSDSimpleTypeDefinition(), factory.createXSDSimpleTypeDefinition() };
XSDElementDeclaration xsdElementDeclaration = factory.createXSDElementDeclaration();
xsdElementDeclaration.setName(names[0]);
xsdElementDeclaration.setTargetNamespace(targetNameSpaces[0]);
XSDComplexTypeDefinition xsdComplexTypeDef = factory.createXSDComplexTypeDefinition();
xsdElementDeclaration.setAnonymousTypeDefinition(xsdComplexTypeDef);
XSDParticle typeParticle = factory.createXSDParticle();
xsdComplexTypeDef.setContent(typeParticle);
XSDModelGroup xsdModelGroup = factory.createXSDModelGroup();
for (int i = 0; i < names.length; i++) {
XSDElementDeclaration xsdEleDec = factory.createXSDElementDeclaration();
xsdEleDec.setName(names[i]);
xsdEleDec.setTargetNamespace(targetNameSpaces[i]);
if (i == 0) {
xsdEleDec.setTypeDefinition(xsdComplexTypeDef);
} else {
xsdEleDec.setTypeDefinition(types[i]);
}
XSDParticle xsdParticle = factory.createXSDParticle();
xsdParticle.setContent(xsdEleDec);
xsdModelGroup.getContents().add(xsdParticle);
}
typeParticle.setContent(xsdModelGroup);
PowerMockito.mockStatic(Util.class);
try {
// $NON-NLS-1$
String methodToExecute = "findOutAllSonElements";
PowerMockito.when(Util.class, methodToExecute, any(XSDElementDeclaration.class), anySet()).thenCallRealMethod();
List<XSDElementDeclaration> allson = Whitebox.invokeMethod(Util.class, methodToExecute, xsdElementDeclaration, complexTypes);
assertNotNull(allson);
assertTrue(allson.size() == 2);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of org.eclipse.xsd.XSDModelGroup in project webtools.sourceediting by eclipse.
the class MoveXSDElementAction method run.
/*
* @see IAction#run()
*/
public void run() {
int originalIndex = 0;
for (Iterator particles = parentModelGroup.getContents().iterator(); particles.hasNext(); ) {
XSDParticle particle = (XSDParticle) particles.next();
XSDParticleContent particleContent = particle.getContent();
if (particleContent == selected) {
parentModelGroup.getContents().remove(particle);
break;
}
originalIndex++;
}
int index = 0;
boolean addedBack = false;
if (insertType == INSERT_DIRECT) {
XSDConcreteComponent container = selected.getContainer();
if (container != null) {
XSDConcreteComponent container2 = container.getContainer();
if (container2 instanceof XSDModelGroup) {
((XSDModelGroup) container2).getContents().remove(container);
}
if (insertAtEnd)
parentModelGroup.getContents().add(container);
else
parentModelGroup.getContents().add(0, container);
addedBack = true;
}
return;
}
List particles = parentModelGroup.getContents();
for (Iterator iterator = particles.iterator(); iterator.hasNext(); ) {
XSDParticle particle = (XSDParticle) iterator.next();
XSDParticleContent particleContent = particle.getContent();
if (insertType == INSERT_BEFORE) {
if (particleContent == nextRefComponent) {
parentModelGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
if (selected == nextRefComponent && originalIndex == index) {
parentModelGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
} else if (insertType == INSERT_AFTER) {
if (particleContent == previousRefComponent) {
parentModelGroup.getContents().add(index + 1, selected.getContainer());
addedBack = true;
break;
}
if (selected == previousRefComponent && originalIndex == index) {
parentModelGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
}
index++;
}
if (particles.size() == 0) {
parentModelGroup.getContents().add(selected.getContainer());
addedBack = true;
}
if (!addedBack) {
parentModelGroup.getContents().add(originalIndex, selected.getContainer());
}
}
use of org.eclipse.xsd.XSDModelGroup in project webtools.sourceediting by eclipse.
the class AddXSDModelGroupAction method run.
public void run() {
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
if (selection instanceof XSDBaseAdapter) {
XSDConcreteComponent xsdComponent = (XSDConcreteComponent) ((XSDBaseAdapter) selection).getTarget();
AddXSDModelGroupCommand command = null;
if (xsdComponent instanceof XSDElementDeclaration) {
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) xsdComponent;
command = new AddXSDModelGroupCommand(getLabel(xsdCompositor), xsdElementDeclaration, xsdCompositor);
getCommandStack().execute(command);
} else if (xsdComponent instanceof XSDModelGroup) {
XSDModelGroup xsdModelGroup = (XSDModelGroup) xsdComponent;
command = new AddXSDModelGroupCommand(getLabel(xsdCompositor), xsdModelGroup, xsdCompositor);
getCommandStack().execute(command);
} else if (xsdComponent instanceof XSDComplexTypeDefinition || xsdComponent instanceof XSDModelGroupDefinition) {
command = new AddXSDModelGroupCommand(getLabel(xsdCompositor), xsdComponent, xsdCompositor);
getCommandStack().execute(command);
}
if (command != null) {
Adapter adapter = XSDAdapterFactory.getInstance().adapt(command.getAddedComponent());
if (adapter != null)
provider.setSelection(new StructuredSelection(adapter));
}
}
}
Aggregations