KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > model > validation > SchemaXsdBasedValidatorTest


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.schema.model.validation;
21
22 import java.util.List JavaDoc;
23 import junit.framework.*;
24 import org.netbeans.modules.xml.schema.model.SchemaModel;
25 import org.netbeans.modules.xml.schema.model.SchemaModelReference;
26 import org.netbeans.modules.xml.schema.model.TestCatalogModel;
27 import org.netbeans.modules.xml.schema.model.Util;
28 import org.netbeans.modules.xml.xam.spi.Validation;
29 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem;
30
31 /**
32  *
33  * @author nn136682
34  */

35 public class SchemaXsdBasedValidatorTest extends TestCase {
36     
37     public SchemaXsdBasedValidatorTest(String JavaDoc testName) {
38         super(testName);
39     }
40     
41     protected void setUp() throws Exception JavaDoc {
42     }
43     
44     protected void tearDown() throws Exception JavaDoc {
45         TestCatalogModel.getDefault().clearDocumentPool();
46     }
47     
48     public static Test suite() {
49         TestSuite suite = new TestSuite(SchemaXsdBasedValidatorTest.class);
50         
51         return suite;
52     }
53     
54     public void testResolveResource() throws Exception JavaDoc {
55         Validation validation = new Validation();
56         SchemaModel model = Util.loadSchemaModel("validation/SynchronousSample.xsd");
57         SchemaModelReference imported = model.getSchema().getSchemaReferences().iterator().next();
58         SchemaModel importedModel = imported.resolveReferencedModel();
59         String JavaDoc expected1 = "s4s-att-not-allowed: Attribute 'nameXXXX' cannot appear in element 'attribute'.";
60         String JavaDoc expected2 = "s4s-att-must-appear: Attribute 'name' must appear in element 'attribute'.";
61
62         validation.validate(importedModel, Validation.ValidationType.COMPLETE);
63         List JavaDoc<ResultItem> results0 = validation.getValidationResult();
64         assertEquals(2, results0.size());
65         assertEquals("from imported model", importedModel, results0.get(0).getModel());
66         assertEquals(expected1, results0.get(0).getDescription());
67         assertEquals("from imported model", importedModel, results0.get(1).getModel());
68         assertEquals(expected2, results0.get(1).getDescription());
69         
70         Validation validation2 = new Validation();
71         validation2.validate(model, Validation.ValidationType.COMPLETE);
72         List JavaDoc<ResultItem> results = validation2.getValidationResult();
73         assertEquals(2, results.size());
74         assertEquals("from imported model", importedModel, results.get(0).getModel());
75         assertEquals(expected1, results.get(0).getDescription());
76         assertEquals("from imported model", importedModel, results.get(1).getModel());
77         assertEquals(expected2, results.get(1).getDescription());
78     }
79     
80 }
81
Popular Tags