Commits

Anonymous committed 514506c

Removing the delegating sax xml config provider

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@21e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits f25eeb0

Comments (0)

Files changed (7)

src/test/com/opensymphony/xwork/xml/DefaultDelegatingHandlerTest.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.xwork.xml;
-
-import com.mockobjects.dynamic.C;
-import com.mockobjects.dynamic.Mock;
-
-import com.opensymphony.xwork.util.OgnlValueStack;
-import com.opensymphony.xwork.xml.DefaultDelegatingHandler;
-import com.opensymphony.xwork.xml.DelegatingHandler;
-import com.opensymphony.xwork.xml.Path;
-import com.opensymphony.xwork.xml.SubHandler;
-
-import junit.framework.TestCase;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-import java.util.List;
-import java.util.Map;
-
-
-/**
- * DefaultDelegatingHandlerTest
- * @author Jason Carreira
- * Created May 16, 2003 10:16:15 PM
- */
-public class DefaultDelegatingHandlerTest extends TestCase {
-    //~ Instance fields ////////////////////////////////////////////////////////
-
-    private DefaultDelegatingHandler delegatingHandler;
-    private Path fooPath = Path.getInstance("/Foo");
-
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    public void setUp() {
-        delegatingHandler = new DefaultDelegatingHandler();
-    }
-
-    public void testAddRemoveHandler() {
-        TestSubHandler handler1 = new TestSubHandler(fooPath);
-        TestSubHandler handler2 = new TestSubHandler(fooPath);
-        delegatingHandler.addHandler(fooPath, handler1);
-
-        List handlers = delegatingHandler.getHandlersForPath(fooPath);
-        assertEquals(1, handlers.size());
-        assertEquals(handler1, handlers.get(0));
-
-        //make sure we can't add this more than once
-        delegatingHandler.addHandler(fooPath, handler1);
-        handlers = delegatingHandler.getHandlersForPath(fooPath);
-        assertEquals(1, handlers.size());
-        assertEquals(handler1, handlers.get(0));
-        delegatingHandler.addHandler(fooPath, handler2);
-        handlers = delegatingHandler.getHandlersForPath(fooPath);
-        assertEquals(2, handlers.size());
-        assertEquals(handler1, handlers.get(0));
-        assertEquals(handler2, handlers.get(1));
-        delegatingHandler.removeHandler(fooPath, handler1);
-        handlers = delegatingHandler.getHandlersForPath(fooPath);
-        assertEquals(1, handlers.size());
-        assertEquals(handler2, handlers.get(0));
-    }
-
-    public void testBuildAttributeMap() {
-        final String key = "testBuildAttributeMap.key";
-        final String value = "testBuildAttributeMap.value";
-
-        Mock attributeMock = new Mock(Attributes.class);
-        attributeMock.expectAndReturn("getLength", new Integer(1));
-        attributeMock.expectAndReturn("getQName", new Integer(0), key);
-        attributeMock.expectAndReturn("getValue", new Integer(0), value);
-
-        Attributes attributes = (Attributes) attributeMock.proxy();
-        Map attrMap = delegatingHandler.buildAttributeMap(attributes);
-        assertTrue(attrMap.containsKey(key));
-        assertEquals(value, attrMap.get(key));
-
-        attributeMock.verify();
-    }
-
-    public void testNestedDelegatingHandlers() {
-        final Path barPath = Path.getInstance("/Bar");
-        DelegatingHandler nestedDelegatingHandler = new DefaultDelegatingHandler(fooPath);
-        nestedDelegatingHandler.registerWith(delegatingHandler);
-
-        Mock subHandlerMock = new Mock(SubHandler.class);
-        SubHandler subHandler = (SubHandler) subHandlerMock.proxy();
-        subHandlerMock.expectAndReturn("hashCode", new Integer(234));
-        subHandlerMock.expect("startingPath", C.args(C.eq(barPath), C.IS_NOT_NULL));
-        subHandlerMock.expect("startElement", C.ANY_ARGS);
-        nestedDelegatingHandler.addHandler(barPath, subHandler);
-
-        try {
-            delegatingHandler.startElement("", "", "Foo", null);
-            delegatingHandler.startElement("", "", "Bar", null);
-        } catch (SAXException e) {
-            e.printStackTrace();
-            fail();
-        }
-
-        subHandlerMock.verify();
-    }
-
-    public void testNestedValueStack() {
-        DelegatingHandler nestedDelegatingHandler = new DefaultDelegatingHandler(fooPath);
-        nestedDelegatingHandler.registerWith(delegatingHandler);
-
-        OgnlValueStack stack = delegatingHandler.getValueStack();
-        assertEquals(stack, nestedDelegatingHandler.getValueStack());
-    }
-}

