~ubuntu-branches/ubuntu/maverick/libcommons-digester-java/maverick

« back to all changes in this revision

Viewing changes to src/test/org/apache/commons/digester/DigesterTestCase.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath, Kumar Appaiah, Varun Hiremath
  • Date: 2007-09-20 22:02:53 UTC
  • mfrom: (0.1.3 upstream) (2.1.3 gutsy)
  • Revision ID: james.westby@ubuntu.com-20070920220253-y7hrhgzfb6ha150y
Tags: 1.8-1
[ Kumar Appaiah ]
* debian/control:
  + Add XS-Vcs-{Svn,Browser}.
  + Add Homepage field.
* Add watch file.

[ Varun Hiremath ]
* New upstream release
* debian/control:
  + Add myself and Kumar Appaiah to Uploaders.
  + move cdbs and debhelper to Build-Depends.
  + modify Description.
* debian/compat: switch to 5
* remove links file from debian/
* debian/rules:
  + Use DEB_UPSTREAM_VERSION to install jar
  + Create a versioned symbolic link to the jar.
  + implement get-orig-source
* Add debian/orig-tar.sh to remove CRLF line terminators from upstream files.
* Update debian/watch to call debian/orig-tar.sh

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: DigesterTestCase.java 156414 2005-03-07 10:12:40Z skitching $
 
1
/* $Id: DigesterTestCase.java 479207 2006-11-25 21:53:07Z craigmcc $
2
2
 *
3
 
 * Copyright 2001-2004 The Apache Software Foundation.
4
 
 * 
5
 
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 
 * you may not use this file except in compliance with the License.
7
 
 * You may obtain a copy of the License at
 
3
 * Licensed to the Apache Software Foundation (ASF) under one or more
 
4
 * contributor license agreements.  See the NOTICE file distributed with
 
5
 * this work for additional information regarding copyright ownership.
 
6
 * The ASF licenses this file to You under the Apache License, Version 2.0
 
7
 * (the "License"); you may not use this file except in compliance with
 
8
 * the License.  You may obtain a copy of the License at
8
9
 * 
9
10
 *      http://www.apache.org/licenses/LICENSE-2.0
10
11
 * 
18
19
 
19
20
package org.apache.commons.digester;
20
21
 
 
22
import java.io.StringReader;
21
23
import java.math.BigDecimal;
22
24
import java.net.URL;
23
 
import java.io.StringReader;
 
25
import java.util.ArrayList;
 
26
import java.util.EmptyStackException;
24
27
import java.util.Iterator;
25
 
import java.util.List;
26
28
import java.util.Map;
27
 
import java.util.EmptyStackException;
28
29
 
29
30
import junit.framework.Test;
30
31
import junit.framework.TestCase;
31
32
import junit.framework.TestSuite;
32
33
 
 
34
import org.xml.sax.Attributes;
33
35
import org.xml.sax.ErrorHandler;
34
 
import org.xml.sax.Attributes;
 
36
import org.xml.sax.InputSource;
35
37
import org.xml.sax.helpers.AttributesImpl;
36
 
import org.xml.sax.InputSource;
37
38
 
38
39
 
39
40
/**
42
43
 * </p>
43
44
 *
44
45
 * @author Craig R. McClanahan
45
 
 * @version $Revision: 156414 $ $Date: 2005-03-07 23:12:40 +1300 (Mon, 07 Mar 2005) $
 
46
 * @version $Revision: 479207 $ $Date: 2006-11-25 16:53:07 -0500 (Sat, 25 Nov 2006) $
46
47
 */
47
48
 
