View Javadoc
1   package org.synchronoss.cpo.jdbc.adapter;
2   
3   /*-
4    * [[
5    * jdbc
6    * ==
7    * Copyright (C) 2003 - 2026 Exaxis LLC, Synchronoss Technologies Inc
8    * ==
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   *
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Lesser Public License for more details.
18   *
19   * You should have received a copy of the GNU General Lesser Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22   * ]]
23   */
24  
25  import static org.testng.Assert.*;
26  
27  import java.util.ArrayList;
28  import org.synchronoss.cpo.core.CpoAdapter;
29  import org.synchronoss.cpo.core.CpoAdapterFactoryManager;
30  import org.synchronoss.cpo.jdbc.ValueObject;
31  import org.testng.annotations.AfterClass;
32  import org.testng.annotations.BeforeClass;
33  import org.testng.annotations.Test;
34  
35  /**
36   * BlobTest is a test class for testing the JdbcAdapter class Constructors
37   *
38   * @author david berry
39   */
40  public class RollbackTest {
41  
42    // unique id base matching the hardcoded ids in this class's meta rollback groups
43    private static final int IDB = 2000000;
44  
45    private CpoAdapter cpoAdapter = null;
46  
47    public RollbackTest() {}
48  
49    /**
50     * <code>setUp</code> Load the datasource from the properties in the property file
51     * jdbc_en_US.properties
52     */
53    @BeforeClass
54    public void setUp() {
55      String method = "setUp:";
56  
57      try {
58        cpoAdapter = CpoAdapterFactoryManager.getCpoAdapter(JdbcStatics.ADAPTER_CONTEXT_JDBC);
59        assertNotNull(cpoAdapter, method + "cpoAdapter is null");
60      } catch (Exception e) {
61        fail(method + e.getMessage());
62      }
63      ValueObject vo = ValueObjectFactory.createValueObject(IDB + 1);
64      try {
65        cpoAdapter.insertBean(vo);
66      } catch (Exception e) {
67        fail(method + e.getMessage());
68      }
69    }
70  
71    /** DOCUMENT ME! */
72    @AfterClass
73    public void tearDown() {
74      ValueObject vo = ValueObjectFactory.createValueObject(IDB + 1);
75      try {
76        cpoAdapter.deleteBean(vo);
77      } catch (Exception e) {
78      }
79      cpoAdapter = null;
80    }
81  
82    /** DOCUMENT ME! */
83    @Test
84    public void testRollbackProcessUpdateCollection() {
85      String method = "testRollbackProcessUpdateCollection:";
86      ValueObject vo = ValueObjectFactory.createValueObject(IDB + 2);
87      ValueObject vo2 = ValueObjectFactory.createValueObject(IDB + 1);
88      ArrayList<ValueObject> al = new ArrayList<>();
89  
90      al.add(vo);
91      al.add(vo2);
92  
93      try {
94        cpoAdapter.insertBeans(ValueObject.FG_CREATE_TESTROLLBACK, al);
95        fail(method + "Insert should have thrown an exception");
96      } catch (Exception e) {
97        try {
98          ValueObject rvo = cpoAdapter.retrieveBean(vo);
99          assertNull(rvo, method + "Value Object did not rollback");
100       } catch (Exception e2) {
101         fail(method + e.getMessage());
102       }
103     }
104   }
105 
106   /** DOCUMENT ME! */
107   @Test
108   public void testSingleRollback() {
109     String method = "testSingleRollback:";
110     ValueObject vo = ValueObjectFactory.createValueObject(IDB + 2);
111     try {
112       cpoAdapter.insertBean(ValueObject.FG_CREATE_TESTSINGLEROLLBACK, vo);
113       fail(method + "Insert should have thrown an exception");
114     } catch (Exception e) {
115       try {
116         ValueObject rvo = cpoAdapter.retrieveBean(vo);
117         assertNull(rvo, method + "Value Object did not rollback");
118       } catch (Exception e2) {
119         fail(method + e.getMessage());
120       }
121     }
122   }
123 }