1 19 20 package org.netbeans.modules.xml.axi.datatype; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.List ; 25 import junit.framework.*; 26 import org.netbeans.modules.xml.axi.*; 27 import org.netbeans.modules.xml.schema.model.GlobalSimpleType; 28 import org.netbeans.modules.xml.schema.model.Length; 29 import org.netbeans.modules.xml.schema.model.Pattern; 30 import org.netbeans.modules.xml.schema.model.SchemaComponent; 31 import org.netbeans.modules.xml.schema.model.TotalDigits; 32 33 34 38 public class DatatypeFactoryTest extends AbstractTestCase { 39 40 public static final String TEST_XSD = "resources/types.xsd"; 41 public static final String GLOBAL_ELEMENT = "purchaseOrder"; 42 43 private List <Attribute> attList;; 44 45 public DatatypeFactoryTest(String testName) { 46 super(testName, TEST_XSD, GLOBAL_ELEMENT); 47 } 48 49 protected void setUp() throws Exception { 50 super.setUp(); 51 attList = new ArrayList <Attribute>(); 52 } 53 54 public static Test suite() { 55 TestSuite suite = new TestSuite(DatatypeFactoryTest.class); 56 57 return suite; 58 } 59 60 63 public void testFindApplicableFacets() { 64 validateSchema(axiModel.getSchemaModel()); 65 Collection <GlobalSimpleType> types = getSchemaModel().getSchema().getSimpleTypes(); 66 assertEquals("primitiveTypes", 7, types.size()); 67 68 for(GlobalSimpleType type:types) { 69 if(type.getName().equals("myDate")) { 70 long start = System.currentTimeMillis(); 71 List <Class <? extends SchemaComponent>> facets = 72 DatatypeFactory.getDefault().getApplicableSchemaFacets(type); 73 long end = System.currentTimeMillis(); 74 print("time taken to find facets from GlobalSimpleType: "+(end-start)+"ms"); 75 assertEquals("Facets", 6, facets.size()); 76 start = System.currentTimeMillis(); 77 facets = 78 DatatypeFactory.getDefault().getApplicableSchemaFacets(type); 79 end = System.currentTimeMillis(); 80 print("time taken to find same facets (second time) from GlobalSimpleType: "+(end-start)+"ms"); 81 } else if(type.getName().equals("myDate1")) { 82 assertEquals("Facets", 7, DatatypeFactory.getDefault().getApplicableSchemaFacets(type).size()); 83 assertEquals("Facets", Pattern.class, DatatypeFactory.getDefault().getApplicableSchemaFacets(type).get(0)); 84 } else if(type.getName().equals("SKU")) { 85 assertEquals("Facets", 6, DatatypeFactory.getDefault().getApplicableSchemaFacets(type).size()); 86 assertEquals("Facets", Length.class, DatatypeFactory.getDefault().getApplicableSchemaFacets(type).get(0)); 87 } else if(type.getName().equals("ListOfMyDate")) { 88 assertEquals("Facets", 6, DatatypeFactory.getDefault().getApplicableSchemaFacets(type).size()); 89 assertEquals("Facets", DatatypeFactory.getDefault().getApplicableSchemaFacets(type), DatatypeFactory.getDefault().getApplicableSchemaFacets(type)); 91 } else if(type.getName().equals("Cost")) { 92 assertEquals("Facets", 9, DatatypeFactory.getDefault().getApplicableSchemaFacets(type).size()); 93 assertEquals("Facets", TotalDigits.class, DatatypeFactory.getDefault().getApplicableSchemaFacets(type).get(0)); 94 } 95 } 96 } 97 98 } 99 | Popular Tags |