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.embedded;
034:
035: import com.flexive.shared.EJBLookup;
036: import com.flexive.shared.exceptions.*;
037: import com.flexive.shared.interfaces.SearchEngine;
038: import com.flexive.shared.search.AdminResultLocations;
039: import com.flexive.shared.search.query.QueryRootNode;
040: import com.flexive.shared.search.query.QueryRootNode.Type;
041: import static com.flexive.tests.embedded.FxTestUtils.login;
042: import static com.flexive.tests.embedded.FxTestUtils.logout;
043: import com.flexive.tests.shared.QueryNodeTreeTests;
044: import com.flexive.tests.shared.QueryNodeTreeTests.InnerNodeGenerator;
045: import org.testng.Assert;
046: import org.testng.annotations.AfterClass;
047: import org.testng.annotations.BeforeClass;
048: import org.testng.annotations.DataProvider;
049: import org.testng.annotations.Test;
050:
051: /**
052: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
053: */
054: @Test(groups={"ejb","search"})
055: public class SearchQueryTest {
056: private static final String QUERYNAME = "AUTOMATED_TEST_QUERY";
057: private SearchEngine searchEngine;
058:
059: @BeforeClass
060: public void beforeClass() throws FxLookupException,
061: FxLoginFailedException, FxAccountInUseException {
062: searchEngine = EJBLookup.getSearchEngine();
063: login(TestUsers.SUPERVISOR);
064: }
065:
066: @AfterClass
067: public void afterClass() throws FxLogoutFailedException {
068: logout();
069: }
070:
071: @Test(dataProvider="sampleQueries")
072: public void loadSaveQuery(QueryRootNode query)
073: throws FxApplicationException {
074: try {
075: query.setName(QUERYNAME);
076: searchEngine.save(query);
077: QueryNodeTreeTests.assertEqualTrees(query, searchEngine
078: .load(AdminResultLocations.DEFAULT, QUERYNAME));
079: } finally {
080: searchEngine
081: .remove(AdminResultLocations.DEFAULT, QUERYNAME);
082: }
083: }
084:
085: @Test
086: public void createDeleteQuery() throws FxApplicationException {
087: QueryRootNode query = QueryNodeTreeTests.buildNestedTree(5,
088: new InnerNodeGenerator(), 5);
089: query.setName(QUERYNAME);
090: searchEngine.save(query);
091: // check that the query actually is stored in the db
092: searchEngine.load(AdminResultLocations.DEFAULT, QUERYNAME);
093:
094: searchEngine.remove(AdminResultLocations.DEFAULT, QUERYNAME);
095: try {
096: searchEngine.load(AdminResultLocations.DEFAULT, QUERYNAME);
097: assert false : "Query " + QUERYNAME
098: + " should have been deleted.";
099: } catch (FxNotFoundException e) {
100: // pass
101: }
102: }
103:
104: @Test
105: public void setDefaultQuery() throws FxApplicationException {
106: QueryRootNode query = new QueryRootNode(Type.CONTENTSEARCH,
107: AdminResultLocations.ADMIN);
108: query.addChild(new QueryNodeTreeTests.InnerTestNode(42));
109: searchEngine.saveSystemDefault(query);
110: Assert.assertEquals(searchEngine.loadDefault(
111: AdminResultLocations.ADMIN).getChild(0).getId(), 42,
112: "First child should have ID 42");
113:
114: // now save user default
115: query.getChild(0).setId(43);
116: searchEngine.saveDefault(query);
117: Assert.assertEquals(searchEngine.loadDefault(
118: AdminResultLocations.ADMIN).getChild(0).getId(), 43,
119: "First child should have ID 43");
120: }
121:
122: @DataProvider(name="sampleQueries")
123: public Object[][] getSampleQueries() {
124: return new Object[][] {
125: { QueryNodeTreeTests.buildFlatTree(
126: new InnerNodeGenerator(), 5) },
127: { QueryNodeTreeTests.buildNestedTree(5,
128: new InnerNodeGenerator(), 5) },
129: { QueryNodeTreeTests.buildNestedTree(25,
130: new InnerNodeGenerator(), 5) }, };
131: }
132: }
|