001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.page;
018:
019: import junit.framework.Test;
020: import junit.framework.TestSuite;
021:
022: import org.apache.jetspeed.components.util.DatasourceEnabledSpringTestCase;
023: import org.apache.jetspeed.om.folder.Folder;
024: import org.apache.jetspeed.om.page.Page;
025: import org.apache.jetspeed.page.impl.DatabasePageManagerCache;
026:
027: /**
028: * Test Transactions
029: *
030: * @author <a href="rwatler@apache.org">Randy Watler</a>
031: * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
032: * @version $Id: $
033: *
034: */
035: public class TestTransactions extends DatasourceEnabledSpringTestCase
036: implements PageManagerTestShared {
037: protected PageManager pageManager;
038:
039: protected String somePortletId;
040:
041: public static void main(String args[]) {
042: junit.awtui.TestRunner
043: .main(new String[] { TestTransactions.class.getName() });
044: }
045:
046: protected void setUp() throws Exception {
047: super .setUp();
048: pageManager = (PageManager) ctx.getBean("pageManager");
049: }
050:
051: public static Test suite() {
052: // System.setProperty("org.apache.jetspeed.database.url", "jdbc:mysql://j2-server/j2");
053: // System.setProperty("org.apache.jetspeed.database.driver", "com.mysql.jdbc.Driver");
054: // System.setProperty("org.apache.jetspeed.database.user", "j2");
055: // System.setProperty("org.apache.jetspeed.database.password", "xxxxx");
056:
057: // All methods starting with "test" will be executed in the test suite.
058: return new TestSuite(TestTransactions.class);
059: }
060:
061: protected String[] getConfigurations() {
062: return new String[] { "tx-page-manager.xml", "transaction.xml",
063: "interceptors.xml" };
064: }
065:
066: protected String[] getBootConfigurations() {
067: return new String[] { "boot/datasource.xml" };
068: }
069:
070: public void testTx() throws Exception {
071: if (pageManager.folderExists("/")) {
072: pageManager.removeFolder(pageManager.getFolder("/"));
073: }
074: Folder root = pageManager.newFolder("/");
075: pageManager.updateFolder(root);
076:
077: System.out.println("--- before new Page");
078: DatabasePageManagerCache.dump();
079:
080: Page[] pages = new Page[3];
081: pages[0] = pageManager.newPage("/tx__test1.psml");
082: pages[1] = pageManager.newPage("/tx__test2.psml");
083: pages[2] = pageManager.newPage("/tx__test3.psml");
084:
085: System.out.println("--- after new Page");
086: DatabasePageManagerCache.dump();
087:
088: try {
089: pageManager.addPages(pages);
090: } catch (Exception e) {
091: System.out.println("Exception adding pages" + e);
092: // e.printStackTrace();
093:
094: }
095: System.out.println("--- after rollback");
096: DatabasePageManagerCache.dump();
097: assertFalse("page 1 found", pageManager
098: .pageExists("/tx__test1.psml"));
099: assertFalse("page 2 found", pageManager
100: .pageExists("/tx__test2.psml"));
101: assertFalse("page 3 found", pageManager
102: .pageExists("/tx__test3.psml"));
103: }
104: }
|