src/test/com/opensymphony/xwork/xml/DefaultSubHandlerTest.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.xwork.xml;
-
-import com.mockobjects.dynamic.C;
-import com.mockobjects.dynamic.Mock;
-
-import com.opensymphony.xwork.xml.DefaultSubHandler;
-import com.opensymphony.xwork.xml.DelegatingHandler;
-import com.opensymphony.xwork.xml.Path;
-
-import junit.framework.TestCase;
-
-
-/**
- * DefaultSubHandlerTest
- * @author Jason Carreira
- * Created May 16, 2003 3:27:55 PM
- */
-public class DefaultSubHandlerTest extends TestCase {
-    //~ Instance fields ////////////////////////////////////////////////////////
-
-    DefaultSubHandler handler;
-
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    public void setUp() {
-        handler = new TestSubHandler("/Foo");
-    }
-
-    public void testRegisterWithAndUnregister() {
-        Path path = Path.getInstance("/Foo");
-        Mock delegatingHandlerMock = new Mock(DelegatingHandler.class);
-        delegatingHandlerMock.expectVoid("addHandler", C.args(C.eq(path), C.eq(handler)));
-
-        DelegatingHandler delegatingHandler = (DelegatingHandler) delegatingHandlerMock.proxy();
-        handler.registerWith(delegatingHandler);
-        assertEquals(delegatingHandler, handler.getRootHandler());
-        delegatingHandlerMock.expectVoid("removeHandler", C.args(C.eq(path), C.eq(handler)));
-        handler.unregisterWith(delegatingHandler);
-        assertNull(handler.getRootHandler());
-        delegatingHandlerMock.verify();
-    }
-
-    public void testXmlEncode() {
-        String inString = "< & > " + '"';
-        String outString = "&lt; &amp; &gt; &quot;";
-        String result = handler.xmlEncode(inString).toString();
-        assertEquals(outString, result);
-    }
-}

src/test/com/opensymphony/xwork/xml/TestSubHandler.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.xwork.xml;
-
-import com.opensymphony.xwork.xml.DefaultSubHandler;
-import com.opensymphony.xwork.xml.Path;
-
-
-/**
- * TestSubHandler
- * @author Jason Carreira
- * Created May 16, 2003 10:27:42 PM
- */
-public class TestSubHandler extends DefaultSubHandler {
-    //~ Constructors ///////////////////////////////////////////////////////////
-
-    public TestSubHandler(Path path) {
-        super(path);
-    }
-
-    public TestSubHandler(String pathString) {
-        super(pathString);
-    }
-}

