001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.tests.shared;
034:
035: import com.flexive.shared.search.*;
036: import org.testng.annotations.DataProvider;
037: import org.testng.annotations.Test;
038:
039: import java.util.Arrays;
040: import java.util.List;
041:
042: /**
043: * Basic unit tests for the ResultPreferences class.
044: *
045: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
046: * @version $Rev: 181 $
047: */
048: @Test(groups="shared")
049: public class ResultPreferencesTest {
050: private static final ResultColumnInfo[][] INFOS_EQUAL = {
051: { new ResultColumnInfo(Table.CONTENT, "type", ""),
052: new ResultColumnInfo(Table.CONTENT, "type", "") },
053: { new ResultColumnInfo(Table.CONTENT, "Type", ""),
054: new ResultColumnInfo(Table.CONTENT, "type", "") },
055: { new ResultColumnInfo(Table.CONTENT, "type", "name"),
056: new ResultColumnInfo(Table.CONTENT, "type", "name") },
057: { new ResultColumnInfo(Table.CONTENT, "type", "Name"),
058: new ResultColumnInfo(Table.CONTENT, "type", "name") },
059: { new ResultColumnInfo(Table.CONTENT, "type", null),
060: new ResultColumnInfo(Table.CONTENT, "type", null) }, };
061: private static final ResultColumnInfo[][] INFOS_UNEQUAL = {
062: { new ResultColumnInfo(Table.CONTENT, "type", ""),
063: new ResultColumnInfo(Table.CONTENT, "type1", "") },
064: { new ResultColumnInfo(Table.CONTENT, "type", "name"),
065: new ResultColumnInfo(Table.CONTENT, "type", "") },
066: { new ResultColumnInfo(Table.CONTENT, "type", "name"),
067: new ResultColumnInfo(Table.CONTENT, "type", null) },
068: { new ResultColumnInfo(Table.CONTENT, "type", "name"),
069: new ResultColumnInfo(Table.CONTENT, "type", "id") }, };
070: private static final ResultOrderByInfo[][] ORDERBY_EQUAL = {
071: {
072: new ResultOrderByInfo(Table.CONTENT, "type", "",
073: SortDirection.ASCENDING),
074: new ResultOrderByInfo(Table.CONTENT, "type", "",
075: SortDirection.ASCENDING) },
076: {
077: new ResultOrderByInfo(Table.CONTENT, "type", "",
078: SortDirection.DESCENDING),
079: new ResultOrderByInfo(Table.CONTENT, "type", "",
080: SortDirection.DESCENDING) } };
081: private static final ResultOrderByInfo[][] ORDERBY_UNEQUAL = { {
082: new ResultOrderByInfo(Table.CONTENT, "type", "",
083: SortDirection.ASCENDING),
084: new ResultOrderByInfo(Table.CONTENT, "type", "",
085: SortDirection.DESCENDING) } };
086:
087: @Test
088: public void resultPreferencesDeepCopy() {
089: ResultPreferences rp = new ResultPreferences();
090: ResultPreferencesEdit rpe = rp.getEditObject();
091:
092: // add a column info, check if base object remains unchanged
093: assert rp.getSelectedColumns().size() == 0;
094: assert rpe.getSelectedColumns().size() == 0;
095: final ResultColumnInfo ci = INFOS_EQUAL[0][0];
096: rpe.addSelectedColumn(ci);
097: assert rp.getSelectedColumns().size() == 0;
098: assert rpe.getSelectedColumns().size() == 1;
099: assert rpe.getSelectedColumns().get(0).equals(ci);
100:
101: // add a order by info, check if base object remains unchanged
102: assert rp.getOrderByColumns().size() == 0;
103: assert rpe.getOrderByColumns().size() == 0;
104: final ResultOrderByInfo obi = ORDERBY_EQUAL[0][0];
105: rpe.addOrderByColumn(obi);
106: assert rpe.getOrderByColumns().size() == 1;
107: assert rp.getOrderByColumns().size() == 0;
108: assert rpe.getOrderByColumns().get(0).equals(obi);
109: }
110:
111: @Test
112: public void resultPreferencesCopy() {
113: final List<ResultColumnInfo> selectedColumns = Arrays
114: .asList(INFOS_UNEQUAL[0]);
115: final List<ResultOrderByInfo> orderByColumns = Arrays
116: .asList(ORDERBY_UNEQUAL[0]);
117: ResultPreferences rp = new ResultPreferences(selectedColumns,
118: orderByColumns, 15, 150);
119: assert rp.getSelectedColumns().size() == 2;
120: assert rp.getOrderByColumns().size() == 2;
121: assert rp.getSelectedColumns().equals(selectedColumns);
122: assert rp.getOrderByColumns().equals(orderByColumns);
123: ResultPreferencesEdit rpe = rp.getEditObject();
124: assert rp.equals(rpe);
125:
126: // remove column, assert unequal, then restore previous state
127: final ResultColumnInfo ci = rpe.removeSelectedColumn(1);
128: assert !rp.equals(rpe);
129: rpe.addSelectedColumn(ci);
130: assert rp.equals(rpe);
131:
132: // remove order by, assert unequal, then restore previous state
133: final ResultOrderByInfo obi = rpe.removeOrderByColumn(1);
134: assert (!rp.equals(rpe));
135: rpe.addOrderByColumn(obi);
136: assert rp.equals(rpe);
137:
138: // other tests
139: rpe.setThumbBoxSize(10);
140: assert !rp.equals(rpe);
141: rpe.setThumbBoxSize(rp.getThumbBoxSize());
142: assert rp.equals(rpe);
143: rpe.setRowsPerPage(100);
144: assert !rp.equals(rpe);
145: rpe.setRowsPerPage(rp.getRowsPerPage());
146: assert rp.equals(rpe);
147: }
148:
149: @Test
150: public void resultPreferencesAddEmpty() {
151: ResultPreferences rp = new ResultPreferences();
152: ResultPreferencesEdit rpe = rp.getEditObject();
153: try {
154: rpe.addSelectedColumn(null);
155: assert false : "It should not be possible to add null column infos";
156: } catch (RuntimeException e) {
157: // pass
158: }
159: try {
160: rpe.addOrderByColumn(null);
161: assert false : "It should not be possible to add null order by column infos";
162: } catch (RuntimeException e) {
163: // pass
164: }
165: }
166:
167: @Test(dataProvider="equalColumnInfos")
168: public void columnInfoEqual(ResultColumnInfo ci1,
169: ResultColumnInfo ci2) {
170: assert ci1.equals(ci2) && ci2.equals(ci1) : ci1
171: + " should be equal to " + ci2;
172: }
173:
174: @Test(dataProvider="unequalColumnInfos")
175: public void columnInfoUnequal(ResultColumnInfo ci1,
176: ResultColumnInfo ci2) {
177: assert !ci1.equals(ci2) && !ci2.equals(ci1) : ci1
178: + " should not be equal to " + ci2;
179: }
180:
181: @Test(dataProvider="equalOrderByInfos")
182: public void orderByEqual(ResultOrderByInfo obi1,
183: ResultOrderByInfo obi2) {
184: assert obi1.equals(obi2) && obi2.equals(obi1) : obi1
185: + " should be equal to " + obi2;
186: }
187:
188: @Test(dataProvider="unequalOrderByInfos")
189: public void orderByUnequal(ResultOrderByInfo obi1,
190: ResultOrderByInfo obi2) {
191: assert !obi1.equals(obi2) && !obi2.equals(obi1) : obi1
192: + " should not be equal to " + obi2;
193: }
194:
195: @DataProvider(name="equalColumnInfos")
196: private Object[][] getEqualColumnInfos() {
197: return INFOS_EQUAL;
198: }
199:
200: @DataProvider(name="unequalColumnInfos")
201: private Object[][] getUnequalColumnInfos() {
202: return INFOS_UNEQUAL;
203: }
204:
205: @DataProvider(name="equalOrderByInfos")
206: private Object[][] getEqualOrderByInfos() {
207: return ORDERBY_EQUAL;
208: }
209:
210: @DataProvider(name="unequalOrderByInfos")
211: private Object[][] getUnequalOrderByInfos() {
212: return ORDERBY_UNEQUAL;
213: }
214: }
|