[exo-jcr-commits] exo-jcr SVN: r5423 - in jcr/branches/1.15.x/exo.jcr.component.core/src/test: java/org/exoplatform/services/jcr/api/reading and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Jan 5 04:57:46 EST 2012


Author: andrew.plotnikov
Date: 2012-01-05 04:57:44 -0500 (Thu, 05 Jan 2012)
New Revision: 5423

Modified:
   jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportDocView.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportSysView.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/reading/TestSession.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/test/resources/conf/test/nodetypes-usecase.xml
Log:
EXOJCR-1703: Writed test to class SessionImpl

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportDocView.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportDocView.java	2012-01-04 14:22:16 UTC (rev 5422)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportDocView.java	2012-01-05 09:57:44 UTC (rev 5423)
@@ -36,6 +36,7 @@
 import java.util.Calendar;
 import java.util.StringTokenizer;
 
+import javax.jcr.InvalidSerializedDataException;
 import javax.jcr.ItemExistsException;
 import javax.jcr.Node;
 import javax.jcr.PathNotFoundException;
@@ -410,4 +411,32 @@
       assertFalse(exportContent.contains("newjcr"));
       newSession.logout();
    }
+
+   public void testExportDocumentViewWhenPathNotFound() throws IOException, InvalidSerializedDataException,
+      SAXException, RepositoryException
+   {
+      try
+      {
+         session.exportDocumentView("/TestChildNode", new MockContentHandler(), false, false);
+         fail();
+      }
+      catch (PathNotFoundException e)
+      {
+      }
+
+
+      ByteArrayOutputStream out = new ByteArrayOutputStream();
+      try
+      {
+         session.exportDocumentView("/TestChildNode", out, false, false);
+         fail();
+      }
+      catch (PathNotFoundException e)
+      {
+      }
+      finally
+      {
+         out.close();
+      }
+   }
 }

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportSysView.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportSysView.java	2012-01-04 14:22:16 UTC (rev 5422)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportSysView.java	2012-01-05 09:57:44 UTC (rev 5423)
@@ -413,4 +413,31 @@
       assertEquals(1, mock.nodes);
       assertEquals(2, mock.properties);
    }
+
+   public void testExportSystemViewWhenPathNotFound() throws IOException, SAXException, RepositoryException
+   {
+      try
+      {
+         session.exportSystemView("/testNode", new MockContentHandler(), false, true);
+         fail();
+      }
+      catch (PathNotFoundException e)
+      {
+      }
+
+      ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+      try
+      {
+         session.exportSystemView("/testNode", out, false, false);
+         fail();
+      }
+      catch (PathNotFoundException e)
+      {
+      }
+      finally
+      {
+         out.close();
+      }
+   }
 }

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/reading/TestSession.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/reading/TestSession.java	2012-01-04 14:22:16 UTC (rev 5422)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/reading/TestSession.java	2012-01-05 09:57:44 UTC (rev 5423)
@@ -20,17 +20,27 @@
 
 import org.exoplatform.services.jcr.JcrAPIBaseTest;
 import org.exoplatform.services.jcr.core.CredentialsImpl;
-import org.exoplatform.services.jcr.impl.core.SessionImpl;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
 import java.util.Calendar;
 
+import javax.jcr.ItemExistsException;
+import javax.jcr.ItemNotFoundException;
 import javax.jcr.LoginException;
