/contrib-fort/rules4jbi/netbeans/project/test/unit/src/org/openesb/components/rules4jbi/netbeans/wsdl/schema/SecondarySchemaCreatorTest.java

https://bitbucket.org/pymma/openesb-components · Java · 176 lines · 130 code · 25 blank · 21 comment · 0 complexity · 3b074d36ee20d02989db5a0a208eeb3c MD5 · raw file

  1. /*
  2. * @(#)SecondarySchemaCreatorTest.java $Revision: 1.1.1.1 $ $Date: 2008/06/30 08:53:20 $
  3. *
  4. * Copyright (c) 2008 Milan Fort (http://www.milanfort.com/). All rights reserved.
  5. *
  6. * The contents of this file are subject to the terms of the Common Development
  7. * and Distribution License (the "License"). You may not use this file except
  8. * in compliance with the License.
  9. *
  10. * You can obtain a copy of the license at http://www.sun.com/cddl/cddl.html.
  11. * See the License for the specific language governing permissions and limitations
  12. * under the License.
  13. */
  14. package org.openesb.components.rules4jbi.netbeans.wsdl.schema;
  15. import org.openesb.components.rules4jbi.shared.util.XOMUtils;
  16. import nu.xom.Element;
  17. import org.junit.Test;
  18. //import static org.junit.Assert.*;
  19. import static nu.xom.tests.XOMTestCase.*;
  20. /**
  21. *
  22. * @author Milan Fort (http://www.milanfort.com/)
  23. * @version $Revision: 1.1.1.1 $ $Date: 2008/06/30 08:53:20 $
  24. *
  25. * @since 0.1
  26. */
  27. public class SecondarySchemaCreatorTest {
  28. @Test
  29. public void removeSchemaLocationFromImports() {
  30. String input = "<xs:schema xmlns:tns='http://www.example.org/xml/ns/test' "
  31. + "xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified' "
  32. + "targetNamespace='http://www.example.org/xml/ns/test' version='1.0'>"
  33. + "</xs:schema>";
  34. Element result = SecondarySchemaCreator.removeSchemaLocationFromImports(XOMUtils.toElement(input));
  35. assertEquals(XOMUtils.toElement(input), result);
  36. input = "<xs:schema xmlns:tns='http://www.example.org/xml/ns/test' "
  37. + "xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified' "
  38. + "targetNamespace='http://www.example.org/xml/ns/test' version='1.0'>"
  39. + "<xs:import namespace='http://www.example.org/xml/ns/whatever' "
  40. + "schemaLocation='../rightthere' />"
  41. + "</xs:schema>";
  42. String expected = "<xs:schema xmlns:tns='http://www.example.org/xml/ns/test' "
  43. + "xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified' "
  44. + "targetNamespace='http://www.example.org/xml/ns/test' version='1.0'>"
  45. + "<xs:import namespace='http://www.example.org/xml/ns/whatever' />"
  46. + "</xs:schema>";
  47. result = SecondarySchemaCreator.removeSchemaLocationFromImports(XOMUtils.toElement(input));
  48. assertEquals(XOMUtils.toElement(expected), result);
  49. input = "<xs:schema xmlns:tns='http://www.example.org/xml/ns/test' "
  50. + "xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified' "
  51. + "targetNamespace='http://www.example.org/xml/ns/test' version='1.0'>"
  52. + "<xs:import namespace='http://www.example.org/xml/ns/whatever' "
  53. + "schemaLocation='http://whereever.com/abc.xsd' />"
  54. + "<xs:element name='client' type='ns1:customerType' />"
  55. + "</xs:schema>";
  56. expected = "<xs:schema xmlns:tns='http://www.example.org/xml/ns/test' "
  57. + "xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified' "
  58. + "targetNamespace='http://www.example.org/xml/ns/test' version='1.0'>"
  59. + "<xs:import namespace='http://www.example.org/xml/ns/whatever' />"
  60. + "<xs:element name='client' type='ns1:customerType' />"
  61. + "</xs:schema>";
  62. result = SecondarySchemaCreator.removeSchemaLocationFromImports(XOMUtils.toElement(input));
  63. assertEquals(XOMUtils.toElement(expected), result);
  64. input = "<xsd:schema xmlns:tns='http://www.example.org/xml/ns/test' "
  65. + "xmlns:xsd='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified' "
  66. + "targetNamespace='http://www.example.org/xml/ns/test'>"
  67. + "<xsd:import namespace='http://www.example.org/xml/ns/whatever' "
  68. + "schemaLocation='../rightthere' />"
  69. + "<xsd:element name='client' type='ns1:customerType' />"
  70. + "<xsd:complexType name='invoice'><xsd:sequence><xsd:element name='amount' type='xsd:int' />"
  71. + "<xsd:element minOccurs='0' name='description' type='xsd:string' />"
  72. + "<xsd:element minOccurs='0' name='status' type='xsd:string' /></xsd:sequence></xsd:complexType>"
  73. + "<xsd:import namespace='http://www.example.org/xml/ns/whatever2' "
  74. + "schemaLocation='../../righthere' />"
  75. + "<xsd:element name='invoice' type='tns:invoice' />"
  76. + "</xsd:schema>";
  77. expected = "<xsd:schema xmlns:tns='http://www.example.org/xml/ns/test' "
  78. + "xmlns:xsd='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified' "
  79. + "targetNamespace='http://www.example.org/xml/ns/test'>"
  80. + "<xsd:import namespace='http://www.example.org/xml/ns/whatever' />"
  81. + "<xsd:element name='client' type='ns1:customerType' />"
  82. + "<xsd:complexType name='invoice'><xsd:sequence><xsd:element name='amount' type='xsd:int' />"
  83. + "<xsd:element minOccurs='0' name='description' type='xsd:string' />"
  84. + "<xsd:element minOccurs='0' name='status' type='xsd:string' /></xsd:sequence></xsd:complexType>"
  85. + "<xsd:import namespace='http://www.example.org/xml/ns/whatever2' "
  86. + " />"
  87. + "<xsd:element name='invoice' type='tns:invoice' />"
  88. + "</xsd:schema>";
  89. result = SecondarySchemaCreator.removeSchemaLocationFromImports(XOMUtils.toElement(input));
  90. assertEquals(XOMUtils.toElement(expected), result);
  91. }
  92. @Test
  93. public void removeImports() {
  94. String input = "<xs:schema xmlns:tns='http://www.example.org/xml/ns/test' "
  95. + "xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified' "
  96. + "targetNamespace='http://www.example.org/xml/ns/test' version='1.0'>"
  97. + "</xs:schema>";
  98. Element result = SecondarySchemaCreator.removeImports(XOMUtils.toElement(input));
  99. assertEquals(XOMUtils.toElement(input), result);
  100. input = "<xs:schema xmlns:tns='http://www.example.org/xml/ns/test' "
  101. + "xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified' "
  102. + "targetNamespace='http://www.example.org/xml/ns/test' version='1.0'>"
  103. + "<xs:import namespace='http://www.example.org/xml/ns/whatever' "
  104. + "schemaLocation='../rightthere' />"
  105. + "</xs:schema>";
  106. String expected = "<xs:schema xmlns:tns='http://www.example.org/xml/ns/test' "
  107. + "xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified' "
  108. + "targetNamespace='http://www.example.org/xml/ns/test' version='1.0'>"
  109. + "</xs:schema>";
  110. result = SecondarySchemaCreator.removeImports(XOMUtils.toElement(input));
  111. assertEquals(XOMUtils.toElement(expected), result);
  112. input = "<xs:schema xmlns:tns='http://www.example.org/xml/ns/test' "
  113. + "xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified' "
  114. + "targetNamespace='http://www.example.org/xml/ns/test' version='1.0'>"
  115. + "<xs:import namespace='http://www.example.org/xml/ns/whatever' "
  116. + "schemaLocation='../rightthere' />"
  117. + "<xs:element name='client' type='ns1:customerType' />"
  118. + "</xs:schema>";
  119. expected = "<xs:schema xmlns:tns='http://www.example.org/xml/ns/test' "
  120. + "xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified' "
  121. + "targetNamespace='http://www.example.org/xml/ns/test' version='1.0'>"
  122. + "<xs:element name='client' type='ns1:customerType' />"
  123. + "</xs:schema>";
  124. result = SecondarySchemaCreator.removeImports(XOMUtils.toElement(input));
  125. assertEquals(XOMUtils.toElement(expected), result);
  126. input = "<xsd:schema xmlns:tns='http://www.example.org/xml/ns/test' "
  127. + "xmlns:xsd='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified' "
  128. + "targetNamespace='http://www.example.org/xml/ns/test'>"
  129. + "<xsd:import namespace='http://www.example.org/xml/ns/whatever' "
  130. + "schemaLocation='../rightthere' />"
  131. + "<xsd:element name='client' type='ns1:customerType' />"
  132. + "<xsd:complexType name='invoice'><xsd:sequence><xsd:element name='amount' type='xsd:int' />"
  133. + "<xsd:element minOccurs='0' name='description' type='xsd:string' />"
  134. + "<xsd:element minOccurs='0' name='status' type='xsd:string' /></xsd:sequence></xsd:complexType>"
  135. + "<xsd:import namespace='http://www.example.org/xml/ns/whatever2' "
  136. + "schemaLocation='../../righthere' />"
  137. + "<xsd:element name='invoice' type='tns:invoice' />"
  138. + "</xsd:schema>";
  139. expected = "<xsd:schema xmlns:tns='http://www.example.org/xml/ns/test' "
  140. + "xmlns:xsd='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified' "
  141. + "targetNamespace='http://www.example.org/xml/ns/test'>"
  142. + "<xsd:element name='client' type='ns1:customerType' />"
  143. + "<xsd:complexType name='invoice'><xsd:sequence><xsd:element name='amount' type='xsd:int' />"
  144. + "<xsd:element minOccurs='0' name='description' type='xsd:string' />"
  145. + "<xsd:element minOccurs='0' name='status' type='xsd:string' /></xsd:sequence></xsd:complexType>"
  146. + "<xsd:element name='invoice' type='tns:invoice' />"
  147. + "</xsd:schema>";
  148. result = SecondarySchemaCreator.removeImports(XOMUtils.toElement(input));
  149. assertEquals(XOMUtils.toElement(expected), result);
  150. }
  151. }