src/test/com/opensymphony/xwork/xml/handlers/AddPartHandlerTest.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.xwork.xml.handlers;
-
-import com.opensymphony.xwork.xml.DefaultDelegatingHandler;
-import com.opensymphony.xwork.xml.Path;
-import com.opensymphony.xwork.xml.handlers.AddPartHandler;
-
-import junit.framework.TestCase;
-
-
-/**
- * AddPartHandlerTest
- * @author Jason Carreira
- * Created May 19, 2003 8:26:54 AM
- */
-public class AddPartHandlerTest extends TestCase {
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    public void testAddPart() {
-        DefaultDelegatingHandler root = new DefaultDelegatingHandler("");
-        TestBean parent = new TestBean();
-        parent.setName("parent");
-
-        TestBean child1 = new TestBean();
-        child1.setName("child1");
-
-        TestBean child2 = new TestBean();
-        child2.setName("child2");
-        root.getValueStack().push(parent);
-        root.getValueStack().push(child1);
-        assertEquals(0, parent.getChildren().size());
-
-        Path fooPath = Path.getInstance("/Foo");
-
-        AddPartHandler handler = new AddPartHandler(fooPath, "addChild");
-        handler.registerWith(root);
-
-        handler.endingPath(fooPath);
-
-        assertEquals(1, parent.getChildren().size());
-        assertEquals(child1, parent.getChildren().get(0));
-
-        root.getValueStack().push(child2);
-        handler.endingPath(fooPath);
-
-        assertEquals(2, parent.getChildren().size());
-        assertEquals(child1, parent.getChildren().get(0));
-        assertEquals(child2, parent.getChildren().get(1));
-    }
-}

src/test/com/opensymphony/xwork/xml/handlers/ObjectCreateHandlerTest.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.xwork.xml.handlers;
-
-import com.mockobjects.dynamic.C;
-import com.mockobjects.dynamic.Mock;
-
-import com.opensymphony.xwork.util.OgnlValueStack;
-import com.opensymphony.xwork.xml.DelegatingHandler;
-import com.opensymphony.xwork.xml.Path;
-import com.opensymphony.xwork.xml.handlers.ObjectCreateHandler;
-
-import junit.framework.TestCase;
-
-import org.xml.sax.Attributes;
-
-import java.util.HashMap;
-import java.util.Map;
-
-
-/**
- * ObjectCreateHandlerTest
- * @author Jason Carreira
- * Created May 17, 2003 1:11:05 PM
- */
-public class ObjectCreateHandlerTest extends TestCase {
-    //~ Instance fields ////////////////////////////////////////////////////////
-
-    DelegatingHandler delegatingHandler;
-    Mock delegatingHandlerMock;
-    ObjectCreateHandler handler;
-    OgnlValueStack stack;
-    Path fooPath = Path.getInstance("/Foo");
-
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    public void setUp() {
-        delegatingHandlerMock = new Mock(DelegatingHandler.class);
-        delegatingHandler = (DelegatingHandler) delegatingHandlerMock.proxy();
-        handler = new ObjectCreateHandler(fooPath, TestBean.class);
-        delegatingHandlerMock.expect("addHandler", C.args(C.eq(fooPath), C.eq(handler)));
-        handler.registerWith(delegatingHandler);
-        stack = new OgnlValueStack();
-        delegatingHandlerMock.expectAndReturn("getValueStack", stack);
-    }
-
-    public void testAttributeMapping() {
-        final String key = "attributeKey";
-        final String propertyKey = "name";
-        final String value = "testCreateHandler.name";
-
-        Map attributeMap = new HashMap();
-        attributeMap.put(key, value);
-        attributeMap.put("foo", "bar");
-
-        handler.addAttributeMapping(key, propertyKey);
-
-        Map propertyMap = handler.buildPropertyMap(attributeMap);
-        assertTrue(propertyMap.containsKey("foo"));
-        assertTrue(propertyMap.containsKey(propertyKey));
-        assertEquals("bar", propertyMap.get("foo"));
-        assertEquals(value, propertyMap.get(propertyKey));
-    }
-
-    public void testCreateHandler() {
-        final String key = "name";
-        final String value = "testCreateHandler.name";
-
-        TestBean expected = new TestBean();
-        expected.setName(value);
-
-        Map attributeMap = new HashMap();
-        attributeMap.put(key, value);
-
-        handler.startingPath(fooPath, attributeMap);
-
-        assertEquals(1, stack.size());
-        assertEquals(expected, stack.peek());
-
-        delegatingHandlerMock.verify();
-    }
-}

