KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > axi > AXIModelTest


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;
21
22 import junit.framework.*;
23 import org.netbeans.modules.xml.axi.util.FileUtil;
24 import org.netbeans.modules.xml.axi.util.ModelValidator;
25 import org.netbeans.modules.xml.schema.model.SchemaComponent;
26 import org.netbeans.modules.xml.schema.model.SchemaModel;
27
28
29 /**
30  * The unit test covers the integrity of the AXI model.
31  * In reverseEngineer(), it reads a schema file and creates the model.
32  * In forwardEngineer(), it reads a xml file creates the model and then
33  * code generates a schema. Generated code may not be available.
34  *
35  * @author Samaresh (Samaresh.Panda@Sun.Com)
36  */

37 public class AXIModelTest extends AbstractTestCase {
38     
39     public static final String JavaDoc TEST_XSD = "resources/po.xsd";
40     public static final String JavaDoc GLOBAL_ELEMENT = "purchaseOrder";
41     
42     
43     /**
44      * AXIModelTest
45      */

46     public AXIModelTest(String JavaDoc testName) {
47         super(testName, TEST_XSD, GLOBAL_ELEMENT);
48     }
49     
50     /**
51      * AXIModelTest
52      */

53     public AXIModelTest(String JavaDoc testName, String JavaDoc schemaFile, String JavaDoc elementName) {
54         super(testName, schemaFile, elementName);
55     }
56     
57     public static Test suite() {
58         TestSuite suite = new TestSuite(AXIModelTest.class);
59         
60         return suite;
61     }
62     
63     public void testAXIModel() {
64         reverseEngineer();
65         axiModel.setSchemaDesignPattern(SchemaGenerator.Pattern.GARDEN_OF_EDEN);
66         forwardEngineer();
67     }
68     
69     /**
70      * Tests forward engineering of AXI model.
71      * Creates an AXI tree by parsing an XML input file
72      * and then compares it against the DOM tree for the
73      * same XML.
74      */

75     private void forwardEngineer() {
76         if(referenceXML == null) return;
77         FileUtil.parseXMLAndPopulateAXIModel(
78                 referenceXML, getAXIModel());
79         ModelValidator visitor = new ModelValidator(referenceXML);
80         Element po = getAXIModel().getRoot().getElements().get(0);
81         Element first = (Element)po.getChildElements().get(0);
82         assert(first.getParentElement() == po);
83         boolean result = visitor.visitAndCompareAgainstDOMElement(po);
84         this.assertEquals(visitor.getErrorMessage(), true, result);
85     }
86     
87     /**
88      * Tests reverse engineering of AXI model.
89      * Creates an AXI tree for a schema global element and
90      * compares it against the DOM tree.
91      */

92     public void reverseEngineer() {
93         assertNotNull(globalElement);
94         assertNotNull(getAXIModel().getRoot());
95         //visit each node in the AXI tree and compare against
96
//corresponding DOM node.
97
ModelValidator visitor = new ModelValidator(referenceXML);
98         boolean result = visitor.visitAndCompareAgainstDOMElement(globalElement);
99         this.assertEquals(visitor.getErrorMessage(),
100                 true, result);
101     }
102 }
103
Popular Tags