48
49
public class DigesterTestCase extends TestCase {
169
170
        for (int i = 0; i < registrations.length; i += 2) {
170
171
            URL url = this.getClass().getResource(registrations[i + 1]);
171
172
            if (url != null) {
172
 
                digester.register(registrations[i], url.toString());
 
173
                digester.register(registrations[i], url);
173
174
                n++;
174
175
            }
175
176
        }
201
202
     */
202
203
    public void testRules() {
203
204
 
204
 
        List list = null;
205
 
 
206
205
        assertEquals("Initial rules list is empty",
207
206
                0, digester.getRules().match(null, "a").size());
208
207
        digester.addSetProperties("a");
497
496
        assertNotNull("root object not retrieved", root);
498
497
        assertTrue("root object not a TestRule instance", (root instanceof TestBean));
499
498
    }
 
499
    
 
500
    /** Utility class for method testStackAction */
 
501
    private static class TrackingStackAction implements StackAction {
 
502
        public ArrayList events = new ArrayList();
 
503
        public Object onPush(Digester d, String stackName, Object o) {
 
504
                String msg = "push:" + stackName + ":" + o.toString();
 
505
                events.add(msg);
 
506
                
 
507
                String str = o.toString();
 
508
                if (str.startsWith("replpush")) {
 
509
                        return new String(str);
 
510
                } else {
 
511
                        return o;
 
512
                }
 
513
        }
 
514
        public Object onPop(Digester d, String stackName, Object o) {
 
515
                String msg = "pop:" + stackName + ":" + o.toString();
 
516
                events.add(msg);
 
517
                String str = o.toString();
 
518
                if (str.startsWith("replpop")) {
 
519
                        return new String(str);
 
520
                } else {
 
521
                        return o;
 
522
                }
 
523
        }
 
524
    }
 
525
 
 
526
    /**
 
527
     * Test custom StackAction subclasses.
 
528
     */
 
529
    public void testStackAction() {
 
530
        TrackingStackAction action = new TrackingStackAction();
 
531
        
 
532
        Object obj1 = new String("obj1");
 
533
        Object obj2 = new String("obj2");
 
534
        Object obj3 = new String("replpop.obj3");
 
535
        Object obj4 = new String("replpush.obj4");
 
536
 
 
537
        Object obj8 = new String("obj8");
 
538
        Object obj9 = new String("obj9");
 
539
 
 
540
        Digester d = new Digester();
 
541
        d.setStackAction(action);
 
542
 
 
543
        assertEquals(0, action.events.size());
 
544
        d.push(obj1);
 
545
        d.push(obj2);
 
546
        d.push(obj3);
 
547
        d.push(obj4);
 
548
 
 
549
        assertNotNull(d.peek(0));
 
550
        // for obj4, a copy should have been pushed
 
551
        assertFalse(obj4 == d.peek(0));
 
552
        assertEquals(obj4, d.peek(0));
 
553
        // for obj3, replacement only occurs on pop
 
554
        assertSame(obj3, d.peek(1));
 
555
        assertSame(obj2, d.peek(2));
 
556
        assertSame(obj1, d.peek(3));
 
557
 
 
558
        Object obj4a = d.pop();
 
559
        Object obj3a = d.pop();
 
560
        Object obj2a = d.pop();
 
561
        Object obj1a = d.pop();
 
562
        
 
563
        assertFalse(obj4 == obj4a);
 
564
        assertEquals(obj4, obj4a);
 
565
        assertFalse(obj3 == obj4a);
 
566
        assertEquals(obj3, obj3a);
 
567
        assertSame(obj2, obj2a);
 
568
        assertSame(obj1, obj1a);
 
569
 
 
570
        d.push("stack1", obj8);
 
571
        d.push("stack1", obj9);
 
572
        Object obj9a = d.pop("stack1");
 
573
        Object obj8a = d.pop("stack1");
 
574
 
 
575
        assertSame(obj8, obj8a);
 
576
        assertSame(obj9, obj9a);
 
577
 
 
578
        assertEquals(12, action.events.size());
 
579
        assertEquals("push:null:obj1", action.events.get(0));
 
580
        assertEquals("push:null:obj2", action.events.get(1));
 
581
        assertEquals("push:null:replpop.obj3", action.events.get(2));
 
582
        assertEquals("push:null:replpush.obj4", action.events.get(3));
 
583
        assertEquals("pop:null:replpush.obj4", action.events.get(4));
 
584
        assertEquals("pop:null:replpop.obj3", action.events.get(5));
 
585
        assertEquals("pop:null:obj2", action.events.get(6));
 
586
        assertEquals("pop:null:obj1", action.events.get(7));
 
587
 
 
588
        assertEquals("push:stack1:obj8", action.events.get(8));
 
589
        assertEquals("push:stack1:obj9", action.events.get(9));
 
590
        assertEquals("pop:stack1:obj9", action.events.get(10));
 
591
        assertEquals("pop:stack1:obj8", action.events.get(11));
 
592
    }
500
593
}