src/test/com/opensymphony/xwork/xml/handlers/SetPropertyHandlerTest.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.xwork.xml.handlers;
-
-import com.mockobjects.dynamic.C;
-import com.mockobjects.dynamic.Mock;
-
-import com.opensymphony.xwork.util.OgnlValueStack;
-import com.opensymphony.xwork.xml.DelegatingHandler;
-import com.opensymphony.xwork.xml.Path;
-import com.opensymphony.xwork.xml.handlers.SetPropertyHandler;
-
-import junit.framework.TestCase;
-
-
-/**
- * SetPropertyHandlerTest
- * @author Jason Carreira
- * Created May 18, 2003 12:25:05 PM
- */
-public class SetPropertyHandlerTest extends TestCase {
-    //~ Instance fields ////////////////////////////////////////////////////////
-
-    DelegatingHandler delegatingHandler;
-    Mock delegatingHandlerMock;
-    OgnlValueStack stack;
-    Path fooPath = Path.getInstance("/Foo");
-
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    public void setUp() {
-        delegatingHandlerMock = new Mock(DelegatingHandler.class);
-        delegatingHandler = (DelegatingHandler) delegatingHandlerMock.proxy();
-        stack = new OgnlValueStack();
-        delegatingHandlerMock.expectAndReturn("getValueStack", stack);
-    }
-
-    public void testAddsErrorOnEmptyStack() {
-        final String propertyName = "name";
-        SetPropertyHandler handler = buildHandler(propertyName);
-        delegatingHandlerMock.expect("addError", C.ANY_ARGS);
-        handler.handleContent("foo");
-        delegatingHandlerMock.verify();
-    }
-
-    public void testSetInt() {
-        SetPropertyHandler handler = buildHandler("count");
-        stack.push(new TestBean());
-
-        final String content = "12";
-        handler.handleContent(content);
-        assertEquals(12, ((TestBean) stack.peek()).getCount());
-        delegatingHandlerMock.verify();
-    }
-
-    public void testSetString() {
-        SetPropertyHandler handler = buildHandler("name");
-        stack.push(new TestBean());
-
-        final String content = "testSetString.name";
-        handler.handleContent(content);
-        assertEquals(content, ((TestBean) stack.peek()).getName());
-        delegatingHandlerMock.verify();
-    }
-
-    private SetPropertyHandler buildHandler(String propertyName) {
-        SetPropertyHandler handler = new SetPropertyHandler(fooPath, propertyName);
-        delegatingHandlerMock.expect("addHandler", C.args(C.eq(fooPath), C.eq(handler)));
-        handler.registerWith(delegatingHandler);
-
-        return handler;
-    }
-}

src/test/com/opensymphony/xwork/xml/handlers/TestBean.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.xwork.xml.handlers;
-
-import java.util.ArrayList;
-import java.util.List;
-
-
-/**
- * TestBean
- * @author Jason Carreira
- * Created May 17, 2003 1:09:38 PM
- */
-public class TestBean {
-    //~ Instance fields ////////////////////////////////////////////////////////
-
-    private List children = new ArrayList();
-    private String name = "name";
-    private int count = 0;
-
-    //~ Constructors ///////////////////////////////////////////////////////////
-
-    public TestBean() {
-    }
-
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    public List getChildren() {
-        return children;
-    }
-
-    public void setCount(int count) {
-        this.count = count;
-    }
-
-    public int getCount() {
-        return count;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public void addChild(TestBean bean) {
-        children.add(bean);
-    }
-
-    public boolean equals(Object o) {
-        if (this == o) {
-            return true;
-        }
-
-        if (!(o instanceof TestBean)) {
-            return false;
-        }
-
-        final TestBean testBean = (TestBean) o;
-
-        if (count != testBean.count) {
-            return false;
-        }
-
-        if (!name.equals(testBean.name)) {
-            return false;
-        }
-
-        return true;
-    }
-
-    public int hashCode() {
-        int result;
-        result = count;
-        result = (29 * result) + name.hashCode();
-
-        return result;
-    }
-}