Search in sources :

Example 36 with XSDFactory

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

Example 37 with XSDFactory

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);
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 38 with XSDFactory

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

Example 39 with XSDFactory

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

Example 40 with XSDFactory

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

Aggregations

XSDFactory (org.eclipse.xsd.XSDFactory)50 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)37 XSDParticle (org.eclipse.xsd.XSDParticle)27 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)26 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)23 Test (org.junit.Test)19 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)15 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)13 ArrayList (java.util.ArrayList)12 XSDSchema (org.eclipse.xsd.XSDSchema)12 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)12 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)12 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)6 HashSet (java.util.HashSet)5 Iterator (java.util.Iterator)5 List (java.util.List)5