+import javax.jcr.NamespaceException;
 import javax.jcr.Node;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.Property;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.version.VersionException;
 
 /**
  * Created by The eXo Platform SAS.
@@ -161,4 +171,136 @@
 
    }
 
-}
+   public void testGetAllNamespacePrefixes() throws RepositoryException
+   {
+      assertTrue(Arrays.asList(session.getWorkspace().getNamespaceRegistry().getPrefixes()).containsAll(
+         Arrays.asList(session.getAllNamespacePrefixes())));
+   }
+
+   public void testGetImportContentHandlerCheckLockException() throws ItemExistsException, PathNotFoundException,
+      VersionException, ConstraintViolationException, LockException, RepositoryException
+   {
+      Node testNode = root.addNode("test");
+      testNode.addMixin("mix:lockable");
+      session.save();
+
+      testNode.lock(true, true);
+
+      Session session2 =
+         repository.login(new CredentialsImpl("admin", "admin".toCharArray()), session.getWorkspace().getName());
+      
+      try
+      {
+         session2.getImportContentHandler("/test", 0);
+         fail();
+      }
+      catch (LockException e)
+      {
+      }
+      finally
+      {
+         session2.logout();
+         testNode.unlock();
+      }
+   }
+
+   public void testGetImportContentHandlerCheckConstraintViolationException() throws ItemExistsException,
+      PathNotFoundException, VersionException, ConstraintViolationException, LockException, RepositoryException
+   {
+      root.addNode("someNode", "exo:myTypeJCR1703");
+
+      try
+      {
+         session.getImportContentHandler("/someNode/exo:myChildNode", 0);
+         fail();
+      }
+      catch (ConstraintViolationException e)
+      {
+      }
+   }
+
+   public void testImportXMLCheckLockException() throws ItemExistsException, PathNotFoundException,
+      NoSuchNodeTypeException, LockException, VersionException, ConstraintViolationException, RepositoryException,
+      IOException
+   {
+      Node testNode = root.addNode("testNode");
+      testNode.setProperty("exo:title", "testNode");
+      testNode.addMixin("mix:versionable");
+
+      Node testNodeImport = root.addNode("testNodeImport");
+      testNodeImport.addMixin("mix:lockable");
+      session.save();
+      
+      testNodeImport.lock(true, true);
+
+      ByteArrayOutputStream bos = new ByteArrayOutputStream();
+      testNode.getSession().exportDocumentView(testNode.getPath(), bos, false, false);
+      ByteArrayInputStream is = new ByteArrayInputStream(bos.toByteArray());
+
+      Session session2 =
+         repository.login(new CredentialsImpl("admin", "admin".toCharArray()), session.getWorkspace().getName());
+
+      try
+      {
+         session2.importXML(testNodeImport.getPath(), is, 1);
+         fail();
+      }
+      catch (LockException e)
+      {
+      }
+      finally
+      {
+         session2.logout();
+         testNodeImport.unlock();
+      }
+   }
+
+   public void testImportXMLCheckConstraintViolationException() throws ItemExistsException, PathNotFoundException,
+      VersionException, ConstraintViolationException, LockException, RepositoryException, IOException
+   {
+      Node testNode = root.addNode("testNode");
+      testNode.setProperty("exo:title", "testNode");
+      testNode.addMixin("mix:versionable");
+
+      root.addNode("someNode", "exo:myTypeJCR1703");
+      session.save();
+
+      ByteArrayOutputStream bos = new ByteArrayOutputStream();
+      testNode.getSession().exportDocumentView(testNode.getPath(), bos, false, false);
+      ByteArrayInputStream is = new ByteArrayInputStream(bos.toByteArray());
+
+      try
+      {
+         session.importXML("/someNode/exo:myChildNode", is, 1);
+         fail();
+      }
+      catch (ConstraintViolationException e)
+      {
+      }
+   }
+
+   public void testGetNodeByIdentifierWhenNodeNotFound() throws ItemExistsException, PathNotFoundException,
+      VersionException, ConstraintViolationException, LockException, RepositoryException
+   {
+      try
+      {
+         session.getNodeByIdentifier("someidentifier");
+         fail();
+      }
+      catch (ItemNotFoundException e)
+      {
+      }
+   }
+
+   public void testSetNamespacePrefix() throws RepositoryException
+   {
+      try
+      {
+         session.setNamespacePrefix("nt", "http://www.jcp.org/jcr/1.0");
+         fail();
+      }
+      catch (NamespaceException e)
+      {
+      }
+   }
+}
\ No newline at end of file

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/test/resources/conf/test/nodetypes-usecase.xml
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/test/resources/conf/test/nodetypes-usecase.xml	2012-01-04 14:22:16 UTC (rev 5422)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/test/resources/conf/test/nodetypes-usecase.xml	2012-01-05 09:57:44 UTC (rev 5423)
@@ -280,4 +280,17 @@
       </childNodeDefinition>
     </childNodeDefinitions>
   </nodeType>
+  
+  <nodeType name="exo:myTypeJCR1703" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
+  	<supertypes>
+      <supertype>nt:base</supertype>
+    </supertypes>
+  	<childNodeDefinitions>
+    	<childNodeDefinition name="exo:myChildNode" defaultPrimaryType="nt:unstructured" autoCreated="true" mandatory="false" onParentVersion="IGNORE" protected="true" sameNameSiblings="false">
+        	<requiredPrimaryTypes>
+               <requiredPrimaryType>nt:base</requiredPrimaryType>
+            </requiredPrimaryTypes>
+        </childNodeDefinition>
+    </childNodeDefinitions>
+  </nodeType>
 </nodeTypes>



More information about the exo-jcr-commits mailing list