KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > util > xml > idefix > test > IdefixProcessorTest


1 package org.sapia.util.xml.idefix.test;
2
3 import org.apache.log4j.BasicConfigurator;
4 import org.sapia.util.xml.Namespace;
5 import org.sapia.util.xml.idefix.CompositeNamespaceFactory;
6 import org.sapia.util.xml.idefix.DefaultNamespaceFactory;
7 import org.sapia.util.xml.idefix.DefaultSerializerFactory;
8 import org.sapia.util.xml.idefix.IdefixProcessorFactory;
9 import org.sapia.util.xml.idefix.IdefixProcessorIF;
10 import org.sapia.util.xml.idefix.NamespaceFactoryIF;
11 import org.sapia.util.xml.idefix.PatternNamespaceFactory;
12 import org.sapia.util.xml.idefix.SerializerFactoryIF;
13
14 import junit.framework.TestCase;
15 import junit.textui.TestRunner;
16
17
18 /**
19  * Class documentation
20  *
21  * @author <a HREF="mailto:jc@sapia-oss.org">Jean-Cedric Desrochers</a>
22  * <dl>
23  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
24  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
25  * <a HREF="http://www.sapia-oss.org/license.html" target="sapia-license">license page</a> at the Sapia OSS web site</dd></dt>
26  * </dl>
27  */

28 public class IdefixProcessorTest extends TestCase {
29
30   static {
31     BasicConfigurator.configure();
32   }
33   
34   private static IdefixProcessorFactory _theFactory = IdefixProcessorFactory.newFactory();
35
36   public static void main(String JavaDoc[] args) {
37     TestRunner.run(IdefixProcessorTest.class);
38   }
39
40   /**
41    * Creates a new IdefixProcessorTest instance.
42    */

43   public IdefixProcessorTest(String JavaDoc aName) {
44     super(aName);
45   }
46
47
48   /**
49    *
50    */

51   public void testSimpleObject() throws Exception JavaDoc {
52     NamespaceFactoryIF aNSFactory = new DefaultNamespaceFactory();
53     SerializerFactoryIF aSerFactory = new DefaultSerializerFactory();
54     IdefixProcessorIF aProcessor = _theFactory.createProcessor(aSerFactory, aNSFactory);
55     
56     SimpleObject anObject = new SimpleObject("maximumPoolSize", "100", "java.lang.int");
57     String JavaDoc aResult = aProcessor.process(anObject);
58     String JavaDoc anExpectedResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><SimpleObject" +
59             " name=\"maximumPoolSize\"" +
60             " value=\"100\"" +
61             " type=\"java.lang.int\"" +
62             " />";
63     assertEquals("The xml of the serializer is invalid", anExpectedResult, aResult);
64   }
65
66
67   /**
68    *
69    */

70   public void testSimpleObjectWithNS() throws Exception JavaDoc {
71     PatternNamespaceFactory aPNSFactory = new PatternNamespaceFactory();
72     aPNSFactory.addNamespace(SimpleObject.class, new Namespace("http://www.sapia-oss.org", "SAPIA"));
73     DefaultNamespaceFactory aDNSFactory = new DefaultNamespaceFactory();
74     CompositeNamespaceFactory aCNSFactory = new CompositeNamespaceFactory();
75     aCNSFactory.registerNamespaceFactory(aPNSFactory);
76     aCNSFactory.registerNamespaceFactory(aDNSFactory);
77
78     SerializerFactoryIF aSerFactory = new DefaultSerializerFactory();
79     IdefixProcessorIF aProcessor = _theFactory.createProcessor(aSerFactory, aCNSFactory);
80     
81     SimpleObject anObject = new SimpleObject("maximumPoolSize", "100", "java.lang.int");
82     String JavaDoc aResult = aProcessor.process(anObject);
83     String JavaDoc anExpectedResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
84             "<SAPIA:SimpleObject xmlns:SAPIA=\"http://www.sapia-oss.org\"" +
85             " name=\"maximumPoolSize\"" +
86             " value=\"100\"" +
87             " type=\"java.lang.int\"" +
88             " />";
89     assertEquals("The xml of the serializer is invalid", anExpectedResult, aResult);
90   }
91
92
93   /**
94    *
95    */

96   public void testBasicTypes() throws Exception JavaDoc {
97     NamespaceFactoryIF aNSFactory = new DefaultNamespaceFactory();
98     SerializerFactoryIF aSerFactory = new DefaultSerializerFactory();
99     IdefixProcessorIF aProcessor = _theFactory.createProcessor(aSerFactory, aNSFactory);
100     
101     String JavaDoc aResult = aProcessor.process(new BasicTypes());
102     String JavaDoc anExpectedResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
103             "<BasicTypes boolean=\"true\" char=\"Z\" string=\"foo-bar\" positiveByte=\"127\"" +
104             " negativeByte=\"-128\" byteObject=\"95\" positiveShort=\"32767\"" +
105             " negativeShort=\"-32768\" shortObject=\"1095\" positiveInt=\"2147483647\"" +
106             " negativeInt=\"-2147483648\" integerObject=\"188295\"" +
107             " postitiveLong=\"9223372036854775807\" negativeLong=\"-9223372036854775808\"" +
108             " longObject=\"100000000095\" positiveFloat=\"3.4028235E38\"" +
109             " negativeFloat=\"1.4E-45\" floatObject=\"1243.95\"" +
110             " positiveDouble=\"1.7976931348623157E308\" negativeDouble=\"4.9E-324\"" +
111             " doubleObject=\"1.000000000024395E13\" booleanObject=\"false\"" +
112             " />";
113     assertEquals("The xml of the serializer is invalid", anExpectedResult, aResult);
114   }
115 }
116
Popular Tags