1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.neethi;
17  
18  import java.io.File;
19  
20  import javax.xml.stream.XMLOutputFactory;
21  import javax.xml.stream.XMLStreamWriter;
22  
23  import org.apache.neethi.util.PolicyComparator;
24  
25  public class NormalizeTest extends PolicyTestCase {
26      
27      PolicyEngine mgr;
28  
29      public NormalizeTest() {
30          super("NormalizeTest");
31      }
32  
33      public void test() throws Exception {
34          String r1, r2;
35          Policy p1, p2;
36          
37          for (int i =1; i < 26; i++) {
38  
39              r1 = "samples" + File.separator + "test" + i + ".xml";
40              r2 = "normalized" + File.separator + "test" + i + ".xml";
41  
42              
43              p1 = PolicyEngine.getPolicy(getResourceAsElement(r1));
44              p1 = (Policy) p1.normalize(true);
45              p2 = PolicyEngine.getPolicy(getResourceAsElement(r2));
46              
47              if (!PolicyComparator.compare(p1, p2)) {
48                  XMLStreamWriter writer;
49                  
50                  writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out);
51                  p1.serialize(writer);
52                  writer.flush();
53                  
54                  System.out.println("\n ------------ \n");
55                  
56                  writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out);
57                  p2.serialize(writer);
58                  writer.flush();
59                  
60                  fail("test" + i + " normalize() FAILED");
61              }
62          }
63      }
64  }