1 /* 2 * Copyright (c) 2003 3 * Information Desire GmbH 4 * All rights reserved. 5 */ 6 package com.infodesire.infobit; 7 8 import com.infodesire.infobit.data.Acl; 9 import com.infodesire.infobit.data.Infobit; 10 11 import com.infodesire.infobit.external.InfobitExporter; 12 import com.infodesire.infobit.external.InfobitImporter; 13 14 import com.infodesire.infobit.external.impl.ImporterImpl; 15 // import com.infodesire.infobit.external.impl.VelocityExporter; 16 import com.infodesire.infobit.external.impl.SimpleExporter; 17 18 import junit.framework.TestCase; 19 import junit.framework.TestSuite; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 24 import java.io.BufferedReader; 25 import java.io.IOException; 26 import java.io.InputStream; 27 import java.io.InputStreamReader; 28 import java.io.Reader; 29 import java.io.StringReader; 30 import java.io.StringWriter; 31 32 import java.util.ArrayList; 33 import java.util.Collection; 34 import java.util.HashMap; 35 import java.util.HashSet; 36 import java.util.List; 37 import java.util.Map; 38 import java.util.Set; 39 40 /*** 41 * Implementation common to Test cases asserting the XML representation of 42 * infobits 43 * 44 * @author peter 45 * @created August 27, 2003 46 * @version $Revision: 1.1 $ 47 */ 48 public class XMLTestBase extends InfobitTestBase { 49 50 /*** 51 * Pool belonging to the fixture 52 */ 53 protected InfobitPool _pool; 54 55 /*** 56 * Manager belonging to the fixture 57 */ 58 protected InfobitManager _manager; 59 60 /*** 61 * Common ACL belonging to the fixture 62 */ 63 protected Acl _defaultAcl; 64 65 /*** 66 * The infobit exporter being part of the fixture 67 */ 68 protected InfobitExporter _exporter; 69 70 71 /*** 72 * Initializes the test cases. 73 * 74 * @param name Test name 75 */ 76 public XMLTestBase(String name) { 77 super(name); 78 } 79 80 81 /*** 82 * Common test case fixture. 83 * 84 * @exception Exception Description of Exception 85 */ 86 public void setUp() throws Exception { 87 super.setUp(); 88 _pool = _configuration.getPool("superuser_pool"); 89 _defaultAcl = _pool.getAclManager().createAcl("default"); 90 _manager = _pool.getInfobitManager(); 91 92 // _exporter = new VelocityExporter(); 93 _exporter = new SimpleExporter(); 94 _exporter.setManager(_manager); 95 _exporter.init(); 96 } 97 98 99 /*** 100 * Common teardown of test case fixtures. 101 * 102 * @exception Exception Description of Exception 103 */ 104 public void tearDown() throws Exception { 105 } 106 107 108 109 /*** 110 * Compares a derived XML document with its expected content, ignoring 111 * leading and trailing whitespace and date elements. 112 * 113 * @param derived Source of the derived document to check 114 * @param expected Sourrce of the expected document, against which to 115 * compare <code>derived</code> 116 * @exception Exception Description of Exception 117 */ 118 protected void checkDocument(BufferedReader derived, 119 BufferedReader expected) 120 throws Exception { 121 122 String ld; 123 String le; 124 boolean inDate = false; 125 126 for (; ; ) { 127 ld = derived.readLine(); 128 while (ld != null && ld.trim().length() == 0) { 129 ld = derived.readLine(); 130 } 131 132 le = expected.readLine(); 133 while (le != null && le.trim().length() == 0) { 134 le = expected.readLine(); 135 } 136 137 if (le == null || ld == null) { 138 break; 139 } 140 141 le = le.trim(); 142 ld = ld.trim(); 143 144 // Skip comparision of date elements 145 if (!inDate) { 146 assertEquals(le, ld); 147 } 148 149 if (inDate) { 150 inDate = !le.endsWith("/>"); 151 } 152 else { 153 inDate = le.startsWith("<date"); 154 } 155 } 156 157 assertTrue(le == null && ld == null); 158 } 159 160 }

This page was automatically generated by Maven