use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.
the class UtilMockTest method testFindOutSpecialSonElement.
@Test
public void testFindOutSpecialSonElement() {
// $NON-NLS-1$
String method_findspecial = "findOutSpecialSonElement";
// $NON-NLS-1$
String method_findall = "findOutAllSonElements";
Set<XSDConcreteComponent> complexTypes = new HashSet<XSDConcreteComponent>();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
String[] names = { "ele1", "ele2", "ele3", "ele4" };
PowerMockito.mockStatic(Util.class);
try {
PowerMockito.when(Util.class, method_findspecial, any(XSDElementDeclaration.class), any(XSDElementDeclaration.class), anySet()).thenCallRealMethod();
XSDFactory factory = XSDFactory.eINSTANCE;
XSDElementDeclaration parent = factory.createXSDElementDeclaration();
XSDElementDeclaration xsdElementDeclaration1 = factory.createXSDElementDeclaration();
xsdElementDeclaration1.setName(names[0]);
XSDElementDeclaration xsdElementDeclaration2 = factory.createXSDElementDeclaration();
xsdElementDeclaration2.setName(names[1]);
List<XSDElementDeclaration> particleElementList1 = new ArrayList<XSDElementDeclaration>();
particleElementList1.add(xsdElementDeclaration1);
particleElementList1.add(xsdElementDeclaration2);
//
PowerMockito.when(Util.class, method_findall, any(XSDElementDeclaration.class), any(XSDComplexTypeDefinition.class)).thenReturn(particleElementList1);
Object result = Whitebox.invokeMethod(Util.class, method_findspecial, parent, xsdElementDeclaration1, complexTypes);
assertSame(parent, result);
//
XSDElementDeclaration xsdEleDeclaration1 = factory.createXSDElementDeclaration();
xsdEleDeclaration1.setName(names[2]);
XSDElementDeclaration xsdEleDeclaration2 = factory.createXSDElementDeclaration();
xsdEleDeclaration2.setName(names[3]);
List<XSDElementDeclaration> particleElementList2 = new ArrayList<XSDElementDeclaration>();
particleElementList2.add(xsdEleDeclaration1);
particleElementList2.add(xsdEleDeclaration2);
PowerMockito.when(Util.class, method_findall, any(XSDElementDeclaration.class), any(XSDComplexTypeDefinition.class)).thenReturn(particleElementList1, particleElementList2);
result = Whitebox.invokeMethod(Util.class, method_findspecial, parent, xsdEleDeclaration1, complexTypes);
assertSame(xsdElementDeclaration1, result);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of org.eclipse.xsd.XSDElementDeclaration 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.XSDElementDeclaration 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.XSDElementDeclaration 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.XSDElementDeclaration in project webtools.sourceediting by eclipse.
the class XSDSubstitutionGroupEditManager method modifyComponentReference.
public void modifyComponentReference(Object referencingObject, ComponentSpecification component) {
XSDElementDeclaration concreteComponent = null;
if (referencingObject instanceof Adapter) {
Adapter adapter = (Adapter) referencingObject;
if (adapter.getTarget() instanceof XSDElementDeclaration) {
concreteComponent = (XSDElementDeclaration) adapter.getTarget();
}
} else if (referencingObject instanceof XSDConcreteComponent) {
concreteComponent = (XSDElementDeclaration) referencingObject;
}
if (concreteComponent != null) {
if (component.isNew()) {
XSDElementDeclaration elementDec = null;
if (component.getMetaName() == IXSDSearchConstants.ELEMENT_META_NAME) {
AddXSDElementCommand command = new AddXSDElementCommand(Messages._UI_ACTION_ADD_ELEMENT, concreteComponent.getSchema());
command.setNameToAdd(component.getName());
command.execute();
elementDec = (XSDElementDeclaration) command.getAddedComponent();
}
if (elementDec != null) {
Command command = new UpdateAttributeValueCommand(concreteComponent.getElement(), XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE, elementDec.getQName(concreteComponent.getSchema()), org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_SUBSTITUTION_GROUP);
command.execute();
}
} else {
Command command = new UpdateAttributeValueCommand(concreteComponent.getElement(), XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE, ((XSDElementDeclaration) component.getObject()).getQName(concreteComponent.getSchema()), org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_SUBSTITUTION_GROUP);
command.execute();
}
XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
}
}
Aggregations