jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r1865971 - in /jackrabbit/commons/filevault/trunk/vault-core/src: main/java/org/apache/jackrabbit/vault/util/ test/java/org/apache/jackrabbit/vault/util/
Date Tue, 27 Aug 2019 06:26:36 GMT
Author: kwin
Date: Tue Aug 27 06:26:36 2019
New Revision: 1865971

URL: http://svn.apache.org/viewvc?rev=1865971&view=rev
Log:
JCRVLT-356 add equals and toString to DocViewNode and DocViewProperty

Migrate Unit tests to JUnit4

Added:
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewNodeTest.java
Modified:
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewNode.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewNode.java?rev=1865971&r1=1865970&r2=1865971&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewNode.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewNode.java
Tue Aug 27 06:26:36 2019
@@ -16,11 +16,11 @@
  ************************************************************************/
 package org.apache.jackrabbit.vault.util;
 
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
 import javax.jcr.NamespaceException;
-import javax.jcr.Value;
 
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
@@ -93,4 +93,62 @@ public class DocViewNode {
         return prop == null ? null : prop.values[0];
     }
 
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((label == null) ? 0 : label.hashCode());
+        result = prime * result + Arrays.hashCode(mixins);
+        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        result = prime * result + ((primary == null) ? 0 : primary.hashCode());
+        result = prime * result + ((props == null) ? 0 : props.hashCode());
+        result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        DocViewNode other = (DocViewNode) obj;
+        if (label == null) {
+            if (other.label != null)
+                return false;
+        } else if (!label.equals(other.label))
+            return false;
+        if (!Arrays.equals(mixins, other.mixins))
+            return false;
+        if (name == null) {
+            if (other.name != null)
+                return false;
+        } else if (!name.equals(other.name))
+            return false;
+        if (primary == null) {
+            if (other.primary != null)
+                return false;
+        } else if (!primary.equals(other.primary))
+            return false;
+        if (props == null) {
+            if (other.props != null)
+                return false;
+        } else if (!props.equals(other.props))
+            return false;
+        if (uuid == null) {
+            if (other.uuid != null)
+                return false;
+        } else if (!uuid.equals(other.uuid))
+            return false;
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return "DocViewNode [name=" + name + ", label=" + label + ", props=" + props + ",
uuid=" + uuid + ", mixins="
+                + Arrays.toString(mixins) + ", primary=" + primary + "]";
+    }
+
 }
