use of org.eclipse.xsd.XSDFactory 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.XSDFactory 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.XSDFactory 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.XSDFactory in project tmdm-studio-se by Talend.
the class UtilMockTest method testGetComplexTypes.
@Test
public void testGetComplexTypes() {
XSDFactory factory = XSDFactory.eINSTANCE;
XSDSchema xSchema = factory.createXSDSchema();
List<XSDComplexTypeDefinition> complexTypes = Util.getComplexTypes(xSchema);
assertNotNull(complexTypes);
assertTrue(complexTypes.isEmpty());
XSDSimpleTypeDefinition simpleTypeDefinition = factory.createXSDSimpleTypeDefinition();
simpleTypeDefinition.setBaseTypeDefinition(// $NON-NLS-1$ );
xSchema.resolveSimpleTypeDefinition(xSchema.getSchemaForSchemaNamespace(), "string"));
xSchema.getContents().add(simpleTypeDefinition);
complexTypes = Util.getComplexTypes(xSchema);
assertNotNull(complexTypes);
assertTrue(complexTypes.isEmpty());
XSDComplexTypeDefinition baseComplexTypeDefinition = xSchema.resolveComplexTypeDefinition(xSchema.getSchemaForSchemaNamespace(), // $NON-NLS-1$
"anyType");
XSDComplexTypeDefinition complexType1 = factory.createXSDComplexTypeDefinition();
complexType1.setBaseTypeDefinition(baseComplexTypeDefinition);
complexType1.setTargetNamespace(null);
// $NON-NLS-1$
complexType1.setName("ctype1");
XSDComplexTypeDefinition complexType2 = factory.createXSDComplexTypeDefinition();
// $NON-NLS-1$
complexType2.setTargetNamespace("targetNameSpace");
// $NON-NLS-1$
complexType2.setName("ctype2");
complexType2.setBaseTypeDefinition(baseComplexTypeDefinition);
XSDComplexTypeDefinition complexType3 = factory.createXSDComplexTypeDefinition();
complexType3.setTargetNamespace(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
// $NON-NLS-1$
complexType3.setName("topLevelComplexType");
complexType3.setBaseTypeDefinition(baseComplexTypeDefinition);
EList<XSDTypeDefinition> contents = new BasicEList<XSDTypeDefinition>();
contents.add(complexType1);
contents.add(complexType2);
contents.add(complexType3);
XSDSchema spySchema = spy(xSchema);
when(spySchema.getTypeDefinitions()).thenReturn(contents);
complexTypes = Util.getComplexTypes(spySchema);
assertNotNull(complexTypes);
assertTrue(complexTypes.size() == 2);
assertTrue(complexTypes.contains(complexType1));
assertTrue(complexTypes.contains(complexType2));
assertFalse(complexTypes.contains(complexType3));
}
use of org.eclipse.xsd.XSDFactory in project tmdm-studio-se by Talend.
the class UtilMockTest method testGetSimpleTypeDefinitionChildren.
@Test
public void testGetSimpleTypeDefinitionChildren() {
// $NON-NLS-1$
String methodToExpect = "isBuildInType";
// $NON-NLS-1$
String methodToExecute = "getSimpleTypeDefinitionChildren";
XSDFactory factory = XSDFactory.eINSTANCE;
XSDSimpleTypeDefinition simpleTypeDefinition = factory.createXSDSimpleTypeDefinition();
PowerMockito.mockStatic(Util.class);
try {
PowerMockito.when(Util.class, methodToExecute, any(XSDSimpleTypeDefinition.class)).thenCallRealMethod();
//
PowerMockito.when(Util.class, methodToExpect, any(XSDSimpleTypeDefinition.class)).thenReturn(true);
List<Object> children = Util.getSimpleTypeDefinitionChildren(simpleTypeDefinition);
assertNotNull(children);
assertTrue(children.size() == 1);
assertTrue(children.contains(simpleTypeDefinition));
//
PowerMockito.when(Util.class, methodToExpect, any(XSDSimpleTypeDefinition.class)).thenReturn(false);
children = Util.getSimpleTypeDefinitionChildren(simpleTypeDefinition);
assertNotNull(children);
assertTrue(children.size() == 1);
assertTrue(children.contains(simpleTypeDefinition));
//
XSDAnnotation annotation1 = factory.createXSDAnnotation();
XSDAnnotation annotation2 = factory.createXSDAnnotation();
simpleTypeDefinition.getAnnotations().add(annotation1);
simpleTypeDefinition.getAnnotations().add(annotation2);
children = Util.getSimpleTypeDefinitionChildren(simpleTypeDefinition);
assertNotNull(children);
assertTrue(children.size() == 3);
assertTrue(children.contains(simpleTypeDefinition));
assertTrue(children.contains(annotation1));
assertTrue(children.contains(annotation2));
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
Aggregations