KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > axi > datatype > DatatypeFactoryTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.axi.datatype;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.List JavaDoc;
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 /**
35  *
36  * @author Ayub Khan
37  */

38 public class DatatypeFactoryTest extends AbstractTestCase {
39     
40     public static final String JavaDoc TEST_XSD = "resources/types.xsd";
41     public static final String JavaDoc GLOBAL_ELEMENT = "purchaseOrder";
42     
43     private List JavaDoc<Attribute> attList;;
44     
45     public DatatypeFactoryTest(String JavaDoc testName) {
46         super(testName, TEST_XSD, GLOBAL_ELEMENT);
47     }
48     
49     protected void setUp() throws Exception JavaDoc {
50         super.setUp();
51         attList = new ArrayList JavaDoc<Attribute>();
52     }
53     
54     public static Test suite() {
55         TestSuite suite = new TestSuite(DatatypeFactoryTest.class);
56         
57         return suite;
58     }
59     
60     /**
61      * Test of createElement method, of class org.netbeans.modules.xml.axi.XAMFactory.
62      */

63     public void testFindApplicableFacets() {
64         validateSchema(axiModel.getSchemaModel());
65         Collection JavaDoc<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 JavaDoc<Class JavaDoc<? 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                 //test same instance is returned
90
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