You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2013/09/13 15:54:17 UTC

svn commit: r1522930 - /sling/whiteboard/bdelacretaz/it-repository/src/test/java/org/apache/sling/jcr/repository/it/SlingRepositoryITBase.java

Author: bdelacretaz
Date: Fri Sep 13 13:54:16 2013
New Revision: 1522930

URL: http://svn.apache.org/r1522930
Log:
SLING-2788 - test login and multi-value behavior

Modified:
    sling/whiteboard/bdelacretaz/it-repository/src/test/java/org/apache/sling/jcr/repository/it/SlingRepositoryITBase.java

Modified: sling/whiteboard/bdelacretaz/it-repository/src/test/java/org/apache/sling/jcr/repository/it/SlingRepositoryITBase.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/it-repository/src/test/java/org/apache/sling/jcr/repository/it/SlingRepositoryITBase.java?rev=1522930&r1=1522929&r2=1522930&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/it-repository/src/test/java/org/apache/sling/jcr/repository/it/SlingRepositoryITBase.java (original)
+++ sling/whiteboard/bdelacretaz/it-repository/src/test/java/org/apache/sling/jcr/repository/it/SlingRepositoryITBase.java Fri Sep 13 13:54:16 2013
@@ -19,18 +19,24 @@ package org.apache.sling.jcr.repository.
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.util.LinkedList;
+import java.util.List;
 
 import javax.inject.Inject;
 import javax.jcr.Credentials;
+import javax.jcr.Item;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
+import javax.jcr.Property;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
 import javax.jcr.query.Query;
 
 import org.apache.sling.jcr.api.SlingRepository;
-import org.junit.Ignore;
+import org.junit.After;
 import org.junit.Test;
 
 /** Base class for SlingRepository tests, contains tests
@@ -49,6 +55,34 @@ public abstract class SlingRepositoryITB
      *  testing the expected implementation. */ 
     protected abstract void doCheckRepositoryDescriptors();
     
+    private final List<String> toDelete = new LinkedList<String>();
+    
+    private Item deleteAfterTests(Item it) throws RepositoryException {
+        toDelete.add(it.getPath());
+        return it;
+    }
+    
+    @After
+    public void deleteTestItems() throws RepositoryException {
+        if(toDelete.isEmpty()) {
+            return;
+            
+        }
+        
+        final Session s = repository.loginAdministrative(null);
+        try {
+            for(String path : toDelete) {
+                if(s.itemExists(path)) {
+                    s.getItem(path).remove();
+                }
+            }
+            s.save();
+            toDelete.clear();
+        } finally {
+            s.logout();
+        }
+    }
+    
     @Test
     public void testRepositoryPresent() {
         assertNotNull(repository);
@@ -73,6 +107,20 @@ public abstract class SlingRepositoryITB
         repository.login(creds);
     }
     
+    @Test
+    public void testAnonymousLoginA() throws RepositoryException {
+        final Session s = repository.login();
+        assertNotNull(s);
+        s.logout();
+    }
+
+    @Test
+    public void testAnonymousLoginB() throws RepositoryException {
+        final Session s = repository.login(null, null);
+        assertNotNull(s);
+        s.logout();
+    }
+    
     private void assertCreateRetrieveNode(String nodeType) throws RepositoryException {
         Session s = repository.loginAdministrative(null);
         try {
@@ -135,4 +183,38 @@ public abstract class SlingRepositoryITB
     public final void checkRepositoryDescriptors() {
         doCheckRepositoryDescriptors();
     }
+    
+    @Test
+    public void testSingleValueInputStream() throws RepositoryException {
+        Session s = repository.loginAdministrative(null);
+        try {
+            final String path = getClass().getSimpleName() + System.currentTimeMillis();
+            final Node child = (Node)deleteAfterTests(s.getRootNode().addNode(path));
+            final Property p = child.setProperty("foo", "bar");
+            s.save();
+            assertNotNull(p.getBinary().getStream());
+        } finally {
+            s.logout();
+        }
+       
+    }
+    
+    @Test
+    public void testMultiValueInputStream() throws RepositoryException {
+        Session s = repository.loginAdministrative(null);
+        try {
+            final String path = getClass().getSimpleName() + System.currentTimeMillis();
+            final Node child = (Node)deleteAfterTests(s.getRootNode().addNode(path));
+            final Property p = child.setProperty("foo", new String[] { "bar", "wii " });
+            s.save();
+            try { 
+                p.getBinary().getStream();
+                fail("Expecting getStream() to fail on a multi-value Property");
+            } catch(RepositoryException asExpected) {
+            }
+        } finally {
+            s.logout();
+        }
+       
+    }
 }
\ No newline at end of file