1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.page;
18  
19  import junit.framework.Test;
20  import junit.framework.TestSuite;
21  
22  import org.apache.jetspeed.components.util.DatasourceEnabledSpringTestCase;
23  import org.apache.jetspeed.om.folder.Folder;
24  import org.apache.jetspeed.om.page.Page;
25  import org.apache.jetspeed.page.impl.DatabasePageManagerCache;
26  
27  /***
28   * Test Transactions
29   * 
30   * @author <a href="rwatler@apache.org">Randy Watler</a>
31   * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
32   * @version $Id: $
33   *          
34   */
35  public class TestTransactions extends  DatasourceEnabledSpringTestCase implements PageManagerTestShared
36  {
37      protected PageManager pageManager;
38  
39      protected String somePortletId;
40      
41      public static void main(String args[])
42      {
43          junit.awtui.TestRunner.main(new String[]
44          { TestTransactions.class.getName() });
45      }
46      
47      protected void setUp() throws Exception
48      {
49          super.setUp();        
50          pageManager = (PageManager)ctx.getBean("pageManager");
51      }
52  
53      public static Test suite()
54      {
55  //        System.setProperty("org.apache.jetspeed.database.url", "jdbc:mysql://j2-server/j2"); 
56  //        System.setProperty("org.apache.jetspeed.database.driver", "com.mysql.jdbc.Driver");
57  //        System.setProperty("org.apache.jetspeed.database.user", "j2");
58  //        System.setProperty("org.apache.jetspeed.database.password", "xxxxx");
59          
60          // All methods starting with "test" will be executed in the test suite.
61          return new TestSuite(TestTransactions.class);
62      }
63      
64      protected String[] getConfigurations()
65      {
66          return new String[]
67          { "tx-page-manager.xml", "transaction.xml", "interceptors.xml" }; 
68      }
69  
70      protected String[] getBootConfigurations()
71      {
72          return new String[]
73          { "boot/datasource.xml"};
74      }
75      
76      public void testTx() throws Exception
77      {
78          if (pageManager.folderExists("/"))
79          {
80              pageManager.removeFolder(pageManager.getFolder("/"));
81          }
82          Folder root = pageManager.newFolder("/");
83          pageManager.updateFolder(root);
84          
85          System.out.println("--- before new Page");
86          DatabasePageManagerCache.dump();
87          
88          Page[] pages = new Page[3];
89          pages[0] = pageManager.newPage("/tx__test1.psml");
90          pages[1] = pageManager.newPage("/tx__test2.psml");
91          pages[2] = pageManager.newPage("/tx__test3.psml");
92          
93          System.out.println("--- after new Page");
94          DatabasePageManagerCache.dump();
95          
96          try
97          {
98              pageManager.addPages(pages);
99          }
100         catch (Exception e)
101         {
102             System.out.println("Exception adding pages" + e);
103            // e.printStackTrace();
104             
105         }
106         System.out.println("--- after rollback");
107         DatabasePageManagerCache.dump();
108         assertFalse("page 1 found", pageManager.pageExists("/tx__test1.psml"));
109         assertFalse("page 2 found", pageManager.pageExists("/tx__test2.psml"));
110         assertFalse("page 3 found", pageManager.pageExists("/tx__test3.psml"));
111     }
112 }