From: Will S. <wsa...@us...> - 2005-05-07 23:42:18
|
Update of /cvsroot/mockobjects/mockobjects-java/src/extensions/test/atg/repository In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31457/src/extensions/test/atg/repository Added Files: MockRepositoryTest.java Log Message: Remove old ATG mockobjects. Add the mock repository test. --- NEW FILE: MockRepositoryTest.java --- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001-2004 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The name "MockObjects" must not be * used to endorse or promote products derived from this software * without prior written permission. For written permission, please * contact ap...@ap.... * * 5. Products derived from this software may not be called * "MockObjects", nor may "MockObjects" appear in their name, * without prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package atg.repository; import atg.repository.rql.RqlStatement; import com.mockobjects.atg.adapter.mock.MockItemDescriptor; import com.mockobjects.atg.adapter.mock.MockRepository; import com.mockobjects.atg.nucleus.logging.MockLogListener; import junit.framework.TestCase; import java.util.List; import java.util.Map; import java.util.Set; /** * A test suite for the mock repository. I realize that it's only a mock * repository in a very loose sense. * * @author wsargent * @version $Revision: 1.1 $ * * @since Feb 16, 2004 */ public class MockRepositoryTest extends TestCase { private static final String ITEM_DESCRIPTOR_NAME = "test"; protected MockRepository repository; /** * Constructor for MockRepositoryTest. * * @param arg0 */ public MockRepositoryTest(String pTest) { super(pTest); } public void setUp() throws RepositoryException { repository = new MockRepository(); MockItemDescriptor itemDesc = setUpItemDescriptor(); repository.addItemDescriptor(itemDesc); repository.addView(itemDesc.getRepositoryView()); repository.setLoggingDebug(true); repository.addLogListener(new MockLogListener()); } /** * Sets up the item descriptor. * * @return * * @throws RepositoryException */ private MockItemDescriptor setUpItemDescriptor() throws RepositoryException { MockItemDescriptor itemDesc = new MockItemDescriptor(repository, ITEM_DESCRIPTOR_NAME); itemDesc.addPropertyDescriptor("foo", String.class); itemDesc.addPropertyDescriptor("age", Integer.class); itemDesc.addPropertyDescriptor("interests", List.class); itemDesc.addPropertyDescriptor("addresses", Map.class); itemDesc.addPropertyDescriptor("accounts", Set.class); RepositoryView view = itemDesc.getRepositoryView(); assertNotNull(view); return itemDesc; } public void testHasItemDescriptor() throws RepositoryException { MutableRepository r = repository; RepositoryItemDescriptor repItemDesc = r.getItemDescriptor(ITEM_DESCRIPTOR_NAME); assertNotNull(repItemDesc); RepositoryView view = r.getView(ITEM_DESCRIPTOR_NAME); assertNotNull(view); } public void testCreateItem() throws RepositoryException { MutableRepository r = repository; // Can we get an item? MutableRepositoryItem item = r.createItem(ITEM_DESCRIPTOR_NAME); assertNotNull(item); // Test that the item descriptors are the same... RepositoryItemDescriptor descriptor = item.getItemDescriptor(); RepositoryItemDescriptor repItemDesc = r.getItemDescriptor(ITEM_DESCRIPTOR_NAME); assertNotNull(repItemDesc); assertNotNull(descriptor); assertTrue(descriptor.equals(repItemDesc)); } public void testAddItem() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); RepositoryItem item = r.addItem(mri); assertNotNull(item); } public void testRemoveItem() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); RepositoryItem item = r.addItem(mri); String id = item.getRepositoryId(); r.removeItem(id, ITEM_DESCRIPTOR_NAME); // Should be no item with that id. RepositoryItem removedItem = r.getItem(id, ITEM_DESCRIPTOR_NAME); assertNull(removedItem); } public void testModifyItem() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); mri.setPropertyValue("foo", "created"); assertNotNull(mri); RepositoryItem item = r.addItem(mri); assertNotNull(item); String id = item.getRepositoryId(); assertNotNull(id); MutableRepositoryItem updateItem = r.getItemForUpdate(id, ITEM_DESCRIPTOR_NAME); assertNotNull(updateItem); // Check that it has the same value. String fooValue = (String) updateItem.getPropertyValue("foo"); assertEquals(fooValue, "created"); updateItem.setPropertyValue("foo", "modified"); r.updateItem(updateItem); RepositoryItem afterItem = r.getItem(id, ITEM_DESCRIPTOR_NAME); String newFooValue = (String) afterItem.getPropertyValue("foo"); assertEquals(newFooValue, "modified"); } public void testQueryAll() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); mri.setPropertyValue("foo", "created"); RepositoryItem addedItem = r.addItem(mri); RepositoryView view = r.getView(ITEM_DESCRIPTOR_NAME); assertNotNull(view); RqlStatement stmt = RqlStatement.parseRqlStatement("ALL"); RepositoryItem[] items = stmt.executeQuery(view, null); assertNotNull(items); assertEquals(1, items.length); assertEquals(items[0], addedItem); } public void testQueryFooIsNotCreated() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); mri.setPropertyValue("foo", "created"); r.addItem(mri); RepositoryView view = r.getView(ITEM_DESCRIPTOR_NAME); assertNotNull(view); RqlStatement stmt = RqlStatement.parseRqlStatement("not (foo = ?0)"); String[] args = { "created" }; RepositoryItem[] items = stmt.executeQuery(view, args); if (items != null) { assertTrue(items.length == 0); } } public void testQueryFooIsCreated() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); mri.setPropertyValue("foo", "created"); r.addItem(mri); MutableRepositoryItem mri2 = r.createItem(ITEM_DESCRIPTOR_NAME); mri2.setPropertyValue("foo", "notcreated"); r.addItem(mri2); RepositoryView view = r.getView(ITEM_DESCRIPTOR_NAME); assertNotNull(view); RqlStatement stmt = RqlStatement.parseRqlStatement("foo = ?0"); String[] args = { "created" }; RepositoryItem[] items = stmt.executeQuery(view, args); assertNotNull(items); assertEquals(1, items.length); } public void testQueryFooIsNull() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); mri.setPropertyValue("foo", null); r.addItem(mri); RepositoryView view = r.getView(ITEM_DESCRIPTOR_NAME); assertNotNull(view); RqlStatement stmt = RqlStatement.parseRqlStatement("foo is null"); String[] args = { null }; RepositoryItem[] items = stmt.executeQuery(view, args); assertNotNull(items); assertEquals(1, items.length); } public void testQueryFooIncludesBar() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); List interests = (List) mri.getPropertyValue("interests"); interests.add("biking"); r.addItem(mri); RepositoryView view = r.getView(ITEM_DESCRIPTOR_NAME); assertNotNull(view); RqlStatement stmt = RqlStatement.parseRqlStatement("interests INCLUDES ?0"); String[] args = { "biking" }; RepositoryItem[] items = stmt.executeQuery(view, args); assertNotNull(items); assertEquals(1, items.length); } public void testQueryFooIncludesAnyBar() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); List interests = (List) mri.getPropertyValue("interests"); interests.add("biking"); r.addItem(mri); RepositoryView view = r.getView(ITEM_DESCRIPTOR_NAME); assertNotNull(view); RqlStatement stmt = RqlStatement.parseRqlStatement("interests INCLUDES ANY { \"biking\", \"swimming\" }"); RepositoryItem[] items = stmt.executeQuery(view, null); assertNotNull(items); assertEquals(1, items.length); } public void testQueryFooIncludesAllBar() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); List interests = (List) mri.getPropertyValue("interests"); interests.add("biking"); r.addItem(mri); RepositoryView view = r.getView(ITEM_DESCRIPTOR_NAME); assertNotNull(view); RqlStatement stmt = RqlStatement.parseRqlStatement("interests INCLUDES ALL ?0"); String[] args = { "biking" }; RepositoryItem[] items = stmt.executeQuery(view, args); assertNotNull(items); assertEquals(1, items.length); } /* public void testQueryFooIncludesItem() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); List interests = (List) mri.getPropertyValue("interests"); interests.add("biking"); r.addItem(mri); RepositoryView view = r.getView(ITEM_DESCRIPTOR_NAME); assertNotNull(view); RqlStatement stmt = RqlStatement.parseRqlStatement("addresses INCLUDES ITEM (zip = \"48322\" AND state = \"MI\")"); String[] args = { "biking" }; RepositoryItem[] items = stmt.executeQuery(view, args); assertNotNull(items); assertEquals(1, items.length); } */ /* public void testIdIn() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); List interests = (List) mri.getPropertyValue("interests"); interests.add("biking"); r.addItem(mri); RepositoryView view = r.getView(ITEM_DESCRIPTOR_NAME); assertNotNull(view); RqlStatement stmt = RqlStatement.parseRqlStatement("ID IN { \"0002421\", \"0002219\", \"0003244\" }"); String[] args = { "biking" }; RepositoryItem[] items = stmt.executeQuery(view, args); assertNotNull(items); assertEquals(1, items.length); } */ public void testLessThan() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); mri.setPropertyValue("age", new Integer(29)); r.addItem(mri); RepositoryView view = r.getView(ITEM_DESCRIPTOR_NAME); assertNotNull(view); RqlStatement stmt = RqlStatement.parseRqlStatement("age < ?0"); Object[] args = { new Integer(30) }; RepositoryItem[] items = stmt.executeQuery(view, args); assertNotNull(items); assertEquals(1, items.length); } public void testGreaterThan() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); mri.setPropertyValue("age", new Integer(31)); r.addItem(mri); RepositoryView view = r.getView(ITEM_DESCRIPTOR_NAME); assertNotNull(view); RqlStatement stmt = RqlStatement.parseRqlStatement("age > ?0"); Object[] args = { new Integer(30) }; RepositoryItem[] items = stmt.executeQuery(view, args); assertNotNull(items); assertEquals(1, items.length); } public void testLessThanOrEquals() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); mri.setPropertyValue("age", new Integer(30)); r.addItem(mri); RepositoryView view = r.getView(ITEM_DESCRIPTOR_NAME); assertNotNull(view); RqlStatement stmt = RqlStatement.parseRqlStatement("age <= ?0"); Object[] args = { new Integer(30) }; RepositoryItem[] items = stmt.executeQuery(view, args); assertNotNull(items); assertEquals(1, items.length); } public void testGreaterThanOrEquals() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); mri.setPropertyValue("age", new Integer(30)); r.addItem(mri); RepositoryView view = r.getView(ITEM_DESCRIPTOR_NAME); assertNotNull(view); RqlStatement stmt = RqlStatement.parseRqlStatement("age >= ?0"); Object[] args = { new Integer(30) }; RepositoryItem[] items = stmt.executeQuery(view, args); assertNotNull(items); assertEquals(1, items.length); } public void testOrderByDesc() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); mri.setPropertyValue("age", new Integer(30)); r.addItem(mri); mri = r.createItem(ITEM_DESCRIPTOR_NAME); mri.setPropertyValue("age", new Integer(31)); r.addItem(mri); RepositoryView view = r.getView(ITEM_DESCRIPTOR_NAME); assertNotNull(view); RqlStatement stmt = RqlStatement.parseRqlStatement("age > ?0 ORDER BY age DESC"); Integer[] args = { new Integer(20) }; RepositoryItem[] items = stmt.executeQuery(view, args); assertNotNull(items); assertEquals(2, items.length); } public void testOrderByAsc() throws RepositoryException { MutableRepository r = repository; MutableRepositoryItem mri = r.createItem(ITEM_DESCRIPTOR_NAME); mri.setPropertyValue("age", new Integer(30)); r.addItem(mri); mri = r.createItem(ITEM_DESCRIPTOR_NAME); mri.setPropertyValue("age", new Integer(31)); r.addItem(mri); RepositoryView view = r.getView(ITEM_DESCRIPTOR_NAME); assertNotNull(view); RqlStatement stmt = RqlStatement.parseRqlStatement("age > ?0 ORDER BY age DESC"); Integer[] args = { new Integer(20) }; RepositoryItem[] items = stmt.executeQuery(view, args); assertNotNull(items); assertEquals(2, items.length); } // More queries I haven't even tested... // age > 30 RANGE +10 // age > 30 RANGE 10+ // age > 30 RANGE 40+10 // age > ?0 AND firstName CONTAINS ?1 RANGE ?2+10 // name = ?0.name AND age = ?0.age } |