Author: echatellier Date: 2012-01-30 12:23:24 +0100 (Mon, 30 Jan 2012) New Revision: 1389 Url: http://nuiton.org/repositories/revision/wikitty/1389 Log: En test refactoring (remove all useless conform test classes) Removed: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/AbstractTestConformance.java trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/AbstractTestSolr.java trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrTestHelper.java trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/TreeTest.java 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-30 10:55:42 UTC (rev 1388) +++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyClientTest.java 2012-01-30 11:23:24 UTC (rev 1389) @@ -2263,8 +2263,7 @@ WikittyQueryResultTreeNode<String> treeNodeResult = wikittyClient.findAllIdTreeNode(catalogNode.getWikittyId(), 0, true, null); - int val = treeNodeResult.getAttCount(); - Assert.assertEquals(9, val); + Assert.assertEquals(9, treeNodeResult.getAttCount()); WikittyQueryResultTreeNode<String> children = wikittyClient.findAllIdTreeNode(bookNode.getWikittyId(), 1, true, null); @@ -2285,7 +2284,7 @@ public void testSearchEngineCountAttachmentFiltered() { WikittyQuery query = new WikittyQueryMaker().and() - .exteq(WikittyTreeNodeImpl.EXT_WIKITTYTREENODE) + .exteq(CatalogNode.EXT_CATALOGNODE) .eq(WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_NAME, "Catalog").end(); CatalogNode catalogNode = wikittyClient.findAllByQuery(CatalogNode.class, query).peek(); @@ -2294,8 +2293,100 @@ WikittyQueryResultTreeNode<String> treeNodeResult = wikittyClient.findAllIdTreeNode(catalogNode.getWikittyId(), 0, true, filter); - int val = treeNodeResult.getAttCount(); // parmis les 9 du test precedent, seulement 1 dans la category society - Assert.assertEquals(1, val); + Assert.assertEquals(1, treeNodeResult.getAttCount()); } + + /** + * Test le nombre d'attachment (fichiers attachés) au noeud des arbres. + */ + @Test + public void testSearchEngineCountAttachmentAfterDeletion() { + + // delete Lanfeust book, attached to tree + WikittyQuery query = new WikittyQueryMaker().and() + .exteq(Product.EXT_PRODUCT) + .eq(Product.FIELD_PRODUCT_NAME, "Lanfeust").end(); + String bookId = wikittyClient.findByQuery(query); + wikittyClient.delete(bookId); + + query = new WikittyQueryMaker().and() + .exteq(CatalogNode.EXT_CATALOGNODE) + .eq(WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_NAME, "Catalog").end(); + CatalogNode catalogNode = wikittyClient.findAllByQuery(CatalogNode.class, query).peek(); + WikittyQueryResultTreeNode<String> treeNodeResult = + wikittyClient.findAllIdTreeNode(catalogNode.getWikittyId(), 0, true, null); + Assert.assertEquals(8, treeNodeResult.getAttCount()); // one deletion + } + + /** + * Test le nombre d'attachment (fichiers attachés) au noeud des arbres. + * + * @throws IOException + */ + @Test + public void testSearchEngineCountAttachmentMultipleSameNode() throws IOException { + importBooks(); + + // delete Lanfeust book, attached to tree + WikittyQuery query = new WikittyQueryMaker().and() + .exteq(CatalogNode.EXT_CATALOGNODE) + .eq(WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_NAME, "Action").end(); + CatalogNode actionNode = wikittyClient.findAllByQuery(CatalogNode.class, query).peek(); + + query = new WikittyQueryMaker().and() + .exteq(CatalogNode.EXT_CATALOGNODE) + .eq(WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_NAME, "Everything else").end(); + CatalogNode eeNode = wikittyClient.findAllByQuery(CatalogNode.class, query).peek(); + + // 4 attachement en plus, mais sur seulement 2 livres + actionNode.addAttachment("db9dc782-e650-4fd4-83ac-3c1c5c136cde"); + actionNode.addAttachment("584adc1e-726d-4348-9a57-77153d245b34"); + eeNode.addAttachment("db9dc782-e650-4fd4-83ac-3c1c5c136cde"); + eeNode.addAttachment("584adc1e-726d-4348-9a57-77153d245b34"); + + + query = new WikittyQueryMaker().and() + .exteq(CatalogNode.EXT_CATALOGNODE) + .eq(WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_NAME, "Catalog").end(); + CatalogNode catalogNode = wikittyClient.findAllByQuery(CatalogNode.class, query).peek(); + WikittyQueryResultTreeNode<String> treeNodeResult = + wikittyClient.findAllIdTreeNode(catalogNode.getWikittyId(), 0, true, null); + Assert.assertEquals(11, treeNodeResult.getAttCount()); // 9 + 2 nouveaux + } + + /** + * Test le nombre d'attachment (fichiers attachés) au noeud des arbres. + * + * @throws IOException + */ + @Test + public void testSearchEngineCountAttachmentNodeMove() throws IOException { + + // delete Lanfeust book, attached to tree + WikittyQuery query = new WikittyQueryMaker().and() + .exteq(CatalogNode.EXT_CATALOGNODE) + .eq(WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_NAME, "Action").end(); + CatalogNode actionNode = wikittyClient.findAllByQuery(CatalogNode.class, query).peek(); + + query = new WikittyQueryMaker().and() + .exteq(CatalogNode.EXT_CATALOGNODE) + .eq(WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_NAME, "Everything else").end(); + CatalogNode eeNode = wikittyClient.findAllByQuery(CatalogNode.class, query).peek(); + + // move action node + actionNode.setParent(eeNode.getWikittyId()); + wikittyClient.store(actionNode); + + query = new WikittyQueryMaker().and() + .exteq(CatalogNode.EXT_CATALOGNODE) + .eq(WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_NAME, "Media").end(); + CatalogNode mediaNode = wikittyClient.findAllByQuery(CatalogNode.class, query).peek(); + WikittyQueryResultTreeNode<String> treeNodeResult = + wikittyClient.findAllIdTreeNode(mediaNode.getWikittyId(), 0, true, null); + Assert.assertEquals(7, treeNodeResult.getAttCount()); // 9 before move + + treeNodeResult = wikittyClient.findAllIdTreeNode(eeNode.getWikittyId(), 0, true, null); + Assert.assertEquals(2, treeNodeResult.getAttCount()); // 0 before move + } } Deleted: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/AbstractTestConformance.java =================================================================== --- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/AbstractTestConformance.java 2012-01-30 10:55:42 UTC (rev 1388) +++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/AbstractTestConformance.java 2012-01-30 11:23:24 UTC (rev 1389) @@ -1,204 +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 java.text.ParseException; -import java.util.ArrayList; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.Map.Entry; - -import junit.framework.Assert; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.ApplicationConfig; -import org.nuiton.wikitty.WikittyProxy; -import org.nuiton.wikitty.entities.FieldType; -import org.nuiton.wikitty.entities.WikittyTypes; -import org.nuiton.wikitty.entities.Wikitty; -import org.nuiton.wikitty.entities.WikittyExtension; -import org.nuiton.wikitty.entities.WikittyImpl; -import org.nuiton.wikitty.WikittyService; -import org.nuiton.wikitty.WikittyServiceFactory; -import org.nuiton.wikitty.WikittyUtil; - -public abstract class AbstractTestConformance { - - public static final String EXTNAME = "wikittyExt"; - public static final String EXTREQUIRED = "wikittyRequired"; - public static final String EXTREQUIRES = "wikittyRequires"; - - private final static Log log = LogFactory.getLog(AbstractTestConformance.class); - - public static final WikittyExtension EXT_REQUIRED = - createExtension(EXTREQUIRED, null); - - public static final WikittyExtension EXT_REQUIRES = - createExtension(EXTREQUIRES, EXTREQUIRED); - - public static final WikittyExtension EXT_TEST = - createExtension(EXTNAME, null, - createType(WikittyTypes.STRING, 0, 1), - createType(WikittyTypes.NUMERIC, 1, 1), - createType(WikittyTypes.DATE, 1, 1) - ); - - private WikittyService ws; - protected WikittyProxy proxy = null; - - abstract public ApplicationConfig getConfig(); - - public WikittyProxy getProxy() { - if (proxy == null) { - proxy = new WikittyProxy(getWikittyService()); - } - return proxy; - } - - public WikittyService getWikittyService() { - if (ws == null) { - ws = WikittyServiceFactory.buildWikittyService(getConfig()); - } - return ws; - } - - public void setWikittyService(WikittyService wikittyService) { - this.ws = wikittyService; - } - - - protected static FieldType createType( WikittyTypes type, int lower, int upper ) { - FieldType fieldType = new FieldType(type, lower, upper); - return fieldType; - } - - protected static Wikitty createBasicWikitty() { - return createWikitty( EXT_TEST ); - } - - protected static Wikitty createWikitty( WikittyExtension... extensions ) { - Wikitty w = new WikittyImpl(); - for ( WikittyExtension ext : extensions ) { - w.addExtension( ext ); - } - return w; - } - - protected static WikittyExtension createExtension(String extName, String requires, - FieldType... types) { - LinkedHashMap<String, FieldType> fieldsMap = new LinkedHashMap<String, FieldType>(); - for ( int i = 0; i < types.length; i++ ) { - fieldsMap.put( "fieldName" + i, types[i] ); - } - return new WikittyExtension(extName, "1", null, requires, fieldsMap); - } - - public static String format(String dateTestFormat) { - try { - return WikittyUtil.formatDate( - dateTestFormat == null || dateTestFormat.isEmpty() - ? new Date() - : parse(dateTestFormat) - ); - } catch (ParseException e) { - Assert.fail( "Error format date : " + dateTestFormat ); - e.printStackTrace(); - return null; - } - } - - public static Date parse(String dateAsString) { - try { - return WikittyUtil.parseDate(dateAsString); - } catch (ParseException e) { - Assert.fail( "Error parsing date : " + dateAsString ); - e.printStackTrace(); - return null; - } - } - - protected static ArrayList<Wikitty> createSampleWikitty( WikittyService ws ) { - ArrayList<Wikitty> result = new ArrayList<Wikitty>(); - String[] wValues = new String[] { - // wikitty[ 0 ] - "fieldName0 = table," + - "fieldName1 = 003300," + - "fieldName2 = " + format("23/01/1982"), - - // wikitty[ 1 ] - "fieldName0 = chaise," + - "fieldName1 = 113311," + - "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 ); - result.add( w ); - } - ws.store(null, result, false); - return result; - } - - - - public static Wikitty createWikitty( String values, String defaultExtName, WikittyExtension... exts ) { - Wikitty w = new WikittyImpl(); - for (WikittyExtension ext : exts) { - w.addExtension(ext); - } - for( Entry<String, String> keyValuePair : getKeyPairs(values) ) { - String[] s = keyValuePair.getKey().split("\\."); - String fieldName = null, extName = null; - if ( s.length > 1 ) { - fieldName = s[1].trim(); - extName = s[0].trim(); - } - else { - fieldName = s[0].trim(); - extName = defaultExtName; - } - w.setField(extName, fieldName, keyValuePair.getValue()); - } - return w; - } - - protected static Iterable<Entry<String, String>> getKeyPairs(String values) { - LinkedHashMap<String, String> keyPairs = new LinkedHashMap<String, String>(); - for ( String keyValuePair : values.split(",") ) { - String[] l = keyValuePair.split("="); - String key = l[0].trim(); - String value = l.length > 1 ? l[1].trim() : null; - keyPairs.put(key, value); - } - return keyPairs.entrySet(); - } - - -} Deleted: trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/AbstractTestSolr.java =================================================================== --- trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/AbstractTestSolr.java 2012-01-30 10:55:42 UTC (rev 1388) +++ trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/AbstractTestSolr.java 2012-01-30 11:23:24 UTC (rev 1389) @@ -1,53 +0,0 @@ -/* - * #%L - * Wikitty :: wikitty-solr-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.storage.solr; - -import org.junit.Before; -import org.nuiton.util.ApplicationConfig; -import org.nuiton.wikitty.WikittyConfig; -import org.nuiton.wikitty.WikittyProxy; -import org.nuiton.wikitty.services.WikittyServiceEnhanced; - -public abstract class AbstractTestSolr { - - protected WikittyProxy proxy = null; - - protected static ApplicationConfig instance = WikittyConfig.getConfig("wikitty-config-sample-inmemory.properties"); - - protected static WikittyServiceEnhanced ws; - - public WikittyProxy getProxy() { - if (proxy == null) { - proxy = new WikittyProxy(ws); - } - return proxy; - } - - @Before - public void deleteAll() throws Exception { - ws.clear(null); - } - -} Deleted: trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrTestHelper.java =================================================================== --- trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrTestHelper.java 2012-01-30 10:55:42 UTC (rev 1388) +++ trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrTestHelper.java 2012-01-30 11:23:24 UTC (rev 1389) @@ -1,63 +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 java.io.File; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.ApplicationConfig; -import org.nuiton.wikitty.WikittyConfigOption; - -/** - * User: couteau - * Date: 12/04/11 - */ -public class SolrTestHelper { - - static private Log log = LogFactory.getLog(SolrTestHelper.class); - - public static void initTests(ApplicationConfig config) { - // Create tmpdir if not exist - String tmpdir = System.getProperty("java.io.tmpdir"); - File file = new File(tmpdir); - if (!file.exists()) { - file.mkdirs(); - } - - // file where to put wikitty datas - File dataDirectory = new File(tmpdir, "wikitty-data-store"); - if (log.isInfoEnabled()) { - log.info("Will use data directory : " + dataDirectory); - } - - // set data dir configuration - config.setOption(WikittyConfigOption.WIKITTY_DATA_DIR.key, - dataDirectory.getAbsolutePath()); - } - - public static void closeTests(WikittyServiceSolr service) { - service.close(); - } -} Deleted: 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-30 10:55:42 UTC (rev 1388) +++ trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/TreeTest.java 2012-01-30 11:23:24 UTC (rev 1389) @@ -1,580 +0,0 @@ -/* - * #%L - * Wikitty :: wikitty-solr-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.storage.solr; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.nuiton.wikitty.conform.AbstractTestConformance; -import org.nuiton.wikitty.entities.ExtensionFactory; -import org.nuiton.wikitty.entities.Wikitty; -import org.nuiton.wikitty.entities.WikittyExtension; -import org.nuiton.wikitty.entities.WikittyImpl; -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; - -/** - * - * @author ruchaud, martel - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ -public class TreeTest extends AbstractTestSolr { - - static private Log log = LogFactory.getLog(TreeTest.class); - - protected WikittyExtension extension; - - @Before - public void onSetUp() throws Exception { - createBasicWikitty(); - createTestData(); - } - - @BeforeClass - public static void initTests() throws Exception { - - SolrTestHelper.initTests(instance); - - ws = new WikittyServiceEnhanced(new WikittyServiceSolr(instance)); - } - - /** - * Create a extension, use to store element in tree - */ - private void createBasicWikitty() { - extension = ExtensionFactory.create("test", "1") - .addField("name", WikittyTypes.STRING) - .extension(); - ws.storeExtension(null, Arrays.asList(extension)); - } - - /** - * Init data with a basic tree - */ - private void createTestData() { - // Create tree as following : - // root - // |_ node 1 - // | |_ node 11 (2) - // | | |_ node 111 (1) - // | |_ node 12 - // | | |_ node 121 (2) - // | |_ node 13 - // |_ node 2 (1) - - createBranch("root/node1/node11/node111"); - createBranch("root/node1/node12/node121"); - createBranch("root/node1/node13"); - createBranch("root/node2"); - - addNode("node11", "value 1"); - addNode("node11", "value 2"); - - addNode("node111", "value 3"); - - addNode("node121", "value 4"); - addNode("node121", "value 5"); - - addNode("node2", "value 6"); - } - - /** - * Create all node contains in path - */ - protected void createBranch(String path) { - String parent = null; - String[] names = path.split("/"); - for (String name : names) { - - Wikitty found = findNode(name); - if(found == null) { - found = createNode(name, parent); - log.debug("[Storing] " + name + " with id " + found.getId()); - ws.store(null, found); - assertNotNull(findNode(name)); - } - parent = found.getId(); - } - } - - /** - * Attach value in node - */ - protected void addNode(String nodeName, String value) { - Wikitty leaf = new WikittyImpl(); - leaf.addExtension(extension); - leaf.setField("test", "name", value); - - log.debug("[Storing] " + value + " with id " + leaf.getId()); - ws.store(null, leaf); - - Wikitty node = findNode(nodeName); - assertNotNull(node); - WikittyTreeNodeHelper.addAttachment(node, leaf.getId()); - ws.store(null, node); - } - - /** - * Find node by name - */ - protected Wikitty findNode(String nodeName) { - Criteria criteria = Search.query().eq( - WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_NAME, nodeName).criteria(); - Wikitty wikitty = getProxy().findByCriteria(criteria); - return wikitty; - } - - /** - * Find value by name - */ - protected Wikitty findValue(String value) { - Criteria criteria = Search.query().eq("test.name", value).criteria(); - Wikitty wikitty = getProxy().findByCriteria(criteria); - return wikitty; - } - - static private class CollectAttachmentVisitor implements TreeNodeResult.Visitor<WikittyTreeNode> { - - protected Set attachment = new HashSet(); - - public Set getAttachment() { - return attachment; - } - - @Override - public boolean visitEnter(TreeNodeResult<WikittyTreeNode> node) { - Collection att = node.getObject().getAttachment(); - if (att != null) { - attachment.addAll(att); - } - return true; - } - - @Override - public boolean visitLeave(TreeNodeResult<WikittyTreeNode> node) { - return true; - } - } - - /** - * Count all element in sub tree, with element in node - */ - protected int sum(Wikitty node) { - // Sum attachment object in node - String nodeId = node.getId(); - TreeNodeResult<WikittyTreeNode> tree = getProxy().findTreeNode( - WikittyTreeNode.class, nodeId, -1, true, null); - CollectAttachmentVisitor visitor = new CollectAttachmentVisitor(); - tree.acceptVisitor(visitor); - - int result=visitor.getAttachment().size(); - return result; - } -// int sum = 0; -// -// // Sum value in node -// Set<String> values = WikittyTreeNodeHelper.getAttachment(node); -// if(values != null) { -// sum = values.size(); -// } -// -// // Sum children node in node -// String nodeId = node.getId(); -// TreeNodeResult<WikittyTreeNode> children = getProxy().findTreeNode( -// nodeId, 1, true, null); -// -// /* -// for (Integer count : children.values()) { -// sum += count; -// } -// */ -// -// for (TreeNodeResult<WikittyTreeNode> e : children.getChildren()) { -// log.debug("*treeNode = " + e.getObject().getName() + " " -// + e.getAttCount() + " -> " + e.getObject().getAttachment()); -// } -// -// for (TreeNodeResult<WikittyTreeNode> treeNodeResult : children) { -// WikittyTreeNode treeNode = treeNodeResult.getObject(); -// Set<String> treeNodeChildren = treeNode.getAttachment(); -// log.debug("+treeNode = " + treeNode.getName() + " " + -// (treeNodeChildren==null?0:treeNodeChildren.size()) + -// " -> " + treeNodeChildren); -//// if (treeNodeChildren == null) { -//// sum += 0; -//// } else { -//// sum += treeNodeChildren.size(); -//// } -// sum += sum(((WikittyTreeNodeImpl)treeNode).getWikitty()); -// } -// -// return sum; -// } - - /** - * Create a Wikitty WikittyTreeNode - * - * @param name - * name of the node - * @param parentId - * id of the parent - * @return - * the wikitty object corresponding to the WikittyTreeNode - */ - protected Wikitty createNode(String name, String parentId) { - // on force l'id pour simplifier le debuggage - WikittyImpl w = new WikittyImpl("id" + name); - WikittyTreeNodeImpl node = new WikittyTreeNodeImpl(w); - node.setName(name); - node.setParent(parentId); - Wikitty nodeWikitty = node.getWikitty(); - return nodeWikitty; - } - - @Test - public void testRestoreTree() throws Exception { - Wikitty root = findNode("root"); - String rootId = root.getId(); - - TreeNodeResult<WikittyTreeNode> tree = - getProxy().findTreeNode(WikittyTreeNode.class, rootId, -1, false, null); - assertNotNull(tree); - } - - @Test - public void testHierarchicalFacet() throws Exception { - Wikitty root = findNode("root"); - int sum = sum(root); - assertEquals(6, sum); - - Wikitty node1 = findNode("node1"); - sum = sum(node1); - assertEquals(5, sum); - - Wikitty node11 = findNode("node11"); - sum = sum(node11); - assertEquals(3, sum); - } - - @Test - public void testRestoreChildren() throws Exception { - Wikitty node1 = findNode("node1"); - String node1Id = node1.getId(); - - TreeNodeResult<WikittyTreeNode> children = getProxy().findTreeNode( - WikittyTreeNode.class, node1Id, 1, false, null); - assertEquals(3, children.getChildCount()); - } - - @Test - public void testFilterRestoreChildren() { - Map<String, Integer> result = new HashMap<String, Integer>(); - result.put("node11", 1); - result.put("node13", 0); - result.put("node12", 0); - - Wikitty node1 = findNode("node1"); - String node1Id = node1.getId(); - - Criteria filter = Search.query().eq("test.name", "value 3").criteria(); - TreeNodeResult<WikittyTreeNode> children = getProxy().findTreeNode( - WikittyTreeNode.class, node1Id, 1, true, filter); - System.out.println(children); - assertEquals(3, children.getChildCount()); - for (TreeNodeResult<WikittyTreeNode> e : children.getChildren()) { - assertEquals(result.get(e.getObject().getName()), Integer.valueOf(e.getAttCount())); - } - } - - @Test - public void testRestoreNode() throws Exception { - Wikitty node11 = findNode("node11"); - String node11Id = node11.getId(); - - TreeNodeResult<WikittyTreeNode> count = getProxy().findTreeNode( - WikittyTreeNode.class, node11Id, 0, true, null); - assertEquals(3, count.getAttCount()); - } - - @Test - public void testFilterRestoreNode() throws Exception { - Wikitty node11 = findNode("node11"); - String node11Id = node11.getId(); - - Criteria filter = Search.query().eq("test.name", "value 3").criteria(); - TreeNodeResult<WikittyTreeNode> count = getProxy().findTreeNode( - WikittyTreeNode.class, node11Id, 0, true, filter); - System.out.println(count); - assertEquals(1, count.getAttCount()); - } - - @Test - public void testNewNode() throws Exception { - // Check that node 2 it has any child - Wikitty node2 = findNode("node2"); - String node2Id = node2.getId(); - TreeNodeResult<WikittyTreeNode> children = getProxy().findTreeNode( - WikittyTreeNode.class, node2Id, 1, true, null); - assertEquals(0, children.getChildCount()); - - // Create a new node, child of node 2 - Wikitty nodeWikitty = createNode("node21", node2Id); - ws.store(null, nodeWikitty); - - // Retrieve it to check - Wikitty found = findNode("node21"); - assertNotNull(found); - - // Check that it was great added as node2 child - children = getProxy().findTreeNode( - WikittyTreeNode.class, node2Id, 1, false, null); - assertEquals(1, children.getChildCount()); - } - - @Test - public void testAddValueInNode() throws Exception { - // Get the initial number of values for Root node - Wikitty root = findNode("root"); - int childInit = sum(root); - - // Create a leaf - Wikitty leaf = AbstractTestConformance.createWikitty("name=totoTheLeaf", "test", extension); - ws.store(null, leaf); - - // Add it in the node2 (now: two values in it) - Wikitty node = findNode("node2"); - assertNotNull(node); - WikittyTreeNodeHelper.addAttachment(node, leaf.getId()); - ws.store(null, node); - - // now, there is one more value for the root node - int newSum = sum(root); - assertEquals(childInit + 1, newSum); - } - - @Test - public void testDeleteNode() throws Exception { - // Get the initial number of values for Root node - Wikitty root = findNode("root"); - int rootChildInit = sum(root); - - // Remove the node 121 - Wikitty node121 = findNode("node121"); - int node121Init = sum(node121); - String node121Id = node121.getId(); - ws.delete(null, node121Id); - - // node12 must have any child - Wikitty node12 = findNode("node12"); - int sum = sum(node12); - assertEquals(0, sum); - - // check that root node has weel one less children value - int newRootChidlren = sum(root); - assertEquals(rootChildInit - node121Init, newRootChidlren); - - // Remove the node 1 and node 11 simultaneously - Wikitty node1 = findNode("node1"); - int node1Init = sum(node1); - String node1Id = node1.getId(); - - Wikitty node11 = findNode("node11"); - String node11Id = node11.getId(); - ws.delete(null, Arrays.asList(node1Id, node11Id)); - - // check that root node has weel one less children value - newRootChidlren = sum(root); - assertEquals(rootChildInit - node121Init - node1Init, newRootChidlren); - } - - @Test - public void testDeleteChild() throws Exception { - // Get the initial number of values for Root node - Wikitty root = findNode("root"); - int childInit = sum(root); - - // Remove a value on node11 - Wikitty node = findNode("node11"); - - List<String> leafs = new ArrayList<String>(WikittyTreeNodeHelper.getAttachment(node)); - node.removeFromField(WikittyTreeNode.EXT_WIKITTYTREENODE, WikittyTreeNode.FIELD_WIKITTYTREENODE_ATTACHMENT, leafs.get(0)); - - leafs = new ArrayList<String>(WikittyTreeNodeHelper.getAttachment(node)); - log.info("leafs after remove = " + leafs); - - ws.store(null, node); - - node = ws.restore(null, node.getId()); - leafs = new ArrayList<String>(WikittyTreeNodeHelper.getAttachment(node)); - log.info("leafs after restore = " + leafs); - - // now, there is one more value for the root node - int newSum = sum(root); - assertEquals(childInit - 1, newSum); - } - - /** regression test, for unknown reason the child may not be removed in the index */ - @Test - public void testSimpleDeleteChild() throws Exception { - - WikittyTreeNodeImpl parent = new WikittyTreeNodeImpl(); - ws.store(null, parent.getWikitty()); - - WikittyTreeNodeImpl child = new WikittyTreeNodeImpl(); - child.setParent(parent.getWikittyId()); - WikittyEvent event = ws.store(null, child.getWikitty()); - event.update(child.getWikitty()); - - TreeNodeResult<WikittyTreeNode> children = getProxy().findTreeNode( - WikittyTreeNode.class, parent.getWikittyId(), 1, true, null); - - assertEquals(1, children.getChildCount()); - assertEquals(0, children.getChild(child).getAttCount()); - - child.setParent(null); - - ws.store(null, child.getWikitty()); - - children = getProxy().findTreeNode( - WikittyTreeNode.class, parent.getWikittyId(), 1, true, null); - - assertEquals(0, children.getChildCount()); - } - - @Test - public void testDeleteValue() throws Exception { - // Get the initial number of values for Root node - Wikitty root = findNode("root"); - int childInit = sum(root); - - // Remove a value - Wikitty value4 = findValue("value 4"); - String value4Id = value4.getId(); - ws.delete(null, value4Id); - - // now, there is one more value for the root node - int newSum = sum(root); - assertEquals(childInit - 1, newSum); - } - - @Test - public void testMoveNode() throws Exception { - // Get the initial number of values for node 1 - Wikitty node1 = findNode("node1"); - int childSum1 = sum(node1); - - // Get the initial number of values for node 121 - Wikitty node121 = findNode("node121"); - int childSum121 = sum(node121); - - // Get the initial number of values for node 2 - Wikitty node2 = findNode("node2"); - int childSum2 = sum(node2); - - // Move node 1 in mode 2 - WikittyTreeNodeHelper.setParent(node121, node2.getId()); - ws.store(null, node121); - - // now, there is less value node 121 for the node 1 - int newSum1 = sum(node1); - assertEquals(childSum1 - childSum121, newSum1); - - // now, there is more value node 121 for the node 2 - int newSum2 = sum(node2); - assertEquals(childSum2 + childSum121, newSum2); - } - - @Test - public void testValueInMultipleNode() throws Exception { - createBranch("node3/node31"); - createBranch("node3/node32"); - - Wikitty value = AbstractTestConformance.createWikitty("name=value", "test", extension); - ws.store(null, value); - String valueId = value.getId(); - - Wikitty node31 = findNode("node31"); - WikittyTreeNodeHelper.addAttachment(node31, valueId); - ws.store(null, node31); - - Wikitty node32 = findNode("node32"); - WikittyTreeNodeHelper.addAttachment(node32, valueId); - ws.store(null, node32); - - Wikitty node3 = findNode("node3"); - int sum = sum(node3); - assertEquals(1, sum); - - TreeNodeResult<WikittyTreeNode> count = getProxy().findTreeNode( - WikittyTreeNode.class, node3.getId(), 0, true, null); - assertEquals(1, count.getAttCount()); - - sum = sum(node31); - assertEquals(1, sum); - - sum = sum(node32); - assertEquals(1, sum); - } - - // verifier que l'indexation de l'arbre fonctionne bien et la reindexation aussi - @Test - public void testReindexation() throws Exception { -// FIXME poussin 20101222 a faire - // creer deux arbres (3 noeud) - // mettre 3 attachments par noeud (les memes) dans les 2 arbres - - // enlever un attachment par noeud et supprime le noeud intermediaire - // en meme temps et store les arbres - - // verifier que tout est bien reindexe et que le dernier noeud est bien - // devenu un noeud root - } - -}
participants (1)
-
echatellier@users.nuiton.org