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 org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  import org.synchronoss.cpo.core.CpoAdapterFactoryManager;
30  import org.synchronoss.cpo.core.CpoQuery;
31  import org.synchronoss.cpo.core.CpoTrxAdapter;
32  import org.synchronoss.cpo.core.helper.ExceptionHelper;
33  import org.synchronoss.cpo.jdbc.ValueObject;
34  import org.testng.annotations.AfterClass;
35  import org.testng.annotations.BeforeClass;
36  import org.testng.annotations.Parameters;
37  import org.testng.annotations.Test;
38  
39  /**
40   * BlobTest is a test class for testing the JdbcAdapter class Constructors
41   *
42   * @author david berry
43   */
44  public class ExecuteTrxTest {
45  
46    // unique id base so this class's rows never collide with another test class's
47    private static final int IDB = 1000000;
48  
49    private static final Logger logger = LoggerFactory.getLogger(ExecuteTrxTest.class);
50    //  private CpoAdapter cpoAdapter = null;
51    private CpoTrxAdapter trxAdapter = null;
52    private boolean isSupportsCalls = true;
53  
54    /** Creates a new RollbackTest object. */
55    public ExecuteTrxTest() {}
56  
57    /**
58     * <code>setUp</code> Load the datasource from the properties in the property file
59     * jdbc_en_US.properties
60     */
61    @Parameters({"db.callsupport"})
62    @BeforeClass
63    public void setUp(boolean callSupport) {
64      String method = "setUp:";
65      isSupportsCalls = callSupport;
66  
67      try {
68        //      cpoAdapter = CpoAdapterFactoryManager.getCpoAdapter(JdbcStatics.ADAPTER_CONTEXT_JDBC);
69        trxAdapter = CpoAdapterFactoryManager.getCpoTrxAdapter(JdbcStatics.ADAPTER_CONTEXT_JDBC);
70        //      assertNotNull(method + "CpoAdapter is null", cpoAdapter);
71        assertNotNull(trxAdapter, method + "trxAdapter is null");
72      } catch (Exception e) {
73        fail(method + e.getMessage());
74      }
75    }
76  
77    /** DOCUMENT ME! */
78    @AfterClass
79    public void tearDown() {
80      try {
81        trxAdapter.close();
82      } catch (Exception e) {
83      }
84      trxAdapter = null;
85    }
86  
87    /** DOCUMENT ME! */
88    @Test
89    public void testExecuteTrx() {
90      if (isSupportsCalls) {
91        String method = "testExecuteTrx:";
92        ValueObject vo = ValueObjectFactory.createValueObject(IDB + 1);
93        vo.setAttrInteger(3);
94        ValueObject rvo;
95  
96        try {
97          rvo = trxAdapter.executeBean(ValueObject.FG_EXECUTE_TESTEXECUTEOBJECT, vo);
98          trxAdapter.commit();
99          assertNotNull(rvo, method + "Returned Value object is null");
100         assertEquals(rvo.getAttrDouble(), 27, "power(3,3)=" + rvo.getAttrDouble());
101       } catch (Exception e) {
102         try {
103           trxAdapter.rollback();
104         } catch (Exception ex) {
105         }
106         logger.error(ExceptionHelper.getLocalizedMessage(e));
107         fail(method + e.getMessage());
108       }
109 
110       try {
111         vo = ValueObjectFactory.createValueObject(IDB + 1);
112         vo.setAttrSmallInt((short) 3);
113         rvo = trxAdapter.executeBean(ValueObject.FG_EXECUTE_TESTEXECUTEOBJECTNOTRANSFORM, vo);
114         trxAdapter.commit();
115         assertNotNull(method + "Returned Value object is null");
116         assertEquals(rvo.getAttrDouble(), 27, "power(3,3)=" + rvo.getAttrDouble());
117       } catch (Exception e) {
118         try {
119           trxAdapter.rollback();
120         } catch (Exception ex) {
121         }
122         logger.error(ExceptionHelper.getLocalizedMessage(e));
123         fail(method + e.getMessage());
124       }
125     } else {
126       logger.error(trxAdapter.getDataSourceName() + " does not support CallableStatements");
127     }
128   }
129 
130   @Test
131   public void testExecute2() {
132     if (isSupportsCalls) {
133       String method = "testExecuteObject:";
134       ValueObject vo = ValueObjectFactory.createValueObject(IDB + 1);
135       vo.setAttrInteger(3);
136       ValueObject rvo;
137 
138       try {
139         rvo =
140             trxAdapter.executeBean(
141                 CpoQuery.group(ValueObject.FG_EXECUTE_TESTEXECUTEOBJECT), vo, vo);
142         trxAdapter.commit();
143         assertNotNull(method + "Returned Value object is null");
144         assertEquals(rvo.getAttrDouble(), 27, "power(3,3)=" + rvo.getAttrDouble());
145       } catch (Exception e) {
146         try {
147           trxAdapter.rollback();
148         } catch (Exception ex) {
149         }
150         logger.error(ExceptionHelper.getLocalizedMessage(e));
151         fail(method + e.getMessage());
152       }
153     }
154   }
155 }