\ No newline at end of file

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty.java?rev=1865971&r1=1865970&r2=1865971&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty.java
Tue Aug 27 06:26:36 2019
@@ -439,4 +439,47 @@ public class DocViewProperty {
         return false;
     }
 
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + (isMulti ? 1231 : 1237);
+        result = prime * result + (isReferenceProperty ? 1231 : 1237);
+        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        result = prime * result + type;
+        result = prime * result + Arrays.hashCode(values);
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        DocViewProperty other = (DocViewProperty) obj;
+        if (isMulti != other.isMulti)
+            return false;
+        if (isReferenceProperty != other.isReferenceProperty)
+            return false;
+        if (name == null) {
+            if (other.name != null)
+                return false;
+        } else if (!name.equals(other.name))
+            return false;
+        if (type != other.type)
+            return false;
+        if (!Arrays.equals(values, other.values))
+            return false;
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return "DocViewProperty [name=" + name + ", values=" + Arrays.toString(values) +
", isMulti=" + isMulti + ", type=" + type
+                + ", isReferenceProperty=" + isReferenceProperty + "]";
+    }
+
 }
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewNodeTest.java?rev=1865971&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewNodeTest.java
(added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewNodeTest.java
Tue Aug 27 06:26:36 2019
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.PropertyType;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DocViewNodeTest {
+
+    @Test
+    public void testEquals() throws NamespaceException {
+        Map<String, DocViewProperty> properties1 = new HashMap<>();
+        properties1.put("property1", new DocViewProperty("property1", new String[] {"value1"},
false, PropertyType.STRING));
+        DocViewNode node1 = new DocViewNode("name", "label", "uuid1", properties1, new String[]
{ "mixin1", "mixin2" }, "primary");
+        DocViewNode node2 = new DocViewNode("name", "label", "uuid1", properties1, new String[]
{ "mixin1", "mixin2" }, "primary");
+        Assert.assertEquals(node1, node2);
+        DocViewNode node3 = new DocViewNode("name", "label", "uuid1", properties1, new String[]
{ "mixin1", "mixin3" }, "primary");
+        Assert.assertNotEquals(node1, node3);
+    }
+}

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java?rev=1865971&r1=1865970&r2=1865971&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java
Tue Aug 27 06:26:36 2019
@@ -22,31 +22,45 @@ import javax.jcr.PropertyType;
 import javax.jcr.Value;
 import javax.jcr.nodetype.PropertyDefinition;
 
-import org.apache.jackrabbit.util.Text;
+import org.junit.Assert;
+import org.junit.Test;
 import org.mockito.Mockito;
 
-import junit.framework.TestCase;
 
 /**
  * {@code DocViewPropertyTest}...
  */
-public class DocViewPropertyTest extends TestCase {
+public class DocViewPropertyTest {
 
+    @Test
     public void testParseUndefined() {
         DocViewProperty p = DocViewProperty.parse("foo", "hello");
-        assertEquals(p, false, PropertyType.UNDEFINED, "hello");
+        Assert.assertEquals(new DocViewProperty("foo", new String[] {"hello"}, false, PropertyType.UNDEFINED),
p);
     }
 
+    @Test
     public void testParseLong() {
         DocViewProperty p = DocViewProperty.parse("foo", "{Long}1234");
-        assertEquals(p, false, PropertyType.LONG, "1234");
+        Assert.assertEquals(new DocViewProperty("foo", new String[] {"1234"}, false, PropertyType.LONG),
p);
     }
 
+    @Test
+    public void testEquals() {
+        DocViewProperty p1 = DocViewProperty.parse("foo", "{Long}1234");
+        DocViewProperty p2 = DocViewProperty.parse("foo", "{Long}1234");
+        Assert.assertEquals(p1, p2);
+        DocViewProperty p3 = DocViewProperty.parse("foo", "{String}1234");
+        Assert.assertNotEquals(p1, p3);
+    }
+
+    @Test
     public void testParseEmpty() {
         DocViewProperty p = DocViewProperty.parse("foo", "{Binary}");
-        assertEquals(p, false, PropertyType.BINARY, "");
+        Assert.assertEquals(new DocViewProperty("foo", new String[] { ""}, false, PropertyType.BINARY),
p);
     }
 
+    
+    @Test
     public void testParseSpecial() {
         DocViewProperty p = DocViewProperty.parse("foo", "\\{hello, world}");
         assertEquals(p, false, PropertyType.UNDEFINED, "{hello, world}");
@@ -54,16 +68,19 @@ public class DocViewPropertyTest extends
         assertEquals(p, false, PropertyType.STRING, "[hello");
     }
 
+    @Test
     public void testParseStringTyped() {
         DocViewProperty p = DocViewProperty.parse("foo", "{String}hello");
         assertEquals(p, false, PropertyType.STRING, "hello");
     }
 
+    @Test
     public void testParseStringUnicode() {
         DocViewProperty p = DocViewProperty.parse("foo", "{String}he\\u000fllo");
         assertEquals(p, false, PropertyType.STRING, "he\u000fllo");
     }
 
+    @Test
     public void testParseMVString() {
         DocViewProperty p = DocViewProperty.parse("foo", "[hello,world]");
         assertEquals(p, true, PropertyType.UNDEFINED, "hello", "world");
@@ -71,6 +88,7 @@ public class DocViewPropertyTest extends
         assertEquals(p, true, PropertyType.UNDEFINED, "hello,world");
     }
 
+    @Test
     public void testParseEmptyMVStrings() {
         DocViewProperty p = DocViewProperty.parse("foo", "[,a,b,c]");
         assertEquals(p, true, PropertyType.UNDEFINED, "", "a", "b", "c");
@@ -80,6 +98,7 @@ public class DocViewPropertyTest extends
         assertEquals(p, true, PropertyType.UNDEFINED, "", "", "", "");
     }
 
+    @Test
     public void testParseMVSpecial() {
         DocViewProperty p = DocViewProperty.parse("foo", "[\\[hello,world]");
         assertEquals(p, true, PropertyType.UNDEFINED, "[hello", "world");
@@ -101,16 +120,19 @@ public class DocViewPropertyTest extends
         assertEquals(p, true, PropertyType.UNDEFINED, "/content/[a-z]{2,3}/[a-z]{2,3}(/.*)");
     }
 
+    @Test
     public void testParseMVLong() {
         DocViewProperty p = DocViewProperty.parse("foo", "{Long}[1,2]");
         assertEquals(p, true, PropertyType.LONG, "1", "2");
     }
 
+    @Test
     public void testParseMVLongEmpty() {
         DocViewProperty p = DocViewProperty.parse("foo", "{Long}[]");
         assertEquals(p, true, PropertyType.LONG);
     }
 
+    @Test
     public void testParseMVStringEmpty() {
         DocViewProperty p = DocViewProperty.parse("foo", "[]");
         assertEquals(p, true, PropertyType.UNDEFINED);
@@ -120,6 +142,7 @@ public class DocViewPropertyTest extends
      * Special test for mv properties with 1 empty string value (JCR-3661)
      * @throws Exception
      */
+    @Test
     public void testEmptyMVString() throws Exception {
         Property p = Mockito.mock(Property.class);
         Value value = Mockito.mock(Value.class);
@@ -135,13 +158,14 @@ public class DocViewPropertyTest extends
         Mockito.when(p.getDefinition()).thenReturn(pd);
 
         String result = DocViewProperty.format(p);
-        assertEquals("formatted property", "[\\0]", result);
+        Assert.assertEquals("formatted property", "[\\0]", result);
 
         // now round trip back
         DocViewProperty dp = DocViewProperty.parse("foo", result);
-        assertEquals(dp, true, PropertyType.UNDEFINED, "");
+        Assert.assertEquals(new DocViewProperty("foo", new String[] {""}, true, PropertyType.UNDEFINED),
dp);
     }
 
+    @Test
     public void testEmptyMVBoolean() throws Exception {
         Property p = Mockito.mock(Property.class);
         Value value = Mockito.mock(Value.class);
@@ -157,13 +181,14 @@ public class DocViewPropertyTest extends
         Mockito.when(p.getDefinition()).thenReturn(pd);
 
         String result = DocViewProperty.format(p);
-        assertEquals("formatted property", "{Boolean}[false]", result);
+        Assert.assertEquals("formatted property", "{Boolean}[false]", result);
 
         // now round trip back
         DocViewProperty dp = DocViewProperty.parse("foo", result);
-        assertEquals(dp, true, PropertyType.BOOLEAN, "false");
+        Assert.assertEquals(new DocViewProperty("foo", new String[] {"false"}, true, PropertyType.BOOLEAN),
dp);
     }
 
+    @Test
     public void testEscape() {
         assertEscaped("hello", "hello", false);
         assertEscaped("hello, world", "hello, world", false);
@@ -181,13 +206,11 @@ public class DocViewPropertyTest extends
     private void assertEscaped(String original, String expected, boolean multi) {
         StringBuffer buf = new StringBuffer();
         DocViewProperty.escape(buf, original, multi);
-        assertEquals(expected, buf.toString());
+        Assert.assertEquals(expected, buf.toString());
     }
 
-    private void assertEquals(DocViewProperty p, boolean m, int type, String ... values)
{
-        assertEquals("Multiple", m, p.isMulti);
-        assertEquals("Type", type, p.type);
-        assertEquals("Array Length", values.length, p.values.length);
-        assertEquals("Values", Text.implode(values, ","), Text.implode(p.values, ","));
+    private void assertEquals(DocViewProperty p, boolean multi, int type, String... values)
{
+        Assert.assertEquals(new DocViewProperty(p.name, values, multi, type), p);
     }
+
 }
\ No newline at end of file



Mime
View raw message