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 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 [] args) { 37 TestRunner.run(IdefixProcessorTest.class); 38 } 39 40 43 public IdefixProcessorTest(String aName) { 44 super(aName); 45 } 46 47 48 51 public void testSimpleObject() throws Exception { 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 aResult = aProcessor.process(anObject); 58 String 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 70 public void testSimpleObjectWithNS() throws Exception { 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 aResult = aProcessor.process(anObject); 83 String 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 96 public void testBasicTypes() throws Exception { 97 NamespaceFactoryIF aNSFactory = new DefaultNamespaceFactory(); 98 SerializerFactoryIF aSerFactory = new DefaultSerializerFactory(); 99 IdefixProcessorIF aProcessor = _theFactory.createProcessor(aSerFactory, aNSFactory); 100 101 String aResult = aProcessor.process(new BasicTypes()); 102 String 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 |