1 /*
2 * Copyright (C) 2003-2012 David E. Berry
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 * A copy of the GNU Lesser General Public License may also be found at
19 * http://www.gnu.org/licenses/lgpl.txt
20 */
21 package org.synchronoss.cpo.cassandra;
22
23 import org.junit.*;
24 import org.synchronoss.cpo.*;
25
26 import java.util.*;
27
28 import static org.junit.Assert.*;
29
30 /**
31 * BlobTest is a JUnit test class for testing the JdbcAdapter class Constructors
32 *
33 * @author david berry
34 */
35 public class OrderByTest {
36
37 private CpoAdapter cpoAdapter = null;
38 private ArrayList<ValueObject> al = new ArrayList<>();
39
40 public OrderByTest() {
41 }
42
43 /**
44 * <code>setUp</code> Load the datasource from the properties in the property file jdbc_en_US.properties
45 */
46 @Before
47 public void setUp() {
48 String method = "setUp:";
49
50 try {
51 cpoAdapter = CpoAdapterFactory.getCpoAdapter(CassandraStatics.ADAPTER_CONTEXT_DEFAULT);
52 assertNotNull(method + "CpoAdapter is null", cpoAdapter);
53 // Add the test valueObjects
54 } catch (Exception e) {
55 fail(method + e.getMessage());
56 }
57
58 al.add(new ValueObjectBean(1));
59 al.add(new ValueObjectBean(2));
60 al.add(new ValueObjectBean(3));
61 al.add(new ValueObjectBean(4));
62 al.add(new ValueObjectBean(5));
63 try {
64 cpoAdapter.insertObjects("TestOrderByInsert", al);
65 } catch (Exception e) {
66 fail(method + e.getMessage());
67 }
68 }
69
70 @After
71 public void tearDown() {
72 String method = "tearDown:";
73 try {
74 cpoAdapter.deleteObjects("TestOrderByDelete", al);
75 } catch (Exception e) {
76 fail(method + e.getMessage());
77 }
78 cpoAdapter = null;
79 }
80
81 @Test
82 public void testNewOrderBy() {
83 String method = "testOrderByAscending:";
84 Collection<ValueObject> col;
85 String marker = "MY_MARKER";
86 String attribute = "MY_ATTRIBUTE";
87 String function = "MY_FUNCTION";
88 boolean ascending = false;
89
90 try {
91 CpoOrderBy cob = cpoAdapter.newOrderBy(marker, attribute, ascending, function);
92 assertEquals(marker, cob.getMarker());
93 assertEquals(attribute, cob.getAttribute());
94 assertEquals(ascending, cob.getAscending());
95 assertEquals(function, cob.getFunction());
96 } catch (Exception e) {
97 fail(method + e.getMessage());
98 }
99 }
100
101 /**
102 * TODO - add back in when you get the tables correct
103 */
104 @Test
105 public void testOrderByAscending() {
106 // String method = "testOrderByAscending:";
107 // Collection<ValueObject> col;
108 //
109 //
110 // try {
111 // Collection<Integer> inColl = new ArrayList<Integer>();
112 // inColl.add(new Integer(1));
113 // inColl.add(new Integer(3));
114 // inColl.add(new Integer(5));
115 //
116 //// CpoWhere cw = cpoAdapter.newWhere();
117 // CpoWhere cw = cpoAdapter.newWhere(CpoWhere.LOGIC_NONE, "id", CpoWhere.COMP_IN, inColl);
118 // ArrayList<CpoWhere> wheres = new ArrayList<CpoWhere>();
119 // wheres.add(cw);
120 //
121 // CpoOrderBy cob = cpoAdapter.newOrderBy("id", true);
122 // Collection<CpoOrderBy> colCob = new ArrayList<CpoOrderBy>();
123 // colCob.add(cob);
124 // ValueObject valObj = new ValueObjectBean();
125 // col = cpoAdapter.retrieveBeans("TestOrderByRetrieve", valObj, wheres, colCob);
126 //
127 // int id = 1;
128 // for (ValueObject vo : col) {
129 // assertEquals(id, vo.getId());
130 // id++;
131 // }
132 // } catch (Exception e) {
133 // fail(method + e.getMessage());
134 // }
135 }
136
137 /**
138 * TODO - add back in when you get the tables correct
139 */
140 @Test
141 public void testOrderByDescending() {
142 // String method = "testOrderByDescending:";
143 // List<ValueObject> col;
144 //
145 // try {
146 // CpoOrderBy cob = cpoAdapter.newOrderBy("id", false, null);
147 // CpoOrderBy cob2 = cpoAdapter.newOrderBy(CpoOrderBy.DEFAULT_MARKER, "attrVarChar", false, null);
148 // Collection<CpoOrderBy> colCob = new ArrayList<CpoOrderBy>();
149 // colCob.add(cob);
150 // colCob.add(cob2);
151 // ValueObject valObj = new ValueObjectBean();
152 // col = cpoAdapter.retrieveBeans("TestOrderByRetrieve", valObj, colCob);
153 // int id = 5;
154 // for (ValueObject vo : col) {
155 // assertEquals(id, vo.getId());
156 // id--;
157 // }
158 // } catch (Exception e) {
159 // fail(method + e.getMessage());
160 // }
161 }
162
163 @Test
164 public void testOrderByFunction() {
165 // String method = "testOrderByAscending:";
166 // Collection<ValueObject> col;
167 //
168 // ValueObject vobj = new ValueObjectBean(-6);
169 // try {
170 // cpoAdapter.insertObject("TestOrderByInsert", vobj);
171 // } catch (Exception e) {
172 // fail(method + e.getMessage());
173 // }
174 // try {
175 // CpoOrderBy cob = cpoAdapter.newOrderBy("id", true, "ABS(id)");
176 // Collection<CpoOrderBy> colCob = new ArrayList<CpoOrderBy>();
177 // colCob.add(cob);
178 // ValueObject valObj = new ValueObjectBean();
179 // col = cpoAdapter.retrieveBeans("TestOrderByRetrieve", valObj, colCob);
180 //
181 // int id = 1;
182 // for (ValueObject vo : col) {
183 // int voId = vo.getId();
184 // if (voId < 0) {
185 // voId *= -1;
186 // }
187 // assertEquals(id, voId);
188 // id++;
189 // }
190 // } catch (Exception e) {
191 // fail(method + e.getMessage());
192 // }
193 //
194 // try {
195 // cpoAdapter.deleteObject("TestOrderByDelete", vobj);
196 //
197 // } catch (Exception e) {
198 // fail(method + e.getMessage());
199 // }
200 }
201 }