Author: nzamosenchuk
Date: 2009-11-27 06:53:44 -0500 (Fri, 27 Nov 2009)
New Revision: 901
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestSearch.java
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/AbstractRestartTest.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestLockCleanup.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestVersionHistory.java
Log:
EXOJCR-199: restart tests added and refactored.
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/AbstractRestartTest.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/AbstractRestartTest.java 2009-11-27
08:21:19 UTC (rev 900)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/AbstractRestartTest.java 2009-11-27
11:53:44 UTC (rev 901)
@@ -33,26 +33,41 @@
*/
public abstract class AbstractRestartTest extends JcrAPIBaseTest
{
- protected boolean firstRun = true;
+ protected static int run = 0;
+ protected static int testCasesCount = 0;
+
private final String runNodeName = "SecondRun";
+ /**
+ * Count of test cases in one test suite. After last test HSSQLDB "SHUTDOWN is
called"
+ */
+ public AbstractRestartTest(int testCasesCount)
+ {
+ super();
+ this.testCasesCount = testCasesCount;
+ }
+
@Override
public void setUp() throws Exception
{
super.setUp();
- try
+ if (run == 0)
{
- root.getNode(runNodeName);
- // node exists, it means than this is second run
- firstRun = false;
+ try
+ {
+ root.getNode(runNodeName);
+ // node exists, it means than this is second run
+ run = 2;
+ }
+ catch (PathNotFoundException e)
+ {
+ root.addNode(runNodeName);
+ run = 1;
+ }
}
- catch (PathNotFoundException e)
- {
- root.addNode(runNodeName);
- }
session.save();
- if (firstRun)
+ if (run < 2)
{
log.info("/!\\ This is FIRST run");
}
@@ -64,7 +79,7 @@
public boolean isFirstRun()
{
- return firstRun;
+ return run < 2;
}
@Override
@@ -72,24 +87,28 @@
{
// super.tearDown in not invoked to prevent DB cleaning
// shutdown HSSQLDB :)
- if (firstRun)
+ testCasesCount--;
+ if (testCasesCount <= 0)
{
- for (Object uri : DatabaseManager.getDatabaseURIs())
+ if (isFirstRun())
{
- try
+ for (Object uri : DatabaseManager.getDatabaseURIs())
{
- Connection c = DriverManager.getConnection("jdbc:hsqldb:" +
uri.toString(), "sa", "");
- c.createStatement().execute("SHUTDOWN");
+ try
+ {
+ Connection c = DriverManager.getConnection("jdbc:hsqldb:" +
uri.toString(), "sa", "");
+ c.createStatement().execute("SHUTDOWN");
+ }
+ catch (Throwable e)
+ {
+ }
}
- catch (Throwable e)
- {
- }
}
+ else
+ {
+ super.tearDown();
+ }
}
- else
- {
- super.tearDown();
- }
}
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestLockCleanup.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestLockCleanup.java 2009-11-27
08:21:19 UTC (rev 900)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestLockCleanup.java 2009-11-27
11:53:44 UTC (rev 901)
@@ -28,6 +28,14 @@
public class TestLockCleanup extends AbstractRestartTest
{
+ /**
+ *
+ */
+ public TestLockCleanup()
+ {
+ super(1);
+ }
+
/*
* This test should be performed manually because it requires JCR tearDown and startup
without
* cleaning it's content.
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestSearch.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestSearch.java
(rev 0)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestSearch.java 2009-11-27
11:53:44 UTC (rev 901)
@@ -0,0 +1,169 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This 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 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.lab.restart;
+
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
+
+import java.io.ByteArrayInputStream;
+import java.util.Calendar;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+
+/**
+ * @author <a href="mailto:nikolazius@gmail.com">Nikolay
Zamosenchuk</a>
+ * @version $Id$
+ *
+ */
+public class TestSearch extends AbstractRestartTest
+{
+ public TestSearch()
+ {
+ super(2);
+ }
+
+ public void testSearch() throws Exception
+ {
+ if (isFirstRun())
+ {
+ Node rootNode = session.getRootNode();
+ Node queryNode = rootNode.addNode("queryNode",
"nt:unstructured");
+ if (!queryNode.canAddMixin("rma:record"))
+ throw new RepositoryException("Cannot add mixin node");
+ else
+ {
+ queryNode.addMixin("rma:record");
+ queryNode.setProperty("rma:recordIdentifier",
"testIdentificator");
+ queryNode.setProperty("rma:originatingOrganization",
"testProperty2");
+ }
+
+ Node node1 = queryNode.addNode("Test1", "nt:file");
+ Node content1 = node1.addNode("jcr:content",
"nt:resource");
+ content1.setProperty("jcr:lastModified", Calendar.getInstance());
+ content1.setProperty("jcr:mimeType", "text/plain");
+ content1.setProperty("jcr:data", new ByteArrayInputStream("ABBA
AAAA".getBytes()));
+ node1.addMixin("rma:record");
+ node1.setProperty("rma:recordIdentifier",
"testIdentificator");
+ node1.setProperty("rma:originatingOrganization",
"testProperty2");
+
+ Node node2 = queryNode.addNode("Test2", "nt:file");
+ Node content2 = node2.addNode("jcr:content",
"nt:resource");
+ content2.setProperty("jcr:lastModified", Calendar.getInstance());
+ content2.setProperty("jcr:mimeType", "text/plain");
+ content2.setProperty("jcr:data", new ByteArrayInputStream("ACDC
EEEE".getBytes()));
+ node2.addMixin("rma:record");
+ node2.setProperty("rma:recordIdentifier",
"testIdentificator");
+ node2.setProperty("rma:originatingOrganization",
"testProperty2");
+
+ session.save();
+ }
+ else
+ {
+ SessionImpl querySession = (SessionImpl)repository.login(credentials,
"ws");
+ String sqlQuery = "SELECT * FROM rma:record WHERE jcr:path LIKE
'/queryNode/%' ";
+ QueryManager manager = querySession.getWorkspace().getQueryManager();
+ Query query = manager.createQuery(sqlQuery, Query.SQL);
+
+ QueryResult queryResult = query.execute();
+ NodeIterator iter = queryResult.getNodes();
+
+ assertTrue(iter.getSize() == 2); // check target nodes for existanse
+ while (iter.hasNext())
+ {
+ assertNotNull(iter.nextNode());
+ }
+
+ sqlQuery = "//*[jcr:contains(., 'ABBA')]";
+ query = manager.createQuery(sqlQuery, Query.XPATH);
+
+ queryResult = query.execute();
+ iter = queryResult.getNodes();
+
+ while (iter.hasNext())
+ {
+ System.out.print(iter.nextNode().getPath());
+ }
+
+ assertEquals("Result nodes count is wrong", 1, iter.getSize());
+ while (iter.hasNext())
+ {
+ assertEquals("Content must be equals", "ABBA AAAA",
iter.nextNode().getProperty("jcr:data").getString());
+ }
+ }
+ }
+
+ public void testSQLQuery() throws Exception
+ {
+ if (isFirstRun())
+ {
+ Node testRoot = root.addNode("testSqlQuery");
+ root.save();
+
+ String prefixPath = testRoot.getPath();
+
+ // files
+ Node subnode = testRoot.addNode("files");
+
+ Node sdata = subnode.addNode("draft");
+ sdata.addNode("content1");
+
+ Node file = subnode.addNode("myFile1", "nt:file");
+ Node cfile = file.addNode("jcr:content",
"nt:unstructured").addNode("myFile1", "nt:file");
+ cfile.addNode("jcr:content", "nt:base");
+
+ file = subnode.addNode("myFile2", "nt:file");
+ cfile = file.addNode("jcr:content",
"nt:unstructured").addNode("myFile1", "nt:file");
+ cfile.addNode("jcr:content", "nt:base");
+
+ // data
+ subnode = testRoot.addNode("data");
+
+ sdata = subnode.addNode("draft");
+ sdata.addNode("content1");
+ sdata.addNode("content2");
+
+ Node data = subnode.addNode("myData1", "nt:file");
+ data.addNode("jcr:content", "nt:unstructured");
+
+ data = subnode.addNode("myData2", "nt:file");
+ data.addNode("jcr:content", "nt:unstructured");
+
+ testRoot.save();
+ }
+ else
+ {
+
+ Query q =
+ session.getWorkspace().getQueryManager().createQuery(
+ "select * from nt:unstructured where jcr:path like
'/testSqlQuery/%/draft/%'", Query.SQL);
+
+ QueryResult res = q.execute();
+ assertEquals("Wrong nodes count in result set", 3,
res.getNodes().getSize());
+
+ for (NodeIterator nodes = res.getNodes(); nodes.hasNext();)
+ {
+ log.info(nodes.nextNode().getPath());
+ }
+ }
+ }
+}
Property changes on:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestSearch.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestVersionHistory.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestVersionHistory.java 2009-11-27
08:21:19 UTC (rev 900)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestVersionHistory.java 2009-11-27
11:53:44 UTC (rev 901)
@@ -46,6 +46,14 @@
* then (without clean!) :
* >mvn test -Dtest=org.exoplatform.services.jcr.lab.restart.TestVersionHistory
*/
+
+ /**
+ *
+ */
+ public TestVersionHistory()
+ {
+ super(1);
+ }
private Node testVersionable = null;