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.CpoAdapter;
30  import org.synchronoss.cpo.core.CpoAdapterFactoryManager;
31  import org.synchronoss.cpo.core.CpoQuery;
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 ExecuteTest {
45  
46    // unique id base so this class's rows never collide with another test class's
47    private static final int IDB = 900000;
48  
49    private static final Logger logger = LoggerFactory.getLogger(ExecuteTest.class);
50    private CpoAdapter cpoAdapter = null;
51    private boolean isSupportsCalls = true;
52  
53    /** Creates a new RollbackTest object. */
54    public ExecuteTest() {}
55  
56    /**
57     * <code>setUp</code> Load the datasource from the properties in the property file
58     * jdbc_en_US.properties
59     */
60    @Parameters({"db.callsupport"})
61    @BeforeClass
62    public void setUp(boolean callSupport) {
63      String method = "setUp:";
64      isSupportsCalls = callSupport;
65  
66      try {
67        cpoAdapter = CpoAdapterFactoryManager.getCpoAdapter(JdbcStatics.ADAPTER_CONTEXT_JDBC);
68        assertNotNull(cpoAdapter, method + "cpoAdapter is null");
69      } catch (Exception e) {
70        fail(method + e.getMessage());
71      }
72    }
73  
74    /** DOCUMENT ME! */
75    @AfterClass
76    public void tearDown() {
77      cpoAdapter = null;
78    }
79  
80    /** DOCUMENT ME! */
81    @Test
82    public void testExecute() {
83      if (isSupportsCalls) {
84        String method = "testExecute:";
85        ValueObject vo = ValueObjectFactory.createValueObject(IDB + 1);
86        vo.setAttrInteger(3);
87        ValueObject rvo;
88  
89        try {
90          rvo = cpoAdapter.executeBean(ValueObject.FG_EXECUTE_TESTEXECUTEOBJECT, vo);
91          assertNotNull(rvo, method + "Returned Value object is null");
92          assertEquals(rvo.getAttrDouble(), 27, "power(3,3)=" + rvo.getAttrDouble());
93        } catch (Exception e) {
94          logger.error(ExceptionHelper.getLocalizedMessage(e));
95          fail(method + e.getMessage());
96        }
97  
98        try {
99          vo = ValueObjectFactory.createValueObject(IDB + 1);
100         vo.setAttrSmallInt((short) 3);
101         rvo = cpoAdapter.executeBean(ValueObject.FG_EXECUTE_TESTEXECUTEOBJECTNOTRANSFORM, vo);
102         assertNotNull(method + "Returned Value object is null");
103         assertEquals(rvo.getAttrDouble(), 27, "power(3,3)=" + rvo.getAttrDouble());
104       } catch (Exception e) {
105         logger.error(ExceptionHelper.getLocalizedMessage(e));
106         fail(method + e.getMessage());
107       }
108     } else {
109       logger.error(cpoAdapter.getDataSourceName() + " does not support CallableStatements");
110     }
111   }
112 
113   @Test
114   public void testExecute2() {
115     if (isSupportsCalls) {
116       String method = "testExecuteObject:";
117       ValueObject vo = ValueObjectFactory.createValueObject(IDB + 1);
118       vo.setAttrInteger(3);
119       ValueObject rvo;
120 
121       try {
122         rvo =
123             cpoAdapter.executeBean(
124                 CpoQuery.group(ValueObject.FG_EXECUTE_TESTEXECUTEOBJECT), vo, vo);
125         assertNotNull(method + "Returned Value object is null");
126         assertEquals(rvo.getAttrDouble(), 27, "power(3,3)=" + rvo.getAttrDouble());
127       } catch (Exception e) {
128         logger.error(ExceptionHelper.getLocalizedMessage(e));
129         fail(method + e.getMessage());
130       }
131     }
132   }
133 }