[exo-jcr-commits] exo-jcr SVN: r4722 - in jcr/trunk/exo.jcr.component.webdav/src: test/java/org/exoplatform/services/jcr/webdav/command and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Aug 9 10:09:18 EDT 2011
Author: dkuleshov
Date: 2011-08-09 10:09:17 -0400 (Tue, 09 Aug 2011)
New Revision: 4722
Modified:
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/resource/FileResource.java
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java
jcr/trunk/exo.jcr.component.webdav/src/test/resources/conf/test/webdav-nodetypes.xml
Log:
EXOJCR-1457: fixed empty multi-valued property processing for PROPFIND requests
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/resource/FileResource.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/resource/FileResource.java 2011-08-09 14:08:31 UTC (rev 4721)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/resource/FileResource.java 2011-08-09 14:09:17 UTC (rev 4722)
@@ -329,7 +329,18 @@
String propertyValue;
if (property.getDefinition().isMultiple())
{
- propertyValue = property.getValues()[0].getString();
+ if (property.getValues().length >= 1)
+ {
+ propertyValue = property.getValues()[0].getString();
+ }
+ else
+ {
+ // this means that we return empty value, because according to WebDAV spec:
+ // this is a property whose semantics and syntax are not enforced by the server
+ // the server only records the value of a dead property;
+ // the client is responsible for maintaining the consistency of the syntax and semantics of a dead property.
+ propertyValue = "";
+ }
}
else
{
@@ -337,7 +348,6 @@
}
return new HierarchicalProperty(name, propertyValue);
}
-
}
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java 2011-08-09 14:08:31 UTC (rev 4721)
+++ jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java 2011-08-09 14:09:17 UTC (rev 4722)
@@ -61,23 +61,33 @@
protected Node testPropFind;
- private final String author = "eXoPlatform";
+ private final static String AUTHOR = "eXoPlatform";
+
+ private final static String WEBDAV_AUTHOR_PROPERTY = "webdav:Author";
+
+ private final static String WEBDAV_NT_FILE = "webdav:file";
+
+ private final static String WEBDAV_NT_RESOURCE = "exo:testResource";
- private final String authorProp = "webdav:Author";
+ private final static String WEBDAV_TEST_PROPERTY = "webdav:test-property";
- private final String nt_webdave_file = "webdav:file";
+ private final static String CONTENT_TYPE = "text/xml";
- private final String USER_ROOT = "root";
+ private final static String USER_ROOT = "root";
- private final String USER_JOHN = "john";
+ private final static String USER_JOHN = "john";
- private final String BASE_URI = "http://localhost";
+ private final static String BASE_URI = "http://localhost";
private String propFindXML =
"<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:propfind xmlns:D=\"DAV:\">"
+ "<D:prop xmlns:webdav=\"http://www.exoplatform.org/jcr/webdav\">"
+ "<webdav:Author/><webdav:author/><webdave:DingALing/></D:prop></D:propfind>";
+ private String multiPropFindXML = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:propfind xmlns:D=\"DAV:\">"
+ + "<D:prop xmlns:webdav=\"http://www.exoplatform.org/jcr/webdav\">" + "<" + WEBDAV_TEST_PROPERTY
+ + "/></D:prop></D:propfind>";
+
private String propnameXML =
"<?xml version=\"1.0\" encoding=\"utf-8\" ?><propfind xmlns=\"DAV:\"><propname/></propfind>";
@@ -121,7 +131,7 @@
{
String content = TestUtils.getFileContent();
String file = TestUtils.getFileName();
- TestUtils.addContent(session, file, new ByteArrayInputStream(content.getBytes()), nt_webdave_file, "");
+ TestUtils.addContent(session, file, new ByteArrayInputStream(content.getBytes()), WEBDAV_NT_FILE, "");
ContainerResponse containerResponseFind = service(WebDAVMethods.PROPFIND, getPathWS() + file, "", null, null);
assertEquals(HTTPStatus.MULTISTATUS, containerResponseFind.getStatus());
}
@@ -140,8 +150,8 @@
String encodedfileName = "%e3%81%82%e3%81%84%e3%81%86%e3%81%88%e3%81%8a";
String decodedfileName = URLDecoder.decode(encodedfileName, "UTF-8");
String content = TestUtils.getFileContent();
- TestUtils.addContent(session, decodedfileName, new ByteArrayInputStream(content.getBytes()), nt_webdave_file, "");
- TestUtils.addNodeProperty(session, decodedfileName, authorProp, author);
+ TestUtils.addContent(session, decodedfileName, new ByteArrayInputStream(content.getBytes()), WEBDAV_NT_FILE, "");
+ TestUtils.addNodeProperty(session, decodedfileName, WEBDAV_AUTHOR_PROPERTY, AUTHOR);
ContainerResponse response =
service(WebDAVMethods.PROPFIND, getPathWS() + "/" + encodedfileName, "", null, allPropsXML.getBytes());
@@ -166,8 +176,8 @@
{
String content = TestUtils.getFileContent();
String file = TestUtils.getFileName();
- TestUtils.addContent(session, file, new ByteArrayInputStream(content.getBytes()), nt_webdave_file, "");
- TestUtils.addNodeProperty(session, file, authorProp, author);
+ TestUtils.addContent(session, file, new ByteArrayInputStream(content.getBytes()), WEBDAV_NT_FILE, "");
+ TestUtils.addNodeProperty(session, file, WEBDAV_AUTHOR_PROPERTY, AUTHOR);
MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
headers.add(HttpHeaders.CONTENT_TYPE, "text/xml");
ContainerResponse responseFind =
@@ -177,16 +187,87 @@
PropFindResponseEntity entity = (PropFindResponseEntity)responseFind.getEntity();
entity.write(outputStream);
String find = outputStream.toString();
- assertTrue(find.contains(authorProp));
- assertTrue(find.contains(author));
+ assertTrue(find.contains(WEBDAV_AUTHOR_PROPERTY));
+ assertTrue(find.contains(AUTHOR));
}
+ /**
+ * Here we test WebDAV PROPFIND method implementation for correct response
+ * in case we are asking for a multi-valued property. It is expected
+ * to receive first value of a values list. That is basicly because WebDAV
+ * actually does not support multi-valued properties in the way JCR does,
+ * though it supports nested (hierarchical) properties.
+ * @throws Exception
+ */
+ public void testNonEmptyMultiPropFind() throws Exception
+ {
+ String content = TestUtils.getFileContent();
+ String file = TestUtils.getFileName();
+ String[] propValues =
+ new String[]{"No sacrifice is too great in the service of freedom.",
+ "Freedom is the right of all sentient beings."};
+
+ Node node =
+ TestUtils.addContent(session, file, new ByteArrayInputStream(content.getBytes()), WEBDAV_NT_FILE,
+ WEBDAV_NT_RESOURCE, CONTENT_TYPE);
+
+ // set multi-valued property
+ node.getNode("jcr:content").setProperty(WEBDAV_TEST_PROPERTY, propValues);
+ session.save();
+
+ MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+ headers.add(HttpHeaders.CONTENT_TYPE, CONTENT_TYPE);
+
+ ContainerResponse responseFind =
+ service(WebDAVMethods.PROPFIND, getPathWS() + file, "", headers, multiPropFindXML.getBytes());
+ assertEquals(HTTPStatus.MULTISTATUS, responseFind.getStatus());
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ PropFindResponseEntity entity = (PropFindResponseEntity)responseFind.getEntity();
+ entity.write(outputStream);
+ String find = outputStream.toString();
+ assertTrue("Response should contain requested property element.", find.contains(WEBDAV_TEST_PROPERTY));
+ assertTrue("Property element should contain value data.",
+ find.contains("No sacrifice is too great in the service of freedom."));
+ }
+
+ /**
+ * Here we test WebDAV PROPFIND method implementation for correct response
+ * in case we are asking for an empty multi-valued property. It is expected
+ * to receive an empty value in response xml representation as it is 'dead'
+ * property and it is not a server responsibility to support its consistency.
+ * @throws Exception
+ */
+ public void testEmptyMultiPropFind() throws Exception
+ {
+ String content = TestUtils.getFileContent();
+ String file = TestUtils.getFileName();
+
+ Node node =
+ TestUtils.addContent(session, file, new ByteArrayInputStream(content.getBytes()), WEBDAV_NT_FILE,
+ WEBDAV_NT_RESOURCE, CONTENT_TYPE);
+ // set empty multi-valued property
+ node.getNode("jcr:content").setProperty(WEBDAV_TEST_PROPERTY, new String[]{});
+ session.save();
+
+ MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+ headers.add(HttpHeaders.CONTENT_TYPE, CONTENT_TYPE);
+
+ ContainerResponse responseFind =
+ service(WebDAVMethods.PROPFIND, getPathWS() + file, "", headers, multiPropFindXML.getBytes());
+ assertEquals(HTTPStatus.MULTISTATUS, responseFind.getStatus());
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ PropFindResponseEntity entity = (PropFindResponseEntity)responseFind.getEntity();
+ entity.write(outputStream);
+ String find = outputStream.toString();
+ assertTrue("Response should contain requested property element.", find.contains(WEBDAV_TEST_PROPERTY));
+ }
+
public void testPropNames() throws Exception
{
String content = TestUtils.getFileContent();
String file = TestUtils.getFileName();
- TestUtils.addContent(session, file, new ByteArrayInputStream(content.getBytes()), nt_webdave_file, "");
- TestUtils.addNodeProperty(session, file, authorProp, author);
+ TestUtils.addContent(session, file, new ByteArrayInputStream(content.getBytes()), WEBDAV_NT_FILE, "");
+ TestUtils.addNodeProperty(session, file, WEBDAV_AUTHOR_PROPERTY, AUTHOR);
ContainerResponse responseFind =
service(WebDAVMethods.PROPFIND, getPathWS() + file, "", null, propnameXML.getBytes());
assertEquals(HTTPStatus.MULTISTATUS, responseFind.getStatus());
@@ -194,7 +275,7 @@
PropFindResponseEntity entity = (PropFindResponseEntity)responseFind.getEntity();
entity.write(outputStream);
String find = outputStream.toString();
- assertTrue(find.contains(authorProp));
+ assertTrue(find.contains(WEBDAV_AUTHOR_PROPERTY));
assertTrue(find.contains("D:getlastmodified"));
assertFalse(find.contains("jcr:lockOwner"));
assertFalse(find.contains("D:lockdiscovery"));
@@ -204,8 +285,8 @@
{
String content = TestUtils.getFileContent();
String file = TestUtils.getFileName();
- TestUtils.addContent(session, file, new ByteArrayInputStream(content.getBytes()), nt_webdave_file, "");
- TestUtils.addNodeProperty(session, file, authorProp, author);
+ TestUtils.addContent(session, file, new ByteArrayInputStream(content.getBytes()), WEBDAV_NT_FILE, "");
+ TestUtils.addNodeProperty(session, file, WEBDAV_AUTHOR_PROPERTY, AUTHOR);
ContainerResponse responseFind =
service(WebDAVMethods.PROPFIND, getPathWS() + file, "", null, allPropsXML.getBytes());
assertEquals(HTTPStatus.MULTISTATUS, responseFind.getStatus());
@@ -214,8 +295,8 @@
entity.write(outputStream);
String find = outputStream.toString();
assertTrue(find.contains("D:getlastmodified"));
- assertTrue(find.contains(authorProp));
- assertTrue(find.contains(author));
+ assertTrue(find.contains(WEBDAV_AUTHOR_PROPERTY));
+ assertTrue(find.contains(AUTHOR));
}
public void testAllPropsWithInclusion() throws Exception
@@ -224,7 +305,7 @@
String content = TestUtils.getFileContent();
String file = TestUtils.getFileName();
Node node =
- TestUtils.addContent(session, file, new ByteArrayInputStream(content.getBytes()), nt_webdave_file, "");
+ TestUtils.addContent(session, file, new ByteArrayInputStream(content.getBytes()), WEBDAV_NT_FILE, "");
node.addMixin("mix:lockable");
node.save();
@@ -282,9 +363,9 @@
{
String content = TestUtils.getFileContent();
String file = TestUtils.getFileName();
- TestUtils.addContent(session, file, new ByteArrayInputStream(content.getBytes()), nt_webdave_file, "");
+ TestUtils.addContent(session, file, new ByteArrayInputStream(content.getBytes()), WEBDAV_NT_FILE, "");
String authorValue = "bla % bla";
- TestUtils.addNodeProperty(session, file, authorProp, authorValue);
+ TestUtils.addNodeProperty(session, file, WEBDAV_AUTHOR_PROPERTY, authorValue);
ContainerResponse responseFind =
service(WebDAVMethods.PROPFIND, getPathWS() + file, "", null, allPropsXML.getBytes());
assertEquals(HTTPStatus.MULTISTATUS, responseFind.getStatus());
@@ -293,7 +374,7 @@
entity.write(outputStream);
String find = outputStream.toString();
assertTrue(find.contains("D:getlastmodified"));
- assertTrue(find.contains(authorProp));
+ assertTrue(find.contains(WEBDAV_AUTHOR_PROPERTY));
assertTrue(find.contains(authorValue));
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/test/resources/conf/test/webdav-nodetypes.xml
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/test/resources/conf/test/webdav-nodetypes.xml 2011-08-09 14:08:31 UTC (rev 4721)
+++ jcr/trunk/exo.jcr.component.webdav/src/test/resources/conf/test/webdav-nodetypes.xml 2011-08-09 14:09:17 UTC (rev 4722)
@@ -113,6 +113,18 @@
<supertype>nt:unstructured</supertype>
</supertypes>
+ <propertyDefinitions>
+ <propertyDefinition name="*" requiredType="undefined" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false"
+
+ multiple="false">
+ <valueConstraints />
+ </propertyDefinition>
+ <propertyDefinition name="webdav:test-property" requiredType="String" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false"
+ multiple="true">
+ <valueConstraints />
+ </propertyDefinition>
+ </propertyDefinitions>
+
</nodeType>
<nodeType name="exo:testContentResource" isMixin="false" hasOrderableChildNodes="true" primaryItemName="">
More information about the exo-jcr-commits
mailing list