1 package org.synchronoss.cpo.jdbc.adapter;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
41
42
43
44 public class ExecuteTrxTest {
45
46
47 private static final int IDB = 1000000;
48
49 private static final Logger logger = LoggerFactory.getLogger(ExecuteTrxTest.class);
50
51 private CpoTrxAdapter trxAdapter = null;
52 private boolean isSupportsCalls = true;
53
54
55 public ExecuteTrxTest() {}
56
57
58
59
60
61 @Parameters({"db.callsupport"})
62 @BeforeClass
63 public void setUp(boolean callSupport) {
64 String method = "setUp:";
65 isSupportsCalls = callSupport;
66
67 try {
68
69 trxAdapter = CpoAdapterFactoryManager.getCpoTrxAdapter(JdbcStatics.ADAPTER_CONTEXT_JDBC);
70
71 assertNotNull(trxAdapter, method + "trxAdapter is null");
72 } catch (Exception e) {
73 fail(method + e.getMessage());
74 }
75 }
76
77
78 @AfterClass
79 public void tearDown() {
80 try {
81 trxAdapter.close();
82 } catch (Exception e) {
83 }
84 trxAdapter = null;
85 }
86
87
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 }