Wikitty-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
January 2012
- 4 participants
- 128 discussions
r1379 - trunk/wikitty-api/src/test/java/org/nuiton/wikitty
by echatellier@users.nuiton.org 27 Jan '12
by echatellier@users.nuiton.org 27 Jan '12
27 Jan '12
Author: echatellier
Date: 2012-01-27 11:44:56 +0100 (Fri, 27 Jan 2012)
New Revision: 1379
Url: http://nuiton.org/repositories/revision/wikitty/1379
Log:
Fix tests
Modified:
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyClientTest.java
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyClientTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyClientTest.java 2012-01-27 09:27:35 UTC (rev 1378)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyClientTest.java 2012-01-27 10:44:56 UTC (rev 1379)
@@ -44,7 +44,6 @@
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Test;
-import org.nuiton.util.ApplicationConfig;
import org.nuiton.wikitty.addons.WikittyI18nTestUtil;
import org.nuiton.wikitty.addons.WikittyI18nUtil;
import org.nuiton.wikitty.addons.WikittyImportExportService;
@@ -63,15 +62,13 @@
import org.nuiton.wikitty.entities.WikittyTreeNodeHelper;
import org.nuiton.wikitty.entities.WikittyTreeNodeImpl;
import org.nuiton.wikitty.entities.WikittyTypes;
+import org.nuiton.wikitty.query.FacetSortType;
import org.nuiton.wikitty.query.WikittyQuery;
import org.nuiton.wikitty.query.WikittyQueryMaker;
import org.nuiton.wikitty.query.WikittyQueryParser;
import org.nuiton.wikitty.query.WikittyQueryResult;
import org.nuiton.wikitty.query.WikittyQueryResultTreeNode;
-import org.nuiton.wikitty.services.WikittyCacheJCS;
import org.nuiton.wikitty.services.WikittyEvent;
-import org.nuiton.wikitty.services.WikittyServiceCached;
-import org.nuiton.wikitty.services.WikittyServiceInMemory;
import org.nuiton.wikitty.test.Category;
import org.nuiton.wikitty.test.Product;
@@ -307,14 +304,16 @@
gf3Movie.addToField(MOVIE_EXTENSION_NAME, "authors", "Pixar");
gf3Movie.setField(MOVIE_EXTENSION_NAME, "date", WikittyUtil.formatDate(df.parse("October 12, 1974")));
+ wikittyClient.store(gf1Movie, gf2Movie, gf3Movie);
+
// search test
Wikitty w = new WikittyImpl();
w.addExtension(MEDIA_EXTENSION);
w.addExtension(MOVIE_EXTENSION);
w.setField(MEDIA_EXTENSION_NAME, "type", "movie");
WikittyQuery query = new WikittyQueryMaker().wikitty(w).end();
- query.addFacetField(new ElementField(MOVIE_EXTENSION_NAME + ".authors"));
- query.addFacetField(new ElementField(MOVIE_EXTENSION_NAME + ".date"));
+ query.addFacetField(new ElementField(MOVIE_EXTENSION_NAME,"authors"));
+ query.addFacetField(new ElementField(MOVIE_EXTENSION_NAME,"date"));
WikittyQueryResult<String> result = wikittyClient.findAllByQuery(query);
Assert.assertTrue(result.getFacetNames().contains(MOVIE_EXTENSION_NAME + ".date"));
@@ -322,21 +321,27 @@
// with must have 2 topic: Pixar and Coppola
Assert.assertEquals(2, result.getTopic(MOVIE_EXTENSION_NAME + ".authors").size());
- Assert.assertEquals("Coppola", result.getTopic(MOVIE_EXTENSION_NAME + ".authors").get(0).getFacetName());
+ Assert.assertEquals("Coppola", result.getTopic(MOVIE_EXTENSION_NAME + ".authors").get(0).getTopicName());
Assert.assertEquals(2, result.getTopic(MOVIE_EXTENSION_NAME + ".authors").get(0).getCount());
- Assert.assertEquals("Pixar", result.getTopic(MOVIE_EXTENSION_NAME + ".authors").get(1).getFacetName());
+ Assert.assertEquals("Pixar", result.getTopic(MOVIE_EXTENSION_NAME + ".authors").get(1).getTopicName());
Assert.assertEquals(1, result.getTopic(MOVIE_EXTENSION_NAME + ".authors").get(1).getCount());
// with must have 2 topic: March 15, 1972 and October 12, 1974
Assert.assertEquals(2, result.getTopic(MOVIE_EXTENSION_NAME + ".date").size());
-
+ }
+
+ @Test
+ public void testSearchExtensionFacet() throws Exception {
// essai de facettiser sur les extensions
- query = new WikittyQueryMaker().keyword("*").end();
+ WikittyQuery query = new WikittyQueryMaker().keyword("*").end();
query.setFirst(0);
query.setLimit(0);
query.addFacetField(Element.EXTENSION);
- result = wikittyClient.findAllByQuery(query);
+ WikittyQueryResult<String> result = wikittyClient.findAllByQuery(query);
Assert.assertEquals(1, result.getFacetNames().size());
- Assert.assertNotNull(result.getFacets().get(Element.EXTENSION));
+ //TODO echatellier 20120112 : revue this code
+ //Assert.assertNotNull(result.getFacets().get(Element.EXTENSION));
+ // is more convenient, but wont work
+ Assert.assertNotNull(result.getFacets().get(Element.EXTENSION.getValue()));
}
/**
@@ -356,12 +361,14 @@
gf1Movie.setField(MOVIE_EXTENSION_NAME, "name", "The godfather");
gf1Movie.addToField(MOVIE_EXTENSION_NAME, "authors", "Coppola");
gf1Movie.setField(MOVIE_EXTENSION_NAME, "date", WikittyUtil.formatDate(df.parse("March 15, 1972")));
+ String oldVersion = gf1Movie.getVersion();
Wikitty newWik = wikittyClient.store(gf1Movie);
- Assert.assertTrue(WikittyUtil.versionGreaterThan(gf1Movie.getId(), newWik.getId()));
+ Assert.assertTrue(WikittyUtil.versionGreaterThan(newWik.getVersion(), oldVersion));
// search test
Wikitty w = new WikittyImpl();
+ w.addExtension(MEDIA_EXTENSION);
w.addExtension(MOVIE_EXTENSION);
w.setField(MOVIE_EXTENSION_NAME, "name", "The godfather");
WikittyQuery query = new WikittyQueryMaker().wikitty(w).end();
@@ -1373,6 +1380,24 @@
}
@Test
+ public void testSearchFacetSingleField() throws Exception {
+ importBooks();
+
+ WikittyQuery query = new WikittyQueryMaker().exteq(Product.EXT_PRODUCT).end();
+ query.setLimit(0);
+ query.addFacetField(Product.ELEMENT_FIELD_PRODUCT_CATEGORY);
+ query.setFacetSort(FacetSortType.count);
+ WikittyQueryResult<String> result = wikittyClient.findAllByQuery(query);
+
+ // les resultats sont répartit en 4 categories
+ Assert.assertEquals(4, result.getTopic(Product.ELEMENT_FIELD_PRODUCT_CATEGORY).size());
+ Assert.assertEquals(10, result.getTopic(Product.ELEMENT_FIELD_PRODUCT_CATEGORY).get(0).getCount());
+ Assert.assertEquals(3, result.getTopic(Product.ELEMENT_FIELD_PRODUCT_CATEGORY).get(1).getCount());
+ Assert.assertEquals(1, result.getTopic(Product.ELEMENT_FIELD_PRODUCT_CATEGORY).get(2).getCount());
+ Assert.assertEquals(1, result.getTopic(Product.ELEMENT_FIELD_PRODUCT_CATEGORY).get(3).getCount());
+ }
+
+ @Test
public void testQueryMarkerWilcardEquals() {
assumeTrueSearchEngineCanRunTest(); // wildcard
1
0
r1378 - trunk/wikitty-api/src/test/java/org/nuiton/wikitty/search
by echatellier@users.nuiton.org 27 Jan '12
by echatellier@users.nuiton.org 27 Jan '12
27 Jan '12
Author: echatellier
Date: 2012-01-27 10:27:35 +0100 (Fri, 27 Jan 2012)
New Revision: 1378
Url: http://nuiton.org/repositories/revision/wikitty/1378
Log:
Deprecate test class
Modified:
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/search/FacetTopicTest.java
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/search/FacetTopicTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/search/FacetTopicTest.java 2012-01-26 16:57:06 UTC (rev 1377)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/search/FacetTopicTest.java 2012-01-27 09:27:35 UTC (rev 1378)
@@ -46,7 +46,9 @@
/**
*
* @author poussin
+ * @deprecated since 3.4, will be removed in 4
*/
+@Deprecated
public class FacetTopicTest {
/**
1
0
r1377 - in trunk/wikitty-api/src/test/java/org/nuiton/wikitty: query search
by echatellier@users.nuiton.org 26 Jan '12
by echatellier@users.nuiton.org 26 Jan '12
26 Jan '12
Author: echatellier
Date: 2012-01-26 17:57:06 +0100 (Thu, 26 Jan 2012)
New Revision: 1377
Url: http://nuiton.org/repositories/revision/wikitty/1377
Log:
Test refactoring
Added:
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query/FacetTopicTest.java
Modified:
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query/WikittyQueryTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/search/FacetTopicTest.java
Added: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query/FacetTopicTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query/FacetTopicTest.java (rev 0)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query/FacetTopicTest.java 2012-01-26 16:57:06 UTC (rev 1377)
@@ -0,0 +1,88 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin, Chatellier Eric
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+package org.nuiton.wikitty.query;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.TreeSet;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+/**
+ * Test FacetTopic and comparators.
+ *
+ * @author poussin
+ */
+public class FacetTopicTest {
+
+ /**
+ * Test of toString method, of class FacetTopic.
+ */
+ @Test
+ public void testNameComparator() {
+ TreeSet<FacetTopic> countSort = new TreeSet<FacetTopic>(new FacetTopicCountComparator());
+ TreeSet<FacetTopic> nameSort = new TreeSet<FacetTopic>(new FacetTopicNameComparator(false));
+ TreeSet<FacetTopic> nameIgnoreCaseSort = new TreeSet<FacetTopic>(new FacetTopicNameComparator(true));
+
+ FacetTopic a5 = new FacetTopic("test", "a", 5);
+ FacetTopic b4 = new FacetTopic("test", "b", 4);
+ FacetTopic c3 = new FacetTopic("test", "c", 3);
+ FacetTopic d2 = new FacetTopic("test", "d", 2);
+ FacetTopic e1 = new FacetTopic("test", "e", 1);
+ FacetTopic A0 = new FacetTopic("test", "A", 0);
+
+
+ countSort.add(a5);
+ nameSort.add(a5);
+ nameIgnoreCaseSort.add(a5);
+
+ countSort.add(b4);
+ nameSort.add(b4);
+ nameIgnoreCaseSort.add(b4);
+
+ countSort.add(c3);
+ nameSort.add(c3);
+ nameIgnoreCaseSort.add(c3);
+
+ countSort.add(d2);
+ nameSort.add(d2);
+ nameIgnoreCaseSort.add(d2);
+
+ countSort.add(e1);
+ nameSort.add(e1);
+ nameIgnoreCaseSort.add(e1);
+
+ countSort.add(A0);
+ nameSort.add(A0);
+ nameIgnoreCaseSort.add(A0);
+
+ Assert.assertEquals(new HashSet<FacetTopic>(Arrays.asList(A0, e1, d2, c3, b4, a5)), countSort);
+ Assert.assertEquals(new HashSet<FacetTopic>(Arrays.asList(A0, a5, b4, c3, d2, e1)), nameSort);
+ Assert.assertEquals(new HashSet<FacetTopic>(Arrays.asList(a5, b4, c3, d2, e1)), nameIgnoreCaseSort);
+ }
+}
Property changes on: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query/FacetTopicTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query/WikittyQueryTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query/WikittyQueryTest.java 2012-01-26 16:39:21 UTC (rev 1376)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query/WikittyQueryTest.java 2012-01-26 16:57:06 UTC (rev 1377)
@@ -46,7 +46,6 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(WikittyQueryTest.class);
-
@Test
public void testParseAliasAndTree() throws Exception {
WikittyQueryParser parser = new WikittyQueryParser();
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/search/FacetTopicTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/search/FacetTopicTest.java 2012-01-26 16:39:21 UTC (rev 1376)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/search/FacetTopicTest.java 2012-01-26 16:57:06 UTC (rev 1377)
@@ -42,7 +42,6 @@
import java.util.TreeSet;
import org.junit.Test;
-import static org.junit.Assert.*;
/**
*
1
0
r1376 - in trunk/wikitty-api/src/test/java/org/nuiton/wikitty: . services
by echatellier@users.nuiton.org 26 Jan '12
by echatellier@users.nuiton.org 26 Jan '12
26 Jan '12
Author: echatellier
Date: 2012-01-26 17:39:21 +0100 (Thu, 26 Jan 2012)
New Revision: 1376
Url: http://nuiton.org/repositories/revision/wikitty/1376
Log:
Move service tests to correct packages
Added:
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceCachedCopyTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceNotifierTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceNotifierXMPPTest.java
Removed:
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory/
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/
Modified:
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyClientTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceCachedTest.java
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyClientTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyClientTest.java 2012-01-26 15:00:35 UTC (rev 1375)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyClientTest.java 2012-01-26 16:39:21 UTC (rev 1376)
@@ -25,6 +25,9 @@
package org.nuiton.wikitty;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -41,6 +44,7 @@
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Test;
+import org.nuiton.util.ApplicationConfig;
import org.nuiton.wikitty.addons.WikittyI18nTestUtil;
import org.nuiton.wikitty.addons.WikittyI18nUtil;
import org.nuiton.wikitty.addons.WikittyImportExportService;
@@ -64,7 +68,10 @@
import org.nuiton.wikitty.query.WikittyQueryParser;
import org.nuiton.wikitty.query.WikittyQueryResult;
import org.nuiton.wikitty.query.WikittyQueryResultTreeNode;
+import org.nuiton.wikitty.services.WikittyCacheJCS;
import org.nuiton.wikitty.services.WikittyEvent;
+import org.nuiton.wikitty.services.WikittyServiceCached;
+import org.nuiton.wikitty.services.WikittyServiceInMemory;
import org.nuiton.wikitty.test.Category;
import org.nuiton.wikitty.test.Product;
Added: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceCachedCopyTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceCachedCopyTest.java (rev 0)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceCachedCopyTest.java 2012-01-26 16:39:21 UTC (rev 1376)
@@ -0,0 +1,77 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin, Benjamin Poussin, Chatellier Eric
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.wikitty.services;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.nuiton.wikitty.WikittyClient;
+import org.nuiton.wikitty.WikittyClientTest;
+import org.nuiton.wikitty.WikittyConfigOption;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.entities.Wikitty;
+
+/**
+ * Same test as {@link WikittyServiceCachedTest} but with different cache policy.
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyServiceCachedCopyTest extends WikittyClientTest {
+
+ /**
+ * Override to method in sub tests to change wikitty client implementation.
+ *
+ * @return wikitty client implementation to use in current test case instance
+ */
+ @Override
+ protected WikittyClient getWikittyClient() {
+ wikittyConfig.setOption(
+ WikittyConfigOption.WIKITTY_CACHE_RESTORE_COPIES.getKey(),
+ "true");
+
+ WikittyService wikittyService = new WikittyServiceInMemory(wikittyConfig);
+ wikittyService = new WikittyServiceCached(wikittyConfig, wikittyService, new WikittyCacheJCS(wikittyConfig));
+ WikittyClient client = new WikittyClient(wikittyConfig, wikittyService);
+ return client;
+ }
+
+ /**
+ * This test is the same but service cache policy is changed.
+ *
+ * Inverse of test {@link WikittyServiceCachedTest#testRestoreNoCopyPolicy()} test
+ */
+ @Test
+ public void testRestoreAllwaysCopyPolicy() {
+ // restoring two times the same wikitty should produces two different copies
+ Wikitty anotherWikitty = wikittyClient.restore("4d221e31-ff9b-44f0-8545-f9884435f30d");
+ Wikitty yetAnotherWikitty = wikittyClient.restore("4d221e31-ff9b-44f0-8545-f9884435f30d");
+
+ Assert.assertEquals(anotherWikitty, yetAnotherWikitty);
+ Assert.assertNotSame(anotherWikitty, yetAnotherWikitty); // two different objects
+ }
+}
Property changes on: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceCachedCopyTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceCachedTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceCachedTest.java 2012-01-26 15:00:35 UTC (rev 1375)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceCachedTest.java 2012-01-26 16:39:21 UTC (rev 1376)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2009 - 2010 CodeLutin, Benjamin Poussin
+ * Copyright (C) 2009 - 2012 CodeLutin, Benjamin Poussin, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -24,49 +24,57 @@
*/
package org.nuiton.wikitty.services;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
import org.junit.Test;
-import org.nuiton.util.ApplicationConfig;
-import org.nuiton.wikitty.WikittyConfig;
-import org.nuiton.wikitty.WikittyProxy;
+import org.nuiton.wikitty.WikittyClient;
+import org.nuiton.wikitty.WikittyClientTest;
+import org.nuiton.wikitty.WikittyConfigOption;
+import org.nuiton.wikitty.WikittyService;
import org.nuiton.wikitty.entities.BusinessEntity;
+import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.entities.WikittyUser;
import org.nuiton.wikitty.entities.WikittyUserImpl;
+import org.nuiton.wikitty.test.Product;
-import java.util.ArrayList;
-import java.util.List;
-import org.nuiton.wikitty.WikittyConfigOption;
-
/**
- *
+ * Re passe les tests du wikitty client en ajoutant une couche de de cache dans
+ * les services.
+ *
* @author poussin
* @version $Revision$
*
* Last update: $Date$
* by : $Author$
*/
-public class WikittyServiceCachedTest {
+public class WikittyServiceCachedTest extends WikittyClientTest {
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittyServiceCachedTest.class);
+ /**
+ * Override to method in sub tests to change wikitty client implementation.
+ *
+ * @return wikitty client implementation to use in current test case instance
+ */
+ @Override
+ protected WikittyClient getWikittyClient() {
+ wikittyConfig.setOption(WikittyConfigOption
+ .JCS_DEFAULT_CACHEATTRIBUTES_MAXOBJECTS.getKey(), "10");
- protected ApplicationConfig getConfig() {
- ApplicationConfig result = WikittyConfig.getConfig();
- return result;
+ WikittyService wikittyService = new WikittyServiceInMemory(wikittyConfig);
+ wikittyService = new WikittyServiceCached(wikittyConfig, wikittyService, new WikittyCacheJCS(wikittyConfig));
+ WikittyClient client = new WikittyClient(wikittyConfig, wikittyService);
+ return client;
}
+ /**
+ * Test
+ * @throws Exception
+ */
@Test
public void testCache() throws Exception {
- ApplicationConfig config = getConfig();
- config.setOption(WikittyConfigOption
- .JCS_DEFAULT_CACHEATTRIBUTES_MAXOBJECTS.getKey(), "10");
- WikittyServiceInMemory ws = new WikittyServiceInMemory(config);
- WikittyCache cache = new WikittyCacheJCS(config);
- WikittyServiceCached wscached = new WikittyServiceCached(config, ws, cache);
-
- WikittyProxy proxy = new WikittyProxy(config, wscached);
+
List<BusinessEntity> toStore = new ArrayList<BusinessEntity>();
List<String> toRestore = new ArrayList<String>();
@@ -82,16 +90,16 @@
toStore.add(u4);
toStore.add(u5);
- toStore = proxy.store(toStore);
+ toStore = wikittyClient.store(toStore);
- u1 = proxy.restore(WikittyUser.class, u1.getWikittyId());
- u2 = proxy.restore(WikittyUser.class, u2.getWikittyId());
- u3 = proxy.restore(WikittyUser.class, u3.getWikittyId());
- u4 = proxy.restore(WikittyUser.class, u4.getWikittyId());
- u5 = proxy.restore(WikittyUser.class, u5.getWikittyId());
- u1 = proxy.restore(WikittyUser.class, u1.getWikittyId());
- u2 = proxy.restore(WikittyUser.class, u2.getWikittyId());
- u3 = proxy.restore(WikittyUser.class, u3.getWikittyId());
+ u1 = wikittyClient.restore(WikittyUser.class, u1.getWikittyId());
+ u2 = wikittyClient.restore(WikittyUser.class, u2.getWikittyId());
+ u3 = wikittyClient.restore(WikittyUser.class, u3.getWikittyId());
+ u4 = wikittyClient.restore(WikittyUser.class, u4.getWikittyId());
+ u5 = wikittyClient.restore(WikittyUser.class, u5.getWikittyId());
+ u1 = wikittyClient.restore(WikittyUser.class, u1.getWikittyId());
+ u2 = wikittyClient.restore(WikittyUser.class, u2.getWikittyId());
+ u3 = wikittyClient.restore(WikittyUser.class, u3.getWikittyId());
toRestore.add(u1.getWikittyId());
toRestore.add(u2.getWikittyId());
@@ -99,6 +107,67 @@
toRestore.add(u4.getWikittyId());
toRestore.add(u5.getWikittyId());
- proxy.restore(WikittyUser.class, toRestore);
+ wikittyClient.restore(WikittyUser.class, toRestore);
}
+
+ /**
+ * Setting a field value doesn't corrupt cache.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testCacheRestore() throws IOException {
+ importBooks(); // to get a known id
+ Product book = wikittyClient.restore(Product.class, "4d221e31-ff9b-44f0-8545-f9884435f30d");
+ Assert.assertNotNull(book);
+
+ // we set the value of a field
+ book.setName("My new name");
+
+ // now let's suppose, the user cancel its modification
+ // we don't have call store()
+ book = wikittyClient.restore(Product.class, "4d221e31-ff9b-44f0-8545-f9884435f30d");
+
+ // the remaining wikitty should hold old value
+ Assert.assertEquals("Harry Potter à l'école des sorciers", book.getName());
+ }
+
+ /**
+ * Same as testCacheRestore() using methods that restore multiple ids.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testCacheRestoreMultipleIds() throws IOException {
+ importBooks(); // to get a known id
+ // now, let's do the same test, just by using others restore() available
+ List<String> idsToRestore = new ArrayList<String>();
+ idsToRestore.add("4d221e31-ff9b-44f0-8545-f9884435f30d");
+
+ List<Product> otherWikitties = wikittyClient.restore(Product.class, idsToRestore);
+ Product book = otherWikitties.get(0);
+
+ // we set the value of a field
+ book.setName("My new name");
+
+ // now let's suppose, the user cancel its modification
+ // we don't have call store()
+ otherWikitties = wikittyClient.restore(Product.class, idsToRestore);
+ book = otherWikitties.get(0);
+
+ // the remaining wikitty should hold old value
+ Assert.assertEquals("Harry Potter à l'école des sorciers", book.getName());
+ }
+
+ /**
+ * Test que deux restore consecutif retourne la même instance (cache).
+ */
+ @Test
+ public void testRestoreNoCopyPolicy() {
+ // restoring two times the same wikitty should produces two different copies
+ Wikitty anotherWikitty = wikittyClient.restore("4d221e31-ff9b-44f0-8545-f9884435f30d");
+ Wikitty yetAnotherWikitty = wikittyClient.restore("4d221e31-ff9b-44f0-8545-f9884435f30d");
+
+ Assert.assertSame(anotherWikitty, yetAnotherWikitty); // same reference
+ }
}
Copied: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceNotifierTest.java (from rev 1356, trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/WikittyServiceNotificationTest.java)
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceNotifierTest.java (rev 0)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceNotifierTest.java 2012-01-26 16:39:21 UTC (rev 1376)
@@ -0,0 +1,232 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin, Benjamin Poussin, Chatellier Eric
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.wikitty.services;
+
+
+import java.util.EnumSet;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+import org.nuiton.wikitty.WikittyService.ServiceListenerType;
+import org.nuiton.wikitty.services.WikittyEvent;
+import org.nuiton.wikitty.services.WikittyListener;
+import org.nuiton.wikitty.services.WikittyServiceNotifier;
+
+/**
+ * Test si la notification par event fonctionne bien (les bons types d'event
+ * sont envoyes et recus.
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyServiceNotifierTest {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyServiceNotifierTest.class);
+
+ protected EnumSet<WikittyEvent.WikittyEventType> lastEvent = null;
+ protected int nbEvent = 0;
+
+ /**
+ * Test si les events sont bien lever et bien recu
+ * @throws Exception
+ */
+ @Test
+ public void testEvent() throws Exception {
+ WikittyServiceNotifier wsn = new WikittyServiceNotifier(null, null, null);
+ Listener l = new Listener();
+
+ // test d'envoi et de bonne reception
+ wsn.addWikittyServiceListener(l, ServiceListenerType.ALL);
+ sendEvent(wsn, true);
+
+ // si on enleve le listener, plus aucun event ne doit arriver
+ wsn.removeWikittyServiceListener(l, ServiceListenerType.ALL);
+ sendEvent(wsn, false);
+
+ // donc au total seulement 5 events on du etre envoye
+ Assert.assertEquals(6, nbEvent);
+
+ }
+
+ /**
+ * Envoi tous les events possible. Permet de tester la methode process et
+ * la method fireEvent de WikittyServiceNotifier vu que la premiere
+ * appelle la deuxieme
+ *
+ * @param wsn
+ */
+ protected void sendEvent(WikittyServiceNotifier wsn, boolean hasListener) throws Exception {
+ {
+ WikittyEvent event = new WikittyEvent("test");
+ event.addType(WikittyEvent.WikittyEventType.PUT_WIKITTY);
+ wsn.processRemoteEvent(event);
+ wsn.getEventThread().waitFor(event.getTime());
+ if (hasListener) {
+ Assert.assertEquals(
+ EnumSet.of(WikittyEvent.WikittyEventType.PUT_WIKITTY),
+ lastEvent);
+ } else {
+ Assert.assertEquals(null, lastEvent);
+ }
+ lastEvent = null;
+ }
+ {
+ WikittyEvent event = new WikittyEvent("test");
+ event.addType(WikittyEvent.WikittyEventType.REMOVE_WIKITTY);
+ wsn.processRemoteEvent(event);
+ wsn.getEventThread().waitFor(event.getTime());
+ if (hasListener) {
+ Assert.assertEquals(
+ EnumSet.of(WikittyEvent.WikittyEventType.REMOVE_WIKITTY),
+ lastEvent);
+ } else {
+ Assert.assertEquals(null, lastEvent);
+ }
+ lastEvent = null;
+ }
+ {
+ WikittyEvent event = new WikittyEvent("test");
+ event.addType(WikittyEvent.WikittyEventType.CLEAR_WIKITTY);
+ wsn.processRemoteEvent(event);
+ wsn.getEventThread().waitFor(event.getTime());
+ if (hasListener) {
+ Assert.assertEquals(
+ EnumSet.of(WikittyEvent.WikittyEventType.CLEAR_WIKITTY),
+ lastEvent);
+ } else {
+ Assert.assertEquals(null, lastEvent);
+ }
+ lastEvent = null;
+ }
+ {
+ WikittyEvent event = new WikittyEvent("test");
+ event.addType(WikittyEvent.WikittyEventType.PUT_EXTENSION);
+ wsn.processRemoteEvent(event);
+ wsn.getEventThread().waitFor(event.getTime());
+ if (hasListener) {
+ Assert.assertEquals(
+ EnumSet.of(WikittyEvent.WikittyEventType.PUT_EXTENSION),
+ lastEvent);
+ } else {
+ Assert.assertEquals(null, lastEvent);
+ }
+ lastEvent = null;
+ }
+ {
+ WikittyEvent event = new WikittyEvent("test");
+ event.addType(WikittyEvent.WikittyEventType.REMOVE_EXTENSION);
+ wsn.processRemoteEvent(event);
+ wsn.getEventThread().waitFor(event.getTime());
+ if (hasListener) {
+ Assert.assertEquals(
+ EnumSet.of(WikittyEvent.WikittyEventType.REMOVE_EXTENSION),
+ lastEvent);
+ } else {
+ Assert.assertEquals(null, lastEvent);
+ }
+ lastEvent = null;
+ }
+ {
+ WikittyEvent event = new WikittyEvent("test");
+ event.addType(WikittyEvent.WikittyEventType.CLEAR_EXTENSION);
+ wsn.processRemoteEvent(event);
+ wsn.getEventThread().waitFor(event.getTime());
+ if (hasListener) {
+ Assert.assertEquals(
+ EnumSet.of(WikittyEvent.WikittyEventType.CLEAR_EXTENSION),
+ lastEvent);
+ } else {
+ Assert.assertEquals(null, lastEvent);
+ }
+ lastEvent = null;
+ }
+ }
+
+ /**
+ * Class listener des events, check la bonne reception
+ */
+ class Listener implements WikittyListener {
+
+ @Override
+ public void putWikitty(WikittyEvent event) {
+ nbEvent++;
+ Assert.assertEquals(
+ EnumSet.of(WikittyEvent.WikittyEventType.PUT_WIKITTY),
+ event.getType());
+ lastEvent = event.getType();
+ }
+
+ @Override
+ public void removeWikitty(WikittyEvent event) {
+ nbEvent++;
+ Assert.assertEquals(
+ EnumSet.of(WikittyEvent.WikittyEventType.REMOVE_WIKITTY),
+ event.getType());
+ lastEvent = event.getType();
+ }
+
+ @Override
+ public void clearWikitty(WikittyEvent event) {
+ nbEvent++;
+ Assert.assertEquals(
+ EnumSet.of(WikittyEvent.WikittyEventType.CLEAR_WIKITTY),
+ event.getType());
+ lastEvent = event.getType();
+ }
+
+ @Override
+ public void putExtension(WikittyEvent event) {
+ nbEvent++;
+ Assert.assertEquals(
+ EnumSet.of(WikittyEvent.WikittyEventType.PUT_EXTENSION),
+ event.getType());
+ lastEvent = event.getType();
+ }
+
+ @Override
+ public void removeExtension(WikittyEvent event) {
+ nbEvent++;
+ Assert.assertEquals(
+ EnumSet.of(WikittyEvent.WikittyEventType.REMOVE_EXTENSION),
+ event.getType());
+ lastEvent = event.getType();
+ }
+
+ @Override
+ public void clearExtension(WikittyEvent event) {
+ nbEvent++;
+ Assert.assertEquals(
+ EnumSet.of(WikittyEvent.WikittyEventType.CLEAR_EXTENSION),
+ event.getType());
+ lastEvent = event.getType();
+ }
+
+ }
+}
Copied: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceNotifierXMPPTest.java (from rev 1356, trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/XMPPNotificationTest.java)
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceNotifierXMPPTest.java (rev 0)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceNotifierXMPPTest.java 2012-01-26 16:39:21 UTC (rev 1376)
@@ -0,0 +1,109 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin, Benjamin Poussin, Chatellier Eric
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.wikitty.services;
+
+import java.util.Date;
+
+import org.jivesoftware.smack.PacketListener;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.packet.Packet;
+import org.jivesoftware.smackx.muc.DiscussionHistory;
+import org.jivesoftware.smackx.muc.MultiUserChat;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.nuiton.util.ApplicationConfig;
+import org.nuiton.wikitty.WikittyConfig;
+import org.nuiton.wikitty.WikittyConfigOption;
+import org.nuiton.wikitty.WikittyUtil;
+
+/**
+ * Wikitty service test based on XMPP transporter.
+ *
+ * Test disabled, need to fix http://www.nuiton.org/issues/1060 before
+ * to add embedded xmpp server available in test.
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+@Ignore
+public class WikittyServiceNotifierXMPPTest {
+
+ @Test
+ public void testXMPP() throws Exception {
+ String server = "im.codelutin.com";
+ String room = "test(a)conference.im.codelutin.com";
+ ApplicationConfig config = WikittyConfig.getConfig();
+ config.setOption(WikittyConfigOption.WIKITTY_EVENT_TRANSPORTER_XMPP_SERVER.getKey(), server);
+ config.setOption(WikittyConfigOption.WIKITTY_EVENT_TRANSPORTER_XMPP_ROOM.getKey(), room);
+
+ // Envoi d'un message avec le transporter normal
+ WikittyServiceNotifier.RemoteNotifierTransporter transporteur =
+ new XMPPNotifierTransporter(config);
+ WikittyServiceNotifier wsn = new WikittyServiceNotifier(config, null, transporteur);
+ WikittyEvent event = new WikittyEvent("test");
+ event.addRemoveDate("theId", new Date());
+
+ transporteur.sendMessage(event);
+
+
+ // essaie de recuperation du message
+
+ XMPPConnection connection = new XMPPConnection(server);
+ connection.connect();
+ connection.loginAnonymously();
+
+ MultiUserChat muc = new MultiUserChat(connection, room);
+ String pseudo = WikittyUtil.getUniqueLoginName();
+ System.out.println("pseudo: " + pseudo);
+
+ DiscussionHistory history = new DiscussionHistory();
+ history.setMaxStanzas(0);
+ muc.join(pseudo, "", history, 4000);
+
+ muc.addMessageListener(new PacketListener() {
+
+ @Override
+ public void processPacket(Packet packet) {
+ System.out.println("ext: " + packet.getExtensions());
+ System.out.println("prop: " + packet.getPropertyNames());
+ Object event = packet.getProperty(XMPPNotifierTransporter.PROPERTY_EVENT_NAME);
+ System.out.println("event " + event + " PACKET: " +
+ " xml: " + packet.toXML());
+ }
+ });
+
+ // Discover information about the room roomName(a)conference.myserver
+// RoomInfo info = MultiUserChat.getRoomInfo(connection, room);
+// System.out.println("Number of occupants:" + info.getOccupantsCount());
+// System.out.println("Room Subject:" + info.getSubject());
+
+// Thread t = new Thread();
+// Thread.currentThread().sleep(1000*60);
+ }
+
+}
1
0
r1375 - trunk/wikitty-jdbc/src/test/java/org/nuiton/wikitty/services
by echatellier@users.nuiton.org 26 Jan '12
by echatellier@users.nuiton.org 26 Jan '12
26 Jan '12
Author: echatellier
Date: 2012-01-26 16:00:35 +0100 (Thu, 26 Jan 2012)
New Revision: 1375
Url: http://nuiton.org/repositories/revision/wikitty/1375
Log:
Remove ProxyTest
Removed:
trunk/wikitty-jdbc/src/test/java/org/nuiton/wikitty/services/ProxyTest.java
Modified:
trunk/wikitty-jdbc/src/test/java/org/nuiton/wikitty/services/WikittyServiceInMemoryJdbcSolr.java
Deleted: trunk/wikitty-jdbc/src/test/java/org/nuiton/wikitty/services/ProxyTest.java
===================================================================
--- trunk/wikitty-jdbc/src/test/java/org/nuiton/wikitty/services/ProxyTest.java 2012-01-26 14:30:07 UTC (rev 1374)
+++ trunk/wikitty-jdbc/src/test/java/org/nuiton/wikitty/services/ProxyTest.java 2012-01-26 15:00:35 UTC (rev 1375)
@@ -1,93 +0,0 @@
-/*
- * #%L
- * Wikitty :: wikitty-jdbc-impl
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 CodeLutin, Benjamin Poussin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.wikitty.services;
-
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Assert;
-import org.junit.Test;
-import org.nuiton.wikitty.WikittyConfig;
-import org.nuiton.wikitty.WikittyProxy;
-import org.nuiton.wikitty.WikittyService;
-import org.nuiton.wikitty.WikittyServiceFactory;
-import org.nuiton.wikitty.entities.Wikitty;
-import org.nuiton.wikitty.entities.WikittyLabel;
-import org.nuiton.wikitty.entities.WikittyLabelImpl;
-import org.nuiton.wikitty.entities.WikittyTreeNode;
-import org.nuiton.wikitty.entities.WikittyTreeNodeImpl;
-
-import java.util.Collections;
-import org.nuiton.util.ApplicationConfig;
-import org.nuiton.wikitty.WikittyConfigOption;
-
-/**
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class ProxyTest {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(ProxyTest.class);
-
- @Test
- public void testProxyStoreRestoreTreeNode() throws Exception {
- ApplicationConfig config = WikittyConfig.getConfig(
- "wikitty-config-sample-standalone.properties");
- config.setOption(WikittyConfigOption.
- WIKITTY_STORAGE_JDBC_URL.getKey(),
- "jdbc:h2:file:./target/data/db");
- config.setOption(WikittyConfigOption.
- WIKITTY_SEARCHENGINE_SOLR_DIRECTORY_DATA.getKey(),
- "./target/data/solr");
-
- WikittyService ws = WikittyServiceFactory.buildWikittyService(config);
-
-// Assert.assertEquals(WikittyServiceStorage.class, ws.getClass());
-
- WikittyProxy proxy = new WikittyProxy(ws);
- WikittyTreeNodeImpl node = new WikittyTreeNodeImpl();
- node.setName("NodeName");
-
- Wikitty w = node.getWikitty();
- WikittyLabelImpl label = new WikittyLabelImpl(w);
- label.addLabels("TheLabel");
-
- proxy.store(label);
-
- WikittyTreeNode nodeRestored = proxy.restore(WikittyTreeNode.class, node.getWikittyId());
-
- Assert.assertEquals("NodeName", nodeRestored.getName());
-
- WikittyLabel labelRestored = proxy.restore(WikittyLabel.class, node.getWikittyId());
- Assert.assertEquals(Collections.singleton("TheLabel"), labelRestored.getLabels());
-
- }
-
-}
Modified: trunk/wikitty-jdbc/src/test/java/org/nuiton/wikitty/services/WikittyServiceInMemoryJdbcSolr.java
===================================================================
--- trunk/wikitty-jdbc/src/test/java/org/nuiton/wikitty/services/WikittyServiceInMemoryJdbcSolr.java 2012-01-26 14:30:07 UTC (rev 1374)
+++ trunk/wikitty-jdbc/src/test/java/org/nuiton/wikitty/services/WikittyServiceInMemoryJdbcSolr.java 2012-01-26 15:00:35 UTC (rev 1375)
@@ -29,7 +29,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.solr.core.RAMDirectoryFactory;
-import org.nuiton.util.ApplicationConfig;
import org.nuiton.wikitty.WikittyConfig;
import org.nuiton.wikitty.WikittyConfigOption;
import org.nuiton.wikitty.jdbc.WikittyExtensionStorageJDBC;
1
0
r1374 - trunk/wikitty-jdbc/src/test/java/org/nuiton/wikitty
by echatellier@users.nuiton.org 26 Jan '12
by echatellier@users.nuiton.org 26 Jan '12
26 Jan '12
Author: echatellier
Date: 2012-01-26 15:30:07 +0100 (Thu, 26 Jan 2012)
New Revision: 1374
Url: http://nuiton.org/repositories/revision/wikitty/1374
Log:
Remove StorageTest class (refactored)
Removed:
trunk/wikitty-jdbc/src/test/java/org/nuiton/wikitty/jdbc/
1
0
r1373 - trunk/wikitty-jdbc/src/test/java/org/nuiton/wikitty/jdbc
by echatellier@users.nuiton.org 26 Jan '12
by echatellier@users.nuiton.org 26 Jan '12
26 Jan '12
Author: echatellier
Date: 2012-01-26 15:29:28 +0100 (Thu, 26 Jan 2012)
New Revision: 1373
Url: http://nuiton.org/repositories/revision/wikitty/1373
Log:
Remove StorageTest class (refactored)
Removed:
trunk/wikitty-jdbc/src/test/java/org/nuiton/wikitty/jdbc/test/
1
0
r1372 - in trunk: wikitty-api/src/test/java/org/nuiton/wikitty/conform wikitty-api/src/test/java/org/nuiton/wikitty/entities wikitty-jdbc/src/test/java/org/nuiton/wikitty/jdbc/test wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr
by echatellier@users.nuiton.org 26 Jan '12
by echatellier@users.nuiton.org 26 Jan '12
26 Jan '12
Author: echatellier
Date: 2012-01-26 15:28:33 +0100 (Thu, 26 Jan 2012)
New Revision: 1372
Url: http://nuiton.org/repositories/revision/wikitty/1372
Log:
Remove StorageTest class (refactored)
Removed:
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/SearchTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java
trunk/wikitty-jdbc/src/test/java/org/nuiton/wikitty/jdbc/test/StorageJDBCTest.java
trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearchInMemoryTest.java
trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearchServerTest.java
Modified:
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/entities/WikittyTest.java
trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearchTest.java
trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/TreeTest.java
Deleted: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/SearchTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/SearchTest.java 2012-01-26 13:32:44 UTC (rev 1371)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/SearchTest.java 2012-01-26 14:28:33 UTC (rev 1372)
@@ -1,182 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 CodeLutin, Benjamin Poussin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.wikitty.conform;
-
-import static junit.framework.Assert.assertEquals;
-
-import java.util.LinkedList;
-import java.util.List;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Before;
-
-import org.junit.Test;
-import org.nuiton.util.ApplicationConfig;
-import org.nuiton.wikitty.WikittyConfig;
-import org.nuiton.wikitty.search.Criteria;
-import org.nuiton.wikitty.entities.ExtensionFactory;
-import org.nuiton.wikitty.entities.WikittyTypes;
-import org.nuiton.wikitty.search.PagedResult;
-import org.nuiton.wikitty.entities.Wikitty;
-import org.nuiton.wikitty.entities.WikittyExtension;
-import org.nuiton.wikitty.entities.WikittyImpl;
-import org.nuiton.wikitty.search.Search;
-
-public class SearchTest extends AbstractTestConformance {
-
- private final static Log log = LogFactory.getLog(AbstractTestConformance.class);
-
- private ApplicationConfig config = null;
-
- @Override
- public ApplicationConfig getConfig() {
- if (config == null) {
- config = WikittyConfig.getConfig(); // default config for in memory
-// String msg = "Try to passe test with " + config.getPrintableConfig("wikitty.*", 50);
-// log.info(msg);
- }
- return config;
- }
-
- @Before
- public void clearStorage() throws Exception {
- getProxy().clear();
- }
-
- /*
- * TODO Will contains all conformance tests to the search features.
- */
-
- public void testSearch() throws Exception {
- String value = "";
- Criteria criteria =
- Search.query()
- .eq( "element", value )
- .gt( "element2", value )
- .or()
- .lt( "element3", value )
- .criteria();
- /*
- * is equivalent to :
- * ( element = value ) AND ( ( element2 > value ) OR ( element3 < value ) )
- */
- }
-
- @Test
- public void testSearch2() throws Exception {
- WikittyExtension ext = ExtensionFactory.create("testExt", "1")
- .addField("name", WikittyTypes.STRING)
- .addField("age", WikittyTypes.NUMERIC)
- .addField("birth", WikittyTypes.DATE)
- .extension();
- List<Wikitty> wikitties = new LinkedList<Wikitty>();
-
- Wikitty w = new WikittyImpl();
- w.addExtension(ext);
- w.setField(ext.getName(), "name", "Guillaume");
- w.setField(ext.getName(), "age", "27");
- w.setField(ext.getName(), "birth", "19/04/1968");
- wikitties.add( w );
-
- w = new WikittyImpl();
- w.addExtension(ext);
- w.setField(ext.getName(), "name", "Toto");
- w.setField(ext.getName(), "age", "125");
- w.setField(ext.getName(), "birth", "19/04/1968 15:12");
- wikitties.add( w );
-
- wikitties = getProxy().storeWikitty(wikitties);
-
- // Testing search on a date criteria
- Criteria criteria = Search.query()
- .gt("testExt.birth", "19/04/1968 15:00")
- .criteria();
- PagedResult<String> result = getProxy().findAllIdByCriteria(criteria);
- List<String> found = result.getAll();
- assertEquals(1, found.size());
- Wikitty wikittyFound = getProxy().restore(found.get(0));
- log.info( wikittyFound.getFieldAsString(ext.getName(), "birth") );
-
- // Testing search on a date criteria
- criteria = Search.query()
- .ge("testExt.birth", "19/04/1968")
- .criteria();
- result = getProxy().findAllIdByCriteria(criteria);
- found = result.getAll();
- assertEquals(2, found.size());
- wikittyFound = getProxy().restore(found.get(0));
- log.info( wikittyFound.getFieldAsString(ext.getName(), "birth") );
-
- criteria = Search.query()
- .eq("testExt.name", "Guillaume")
- .criteria();
- result = getProxy().findAllIdByCriteria(criteria);
- found = result.getAll();
- assertEquals(1, found.size());
- wikittyFound = getProxy().restore(found.get(0));
- log.info( wikittyFound.getFieldAsString(ext.getName(), "name") );
-
- criteria = Search.query()
- .eq("testExt.age", "125")
- .criteria();
- result = getProxy().findAllIdByCriteria(criteria);
- found = result.getAll();
- assertEquals(1, found.size());
- wikittyFound = getProxy().restore(found.get(0));
- log.info( wikittyFound.getFieldAsString(ext.getName(), "name") );
-
- criteria = Search.query()
- .gt("testExt.age", "10")
- .criteria();
- result = getProxy().findAllIdByCriteria(criteria);
- found = result.getAll();
- assertEquals(2, found.size());
- wikittyFound = getProxy().restore(found.get(0));
- log.info( wikittyFound.getFieldAsString(ext.getName(), "name") );
- wikittyFound = getProxy().restore(found.get(1));
- log.info( wikittyFound.getFieldAsString(ext.getName(), "name") );
-
- Wikitty exemple = new WikittyImpl();
- exemple.addExtension(ext);
- exemple.setField(ext.getName(), "name", "Guillaume");
- exemple.setField(ext.getName(), "age", "27");
- result = getProxy().findAllIdByCriteria(Search.query(exemple).criteria() );
- found = result.getAll();
- assertEquals(1, found.size());
- wikittyFound = getProxy().restore(found.get(0));
- log.info( wikittyFound.getFieldAsString(ext.getName(), "name") );
-
- exemple = new WikittyImpl();
- exemple.addExtension(ext);
- exemple.setField(ext.getName(), "name", "Guillaume");
- exemple.setField(ext.getName(), "age", "125");
- result = getProxy().findAllIdByCriteria(Search.query(exemple).criteria() );
- found = result.getAll();
- assertEquals(0, found.size());
- // log.info( found.get(0).getFieldAsString(ext.getName(), "name") );
-
- }
-
-}
Deleted: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java 2012-01-26 13:32:44 UTC (rev 1371)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java 2012-01-26 14:28:33 UTC (rev 1372)
@@ -1,29 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 CodeLutin, Benjamin Poussin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.wikitty.conform;
-
-public abstract class StorageTest extends AbstractTestConformance {
-
-}
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/entities/WikittyTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/entities/WikittyTest.java 2012-01-26 13:32:44 UTC (rev 1371)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/entities/WikittyTest.java 2012-01-26 14:28:33 UTC (rev 1372)
@@ -40,7 +40,6 @@
import org.junit.Test;
import org.nuiton.wikitty.WikittyException;
import org.nuiton.wikitty.WikittyUtil;
-import org.nuiton.wikitty.conform.StorageTest;
/**
* Tests on wikitty object only.
@@ -230,33 +229,33 @@
@Test
public void testFieldCastRules() throws Exception {
Wikitty w = createBasicWikitty();
- w.addExtension(StorageTest.EXT_TEST);
+ w.addExtension(EXT_TEST);
// casted assignment ...
final String stringValue = "Hello";
// test any object => string type (casted as its toString() value)
- w.setField(StorageTest.EXTNAME, "fieldName0", new Object() {
+ w.setField(EXTNAME, "fieldName0", new Object() {
public String toString() {
return stringValue;
}
});
// test java.lang.Integer => int
- w.setField(StorageTest.EXTNAME, "fieldName1", Integer.valueOf(123));
- Assert.assertEquals(123, w.getFieldAsInt(StorageTest.EXTNAME, "fieldName1") );
+ w.setField(EXTNAME, "fieldName1", Integer.valueOf(123));
+ Assert.assertEquals(123, w.getFieldAsInt(EXTNAME, "fieldName1") );
// test String => int
- w.setField(StorageTest.EXTNAME, "fieldName1", "123");
- Assert.assertEquals(123, w.getFieldAsInt(StorageTest.EXTNAME, "fieldName1") );
+ w.setField(EXTNAME, "fieldName1", "123");
+ Assert.assertEquals(123, w.getFieldAsInt(EXTNAME, "fieldName1") );
// test String => Date
Calendar cal = Calendar.getInstance(Locale.ROOT);
cal.set(1982, 0, 23, 0, 0, 0); cal.set( Calendar.MILLISECOND, 0 );
- w.setField( StorageTest.EXTNAME, "fieldName2", WikittyUtil.formatDate(cal.getTime()) );
- Assert.assertEquals(cal.getTime(), w.getFieldAsDate(StorageTest.EXTNAME, "fieldName2") );
+ w.setField( EXTNAME, "fieldName2", WikittyUtil.formatDate(cal.getTime()) );
+ Assert.assertEquals(cal.getTime(), w.getFieldAsDate(EXTNAME, "fieldName2") );
}
@Test
public void testFieldBoundsManagement() throws Exception {
String fieldName = "fieldName0";
- WikittyExtension ext = ExtensionFactory.create(StorageTest.EXTNAME, "1")
+ WikittyExtension ext = ExtensionFactory.create(EXTNAME, "1")
.addField(fieldName, WikittyTypes.NUMERIC)
.maxOccur(FieldType.NOLIMIT)
.extension();
@@ -266,7 +265,7 @@
// test setting a (primitive) value to the field ...
try {
- w.setField(StorageTest.EXTNAME, fieldName, 123);
+ w.setField(EXTNAME, fieldName, 123);
Assert.fail("setting an int to a list of int is forbidden !");
} catch (WikittyException e) {
// OK
@@ -274,10 +273,10 @@
// test adding elements to the field ...
for ( int i = 0; i < 10; i++ ) {
- w.addToField(StorageTest.EXTNAME, fieldName, i);
+ w.addToField(EXTNAME, fieldName, i);
}
int z = 0;
- for ( int value : w.getFieldAsList(StorageTest.EXTNAME, fieldName, Integer.class) ) {
+ for ( int value : w.getFieldAsList(EXTNAME, fieldName, Integer.class) ) {
Assert.assertEquals( "element " + z + " failed",
z, value );
z++;
@@ -285,17 +284,17 @@
// test set a list as the field value ...
Integer[] listInt = new Integer[] {4, 2, 8, 9, 5, -12, Integer.MIN_VALUE, Integer.MAX_VALUE };
- w.setField( StorageTest.EXTNAME, fieldName, Arrays.asList(listInt) );
+ w.setField( EXTNAME, fieldName, Arrays.asList(listInt) );
z = 0;
- for ( int value : w.getFieldAsList(StorageTest.EXTNAME, fieldName, Integer.class) ) {
+ for ( int value : w.getFieldAsList(EXTNAME, fieldName, Integer.class) ) {
Assert.assertEquals( listInt[z++].intValue(), value );
}
// test remove an element ...
- w.removeFromField( StorageTest.EXTNAME, fieldName, Integer.MIN_VALUE );
- List<Integer> values = w.getFieldAsList(StorageTest.EXTNAME, fieldName, Integer.class);
+ w.removeFromField( EXTNAME, fieldName, Integer.MIN_VALUE );
+ List<Integer> values = w.getFieldAsList(EXTNAME, fieldName, Integer.class);
z = 0;
- for ( int value : w.getFieldAsList(StorageTest.EXTNAME, fieldName, Integer.class) ) {
+ for ( int value : w.getFieldAsList(EXTNAME, fieldName, Integer.class) ) {
Assert.assertEquals(
// on the last element, we expect MAX_VALUE because MIN_VALUE was deleted.
z == values.size() - 1 ? Integer.MAX_VALUE : listInt[z++].intValue()
@@ -303,8 +302,8 @@
}
// test clear field ...
- w.clearField(StorageTest.EXTNAME, fieldName);
- values = w.getFieldAsList(StorageTest.EXTNAME, fieldName, Integer.class);
+ w.clearField(EXTNAME, fieldName);
+ values = w.getFieldAsList(EXTNAME, fieldName, Integer.class);
Assert.assertTrue( values.isEmpty() );
}
@@ -345,31 +344,31 @@
Map<String, Object> m = new HashMap<String, Object>();
Wikitty w = createBasicWikitty();
- w.addExtension(StorageTest.EXT_TEST);
+ w.addExtension(EXT_TEST);
PerfFieldAccesClass z = new PerfFieldAccesClass();
long time = System.currentTimeMillis();
for (int i=0; i<MAX; i++) {
// basic valid assignment ...
String stringValue = "A Test Value";
- m.put(StorageTest.EXTNAME+".fieldName0", stringValue);
+ m.put(EXTNAME+".fieldName0", stringValue);
int intValue = 123456;
- m.put(StorageTest.EXTNAME + ".fieldName1", intValue);
+ m.put(EXTNAME + ".fieldName1", intValue);
Date dateValue = new Date();
- m.put(StorageTest.EXTNAME + ".fieldName2", dateValue);
+ m.put(EXTNAME + ".fieldName2", dateValue);
}
long timeSetM = System.currentTimeMillis() - time;
time = System.currentTimeMillis();
String tmp = "";
for (int i = 0; i < MAX; i++) {
- String stringValue = (String)m.get(StorageTest.EXTNAME + ".fieldName0");
+ String stringValue = (String)m.get(EXTNAME + ".fieldName0");
- int intValue = (Integer) m.get(StorageTest.EXTNAME + ".fieldName1");
+ int intValue = (Integer) m.get(EXTNAME + ".fieldName1");
- Date dateValue = (Date)m.get(StorageTest.EXTNAME + ".fieldName2");
+ Date dateValue = (Date)m.get(EXTNAME + ".fieldName2");
tmp = stringValue + intValue + dateValue;
}
long timeGetM = System.currentTimeMillis() - time;
@@ -379,23 +378,23 @@
for (int i=0; i<MAX; i++) {
// basic valid assignment ...
String stringValue = "A Test Value";
- w.setField(StorageTest.EXTNAME, "fieldName0", stringValue);
+ w.setField(EXTNAME, "fieldName0", stringValue);
int intValue = 123456;
- w.setField(StorageTest.EXTNAME, "fieldName1", intValue);
+ w.setField(EXTNAME, "fieldName1", intValue);
- w.setField(StorageTest.EXTNAME, "fieldName2", new Date());
+ w.setField(EXTNAME, "fieldName2", new Date());
}
long timeSetW = System.currentTimeMillis() - time;
time = System.currentTimeMillis();
for (int i=0; i<MAX; i++) {
// basic valid assignment ...
- String stringValue = w.getFieldAsString(StorageTest.EXTNAME, "fieldName0");
+ String stringValue = w.getFieldAsString(EXTNAME, "fieldName0");
- int intValue = w.getFieldAsInt(StorageTest.EXTNAME, "fieldName1");
+ int intValue = w.getFieldAsInt(EXTNAME, "fieldName1");
- Date dateValue = w.getFieldAsDate(StorageTest.EXTNAME, "fieldName2");
+ Date dateValue = w.getFieldAsDate(EXTNAME, "fieldName2");
tmp = stringValue + intValue + dateValue;
}
long timeGetW = System.currentTimeMillis() - time;
Deleted: trunk/wikitty-jdbc/src/test/java/org/nuiton/wikitty/jdbc/test/StorageJDBCTest.java
===================================================================
--- trunk/wikitty-jdbc/src/test/java/org/nuiton/wikitty/jdbc/test/StorageJDBCTest.java 2012-01-26 13:32:44 UTC (rev 1371)
+++ trunk/wikitty-jdbc/src/test/java/org/nuiton/wikitty/jdbc/test/StorageJDBCTest.java 2012-01-26 14:28:33 UTC (rev 1372)
@@ -1,68 +0,0 @@
-/*
- * #%L
- * Wikitty :: wikitty-jdbc-impl
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2010 CodeLutin, Benjamin Poussin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.wikitty.jdbc.test;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Before;
-import org.nuiton.util.ApplicationConfig;
-import org.nuiton.wikitty.WikittyConfig;
-import org.nuiton.wikitty.WikittyConfigOption;
-import org.nuiton.wikitty.conform.StorageTest;
-
-
-/**
- *
- * @author ruchaud, martel
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class StorageJDBCTest extends StorageTest {
-
- protected final static Log log = LogFactory.getLog(StorageJDBCTest.class);
-
- private ApplicationConfig config = null;
-
- @Override
- public ApplicationConfig getConfig() {
- if (config == null) {
- config = WikittyConfig.getConfig("wikitty-config-sample-standalone.properties");
- config.setOption(WikittyConfigOption.WIKITTY_DATA_DIR.getKey(),
- "./target/data");
-// String msg = "Try to passe test with " + config.getPrintableConfig("wikitty.*", 50);
-// log.info(msg);
- }
- return config;
- }
-
- @Before
- public void clearStorage() throws Exception {
- getProxy().clear();
- }
-
-}
Deleted: trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearchInMemoryTest.java
===================================================================
--- trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearchInMemoryTest.java 2012-01-26 13:32:44 UTC (rev 1371)
+++ trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearchInMemoryTest.java 2012-01-26 14:28:33 UTC (rev 1372)
@@ -1,65 +0,0 @@
-/*
- * #%L
- * Wikitty :: wikitty-solr-impl
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.wikitty.storage.solr;
-
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.nuiton.util.ApplicationConfig;
-import org.nuiton.wikitty.WikittyConfig;
-import org.nuiton.wikitty.WikittyService;
-import org.nuiton.wikitty.api.AbstractSearchTest;
-
-/**
- * User: couteau
- * Date: 06/04/11
- */
-public class SolrSearchInMemoryTest extends AbstractSearchTest {
-
- static protected WikittyService service;
-
- static protected ApplicationConfig config = WikittyConfig.getConfig("wikitty-config-sample-inmemory.properties");
-
- @BeforeClass
- public static void initTests() {
- SolrTestHelper.initTests(config);
- }
-
- @AfterClass
- public static void closeTests() {
- SolrTestHelper.closeTests((WikittyServiceSolr)service);
- }
-
- @Override
- public WikittyService getWikittyService() {
-
- if (service == null) {
- service = new WikittyServiceSolr(config);
- }
-
- service.clear(null);
-
- return service;
- }
-}
\ No newline at end of file
Deleted: trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearchServerTest.java
===================================================================
--- trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearchServerTest.java 2012-01-26 13:32:44 UTC (rev 1371)
+++ trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearchServerTest.java 2012-01-26 14:28:33 UTC (rev 1372)
@@ -1,64 +0,0 @@
-/*
- * #%L
- * Wikitty :: wikitty-solr
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.wikitty.storage.solr;
-
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.nuiton.util.ApplicationConfig;
-import org.nuiton.wikitty.WikittyConfig;
-import org.nuiton.wikitty.WikittyService;
-import org.nuiton.wikitty.api.AbstractSearchTest;
-
-/**
- * @author sletellier
- */
-public class SolrSearchServerTest extends AbstractSearchTest {
-
- protected static WikittyService service;
-
- protected static ApplicationConfig config = WikittyConfig.getConfig("wikitty-config-sample-server.properties");
-
- @BeforeClass
- public static void initTests() {
- SolrTestHelper.initTests(config);
- }
-
- @AfterClass
- public static void closeTests() {
- SolrTestHelper.closeTests((WikittyServiceSolr) service);
- }
-
- @Override
- public WikittyService getWikittyService() {
-
- if (service == null) {
- service = new WikittyServiceSolr(config);
- }
-
- service.clear(null);
-
- return service;
- }
-}
\ No newline at end of file
Modified: trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearchTest.java
===================================================================
--- trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearchTest.java 2012-01-26 13:32:44 UTC (rev 1371)
+++ trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearchTest.java 2012-01-26 14:28:33 UTC (rev 1372)
@@ -48,7 +48,6 @@
import org.nuiton.wikitty.entities.WikittyImpl;
import org.nuiton.wikitty.WikittyUtil;
import org.nuiton.wikitty.conform.AbstractTestConformance;
-import org.nuiton.wikitty.conform.StorageTest;
import org.nuiton.wikitty.entities.WikittyGroup;
import org.nuiton.wikitty.entities.WikittyGroupImpl;
import org.nuiton.wikitty.search.operators.Element;
@@ -161,7 +160,7 @@
private Wikitty[] createWikitties(WikittyExtension lonelyExtension, String[] wValues) {
ArrayList<Wikitty> result = new ArrayList<Wikitty>();
for ( String wValue : wValues ) {
- Wikitty w = StorageTest.createWikitty( wValue, lonelyExtension.getName(), lonelyExtension );
+ Wikitty w = AbstractTestConformance.createWikitty( wValue, lonelyExtension.getName(), lonelyExtension );
result.add( w );
}
ws.store(null, result);
Modified: trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/TreeTest.java
===================================================================
--- trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/TreeTest.java 2012-01-26 13:32:44 UTC (rev 1371)
+++ trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/TreeTest.java 2012-01-26 14:28:33 UTC (rev 1372)
@@ -42,19 +42,19 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.conform.AbstractTestConformance;
import org.nuiton.wikitty.entities.ExtensionFactory;
-import org.nuiton.wikitty.entities.WikittyTypes;
-import org.nuiton.wikitty.entities.WikittyTreeNode;
-import org.nuiton.wikitty.entities.WikittyTreeNodeImpl;
import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.entities.WikittyExtension;
import org.nuiton.wikitty.entities.WikittyImpl;
-import org.nuiton.wikitty.services.WikittyEvent;
-import org.nuiton.wikitty.conform.StorageTest;
+import org.nuiton.wikitty.entities.WikittyTreeNode;
import org.nuiton.wikitty.entities.WikittyTreeNodeHelper;
+import org.nuiton.wikitty.entities.WikittyTreeNodeImpl;
+import org.nuiton.wikitty.entities.WikittyTypes;
+import org.nuiton.wikitty.search.Criteria;
import org.nuiton.wikitty.search.Search;
import org.nuiton.wikitty.search.TreeNodeResult;
+import org.nuiton.wikitty.services.WikittyEvent;
import org.nuiton.wikitty.services.WikittyServiceEnhanced;
/**
@@ -385,7 +385,7 @@
int childInit = sum(root);
// Create a leaf
- Wikitty leaf = StorageTest.createWikitty("name=totoTheLeaf", "test", extension);
+ Wikitty leaf = AbstractTestConformance.createWikitty("name=totoTheLeaf", "test", extension);
ws.store(null, leaf);
// Add it in the node2 (now: two values in it)
@@ -536,7 +536,7 @@
createBranch("node3/node31");
createBranch("node3/node32");
- Wikitty value = StorageTest.createWikitty("name=value", "test", extension);
+ Wikitty value = AbstractTestConformance.createWikitty("name=value", "test", extension);
ws.store(null, value);
String valueId = value.getId();
1
0
r1371 - in trunk/wikitty-api/src/test/java/org/nuiton/wikitty: . conform
by echatellier@users.nuiton.org 26 Jan '12
by echatellier@users.nuiton.org 26 Jan '12
26 Jan '12
Author: echatellier
Date: 2012-01-26 14:32:44 +0100 (Thu, 26 Jan 2012)
New Revision: 1371
Url: http://nuiton.org/repositories/revision/wikitty/1371
Log:
Move all tests from StorageTest (can't be removed yet)
Modified:
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyClientAbstractTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyClientTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyClientAbstractTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyClientAbstractTest.java 2012-01-26 13:28:55 UTC (rev 1370)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyClientAbstractTest.java 2012-01-26 13:32:44 UTC (rev 1371)
@@ -59,6 +59,10 @@
*
* Just init object, and load defaut and import data. Asserts are subclassed.
*
+ * Abstract test defini and use to data type:
+ * - Business entity : generated from modele
+ * - Manual extension : movies
+ *
* @author chatellier
* @version $Revision$
*
@@ -203,39 +207,51 @@
client.store(rootNode, livreNode, bdNode, newsNode, romanNode, otherNode);
}
+ /** Manual extension name : media. */
+ protected static final String MEDIA_EXTENSION_NAME = "Media";
+ /** Manual extension media. */
+ protected static final WikittyExtension MEDIA_EXTENSION = ExtensionFactory.create(MEDIA_EXTENSION_NAME, "6.0")
+ .addField("type", WikittyTypes.STRING)
+ .extension();
+ protected static final String MOVIE_EXTENSION_NAME = "Movies";
+ /** Manual extension movies. */
+ protected static final WikittyExtension MOVIE_EXTENSION = ExtensionFactory.create(MOVIE_EXTENSION_NAME, "2.0", MEDIA_EXTENSION_NAME)
+ .addField("name", WikittyTypes.STRING)
+ .addField("authors", WikittyTypes.STRING).maxOccur(Integer.MAX_VALUE)
+ .addField("category", WikittyTypes.WIKITTY)
+ .addField("date", WikittyTypes.DATE)
+ .extension();
+
/**
* Create new "movies" extension.
*
* @param wikittyClient client
*/
protected void addManualExtension(WikittyClient client) {
- // create extension
- WikittyExtension movieExtension = ExtensionFactory.create("Movies", "1.0")
- .addField("name", WikittyTypes.STRING)
- .addField("author", WikittyTypes.STRING).maxOccur(Integer.MAX_VALUE)
- .addField("category", WikittyTypes.WIKITTY)
- .addField("year", WikittyTypes.STRING)
- .extension();
- client.storeExtension(movieExtension);
+ client.storeExtension(MOVIE_EXTENSION);
+
// create wikitty movies
Wikitty dieHardMovie = new WikittyImpl();
- dieHardMovie.addExtension(movieExtension);
- dieHardMovie.setField("Movies", "name", "Die hard 4");
- dieHardMovie.addToField("Movies", "author", "Willis");
- dieHardMovie.addToField("Movies", "year", "2009");
+ dieHardMovie.addExtension(MEDIA_EXTENSION);
+ dieHardMovie.addExtension(MOVIE_EXTENSION);
+ dieHardMovie.setField(MOVIE_EXTENSION_NAME, "name", "Die hard 4");
+ dieHardMovie.addToField(MOVIE_EXTENSION_NAME, "authors", "Willis");
+ dieHardMovie.setField(MOVIE_EXTENSION_NAME, "date", "04/02/2009");
Wikitty edgarMovie = new WikittyImpl();
- edgarMovie.addExtension(movieExtension);
- edgarMovie.setField("Movies", "name", "J. Edgar");
- edgarMovie.addToField("Movies", "author", "Eastwood");
- edgarMovie.addToField("Movies", "year", "2011");
+ edgarMovie.addExtension(MEDIA_EXTENSION);
+ edgarMovie.addExtension(MOVIE_EXTENSION);
+ edgarMovie.setField(MOVIE_EXTENSION_NAME, "name", "J. Edgar");
+ edgarMovie.addToField(MOVIE_EXTENSION_NAME, "authors", "Eastwood");
+ edgarMovie.setField("Movies", "date", "25/12/2011");
Wikitty dnrMovie = new WikittyImpl();
- dnrMovie.addExtension(movieExtension);
- dnrMovie.setField("Movies", "name", "The Dark Knight Rises");
- dnrMovie.addToField("Movies", "author", "Nolan");
- dnrMovie.addToField("Movies", "year", "2012");
+ dnrMovie.addExtension(MEDIA_EXTENSION);
+ dnrMovie.addExtension(MOVIE_EXTENSION);
+ dnrMovie.setField(MOVIE_EXTENSION_NAME, "name", "The Dark Knight Rises");
+ dnrMovie.addToField(MOVIE_EXTENSION_NAME, "authors", "Nolan");
+ dnrMovie.setField(MOVIE_EXTENSION_NAME, "date", "13/03/2012");
client.store(dieHardMovie, edgarMovie, dnrMovie);
}
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyClientTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyClientTest.java 2012-01-26 13:28:55 UTC (rev 1370)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyClientTest.java 2012-01-26 13:32:44 UTC (rev 1371)
@@ -28,11 +28,17 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Test;
import org.nuiton.wikitty.addons.WikittyI18nTestUtil;
@@ -41,6 +47,7 @@
import org.nuiton.wikitty.addons.WikittyImportExportService.FORMAT;
import org.nuiton.wikitty.addons.WikittyLabelUtil;
import org.nuiton.wikitty.entities.Element;
+import org.nuiton.wikitty.entities.ElementField;
import org.nuiton.wikitty.entities.ExtensionFactory;
import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.entities.WikittyExtension;
@@ -49,11 +56,15 @@
import org.nuiton.wikitty.entities.WikittyLabel;
import org.nuiton.wikitty.entities.WikittyLabelImpl;
import org.nuiton.wikitty.entities.WikittyTreeNode;
+import org.nuiton.wikitty.entities.WikittyTreeNodeHelper;
+import org.nuiton.wikitty.entities.WikittyTreeNodeImpl;
import org.nuiton.wikitty.entities.WikittyTypes;
import org.nuiton.wikitty.query.WikittyQuery;
import org.nuiton.wikitty.query.WikittyQueryMaker;
import org.nuiton.wikitty.query.WikittyQueryParser;
import org.nuiton.wikitty.query.WikittyQueryResult;
+import org.nuiton.wikitty.query.WikittyQueryResultTreeNode;
+import org.nuiton.wikitty.services.WikittyEvent;
import org.nuiton.wikitty.test.Category;
import org.nuiton.wikitty.test.Product;
@@ -63,6 +74,9 @@
* This test is designed to be overridden and change {@link WikittyClient}
* implementation.
*
+ * Test begin with 'testStorage' focus on store/restore.
+ * Test begin with 'testFind' or 'testSearch' focus on search engine.
+ *
* @author chatellier
* @version $Revision$
*
@@ -71,7 +85,547 @@
*/
public class WikittyClientTest extends WikittyClientAbstractTest {
+ static private Log log = LogFactory.getLog(WikittyClientTest.class);
+
+ @Test
+ public void testStorageRestoreBasics() {
+ // create basic wikitty
+ Wikitty w = new WikittyImpl();
+ w.addExtension(MEDIA_EXTENSION);
+ w.addExtension(MOVIE_EXTENSION);
+
+ String id = w.getId();
+ w = wikittyClient.store(w);
+ w = wikittyClient.restore(id);
+ Assert.assertTrue(w.hasExtension(MOVIE_EXTENSION_NAME));
+ Assert.assertTrue(w.hasField("Movies", "name"));
+ Assert.assertTrue(w.hasField("Movies", "authors"));
+ Assert.assertTrue(w.hasField("Movies", "category"));
+ Assert.assertTrue(w.hasField("Movies", "date"));
+ }
+
+ @Test
+ public void testStorageExtensionMethod() {
+ // store extension
+ List<String> extIds = wikittyClient.getAllExtensionIds();
+ log.debug("extIds: " + extIds);
+ Assert.assertEquals(8, extIds.size());
+ Assert.assertTrue(extIds.contains("Movies[2.0]"));
+ WikittyExtension ext = wikittyClient.restoreExtension("Movies[2.0]");
+ Assert.assertEquals("Movies", ext.getName());
+ Assert.assertEquals("2.0", ext.getVersion());
+ Assert.assertEquals(MOVIE_EXTENSION, ext);
+ }
+
/**
+ * Test que la suppression d'une extension est possible.
+ */
+ @Test
+ public void testStorageExtensionDelete() {
+ // new one
+ WikittyExtension volatileExt = new WikittyExtension("VolatileExt",
+ "4.0", // version
+ WikittyUtil.buildFieldMapExtension( // building field map
+ "String name unique=\"true\""));
+ wikittyClient.storeExtension(volatileExt);
+
+ // test existance
+ List<String> extIds = wikittyClient.getAllExtensionIds();
+ Assert.assertTrue(extIds.contains("VolatileExt[4.0]"));
+
+ // delete
+ wikittyClient.deleteExtension("VolatileExt");
+
+ // restest existance
+ extIds = wikittyClient.getAllExtensionIds();
+ Assert.assertFalse(extIds.contains("VolatileExt[4.0]"));
+ }
+
+ /**
+ * Test que la suppression echoue si l'extension est utilisee.
+ */
+ @Test(expected=WikittyException.class)
+ public void testStorageExtensionDeleteUsed() {
+ // try to delete it (throws WikittyException)
+ wikittyClient.deleteExtension(MOVIE_EXTENSION_NAME);
+ }
+
+ @Test
+ public void testStorageExtensionRequires() {
+ wikittyClient.storeExtension(MEDIA_EXTENSION);
+ wikittyClient.storeExtension(MOVIE_EXTENSION);
+ List<String> extIds = wikittyClient.getAllExtensionsRequires(MEDIA_EXTENSION_NAME);
+ log.debug("extIds: " + extIds);
+ Assert.assertEquals(1, extIds.size());
+
+ WikittyExtension ext = wikittyClient.restoreExtension(extIds.get(0));
+ Assert.assertEquals("Movies", ext.getName());
+ Assert.assertEquals("2.0", ext.getVersion());
+ Assert.assertEquals(MOVIE_EXTENSION, ext);
+ }
+
+ /**
+ * Test seulement la methode restore().
+ *
+ * @throws ParseException
+ */
+ @Test
+ public void testStorageRestoreLists() throws ParseException {
+
+ // create some wikitty
+ Wikitty gf1Movie = new WikittyImpl();
+ gf1Movie.addExtension(MEDIA_EXTENSION);
+ gf1Movie.addExtension(MOVIE_EXTENSION);
+ gf1Movie.setField(MOVIE_EXTENSION_NAME, "name", "The godfather");
+ gf1Movie.addToField(MOVIE_EXTENSION_NAME, "authors", "Coppola");
+ gf1Movie.setField(MOVIE_EXTENSION_NAME, "date", WikittyUtil.formatDate(df.parse("March 15, 1972")));
+
+ Wikitty gf2Movie = new WikittyImpl();
+ gf2Movie.addExtension(MEDIA_EXTENSION);
+ gf2Movie.addExtension(MOVIE_EXTENSION);
+ gf2Movie.setField(MOVIE_EXTENSION_NAME, "name", "The godfather 2");
+ gf2Movie.addToField(MOVIE_EXTENSION_NAME, "authors", "Coppola");
+ gf2Movie.setField(MOVIE_EXTENSION_NAME, "date", WikittyUtil.formatDate(df.parse("October 12, 1974")));
+
+ Wikitty gf3Movie = new WikittyImpl();
+ gf3Movie.addExtension(MEDIA_EXTENSION);
+ gf3Movie.addExtension(MOVIE_EXTENSION);
+ gf3Movie.setField(MOVIE_EXTENSION_NAME, "name", "The godfather 3");
+ gf3Movie.addToField(MOVIE_EXTENSION_NAME, "authors", "Coppola");
+ gf3Movie.setField(MOVIE_EXTENSION_NAME, "date", WikittyUtil.formatDate(df.parse("July 30, 1990")));
+
+ wikittyClient.store(gf1Movie, gf2Movie, gf3Movie);
+
+ List<String> ids = new ArrayList<String>();
+ ids.add(gf1Movie.getId());
+ ids.add(gf2Movie.getId());
+ ids.add(gf3Movie.getId());
+
+ List<Wikitty> wikitties = wikittyClient.restore(ids);
+
+ Assert.assertEquals("The godfather", wikitties.get(0).getFieldAsString(MOVIE_EXTENSION_NAME, "name"));
+ Assert.assertEquals("The godfather 2", wikitties.get(1).getFieldAsString(MOVIE_EXTENSION_NAME, "name"));
+ Assert.assertEquals("The godfather 3", wikitties.get(2).getFieldAsString(MOVIE_EXTENSION_NAME, "name"));
+ }
+
+ @Test
+ public void testStorageRestoreSingle() throws Exception {
+ Wikitty w = new WikittyImpl();
+ String id = w.getId();
+ w = wikittyClient.store(w);
+ w = wikittyClient.restore(id);
+ Assert.assertEquals(id, w.getId());
+ }
+
+ @Test(expected=WikittyException.class)
+ public void testStorageRestoreNull() throws Exception {
+ wikittyClient.store((Wikitty)null);
+ }
+
+ @Test
+ public void testFieldConstraint() throws Exception {
+ // Store ext
+ WikittyExtension ext = new WikittyExtension("TestConstraint", "1",
+ WikittyUtil.buildFieldMapExtension(
+ "String id notNull=true",
+ "String ext[0-n] unique=true",
+ "String other[0-n] unique=true notNull=true"
+ ));
+ wikittyClient.storeExtension(ext);
+
+ // store wikitty
+ Wikitty w = new WikittyImpl();
+ w.addExtension(ext);
+
+ try {
+ w = wikittyClient.store(w);
+ Assert.fail("not null contraint don't work on String");
+ } catch (WikittyException eee) {
+ eee.printStackTrace();
+ // ok id must not be null
+ }
+
+ w.setField("TestConstraint", "id", "toto");
+ try {
+ w = wikittyClient.store(w);
+ Assert.fail("not null contraint don't work in Collection");
+ } catch (WikittyException eee) {
+ eee.printStackTrace();
+ // ok id must not be null
+ }
+
+ w.addToField("TestConstraint", "other", "titi");
+ w = wikittyClient.store(w);
+
+ w.addToField("TestConstraint", "ext", "tata");
+ w.addToField("TestConstraint", "ext", "titi"); // titi ne doit pas s'ajouter
+ w = wikittyClient.store(w);
+
+ Wikitty w2 = wikittyClient.restore(w.getId());
+ w2.addToField("TestConstraint", "ext", "tata"); // tata ne doit pas s'ajouter
+ w2.addToField("TestConstraint", "ext", "toto");
+
+ w2 = wikittyClient.store(w2);
+ Wikitty w3 = wikittyClient.restore(w.getId());
+
+ Set set = new HashSet(Arrays.asList("tata", "titi", "toto"));
+ Assert.assertEquals(set, w3.getFieldAsSet("TestConstraint", "ext", String.class));
+ }
+
+ @Test
+ public void testSearchByExampleFacet() throws Exception {
+
+ // create some wikitty
+ Wikitty gf1Movie = new WikittyImpl();
+ gf1Movie.addExtension(MEDIA_EXTENSION);
+ gf1Movie.addExtension(MOVIE_EXTENSION);
+ gf1Movie.setField(MEDIA_EXTENSION_NAME, "type", "movie");
+ gf1Movie.setField(MOVIE_EXTENSION_NAME, "name", "The godfather");
+ gf1Movie.addToField(MOVIE_EXTENSION_NAME, "authors", "Coppola");
+ gf1Movie.setField(MOVIE_EXTENSION_NAME, "date", WikittyUtil.formatDate(df.parse("March 15, 1972")));
+
+ Wikitty gf2Movie = new WikittyImpl();
+ gf2Movie.addExtension(MEDIA_EXTENSION);
+ gf2Movie.addExtension(MOVIE_EXTENSION);
+ gf2Movie.setField(MEDIA_EXTENSION_NAME, "type", "movie");
+ gf2Movie.setField(MOVIE_EXTENSION_NAME, "name", "The godfather 2");
+ gf2Movie.addToField(MOVIE_EXTENSION_NAME, "authors", "Coppola");
+ gf2Movie.setField(MOVIE_EXTENSION_NAME, "date", WikittyUtil.formatDate(df.parse("October 12, 1974")));
+
+ Wikitty gf3Movie = new WikittyImpl();
+ gf3Movie.addExtension(MEDIA_EXTENSION);
+ gf3Movie.addExtension(MOVIE_EXTENSION);
+ gf3Movie.setField(MEDIA_EXTENSION_NAME, "type", "movie");
+ gf3Movie.setField(MOVIE_EXTENSION_NAME, "name", "Fly me to the moon");
+ gf3Movie.addToField(MOVIE_EXTENSION_NAME, "authors", "Pixar");
+ gf3Movie.setField(MOVIE_EXTENSION_NAME, "date", WikittyUtil.formatDate(df.parse("October 12, 1974")));
+
+ // search test
+ Wikitty w = new WikittyImpl();
+ w.addExtension(MEDIA_EXTENSION);
+ w.addExtension(MOVIE_EXTENSION);
+ w.setField(MEDIA_EXTENSION_NAME, "type", "movie");
+ WikittyQuery query = new WikittyQueryMaker().wikitty(w).end();
+ query.addFacetField(new ElementField(MOVIE_EXTENSION_NAME + ".authors"));
+ query.addFacetField(new ElementField(MOVIE_EXTENSION_NAME + ".date"));
+ WikittyQueryResult<String> result = wikittyClient.findAllByQuery(query);
+
+ Assert.assertTrue(result.getFacetNames().contains(MOVIE_EXTENSION_NAME + ".date"));
+ Assert.assertTrue(result.getFacetNames().contains(MOVIE_EXTENSION_NAME + ".authors"));
+
+ // with must have 2 topic: Pixar and Coppola
+ Assert.assertEquals(2, result.getTopic(MOVIE_EXTENSION_NAME + ".authors").size());
+ Assert.assertEquals("Coppola", result.getTopic(MOVIE_EXTENSION_NAME + ".authors").get(0).getFacetName());
+ Assert.assertEquals(2, result.getTopic(MOVIE_EXTENSION_NAME + ".authors").get(0).getCount());
+ Assert.assertEquals("Pixar", result.getTopic(MOVIE_EXTENSION_NAME + ".authors").get(1).getFacetName());
+ Assert.assertEquals(1, result.getTopic(MOVIE_EXTENSION_NAME + ".authors").get(1).getCount());
+ // with must have 2 topic: March 15, 1972 and October 12, 1974
+ Assert.assertEquals(2, result.getTopic(MOVIE_EXTENSION_NAME + ".date").size());
+
+ // essai de facettiser sur les extensions
+ query = new WikittyQueryMaker().keyword("*").end();
+ query.setFirst(0);
+ query.setLimit(0);
+ query.addFacetField(Element.EXTENSION);
+ result = wikittyClient.findAllByQuery(query);
+ Assert.assertEquals(1, result.getFacetNames().size());
+ Assert.assertNotNull(result.getFacets().get(Element.EXTENSION));
+ }
+
+ /**
+ * Test qu'une recherche fonctionne et que la même recherche apres
+ * suppression ne trouve plus l'element.
+ *
+ * @throws ParseException
+ */
+ @Test
+ public void testStorageFindDelete() throws ParseException {
+
+ // create some wikitty
+ Wikitty gf1Movie = new WikittyImpl();
+ gf1Movie.addExtension(MEDIA_EXTENSION);
+ gf1Movie.addExtension(MOVIE_EXTENSION);
+ gf1Movie.setField(MEDIA_EXTENSION_NAME, "type", "movie");
+ gf1Movie.setField(MOVIE_EXTENSION_NAME, "name", "The godfather");
+ gf1Movie.addToField(MOVIE_EXTENSION_NAME, "authors", "Coppola");
+ gf1Movie.setField(MOVIE_EXTENSION_NAME, "date", WikittyUtil.formatDate(df.parse("March 15, 1972")));
+
+ Wikitty newWik = wikittyClient.store(gf1Movie);
+ Assert.assertTrue(WikittyUtil.versionGreaterThan(gf1Movie.getId(), newWik.getId()));
+
+ // search test
+ Wikitty w = new WikittyImpl();
+ w.addExtension(MOVIE_EXTENSION);
+ w.setField(MOVIE_EXTENSION_NAME, "name", "The godfather");
+ WikittyQuery query = new WikittyQueryMaker().wikitty(w).end();
+ Wikitty resultFind = wikittyClient.findByQuery(Wikitty.class, query);
+
+ Assert.assertEquals(w.getFieldAsString(MOVIE_EXTENSION_NAME, "name"),
+ resultFind.getFieldAsString(MOVIE_EXTENSION_NAME, "name"));
+
+ Assert.assertEquals(gf1Movie.getId(), resultFind.getId());
+ // test equals implantation method
+ Assert.assertEquals(gf1Movie, resultFind);
+
+ Assert.assertEquals(gf1Movie.getFieldAsString(MOVIE_EXTENSION_NAME, "name"),
+ resultFind.getFieldAsString(MOVIE_EXTENSION_NAME, "name"));
+ Assert.assertEquals(gf1Movie.getFieldAsDate(MOVIE_EXTENSION_NAME, "date"),
+ resultFind.getFieldAsDate(MOVIE_EXTENSION_NAME, "date"));
+ Assert.assertEquals(gf1Movie.getFieldAsSet(MOVIE_EXTENSION_NAME, "authors", String.class),
+ resultFind.getFieldAsSet(MOVIE_EXTENSION_NAME, "authors", String.class));
+
+ // test to find deleted wikitty
+ // test if solr index is coherent with database
+ WikittyQuery query1 = new WikittyQueryMaker().ideq(gf1Movie.getId()).end();
+ Wikitty searchedWikitty1 = wikittyClient.findByQuery(Wikitty.class, query1);
+ Assert.assertNotNull(searchedWikitty1);
+
+ wikittyClient.delete(gf1Movie.getId());
+ Wikitty deletedObject = wikittyClient.restore(gf1Movie.getId());
+ Assert.assertNull(deletedObject);
+
+ // test to find deleted wikitty
+ // test if solr index is coherent with database
+ Wikitty searchedWikitty2 = wikittyClient.findByQuery(Wikitty.class, query1);
+ Assert.assertNull(searchedWikitty2);
+ }
+
+ @Test
+ public void testStorageAndLabel() throws Exception {
+
+ // create some wikitty to permit search test
+ WikittyQuery query1 = new WikittyQueryMaker().exteq(MOVIE_EXTENSION_NAME).end();
+ List<Wikitty> wikitties = wikittyClient.findAllByQuery(Wikitty.class, query1).getAll();
+ long ts = new Date().getTime();
+
+ // labelisation test
+ Wikitty w1 = wikitties.get(0);
+ WikittyLabelUtil.addLabel(wikittyClient, w1.getId(), "titi"+ts);
+ WikittyLabelUtil.addLabel(wikittyClient, w1.getId(), "toto"+ts);
+
+ Wikitty w2 = wikitties.get(1);
+ WikittyLabelUtil.addLabel(wikittyClient, w2.getId(), "tata"+ts);
+ WikittyLabelUtil.addLabel(wikittyClient, w2.getId(), "titi"+ts);
+
+ Wikitty w3 = wikitties.get(2);
+ WikittyLabelUtil.addLabel(wikittyClient, w3.getId(), "tutu"+ts);
+ WikittyLabelUtil.addLabel(wikittyClient, w3.getId(), "titi"+ts);
+
+ Wikitty wt = WikittyLabelUtil.findByLabel(wikittyClient, "toto"+ts );
+ Assert.assertEquals(w1, wt);
+
+ Set<String> labels = WikittyLabelUtil.findAllAppliedLabels(wikittyClient, w2.getId());
+ Assert.assertEquals(new HashSet(Arrays.asList("tata"+ts, "titi"+ts)), labels);
+ }
+
+ @Test
+ public void testStorageAndClassification() throws Exception {
+ // create some wikitty to permit search test
+ WikittyQuery query1 = new WikittyQueryMaker().exteq(MOVIE_EXTENSION_NAME).end();
+ List<Wikitty> wikitties = wikittyClient.findAllByQuery(Wikitty.class, query1).getAll();
+ List<Wikitty> wikittyNodes = new ArrayList<Wikitty>();
+
+ WikittyTreeNodeImpl root = new WikittyTreeNodeImpl();
+ wikittyNodes.add(root.getWikitty());
+ root.setName("MyCategoryRoot");
+ for ( int i = 0; i < 3; i++ ) {
+ WikittyTreeNodeImpl leaf = new WikittyTreeNodeImpl();
+ wikittyNodes.add( leaf.getWikitty() );
+ leaf.setName( "cat-"+i );
+ leaf.setParent( root.getWikittyId() );
+ // root.addChild( leaf.getWikittyId() );
+
+ for ( int j = 0; j < 5; j++ ) {
+ WikittyTreeNodeImpl subLeaf = new WikittyTreeNodeImpl();
+ subLeaf.setName( "subcat-"+i+"-"+j );
+ subLeaf.setParent( leaf.getWikittyId() );
+ wikittyNodes.add( subLeaf.getWikitty() );
+ // leaf.addChild( subLeaf.getWikittyId() );
+ }
+ }
+ wikittyNodes = wikittyClient.storeWikitty(wikittyNodes); // store treeNodes.
+
+ Wikitty dieHard = wikitties.get(0);
+ Wikitty edgar = wikitties.get(1);
+ Wikitty knight = wikitties.get(2);
+
+ assign( dieHard, root, "cat-1/subcat-1-4" );
+ assign( edgar, root, "cat-1" );
+ assign( knight, root, "cat-2/subcat-2-4" );
+
+ WikittyQueryResultTreeNode<WikittyTreeNode> t = wikittyClient.findTreeNode(
+ WikittyTreeNode.class,
+ root.getWikitty().getId(), 0, false, null);
+ Assert.assertEquals("MyCategoryRoot", t.getObject().getName());
+ }
+
+ /**
+ * @deprecated remove this undocumented method
+ */
+ @Deprecated
+ protected void assign(Wikitty wikitty, WikittyTreeNodeImpl root, String path) {
+ String[] nodeNames = path.split("/");
+ WikittyTreeNodeImpl currentNode = root;
+ outerloop : for( String nodeName : nodeNames ) {
+ WikittyTreeNodeImpl node = new WikittyTreeNodeImpl();
+ node.setName(nodeName);
+
+ WikittyQuery query = new WikittyQueryMaker().wikitty(node.getWikitty()).end();
+ List<String> wikittiesId = wikittyClient.findAllByQuery(query).getAll();
+ List<Wikitty> wikitties = wikittyClient.restore(wikittiesId);
+ for ( Wikitty child : wikitties ) {
+ if (!child.hasExtension(WikittyTreeNode.EXT_WIKITTYTREENODE)) {
+ continue;
+ }
+ node = new WikittyTreeNodeImpl(child);
+ if ( node.getName().equals(nodeName) ) {
+ currentNode = node;
+ continue outerloop;
+ }
+ }
+ Assert.fail( "Unable to find node " + nodeName + " inside " + currentNode.getName() );
+ }
+ currentNode.addAttachment(wikitty.getId());
+ wikittyClient.store(currentNode.getWikitty());
+ }
+
+ /**
+ * Test de la methode cast du wikitty client.
+ */
+ @Test
+ public void testStorageCastTo() {
+ WikittyTreeNode node = new WikittyTreeNodeImpl();
+ node.setName("nodeName");
+
+ // cast, different business object, same wikitty
+ WikittyLabel label = wikittyClient.castTo(WikittyLabel.class, node);
+ label.addLabels("testlabel");
+
+ label = wikittyClient.store(label);
+ String wikittyId = label.getWikittyId();
+
+ WikittyTreeNode node2 = wikittyClient.restore(WikittyTreeNode.class, wikittyId);
+ Assert.assertEquals("nodeName", node2.getName());
+
+ WikittyLabel label2 = wikittyClient.castTo(WikittyLabel.class, node);
+ List<String> labels = new ArrayList<String>(label2.getLabels());
+ Assert.assertFalse(labels.isEmpty());
+ Assert.assertEquals("testlabel", labels.get(0));
+ }
+
+ /**
+ * Test les differents cas du forcage de version lors du store.
+ */
+ @Test
+ public void testStorageVersionForce() {
+
+ // store 1
+ Wikitty myWikitty = new WikittyImpl();
+ myWikitty.addExtension(WikittyTreeNodeImpl.extensions);
+ WikittyTreeNodeHelper.setName(myWikitty, "name");
+ myWikitty = wikittyClient.store(myWikitty);
+ Assert.assertEquals("1.0", myWikitty.getVersion());
+
+ // store 2 : no modification
+ myWikitty = wikittyClient.store(myWikitty);
+ Assert.assertEquals("1.0", myWikitty.getVersion());
+
+ // store 3 : modification
+ WikittyTreeNodeHelper.setName(myWikitty, "new name");
+ myWikitty = wikittyClient.store(myWikitty);
+ Assert.assertEquals("2.0", myWikitty.getVersion());
+
+ // store 4 : new wikitty with same wikitty id (obsolete)
+ Wikitty myNewWikitty = new WikittyImpl(myWikitty.getId());
+ myNewWikitty.addExtension(WikittyTreeNodeImpl.extensions);
+ WikittyTreeNodeHelper.setName(myNewWikitty, "new wikitty");
+ try {
+ myWikitty = wikittyClient.store(myNewWikitty);
+ Assert.fail("Test must throw WikittyObsoleteException");
+ }
+ catch (WikittyObsoleteException ex) {
+ if (log.isTraceEnabled()) {
+ log.trace("Wikitty obsolete", ex);
+ }
+ }
+
+ // store 4 : same but with force (increased by force)
+ WikittyEvent event = wikittyClient.getWikittyService().store(
+ null, Collections.singletonList(myWikitty), true);
+ event.update(myWikitty);
+ Assert.assertEquals("3.0", myWikitty.getVersion());
+
+ // store 5 : fix version (not increased by force)
+ myNewWikitty.setVersion("11.0");
+ event = wikittyClient.getWikittyService().store(
+ null, Collections.singletonList(myNewWikitty), true);
+ event.update(myNewWikitty);
+ Assert.assertEquals("11.0", myNewWikitty.getVersion());
+ }
+
+ /**
+ * Test qu'une sauvegarde de wikitty précédemment supprimé fonctionne.
+ */
+ @Test
+ public void testStoragePreviouslyDeleted() {
+
+ // store 1
+ Wikitty myWikitty = new WikittyImpl();
+ myWikitty.addExtension(WikittyTreeNodeImpl.extensions);
+ WikittyTreeNodeHelper.setName(myWikitty, "name");
+
+ myWikitty = wikittyClient.store(myWikitty);
+
+ // delete
+ wikittyClient.delete(myWikitty.getId());
+ Wikitty restoredWikitty = wikittyClient.restore(myWikitty.getId());
+ Assert.assertNull(restoredWikitty);
+
+ // store again
+ myWikitty = wikittyClient.store(myWikitty);
+ restoredWikitty = wikittyClient.restore(myWikitty.getId());
+ Assert.assertNotNull(restoredWikitty);
+ }
+
+ @Test
+ public void testStorageBinaryField() {
+ String extName = "BinaryExt";
+ byte[] bytes = "Coucou le monde".getBytes();
+
+ WikittyExtension BinaryExt = new WikittyExtension(extName,
+ "1.0", // version
+ WikittyUtil.buildFieldMapExtension( // building field map
+ "String name unique=\"true\"",
+ "Binary content"));
+ Wikitty w = new WikittyImpl();
+ w.addExtension(BinaryExt);
+ w.setField(extName, "name", "LeBin");
+ w.setField(extName, "content", bytes);
+
+ w = wikittyClient.store(w);
+
+ Wikitty restoredWikitty = wikittyClient.restore(w.getId());
+ Assert.assertNotNull(restoredWikitty);
+ Assert.assertEquals("LeBin", restoredWikitty.getFieldAsString(extName, "name"));
+ Assert.assertEquals(bytes, restoredWikitty.getFieldAsBytes(extName, "content"));
+ }
+
+ @Test
+ public void testStoreUnmodifiedEntity() {
+ WikittyLabel wikitty1 = new WikittyLabelImpl();
+ WikittyLabel wikitty2 = new WikittyLabelImpl();
+
+ List<WikittyLabel> toStore = new ArrayList<WikittyLabel>();
+ Collections.addAll(toStore, wikitty1, wikitty2);
+ List<WikittyLabel> stored = wikittyClient.store(toStore);
+
+ stored.get(0).addLabels("lbl");
+
+ stored = wikittyClient.store(toStore);
+ Assert.assertEquals(Collections.singleton("lbl"), stored.get(0).getLabels());
+ }
+
+ /**
* Test a query with query maker.
*/
@Test
@@ -254,7 +808,7 @@
Assert.assertEquals(1, results.getTotalResult());
// test normal import
- WikittyQuery query2 = new WikittyQueryMaker().eq("Client.name", "Toto").end();
+ WikittyQuery query2 = new WikittyQueryMaker().eq("Client.name", "Entreprise dupont").end();
WikittyQueryResult<String> results2 = wikittyClient.findAllByQuery(query2);
Assert.assertEquals(1, results2.getTotalResult());
@@ -295,7 +849,7 @@
// aa
w = wikittyClient.restore("fbcc8aed-7f67-4e3c-a9aa-221373765f8d");
- Assert.assertEquals("Toto", w.getFieldAsString("Client", "name"));
+ Assert.assertEquals("Entreprise dupont", w.getFieldAsString("Client", "name"));
}
/**
@@ -907,9 +1461,9 @@
assumeTrueSearchEngineCanRunTest(); // sorting
WikittyQuery query1 = WikittyQueryParser.parse("*.name=*");
- // FIXME uncomment query1.setSortAscending("*.name");
+ query1.setSortAscending(new ElementField("*.name"));
WikittyQueryResult<Product> results1 = wikittyClient.findAllByQuery(Product.class, query1);
- Assert.assertEquals(18, results1.getTotalResult());
+ Assert.assertEquals(14, results1.getTotalResult());
}
/**
@@ -943,7 +1497,7 @@
}
Collections.sort(expected);
WikittyQuery query2 = new WikittyQueryMaker().exteq(sortableExtName).end();
- // FIXME uncomment query2.setSortAscending(WikittyUtil.getFQFieldName(sortableExtName, numFieldName));
+ query2.setSortAscending(new ElementField(WikittyUtil.getFQFieldName(sortableExtName, numFieldName)));
WikittyQueryResult<Wikitty> results2 = wikittyClient.findAllByQuery(Wikitty.class, query2);
List<Integer> resulted = new ArrayList<Integer>();
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java 2012-01-26 13:28:55 UTC (rev 1370)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java 2012-01-26 13:32:44 UTC (rev 1371)
@@ -24,674 +24,6 @@
*/
package org.nuiton.wikitty.conform;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Assert;
-import org.junit.Test;
-import org.nuiton.wikitty.entities.WikittyLabelImpl;
-import org.nuiton.wikitty.search.Criteria;
-import org.nuiton.wikitty.entities.WikittyLabel;
-import org.nuiton.wikitty.search.PagedResult;
-import org.nuiton.wikitty.entities.WikittyTreeNode;
-import org.nuiton.wikitty.entities.WikittyTreeNodeImpl;
-import org.nuiton.wikitty.entities.Wikitty;
-import org.nuiton.wikitty.WikittyException;
-import org.nuiton.wikitty.entities.WikittyExtension;
-import org.nuiton.wikitty.entities.WikittyImpl;
-import org.nuiton.wikitty.addons.WikittyLabelUtil;
-import org.nuiton.wikitty.WikittyObsoleteException;
-import org.nuiton.wikitty.services.WikittyEvent;
-import org.nuiton.wikitty.WikittyUtil;
-import org.nuiton.wikitty.entities.WikittyTreeNodeHelper;
-import org.nuiton.wikitty.search.operators.Element;
-import org.nuiton.wikitty.search.Search;
-import org.nuiton.wikitty.search.TreeNodeResult;
-
public abstract class StorageTest extends AbstractTestConformance {
- private final static Log log = LogFactory.getLog(StorageTest.class);
-
- @Test
- public void testStoreRestoreBasics() throws Exception {
- Wikitty w = createBasicWikitty();
- String id = w.getId();
- w = getProxy().store(w);
- w = getProxy().restore(id);
- assertTrue(w.hasExtension(EXTNAME));
- for ( int i = 0; i < 3; i++ ) {
- assertTrue( w.hasField(EXTNAME, "fieldName" + i));
- }
- }
-
- @Test
- public void testExtensionMethod() throws Exception {
- {
- getProxy().storeExtension(EXT_TEST);
- List<String> extIds = getProxy().getAllExtensionIds();
- log.debug("extIds: " + extIds);
- assertEquals(1, extIds.size());
- WikittyExtension ext = getProxy().restoreExtension(extIds.get(0));
- assertEquals(EXT_TEST.getName(), ext.getName());
- assertEquals(EXT_TEST.getVersion(), ext.getVersion());
- assertEquals(EXT_TEST, ext);
- }
- {
- // test de la suppression de l'extension
- getProxy().deleteExtension(EXT_TEST.getName());
- List<String> extIds = getProxy().getAllExtensionIds();
- assertEquals(0, extIds.size());
- }
- {
- // test que la suppression echoue si l'extension est utilisee
- getProxy().storeExtension(EXT_TEST);
-
- Wikitty w = new WikittyImpl();
- w.addExtension(EXT_TEST);
- w = getProxy().store(w);
-
- try {
- getProxy().deleteExtension(EXT_TEST.getName());
- assertTrue(false); // il doit y avoir une exception, donc on ne passe pas la
- } catch (WikittyException eee) {
- assertTrue(true);
- }
- List<String> extIds = getProxy().getAllExtensionIds();
- assertEquals(1, extIds.size());
- }
- }
-
- @Test
- public void testExtensionRequires() throws Exception {
- getProxy().storeExtension(Arrays.asList(EXT_REQUIRED, EXT_REQUIRES));
- List<String> extIds = getProxy().getAllExtensionsRequires(EXTREQUIRED);
- log.debug("extIds: " + extIds);
- assertEquals(1, extIds.size());
-
- WikittyExtension ext = getProxy().restoreExtension(extIds.get(0));
- assertEquals(EXT_REQUIRES.getName(), ext.getName());
- assertEquals(EXT_REQUIRES.getVersion(), ext.getVersion());
- assertEquals(EXT_REQUIRES, ext);
- }
-
- @Test
- public void testStoreRestoreLists() throws Exception {
- List<Wikitty> wikitties = new ArrayList<Wikitty>();
- List<String> ids = new ArrayList<String>();
- String[] wValues = new String[] {
- // wikitty[ 0 ]
- "fieldName0 = hello," +
- "fieldName1 = 123456," +
- "fieldName2 = " + format("23/01/1982"),
-
- // wikitty[ 1 ]
- "fieldName0 = Bonzai !," +
- "fieldName1 = 111111," +
- "fieldName2 = " + format("26/09/2009"),
-
- // wikitty[ 2 ]
- "fieldName0 = ho ho ho !," +
- "fieldName1 = 987654," +
- "fieldName2 = " + format("25/12/2029")
- };
- for ( String wValue : wValues ) {
- Wikitty w = createWikitty( wValue, EXTNAME, EXT_TEST );
- wikitties.add( w );
- ids.add( w.getId() );
- }
- wikitties = getProxy().storeWikitty(wikitties);
-
- wikitties = getProxy().restore(ids);
- int wIndex = 0;
- for ( String wValue : wValues ) {
- Wikitty w = wikitties.get(wIndex);
- int i = 0;
- for( Entry<String, String> keyValuePair : getKeyPairs(wValue) ) {
- String fieldName = "fieldName" + i;
- assertEquals(fieldName, keyValuePair.getKey());
- String errorMsg = "Error check field '" + fieldName + "' on wikitty[" + i + "]";
- switch( i ) {
- case 0: // check fieldName0
- assertEquals( errorMsg,
- keyValuePair.getValue(), w.getFieldAsString(EXTNAME, fieldName) );
- break;
- case 1: // check fieldName1
- assertEquals( errorMsg,
- Integer.parseInt(keyValuePair.getValue()),
- w.getFieldAsInt(EXTNAME, fieldName) );
- break;
- case 2: // check fieldName2
- assertEquals( errorMsg,
- WikittyUtil.parseDate(keyValuePair.getValue()),
- w.getFieldAsDate(EXTNAME, fieldName) );
- break;
- default:
- fail( "this structure should only get 3 elements, unexpected : " + keyValuePair.getKey() );
- }
- i++;
- }
- wIndex++;
- }
- }
-
- @Test
- public void testStoreRestoreNullEmpty() throws Exception {
- Wikitty w = null;
- // should be ignored (?)
- try {
- w = getProxy().store(w);
- fail("store(null) Must throw an exception !");
- } catch (Exception e) {
- // OK !
- }
-
- w = new WikittyImpl();
- String id = w.getId();
- w = getProxy().store(w);
- w = getProxy().restore(id);
- assertEquals( id, w.getId() );
- }
-
- @Test
- public void testFieldConstraint() throws Exception {
- WikittyExtension ext = new WikittyExtension("TestConstraint", "1",
- WikittyUtil.buildFieldMapExtension(
- "String id notNull=true",
- "String ext[0-n] unique=true",
- "String other[0-n] unique=true notNull=true"
- ));
-
- getProxy().storeExtension(ext);
- Wikitty w = new WikittyImpl();
- w.addExtension(ext);
-
- try {
- w = getProxy().store(w);
- Assert.fail("not null contraint don't work on String");
- } catch (WikittyException eee) {
- eee.printStackTrace();
- // ok id must not be null
- }
-
- w.setField("TestConstraint", "id", "toto");
- try {
- w = getProxy().store(w);
- Assert.fail("not null contraint don't work in Collection");
- } catch (WikittyException eee) {
- eee.printStackTrace();
- // ok id must not be null
- }
-
- w.addToField("TestConstraint", "other", "titi");
- w = getProxy().store(w);
-
- w.addToField("TestConstraint", "ext", "tata");
- w.addToField("TestConstraint", "ext", "titi");
- w = getProxy().store(w);
-
- Wikitty w2 = getProxy().restore(w.getId());
- w2.addToField("TestConstraint", "ext", "tata"); // tata ne doit pas s'ajouter
- w2.addToField("TestConstraint", "ext", "toto");
-
- w2 = getProxy().store(w2);
- Wikitty w3 = getProxy().restore(w.getId());
-
- HashSet set = new HashSet(Arrays.asList("tata", "titi", "toto"));
- assertEquals(set, w3.getFieldAsSet("TestConstraint", "ext", String.class));
- }
-
- @Test
- public void testStoreFindAll() throws Exception {
-
- // create some wikitty to permit search test
- List<Wikitty> wikitties = new ArrayList<Wikitty>();
- String[] wValues = new String[] {
- // wikitty[ 0 ]
- "fieldName0 = table," +
- "fieldName1 = 003309," +
- "fieldName2 = " + format("23/01/1982"),
-
- // wikitty[ 1 ]
- "fieldName0 = chaise," +
- "fieldName1 = 003309," +
- "fieldName2 = " + format("26/09/2009"),
-
- // wikitty[ 2 ]
- "fieldName0 = bureau," +
- "fieldName1 = 223322," +
- "fieldName2 = " + format("25/12/2029")
- };
- for ( String wValue : wValues ) {
- Wikitty w = createWikitty( wValue, EXTNAME, EXT_TEST );
- wikitties.add( w );
- }
- wikitties = getProxy().storeWikitty(wikitties);
-
- // search test
- Wikitty w = new WikittyImpl();
- w.addExtension(EXT_TEST);
- w.setField(EXT_TEST.getName(), "fieldName1", "003309");
- Criteria criteria = Search.query(w).criteria()
- .addSortDescending(EXT_TEST.getName() + ".fieldName0");
- PagedResult<Wikitty> resultFind = getProxy().findAllByCriteria(criteria);
-
- assertEquals(2, resultFind.size());
- List<Wikitty> wikittyFind = resultFind.getAll();
- assertEquals(wikitties.subList(0, 2), wikittyFind);
- }
-
- /**
- * Test ignored because WikittyServiceInMemory don't support facets.
- *
- * @throws Exception
- */
- @Test
- public void testStoreFindAllFacet() throws Exception {
-
- // create some wikitty to permit search test
- List<Wikitty> wikitties = new ArrayList<Wikitty>();
- String[] wValues = new String[] {
- // wikitty[ 0 ]
- "fieldName0 = table," +
- "fieldName1 = 663300," +
- "fieldName2 = " + format("23/01/1982"),
-
- // wikitty[ 1 ]
- "fieldName0 = chaise," +
- "fieldName1 = 663300," +
- "fieldName2 = " + format("26/09/2009"),
-
- // wikitty[ 2 ]
- "fieldName0 = bureau," +
- "fieldName1 = 223322," +
- "fieldName2 = " + format("25/12/2029")
- };
- for ( String wValue : wValues ) {
- Wikitty w = createWikitty( wValue, EXTNAME, EXT_TEST );
- wikitties.add( w );
- }
- wikitties = getProxy().storeWikitty(wikitties);
-
- // search test
- Wikitty w = new WikittyImpl();
- w.addExtension(EXT_TEST);
- w.setField(EXT_TEST.getName(), "fieldName1", "663300");
- Criteria criteria = Search.query(w).criteria()
- .setFirstIndex(0).setEndIndex(Criteria.ALL_ELEMENTS)
- .addFacetField(EXT_TEST.getName()+".fieldName0")
- .addFacetField(EXT_TEST.getName()+".fieldName1");
- PagedResult<String> resultFind = getProxy().findAllIdByCriteria(criteria);
-
- List<String> facetNames = new ArrayList<String>(resultFind.getFacetNames());
- Collections.sort(facetNames);
- assertEquals(Arrays.asList(EXT_TEST.getName()+".fieldName0",
- EXT_TEST.getName()+".fieldName1"), facetNames);
-
- // with must have 2 topic: table and chaise
- assertEquals(2, resultFind.getTopic(EXT_TEST.getName()+".fieldName0").size());
- // with must have 1 topic: 663300
- assertEquals(1, resultFind.getTopic(EXT_TEST.getName()+".fieldName1").size());
-
-
- // essai de facettiser sur les extensions
- criteria = Search.query().keyword("*").criteria()
- .setFirstIndex(0).setEndIndex(0)
- .addFacetField(Element.ELT_EXTENSION);
- resultFind = getProxy().findAllIdByCriteria(criteria);
- assertEquals(1, resultFind.getFacetNames().size());
- assertNotNull(resultFind.getFacets().get(Element.ELT_EXTENSION));
- }
-
- @Test
- public void testStoreFindDelete() throws Exception {
-
- // create some wikitty to permit search test
- List<Wikitty> wikitties = new ArrayList<Wikitty>();
- String[] wValues = new String[] {
- // wikitty[ 0 ]
- "fieldName0 = table," +
- "fieldName1 = 003301," +
- "fieldName2 = " + format("23/01/1982"),
-
- // wikitty[ 1 ]
- "fieldName0 = chaiseICI," +
- "fieldName1 = 113312," +
- "fieldName2 = " + format("26/09/2009"),
-
- // wikitty[ 2 ]
- "fieldName0 = bureau," +
- "fieldName1 = 223323," +
- "fieldName2 = " + format("25/12/2029")
- };
- for ( String wValue : wValues ) {
- Wikitty w = createWikitty( wValue, EXTNAME, EXT_TEST );
- wikitties.add( w );
- }
- Map<String, String> oldIdVersion = new HashMap<String, String>();
- for( Wikitty w : wikitties ) {
- oldIdVersion.put(w.getId(), w.getVersion());
- }
- WikittyEvent response = getWikittyService().store(null, wikitties, false);
- for (Wikitty w : wikitties) {
- response.update(w);
- String v1 = w.getVersion();
- String v2 = oldIdVersion.get( w.getId() );
- assertNotNull( v1 );
- assertNotNull( v2 );
- assertTrue(WikittyUtil.versionGreaterThan(v1, v2));
- }
-
- // search test
- Wikitty w = new WikittyImpl();
- w.addExtension(EXT_TEST);
- w.setField(EXT_TEST.getName(), "fieldName0", "chaiseICI");
- Criteria criteria = Search.query(w).criteria();
- Wikitty resultFind = getProxy().findByCriteria(criteria);
-
- Wikitty wikittySource = wikitties.get(1);
- assertEquals(w.getFieldAsString(EXT_TEST.getName(), "fieldName0"),
- resultFind.getFieldAsString(EXT_TEST.getName(), "fieldName0"));
-
- assertEquals(wikittySource.getId(), resultFind.getId());
- // test equals implantation method
- assertEquals(wikittySource, resultFind);
-
- assertEquals(wikittySource.getFieldAsString(EXT_TEST.getName(), "fieldName0"),
- resultFind.getFieldAsString(EXT_TEST.getName(), "fieldName0"));
- assertEquals(wikittySource.getFieldAsString(EXT_TEST.getName(), "fieldName1"),
- resultFind.getFieldAsString(EXT_TEST.getName(), "fieldName1"));
- assertEquals(wikittySource.getFieldAsString(EXT_TEST.getName(), "fieldName2"),
- resultFind.getFieldAsString(EXT_TEST.getName(), "fieldName2"));
-
-
- // test to find deleted wikitty
- // test if solr index is coherent with database
- Criteria criteria1 = Search.query().eq(Element.ELT_ID, wikittySource.getId()).criteria();
- Wikitty searchedWikitty1 = getProxy().findByCriteria(criteria1);
- Assert.assertNotNull(searchedWikitty1);
-
- getProxy().delete(wikittySource.getId());
- Wikitty deletedObject = getProxy().restore(wikittySource.getId());
- assertNull(deletedObject);
-
- // test to find deleted wikitty
- // test if solr index is coherent with database
- Criteria criteria2 = Search.query().eq(Element.ELT_ID, wikittySource.getId()).criteria();
- Wikitty searchedWikitty2 = getProxy().findByCriteria(criteria2);
- Assert.assertNull(searchedWikitty2);
- }
-
- /**
- * Test ignored because WikittyServiceInMemory don't support labels.
- *
- * @throws Exception
- */
- @Test
- public void testStoreAndLabel() throws Exception {
-
- // create some wikitty to permit search test
- List<Wikitty> wikitties = createSampleWikitty(getWikittyService());
- long ts = new Date().getTime();
-
- // labelisation test
- Wikitty w1 = wikitties.get(0);
- WikittyLabelUtil.addLabel(getProxy(), w1.getId(), "titi"+ts);
- WikittyLabelUtil.addLabel(getProxy(), w1.getId(), "toto"+ts);
-
- Wikitty w2 = wikitties.get(1);
- WikittyLabelUtil.addLabel(getProxy(), w2.getId(), "tata"+ts);
- WikittyLabelUtil.addLabel(getProxy(), w2.getId(), "titi"+ts);
-
- Wikitty w3 = wikitties.get(2);
- WikittyLabelUtil.addLabel(getProxy(), w3.getId(), "tutu"+ts);
- WikittyLabelUtil.addLabel(getProxy(), w3.getId(), "titi"+ts);
-
- Wikitty wt = WikittyLabelUtil.findByLabel(getProxy(), "toto"+ts );
-
- assertEquals(w1, wt);
-
- Set<String> labels = WikittyLabelUtil.findAllAppliedLabels(getProxy(), w2.getId());
-
- assertEquals(new HashSet(Arrays.asList("tata"+ts, "titi"+ts)), labels);
- }
-
- @Test
- public void testStoreAndClassification() throws Exception {
- // create some wikitty to permit search test
- List<Wikitty> wikitties = createSampleWikitty(getWikittyService());
- List<Wikitty> wikittyNodes = new ArrayList<Wikitty>();
-
- WikittyTreeNodeImpl root = new WikittyTreeNodeImpl();
- wikittyNodes.add(root.getWikitty());
- root.setName("MyCategoryRoot");
- for ( int i = 0; i < 3; i++ ) {
- WikittyTreeNodeImpl leaf = new WikittyTreeNodeImpl();
- wikittyNodes.add( leaf.getWikitty() );
- leaf.setName( "cat-"+i );
- leaf.setParent( root.getWikittyId() );
- // root.addChild( leaf.getWikittyId() );
-
- for ( int j = 0; j < 5; j++ ) {
- WikittyTreeNodeImpl subLeaf = new WikittyTreeNodeImpl();
- subLeaf.setName( "subcat-"+i+"-"+j );
- subLeaf.setParent( leaf.getWikittyId() );
- wikittyNodes.add( subLeaf.getWikitty() );
- // leaf.addChild( subLeaf.getWikittyId() );
- }
- }
- wikittyNodes = getProxy().storeWikitty(wikittyNodes); // store treeNodes.
-
- Wikitty table = wikitties.get(0);
- Wikitty chaise = wikitties.get(1);
- Wikitty bureau = wikitties.get(2);
-
- assign( chaise, root, "cat-1/subcat-1-4" );
- assign( table, root, "cat-1" );
- assign( bureau, root, "cat-2/subcat-2-4" );
-
- TreeNodeResult<WikittyTreeNode> t = getProxy().findTreeNode(
- WikittyTreeNode.class,
- root.getWikitty().getId(), 0, false, null);
-
- Assert.assertEquals("MyCategoryRoot", t.getObject().getName());
-
-
- }
-
- protected void assign(Wikitty wikitty, WikittyTreeNodeImpl root, String path) {
- String[] nodeNames = path.split("/");
- WikittyTreeNodeImpl currentNode = root;
- outerloop : for( String nodeName : nodeNames ) {
- WikittyTreeNodeImpl node = new WikittyTreeNodeImpl();
- node.setName(nodeName);
-
- Criteria criteria = Search.query(node.getWikitty()).criteria()
- .setFirstIndex(0).setEndIndex(Criteria.ALL_ELEMENTS);
- List<String> wikittiesId = getProxy().findAllIdByCriteria(criteria).getAll();
- List<Wikitty> wikitties = getProxy().restore(wikittiesId);
- for ( Wikitty child : wikitties ) {
- if (!child.hasExtension(WikittyTreeNode.EXT_WIKITTYTREENODE)) {
- continue;
- }
- node = new WikittyTreeNodeImpl(child);
- if ( node.getName().equals(nodeName) ) {
- currentNode = node;
- continue outerloop;
- }
- }
- fail( "Unable to find node " + nodeName + " inside " + currentNode.getName() );
- }
- currentNode.addAttachment(wikitty.getId());
- getProxy().store(currentNode.getWikitty());
- }
-
- /**
- * Test la creation d'une entité business par introspection avec un wikitty.
- */
- @Test
- public void testWikittyUtilNewInstanceWithWikitty() {
-
- Wikitty w = new WikittyImpl();
- w.addExtension(WikittyTreeNodeImpl.extensions);
-
- WikittyTreeNode treeNode = WikittyUtil.newInstance(
- null, getWikittyService(), WikittyTreeNode.class, w);
- Assert.assertNotNull(treeNode);
- }
-
- /**
- * Test de la methode cast du proxy.
- */
- @Test
- public void testCast() {
-
- WikittyTreeNode node = new WikittyTreeNodeImpl();
- node.setName("nodeName");
-
- // cast, different business object, same wikitty
- WikittyLabel label = getProxy().cast(node, WikittyLabel.class);
- label.addLabels("toto");
-
- label = getProxy().store(label);
- String wikittyId = label.getWikittyId();
-
- WikittyTreeNode node2 = getProxy().restore(WikittyTreeNode.class, wikittyId);
- Assert.assertEquals("nodeName", node2.getName());
-
- WikittyLabel label2 = getProxy().cast(node, WikittyLabel.class);
- List<String> labels = new ArrayList<String>(label2.getLabels());
- Assert.assertFalse(labels.isEmpty());
- Assert.assertEquals("toto", labels.get(0));
- }
-
- /**
- * Test les differents cas du forage de version lors du store.
- */
- @Test
- public void testStorageVersionForce() {
-
- // store 1
- Wikitty myWikitty = new WikittyImpl();
- myWikitty.addExtension(WikittyTreeNodeImpl.extensions);
- WikittyTreeNodeHelper.setName(myWikitty, "name");
- myWikitty = getProxy().store(myWikitty);
- Assert.assertEquals("1.0", myWikitty.getVersion());
-
- // store 2 : no modification
- myWikitty = getProxy().store(myWikitty);
- Assert.assertEquals("1.0", myWikitty.getVersion());
-
- // store 3 : modification
- WikittyTreeNodeHelper.setName(myWikitty, "new name");
- myWikitty = getProxy().store(myWikitty);
- Assert.assertEquals("2.0", myWikitty.getVersion());
-
- // store 4 : new wikitty with same wikitty id (obsolete)
- Wikitty myNewWikitty = new WikittyImpl(myWikitty.getId());
- myNewWikitty.addExtension(WikittyTreeNodeImpl.extensions);
- WikittyTreeNodeHelper.setName(myNewWikitty, "new wikitty");
- try {
- myWikitty = getProxy().store(myNewWikitty);
- Assert.fail("Test must throw WikittyObsoleteException");
- }
- catch (WikittyObsoleteException ex) {
- if (log.isTraceEnabled()) {
- log.trace("Wikitty obsolete", ex);
- }
- }
-
- // store 4 : same but with force (increased by force)
- WikittyEvent event = getWikittyService().store(
- null, Collections.singletonList(myWikitty), true);
- event.update(myWikitty);
- Assert.assertEquals("3.0", myWikitty.getVersion());
-
- // store 5 : fix version (not increased by force)
- myNewWikitty.setVersion("11.0");
- event = getWikittyService().store(
- null, Collections.singletonList(myNewWikitty), true);
- event.update(myNewWikitty);
- Assert.assertEquals("11.0", myNewWikitty.getVersion());
- }
-
- /**
- * Test qu'une sauvegarde de wikitty précédemment supprimé fonctionne.
- */
- @Test
- public void testStoragePreviouslyDeleted() {
-
- // store 1
- Wikitty myWikitty = new WikittyImpl();
- myWikitty.addExtension(WikittyTreeNodeImpl.extensions);
- WikittyTreeNodeHelper.setName(myWikitty, "name");
-
- myWikitty = getProxy().store(myWikitty);
-
- // delete
- getProxy().delete(myWikitty.getId());
- Wikitty restoredWikitty = getProxy().restore(myWikitty.getId());
- Assert.assertNull(restoredWikitty);
-
- // store again
- myWikitty = getProxy().store(myWikitty);
- restoredWikitty = getProxy().restore(myWikitty.getId());
- Assert.assertNotNull(restoredWikitty);
- }
-
- @Test
- public void testBinaryFieldStorage() {
- String extName = "BinaryExt";
- byte[] bytes = "Coucou le monde".getBytes();
-
- WikittyExtension BinaryExt = new WikittyExtension(extName,
- "1.0", // version
- WikittyUtil.buildFieldMapExtension( // building field map
- "String name unique=\"true\"",
- "Binary content"));
- Wikitty w = new WikittyImpl();
- w.addExtension(BinaryExt);
- w.setField(extName, "name", "LeBin");
- w.setField(extName, "content", bytes);
-
- w = getProxy().store(w);
-
- Wikitty restoredWikitty = getProxy().restore(w.getId());
- Assert.assertNotNull(restoredWikitty);
- Assert.assertEquals("LeBin", restoredWikitty.getFieldAsString(extName, "name"));
- Assert.assertEquals(bytes, restoredWikitty.getFieldAsBytes(extName, "content"));
- }
-
- @Test
- public void testStoreUnmodifiedEntity() {
- WikittyLabel wikitty1 = new WikittyLabelImpl();
- WikittyLabel wikitty2 = new WikittyLabelImpl();
-
- List<WikittyLabel> toStore = new ArrayList<WikittyLabel>();
- Collections.addAll(toStore, wikitty1, wikitty2);
- List<WikittyLabel> stored = getProxy().store(toStore);
-
- stored.get(0).addLabels("lbl");
-
- try {
- getProxy().store(toStore);
- } catch (Exception eee) {
- Assert.fail();
- }
- }
}
1
0
r1370 - trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services
by echatellier@users.nuiton.org 26 Jan '12
by echatellier@users.nuiton.org 26 Jan '12
26 Jan '12
Author: echatellier
Date: 2012-01-26 14:28:55 +0100 (Thu, 26 Jan 2012)
New Revision: 1370
Url: http://nuiton.org/repositories/revision/wikitty/1370
Log:
Wording
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyEvent.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyEvent.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyEvent.java 2012-01-25 14:55:04 UTC (rev 1369)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyEvent.java 2012-01-26 13:28:55 UTC (rev 1370)
@@ -255,17 +255,17 @@
/**
* Update data directly in object passed in argument.
- * Actualy only version and deletion date are updated.
+ * Actually only version and deletion date are updated.
* <p>
* rem: during store action, no migration has done. Migration is only
* done during restore process. This implies that extension don't change
* after store. But another client, may can load wikitty with migration
- * and store it, or add manualy some extension. In that case, stored wikitty
+ * and store it, or add manually some extension. In that case, stored wikitty
* has new/more extension that another client.
* <p>
- * And internaly wikitty object is marked clean (not dirty)
+ * And internally wikitty object is marked clean (not dirty)
* @param e
- * @return wikitty passed in arguement or null, if event is CLEAR_WIKITTY
+ * @return wikitty passed in argument or null, if event is CLEAR_WIKITTY
*/
public Wikitty update(Wikitty e) {
if (e != null) {
@@ -308,7 +308,7 @@
/**
* Permet de serializer en XML l'event. Pourrait etre utilise pour l'envoi
- * sur un transporteur qui ne peremt pas la serialisation java
+ * sur un transporteur qui ne permet pas la serialisation java
* @return
*/
public String toXML() {
1
0