Author: fmui
Date: Wed May 14 10:51:46 2014
New Revision: 1594541
URL: http://svn.apache.org/r1594541
Log:
improved ContentStreamHashImpl and fixed tests
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ContentStreamHashImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/misc/ContentStreamHashTest.java
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ContentStreamHashImpl.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ContentStreamHashImpl.java?rev=1594541&r1=1594540&r2=1594541&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ContentStreamHashImpl.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ContentStreamHashImpl.java
Wed May 14 10:51:46 2014
@@ -90,6 +90,28 @@ public class ContentStreamHashImpl imple
this.propertyValue = "{" + algorithm + "}" + hash;
}
+ /**
+ * Constructs an object from the algorithm and hash.
+ *
+ * @param algorithm
+ * the algorithm
+ * @param hashBytes
+ * the hash value as byte array
+ */
+ public ContentStreamHashImpl(String algorithm, byte[] hashBytes) {
+ if (algorithm == null || algorithm.trim().length() == 0) {
+ throw new IllegalArgumentException("Algorithm must be set!");
+ }
+
+ if (hashBytes == null || hashBytes.length == 0) {
+ throw new IllegalArgumentException("Hash must be set!");
+ }
+
+ this.algorithm = algorithm.toLowerCase(Locale.ENGLISH);
+ this.hash = byteArrayToHexString(hashBytes);
+ this.propertyValue = "{" + algorithm + "}" + hash;
+ }
+
public String getPropertyValue() {
return propertyValue;
}
@@ -139,7 +161,7 @@ public class ContentStreamHashImpl imple
List<ContentStreamHash> result = new ArrayList<ContentStreamHash>();
for (int i = 0; i < md.length; i++) {
- result.add(new ContentStreamHashImpl(algorithm[i],
byteArrayToHexString(md[i].digest())));
+ result.add(new ContentStreamHashImpl(algorithm[i],
md[i].digest()));
}
return result;
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/misc/ContentStreamHashTest.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/misc/ContentStreamHashTest.java?rev=1594541&r1=1594540&r2=1594541&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/misc/ContentStreamHashTest.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/misc/ContentStreamHashTest.java
Wed May 14 10:51:46 2014
@@ -40,20 +40,25 @@ public class ContentStreamHashTest {
assertEquals("0123456789abcdef", hash1.getHash());
assertEquals(hash1.getPropertyValue(), hash2.getPropertyValue());
- assertEquals(hash2.getAlgorithm(), hash2.getAlgorithm());
- assertEquals(hash2.getHash(), hash2.getHash());
+ assertEquals(hash1.getAlgorithm(), hash2.getAlgorithm());
+ assertEquals(hash1.getHash(), hash2.getHash());
}
@Test
public void testHashCorrected() throws Exception {
ContentStreamHashImpl hash1 = new ContentStreamHashImpl("{alg} 01 23
45 67 89 AB CD EF ");
ContentStreamHashImpl hash2 = new ContentStreamHashImpl("ALG", "0123
4567 89ab cdef");
+ ContentStreamHashImpl hash3 = new ContentStreamHashImpl("aLg", new
byte[] { (byte) 0x01, (byte) 0x23,
+ (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xab, (byte)
0xcd, (byte) 0xef });
assertEquals("alg", hash1.getAlgorithm());
assertEquals("0123456789abcdef", hash1.getHash());
- assertEquals(hash2.getAlgorithm(), hash2.getAlgorithm());
- assertEquals(hash2.getHash(), hash2.getHash());
+ assertEquals(hash1.getAlgorithm(), hash2.getAlgorithm());
+ assertEquals(hash1.getHash(), hash2.getHash());
+
+ assertEquals(hash1.getAlgorithm(), hash3.getAlgorithm());
+ assertEquals(hash1.getHash(), hash3.getHash());
}
@Test