1 package org.synchronoss.cpo.cassandra;
2
3 /*-
4 * [[
5 * cassandra
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 java.util.Collection;
29 import org.synchronoss.cpo.core.CpoAdapter;
30 import org.synchronoss.cpo.core.CpoAdapterFactoryManager;
31 import org.synchronoss.cpo.core.CpoOrderBy;
32 import org.testng.annotations.AfterClass;
33 import org.testng.annotations.BeforeClass;
34 import org.testng.annotations.Test;
35
36 /**
37 * BlobTest is a test class for testing the JdbcAdapter class Constructors
38 *
39 * @author david berry
40 */
41 public class OrderByTest {
42
43 // unique id base so this class's rows never collide with another test class's
44 private static final int IDB = 900000;
45
46 private CpoAdapter cpoAdapter = null;
47 private ArrayList<ValueObject> al = new ArrayList<>();
48
49 public OrderByTest() {}
50
51 /**
52 * <code>setUp</code> Load the datasource from the properties in the property file
53 * jdbc_en_US.properties
54 */
55 @BeforeClass
56 public void setUp() {
57 String method = "setUp:";
58
59 try {
60 cpoAdapter = CpoAdapterFactoryManager.getCpoAdapter(CassandraStatics.ADAPTER_CONTEXT_DEFAULT);
61 assertNotNull(cpoAdapter, method + "CpoAdapter is null");
62 // Add the test valueObjects
63 } catch (Exception e) {
64 fail(method + e.getMessage());
65 }
66
67 al.add(ValueObjectFactory.createValueObject(IDB + 1));
68 al.add(ValueObjectFactory.createValueObject(IDB + 2));
69 al.add(ValueObjectFactory.createValueObject(IDB + 3));
70 al.add(ValueObjectFactory.createValueObject(IDB + 4));
71 al.add(ValueObjectFactory.createValueObject(IDB + 5));
72 try {
73 cpoAdapter.insertBeans("TestOrderByInsert", al);
74 } catch (Exception e) {
75 fail(method + e.getMessage());
76 }
77 }
78
79 @AfterClass
80 public void tearDown() {
81 String method = "tearDown:";
82 try {
83 cpoAdapter.deleteBeans("TestOrderByDelete", al);
84 } catch (Exception e) {
85 fail(method + e.getMessage());
86 }
87 cpoAdapter = null;
88 }
89
90 @Test
91 public void testNewOrderBy() {
92 String method = "testOrderByAscending:";
93 Collection<ValueObject> col;
94 String marker = "MY_MARKER";
95 String attribute = "MY_ATTRIBUTE";
96 String function = "MY_FUNCTION";
97 boolean ascending = false;
98
99 try {
100 CpoOrderBy cob = cpoAdapter.newOrderBy(marker, attribute, ascending, function);
101 assertEquals(marker, cob.getMarker());
102 assertEquals(attribute, cob.getAttribute());
103 assertEquals(ascending, cob.getAscending());
104 assertEquals(function, cob.getFunction());
105 } catch (Exception e) {
106 fail(method + e.getMessage());
107 }
108 }
109
110 /** TODO - add back in when you get the tables correct */
111 @Test
112 public void testOrderByAscending() {
113 // String method = "testOrderByAscending:";
114 // Collection<ValueObject> col;
115 //
116 //
117 // try {
118 // Collection<Integer> inColl = new ArrayList<Integer>();
119 // inColl.add(new Integer(1));
120 // inColl.add(new Integer(3));
121 // inColl.add(new Integer(5));
122 //
123 //// CpoWhere cw = cpoAdapter.newWhere();
124 // CpoWhere cw = cpoAdapter.newWhere(Logical.NONE, "id", Comparison.IN, inColl);
125 // ArrayList<CpoWhere> wheres = new ArrayList<CpoWhere>();
126 // wheres.add(cw);
127 //
128 // CpoOrderBy cob = cpoAdapter.newOrderBy("id", true);
129 // Collection<CpoOrderBy> colCob = new ArrayList<CpoOrderBy>();
130 // colCob.add(cob);
131 // ValueObject valObj = ValueObjectFactory.createValueObject();
132 // col = cpoAdapter.retrieveBeans("TestOrderByRetrieve", valObj, wheres, colCob);
133 //
134 // int id = 1;
135 // for (ValueObject vo : col) {
136 // assertEquals(id, vo.getId());
137 // id++;
138 // }
139 // } catch (Exception e) {
140 // fail(method + e.getMessage());
141 // }
142 }
143
144 /** TODO - add back in when you get the tables correct */
145 @Test
146 public void testOrderByDescending() {
147 // String method = "testOrderByDescending:";
148 // List<ValueObject> col;
149 //
150 // try {
151 // CpoOrderBy cob = cpoAdapter.newOrderBy("id", false, null);
152 // CpoOrderBy cob2 = cpoAdapter.newOrderBy(CpoOrderBy.DEFAULT_MARKER, "attrVarChar", false,
153 // null);
154 // Collection<CpoOrderBy> colCob = new ArrayList<CpoOrderBy>();
155 // colCob.add(cob);
156 // colCob.add(cob2);
157 // ValueObject valObj = ValueObjectFactory.createValueObject();
158 // col = cpoAdapter.retrieveBeans("TestOrderByRetrieve", valObj, colCob);
159 // int id = 5;
160 // for (ValueObject vo : col) {
161 // assertEquals(id, vo.getId());
162 // id--;
163 // }
164 // } catch (Exception e) {
165 // fail(method + e.getMessage());
166 // }
167 }
168
169 @Test
170 public void testOrderByFunction() {
171 // String method = "testOrderByAscending:";
172 // Collection<ValueObject> col;
173 //
174 // ValueObject vobj = ValueObjectFactory.createValueObject(IDB + -6);
175 // try {
176 // cpoAdapter.insertObject("TestOrderByInsert", vobj);
177 // } catch (Exception e) {
178 // fail(method + e.getMessage());
179 // }
180 // try {
181 // CpoOrderBy cob = cpoAdapter.newOrderBy("id", true, "ABS(id)");
182 // Collection<CpoOrderBy> colCob = new ArrayList<CpoOrderBy>();
183 // colCob.add(cob);
184 // ValueObject valObj = ValueObjectFactory.createValueObject();
185 // col = cpoAdapter.retrieveBeans("TestOrderByRetrieve", valObj, colCob);
186 //
187 // int id = 1;
188 // for (ValueObject vo : col) {
189 // int voId = vo.getId();
190 // if (voId < 0) {
191 // voId *= -1;
192 // }
193 // assertEquals(id, voId);
194 // id++;
195 // }
196 // } catch (Exception e) {
197 // fail(method + e.getMessage());
198 // }
199 //
200 // try {
201 // cpoAdapter.deleteObject("TestOrderByDelete", vobj);
202 //
203 // } catch (Exception e) {
204 // fail(method + e.getMessage());
205 // }
206 }
207 }