jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r800862 - /jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/RepositoryCopierTest.java
Date Tue, 04 Aug 2009 16:23:42 GMT
Author: jukka
Date: Tue Aug  4 16:23:41 2009
New Revision: 800862

URL: http://svn.apache.org/viewvc?rev=800862&view=rev
Log:
JCR-442: Implement a backup tool

Add test for backing up binary properties.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/RepositoryCopierTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/RepositoryCopierTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/RepositoryCopierTest.java?rev=800862&r1=800861&r2=800862&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/RepositoryCopierTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/RepositoryCopierTest.java
Tue Aug  4 16:23:41 2009
@@ -16,10 +16,14 @@
  */
 package org.apache.jackrabbit.core;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
+import java.io.InputStream;
 import java.math.BigDecimal;
 import java.util.Calendar;
+import java.util.Random;
 
+import javax.jcr.Binary;
 import javax.jcr.Credentials;
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.Node;
@@ -41,13 +45,19 @@
     private static final Credentials CREDENTIALS =
         new SimpleCredentials("admin", "admin".toCharArray());
 
-    private final File BASE = new File("target", "RepositoryCopierTest");
+    private static final File BASE = new File("target", "RepositoryCopierTest");
 
-    private final File SOURCE = new File(BASE, "source");
+    private static final File SOURCE = new File(BASE, "source");
 
-    private final File TARGET = new File(BASE, "target");
+    private static final File TARGET = new File(BASE, "target");
 
-    private final Calendar DATE = Calendar.getInstance();
+    private static final Calendar DATE = Calendar.getInstance();
+
+    private static final byte[] BINARY = new byte[64 * 1024];
+
+    static {
+        new Random().nextBytes(BINARY);
+    }
 
     private String identifier;
 
@@ -93,6 +103,13 @@
 
                 Node properties = root.addNode("properties", "test:unstructured");
                 properties.setProperty("boolean", true);
+                Binary binary = session.getValueFactory().createBinary(
+                        new ByteArrayInputStream(BINARY));
+                try {
+                    properties.setProperty("binary", binary);
+                } finally {
+                    binary.dispose();
+                }
                 properties.setProperty("date", DATE);
                 properties.setProperty("decimal", new BigDecimal(123));
                 properties.setProperty("double", Math.PI);
@@ -101,6 +118,21 @@
                 properties.setProperty("string", "test");
                 properties.setProperty("multiple", "a,b,c".split(","));
                 session.save();
+
+                binary = properties.getProperty("binary").getBinary();
+                try {
+                    InputStream stream = binary.getStream();
+                    try {
+                        for (int i = 0; i < BINARY.length; i++) {
+                            assertEquals(BINARY[i], (byte) stream.read());
+                        }
+                        assertEquals(-1, stream.read());
+                    } finally {
+                        stream.close();
+                    }
+                } finally {
+                    binary.dispose();
+                }
             } finally {
                 session.logout();
             }
@@ -134,6 +166,23 @@
                 assertEquals(
                         true, properties.getProperty("boolean").getBoolean());
                 assertEquals(
+                        PropertyType.BINARY,
+                        properties.getProperty("binary").getType());
+                Binary binary = properties.getProperty("binary").getBinary();
+                try {
+                    InputStream stream = binary.getStream();
+                    try {
+                        for (int i = 0; i < BINARY.length; i++) {
+                            assertEquals(BINARY[i], (byte) stream.read());
+                        }
+                        assertEquals(-1, stream.read());
+                    } finally {
+                        stream.close();
+                    }
+                } finally {
+                    binary.dispose();
+                }
+                assertEquals(
                         PropertyType.DATE,
                         properties.getProperty("date").getType());
                 assertEquals(



Mime
View raw message