Search in sources :

Example 76 with XSDElementDeclaration

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);
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 77 with XSDElementDeclaration

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;
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 78 with XSDElementDeclaration

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);
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) BasicEList(org.eclipse.emf.common.util.BasicEList) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 79 with XSDElementDeclaration

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);
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 80 with XSDElementDeclaration

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());
    }
}
Also used : AddXSDElementCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand) UpdateAttributeValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) UpdateAttributeValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand) Command(org.eclipse.gef.commands.Command) AddXSDElementCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Adapter(org.eclipse.emf.common.notify.Adapter)

Aggregations

XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)222 XSDParticle (org.eclipse.xsd.XSDParticle)103 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)93 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)87 ArrayList (java.util.ArrayList)60 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)57 XSDSchema (org.eclipse.xsd.XSDSchema)48 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)47 Test (org.junit.Test)44 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)38 XSDFactory (org.eclipse.xsd.XSDFactory)37 XSDTerm (org.eclipse.xsd.XSDTerm)32 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)30 EList (org.eclipse.emf.common.util.EList)29 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)28 Iterator (java.util.Iterator)27 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)27 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)24 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)21 Element (org.w3c.dom.Element)21