Author: sdumitriu
Date: 2008-01-03 20:13:22 +0100 (Thu, 03 Jan 2008)
New Revision: 6616
Added:
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/impl/AttachmentAddOperation.java
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/impl/AttachmentDeleteOperation.java
xwiki-platform/core/trunk/xwiki-patchservice/src/test/java/org/xwiki/platform/AttachmentOperationsTest.java
Modified:
xwiki-platform/core/trunk/xwiki-patchservice/pom.xml
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/api/RWOperation.java
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/impl/AbstractOperationImpl.java
xwiki-platform/core/trunk/xwiki-patchservice/src/main/resources/META-INF/services/org.xwiki.platform.patchservice.api.RWOperation
xwiki-platform/core/trunk/xwiki-patchservice/src/test/java/org/xwiki/platform/CheckAllOperationsImplementedTest.java
Log:
XWIKI-1977: Create a patchservice data model
Added the implementatins for attachment operations.
All done.
Modified: xwiki-platform/core/trunk/xwiki-patchservice/pom.xml
===================================================================
--- xwiki-platform/core/trunk/xwiki-patchservice/pom.xml 2008-01-03
17:37:32 UTC (rev 6615)
+++ xwiki-platform/core/trunk/xwiki-patchservice/pom.xml 2008-01-03
19:13:22 UTC (rev 6616)
@@ -64,6 +64,16 @@
<version>2.8.1</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.2</version>
+ </dependency>
</dependencies>
<build>
<plugins>
Modified:
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/api/RWOperation.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/api/RWOperation.java
2008-01-03 17:37:32 UTC (rev 6615)
+++
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/api/RWOperation.java
2008-01-03 19:13:22 UTC (rev 6616)
@@ -47,7 +47,9 @@
Position position);
/* Operations affeting the attachments */
- boolean setAttachment(InputStream is);
+ boolean addAttachment(InputStream is, String filename, String author);
+
+ boolean setAttachment(InputStream is, String filename, String author);
boolean deleteAttachment(String name);
Modified:
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/impl/AbstractOperationImpl.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/impl/AbstractOperationImpl.java
2008-01-03 17:37:32 UTC (rev 6615)
+++
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/impl/AbstractOperationImpl.java
2008-01-03 19:13:22 UTC (rev 6616)
@@ -1,8 +1,11 @@
package org.xwiki.platform.patchservice.impl;
import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
import java.util.Map;
+import org.apache.commons.codec.binary.Base64;
+import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xwiki.platform.patchservice.api.Position;
@@ -38,12 +41,16 @@
public static final String ATTACHMENT_NODE_NAME = "attachment";
+ public static final String ATTACHMENT_FILANAME_ATTRIBUTE_NAME =
CLASS_NAME_ATTRIBUTE_NAME;
+
+ public static final String ATTACHMENT_AUTHOR_ATTRIBUTE_NAME = "author";
+
private String type;
/**
* [EMAIL PROTECTED]
*/
- public boolean addObject(String objectClass)
+ public boolean insert(String text, Position position)
{
return false;
}
@@ -51,8 +58,7 @@
/**
* [EMAIL PROTECTED]
*/
- public boolean createType(String className, String propertyName, String
propertyType,
- Map properties)
+ public boolean delete(String text, Position position)
{
return false;
}
@@ -60,7 +66,7 @@
/**
* [EMAIL PROTECTED]
*/
- public boolean delete(String text, Position position)
+ public boolean setProperty(String property, String value)
{
return false;
}
@@ -68,7 +74,8 @@
/**
* [EMAIL PROTECTED]
*/
- public boolean deleteAttachment(String name)
+ public boolean createType(String className, String propertyName, String
propertyType,
+ Map properties)
{
return false;
}
@@ -76,8 +83,7 @@
/**
* [EMAIL PROTECTED]
*/
- public boolean deleteFromProperty(String objectClass, int index, String
property,
- String text, Position position)
+ public boolean modifyType(String className, String propertyName, Map
properties)
{
return false;
}
@@ -85,7 +91,7 @@
/**
* [EMAIL PROTECTED]
*/
- public boolean deleteObject(String objectClass, int index)
+ public boolean deleteType(String className, String propertyName)
{
return false;
}
@@ -93,7 +99,7 @@
/**
* [EMAIL PROTECTED]
*/
- public boolean deleteType(String className, String propertyName)
+ public boolean addObject(String objectClass)
{
return false;
}
@@ -101,7 +107,7 @@
/**
* [EMAIL PROTECTED]
*/
- public boolean insert(String text, Position position)
+ public boolean deleteObject(String objectClass, int index)
{
return false;
}
@@ -109,6 +115,15 @@
/**
* [EMAIL PROTECTED]
*/
+ public boolean setObjectProperty(String objectClass, int index, String
propertyName,
+ String value)
+ {
+ return false;
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
public boolean insertInProperty(String objectClass, int index, String
property, String text,
Position position)
{
@@ -118,7 +133,8 @@
/**
* [EMAIL PROTECTED]
*/
- public boolean modifyType(String className, String propertyName, Map
properties)
+ public boolean deleteFromProperty(String objectClass, int index, String
property,
+ String text, Position position)
{
return false;
}
@@ -126,7 +142,7 @@
/**
* [EMAIL PROTECTED]
*/
- public boolean setAttachment(InputStream is)
+ public boolean addAttachment(InputStream is, String filename, String
author)
{
return false;
}
@@ -134,8 +150,7 @@
/**
* [EMAIL PROTECTED]
*/
- public boolean setObjectProperty(String objectClass, int index, String
propertyName,
- String value)
+ public boolean setAttachment(InputStream is, String filename, String
author)
{
return false;
}
@@ -143,7 +158,7 @@
/**
* [EMAIL PROTECTED]
*/
- public boolean setProperty(String property, String value)
+ public boolean deleteAttachment(String name)
{
return false;
}
@@ -289,6 +304,51 @@
return getClassNode(e).getAttribute(CLASS_NAME_ATTRIBUTE_NAME);
}
+ public Element createAttachmentNode(String filename, Document doc)
+ {
+ return createAttachmentNode(null, filename, null, doc);
+ }
+
+ public Element createAttachmentNode(byte[] content, String filename,
String author,
+ Document doc)
+ {
+ Element xmlNode = doc.createElement(ATTACHMENT_NODE_NAME);
+ xmlNode.setAttribute(ATTACHMENT_FILANAME_ATTRIBUTE_NAME, filename);
+ if (author != null) {
+ xmlNode.setAttribute(ATTACHMENT_AUTHOR_ATTRIBUTE_NAME, author);
+ }
+ if (content != null) {
+ xmlNode.setTextContent(new String(Base64.encodeBase64(content)));
+ }
+ return xmlNode;
+ }
+
+ public Element getAttachmentNode(Element e)
+ {
+ return (Element) e.getElementsByTagName(ATTACHMENT_NODE_NAME).item(0);
+ }
+
+ public byte[] getAttachmentContent(Element e)
+ {
+ try {
+ return
Base64.decodeBase64(getAttachmentNode(e).getTextContent().getBytes(
+ "ISO-8859-1"));
+ } catch (UnsupportedEncodingException e1) {
+ } catch (DOMException e1) {
+ }
+ return new byte[0];
+ }
+
+ public String getAttachmentFilename(Element e)
+ {
+ return
getAttachmentNode(e).getAttribute(ATTACHMENT_FILANAME_ATTRIBUTE_NAME);
+ }
+
+ public String getAttachmentAuthor(Element e)
+ {
+ return
getAttachmentNode(e).getAttribute(ATTACHMENT_AUTHOR_ATTRIBUTE_NAME);
+ }
+
public Position loadPositionNode(Element e) throws XWikiException
{
Position position = new PositionImpl();
Added:
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/impl/AttachmentAddOperation.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/impl/AttachmentAddOperation.java
(rev 0)
+++
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/impl/AttachmentAddOperation.java
2008-01-03 19:13:22 UTC (rev 6616)
@@ -0,0 +1,144 @@
+package org.xwiki.platform.patchservice.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Formatter;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xwiki.platform.patchservice.api.Operation;
+import org.xwiki.platform.patchservice.api.RWOperation;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.doc.XWikiAttachment;
+import com.xpn.xwiki.doc.XWikiDocument;
+
+public class AttachmentAddOperation extends AbstractOperationImpl implements
RWOperation
+{
+ private byte[] data;
+
+ private String filename;
+
+ private String author;
+
+ static {
+
OperationFactoryImpl.registerTypeProvider(Operation.TYPE_ATTACHMENT_ADD,
+ AttachmentAddOperation.class);
+
OperationFactoryImpl.registerTypeProvider(Operation.TYPE_ATTACHMENT_SET,
+ AttachmentAddOperation.class);
+ }
+
+ public AttachmentAddOperation()
+ {
+ this.setType(Operation.TYPE_ATTACHMENT_ADD);
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public void apply(XWikiDocument doc, XWikiContext context) throws
XWikiException
+ {
+ try {
+ XWikiAttachment attachment = doc.getAttachment(filename);
+ if (this.getType().equals(TYPE_ATTACHMENT_ADD)) {
+ if (attachment != null) {
+ throw new
XWikiException(XWikiException.MODULE_XWIKI_PLUGINS,
+ XWikiException.ERROR_XWIKI_UNKNOWN,
+ new Formatter().format(
+ "Cannot apply patch: Attachment already exists:
[%s]",
+ new Object[] {filename}).toString());
+ }
+ attachment = new XWikiAttachment();
+ }
+ doc.getAttachmentList().add(attachment);
+ attachment.setContent(data);
+ attachment.setFilename(filename);
+ attachment.setAuthor(author);
+ attachment.setDoc(doc);
+ } catch (Exception ex) {
+ throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS,
+ XWikiException.ERROR_XWIKI_UNKNOWN,
+ "Invalid attachment: " + this.filename);
+ }
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public boolean addAttachment(InputStream is, String filename, String
author)
+ {
+ this.setType(TYPE_ATTACHMENT_ADD);
+ try {
+ data = org.apache.commons.io.IOUtils.toByteArray(is);
+ this.filename = filename;
+ this.author = author;
+ } catch (IOException e) {
+ return false;
+ }
+ return true;
+ }
+
+ public boolean setAttachment(InputStream is, String filename, String
author)
+ {
+ if (!this.addAttachment(is, filename, author)) {
+ return false;
+ }
+ this.setType(TYPE_ATTACHMENT_SET);
+ return true;
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public void fromXml(Element e) throws XWikiException
+ {
+ this.setType(getOperationType(e));
+ this.data = getAttachmentContent(e);
+ this.filename = getAttachmentFilename(e);
+ this.author = getAttachmentAuthor(e);
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public Element toXml(Document doc) throws XWikiException
+ {
+ Element xmlNode = createOperationNode(doc);
+ xmlNode.appendChild(createAttachmentNode(data, filename, author, doc));
+ return xmlNode;
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public boolean equals(Object other)
+ {
+ try {
+ AttachmentAddOperation that = (AttachmentAddOperation) other;
+ return this.getType().equals(that.getType()) &&
this.filename.equals(that.filename)
+ && this.author.equals(that.author) &&
ArrayUtils.isEquals(this.data, that.data);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public int hashCode()
+ {
+ return new HashCodeBuilder(37,
41).append(this.getType()).append(this.filename).append(
+ this.author).append(this.data).toHashCode();
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public String toString()
+ {
+ return this.getType() + ": [" + this.filename + "] by [" + this.author
+ "]";
+ }
+}
Property changes on:
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/impl/AttachmentAddOperation.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added:
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/impl/AttachmentDeleteOperation.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/impl/AttachmentDeleteOperation.java
(rev 0)
+++
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/impl/AttachmentDeleteOperation.java
2008-01-03 19:13:22 UTC (rev 6616)
@@ -0,0 +1,108 @@
+package org.xwiki.platform.patchservice.impl;
+
+import java.util.Formatter;
+
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xwiki.platform.patchservice.api.Operation;
+import org.xwiki.platform.patchservice.api.RWOperation;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.doc.XWikiAttachment;
+import com.xpn.xwiki.doc.XWikiDocument;
+
+public class AttachmentDeleteOperation extends AbstractOperationImpl
implements RWOperation
+{
+ private String filename;
+
+ static {
+
OperationFactoryImpl.registerTypeProvider(Operation.TYPE_ATTACHMENT_DELETE,
+ AttachmentDeleteOperation.class);
+ }
+
+ public AttachmentDeleteOperation()
+ {
+ this.setType(Operation.TYPE_ATTACHMENT_DELETE);
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public void apply(XWikiDocument doc, XWikiContext context) throws
XWikiException
+ {
+ try {
+ XWikiAttachment attachment = doc.getAttachment(filename);
+ if (attachment == null) {
+ throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS,
+ XWikiException.ERROR_XWIKI_UNKNOWN,
+ new Formatter().format(
+ "Cannot apply patch: Attachment does not exists: [%s]",
+ new Object[] {filename}).toString());
+ }
+ doc.deleteAttachment(attachment, context);
+ } catch (Exception ex) {
+ throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS,
+ XWikiException.ERROR_XWIKI_UNKNOWN,
+ "Invalid attachment: " + this.filename);
+ }
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public boolean deleteAttachment(String filename)
+ {
+ this.filename = filename;
+ return true;
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public void fromXml(Element e) throws XWikiException
+ {
+ this.filename = getAttachmentFilename(e);
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public Element toXml(Document doc) throws XWikiException
+ {
+ Element xmlNode = createOperationNode(doc);
+ xmlNode.appendChild(createAttachmentNode(filename, doc));
+ return xmlNode;
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public boolean equals(Object other)
+ {
+ try {
+ AttachmentDeleteOperation that = (AttachmentDeleteOperation) other;
+ return this.getType().equals(that.getType()) &&
this.filename.equals(that.filename);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public int hashCode()
+ {
+ return new HashCodeBuilder(37,
41).append(this.getType()).append(this.filename)
+ .toHashCode();
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public String toString()
+ {
+ return this.getType() + ": [" + this.filename + "]";
+ }
+}
Property changes on:
xwiki-platform/core/trunk/xwiki-patchservice/src/main/java/org/xwiki/platform/patchservice/impl/AttachmentDeleteOperation.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified:
xwiki-platform/core/trunk/xwiki-patchservice/src/main/resources/META-INF/services/org.xwiki.platform.patchservice.api.RWOperation
===================================================================
---
xwiki-platform/core/trunk/xwiki-patchservice/src/main/resources/META-INF/services/org.xwiki.platform.patchservice.api.RWOperation
2008-01-03 17:37:32 UTC (rev 6615)
+++
xwiki-platform/core/trunk/xwiki-patchservice/src/main/resources/META-INF/services/org.xwiki.platform.patchservice.api.RWOperation
2008-01-03 19:13:22 UTC (rev 6616)
@@ -9,3 +9,5 @@
org.xwiki.platform.patchservice.impl.ObjectPropertySetOperation
org.xwiki.platform.patchservice.impl.ObjectPropertyInsertAtOperation
org.xwiki.platform.patchservice.impl.ObjectPropertyDeleteAtOperation
+org.xwiki.platform.patchservice.impl.AttachmentAddOperation
+org.xwiki.platform.patchservice.impl.AttachmentDeleteOperation
Added:
xwiki-platform/core/trunk/xwiki-patchservice/src/test/java/org/xwiki/platform/AttachmentOperationsTest.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-patchservice/src/test/java/org/xwiki/platform/AttachmentOperationsTest.java
(rev 0)
+++
xwiki-platform/core/trunk/xwiki-patchservice/src/test/java/org/xwiki/platform/AttachmentOperationsTest.java
2008-01-03 19:13:22 UTC (rev 6616)
@@ -0,0 +1,148 @@
+package org.xwiki.platform;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xwiki.platform.patchservice.api.Operation;
+import org.xwiki.platform.patchservice.api.RWOperation;
+import org.xwiki.platform.patchservice.impl.OperationFactoryImpl;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.doc.XWikiAttachment;
+import com.xpn.xwiki.doc.XWikiDocument;
+
+public class AttachmentOperationsTest extends TestCase
+{
+ Document domDoc;
+
+ XWikiDocument doc;
+
+ XWikiContext context;
+
+ InputStream helloContent;
+
+ protected void setUp()
+ {
+ try {
+ domDoc =
DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+ doc = new XWikiDocument();
+ context = new XWikiContext();
+ helloContent = new ByteArrayInputStream("hello".getBytes());
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void testApplyAttachmentAddOperation() throws XWikiException
+ {
+ RWOperation operation =
+
OperationFactoryImpl.getInstance().newOperation(RWOperation.TYPE_ATTACHMENT_ADD);
+ operation.addAttachment(helloContent, "file.txt", "XWiki.Admin");
+ assertNull(doc.getAttachment("file.txt"));
+ operation.apply(doc, context);
+ assertNotNull(doc.getAttachment("file.txt"));
+ assertTrue(ArrayUtils.isEquals("hello".getBytes(),
doc.getAttachment("file.txt")
+ .getContent(context)));
+ }
+
+ public void testApplyTwiceAttachmentAddOperation() throws XWikiException
+ {
+ RWOperation operation =
+
OperationFactoryImpl.getInstance().newOperation(RWOperation.TYPE_ATTACHMENT_ADD);
+ operation.addAttachment(helloContent, "file.txt", "XWiki.Admin");
+ assertNull(doc.getAttachment("file.txt"));
+ operation.apply(doc, context);
+ try {
+ operation.apply(doc, context);
+ assertTrue(false);
+ } catch (XWikiException ex) {
+ assertTrue(true);
+ }
+ }
+
+ public void testXmlRoundtripAttachmentAddOperation() throws XWikiException
+ {
+ RWOperation operation =
+
OperationFactoryImpl.getInstance().newOperation(RWOperation.TYPE_ATTACHMENT_ADD);
+ operation.addAttachment(helloContent, "file.txt", "XWiki.Admin");
+ Element e = operation.toXml(domDoc);
+ Operation loadedOperation =
OperationFactoryImpl.getInstance().loadOperation(e);
+ assertEquals(loadedOperation, operation);
+ }
+
+ public void testApplyAttachmentSetOperation() throws XWikiException
+ {
+ RWOperation operation =
+
OperationFactoryImpl.getInstance().newOperation(RWOperation.TYPE_ATTACHMENT_SET);
+ XWikiAttachment a = new XWikiAttachment(doc, "file.txt");
+ a.setContent("old hello".getBytes());
+ doc.getAttachmentList().add(a);
+ assertNotNull(doc.getAttachment("file.txt"));
+ operation.setAttachment(helloContent, "file.txt", "XWiki.Admin");
+ assertTrue(ArrayUtils.isEquals("old hello".getBytes(),
doc.getAttachment("file.txt")
+ .getContent(context)));
+ operation.apply(doc, context);
+ assertNotNull(doc.getAttachment("file.txt"));
+ assertTrue(ArrayUtils.isEquals("hello".getBytes(),
doc.getAttachment("file.txt")
+ .getContent(context)));
+ }
+
+ public void testApplyInvalidAttachmentSetOperation() throws XWikiException
+ {
+ RWOperation operation =
+
OperationFactoryImpl.getInstance().newOperation(RWOperation.TYPE_ATTACHMENT_SET);
+ operation.setAttachment(helloContent, "file.txt", "XWiki.Admin");
+ assertNull(doc.getAttachment("file.txt"));
+ try {
+ operation.apply(doc, context);
+ assertTrue(false);
+ } catch (XWikiException ex) {
+ assertTrue(true);
+ }
+ }
+
+ public void testXmlRoundtripAttachmentSetOperation() throws XWikiException
+ {
+ RWOperation operation =
+
OperationFactoryImpl.getInstance().newOperation(RWOperation.TYPE_ATTACHMENT_SET);
+ operation.setAttachment(helloContent, "file.txt", "XWiki.Admin");
+ Element e = operation.toXml(domDoc);
+ Operation loadedOperation =
OperationFactoryImpl.getInstance().loadOperation(e);
+ assertEquals(loadedOperation, operation);
+ }
+
+ // We can't easily test the attachment delete due to XWIKI-1982
+
+ public void testApplyInvalidAttachmentDeleteOperation() throws
XWikiException
+ {
+ RWOperation operation =
+
OperationFactoryImpl.getInstance().newOperation(RWOperation.TYPE_ATTACHMENT_DELETE);
+ operation.deleteAttachment("file.txt");
+ assertNull(doc.getAttachment("file.txt"));
+ try {
+ operation.apply(doc, context);
+ assertTrue(false);
+ } catch (XWikiException ex) {
+ assertTrue(true);
+ }
+ }
+
+ public void testXmlRoundtripAttachmentDeleteOperation() throws
XWikiException
+ {
+ RWOperation operation =
+
OperationFactoryImpl.getInstance().newOperation(RWOperation.TYPE_ATTACHMENT_DELETE);
+ operation.deleteAttachment("file.txt");
+ Element e = operation.toXml(domDoc);
+ Operation loadedOperation =
OperationFactoryImpl.getInstance().loadOperation(e);
+ assertEquals(loadedOperation, operation);
+ }
+}
Property changes on:
xwiki-platform/core/trunk/xwiki-patchservice/src/test/java/org/xwiki/platform/AttachmentOperationsTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified:
xwiki-platform/core/trunk/xwiki-patchservice/src/test/java/org/xwiki/platform/CheckAllOperationsImplementedTest.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-patchservice/src/test/java/org/xwiki/platform/CheckAllOperationsImplementedTest.java
2008-01-03 17:37:32 UTC (rev 6615)
+++
xwiki-platform/core/trunk/xwiki-patchservice/src/test/java/org/xwiki/platform/CheckAllOperationsImplementedTest.java
2008-01-03 19:13:22 UTC (rev 6616)
@@ -1,5 +1,6 @@
package org.xwiki.platform;
+import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -46,9 +47,9 @@
RWOperation.TYPE_OBJECT_PROPERTY_INSERT_AT));
assertNotNull(OperationFactoryImpl.getInstance().newOperation(
RWOperation.TYPE_OBJECT_PROPERTY_DELETE_AT));
+ assertNotNull(OperationFactoryImpl.getInstance().newOperation(
+ RWOperation.TYPE_ATTACHMENT_ADD));
// assertNotNull(OperationFactoryImpl.getInstance().newOperation(
- // RWOperation.TYPE_ATTACHMENT_ADD));
- // assertNotNull(OperationFactoryImpl.getInstance().newOperation(
// RWOperation.TYPE_ATTACHMENT_SET));
// assertNotNull(OperationFactoryImpl.getInstance().newOperation(
// RWOperation.TYPE_ATTACHMENT_DELETE));
@@ -121,6 +122,20 @@
root.appendChild(operation.toXml(doc));
root.appendChild(doc.createTextNode("\n"));
+ operation =
+ OperationFactoryImpl.getInstance().newOperation(
+ RWOperation.TYPE_OBJECT_PROPERTY_DELETE_AT);
+ operation.deleteFromProperty("XWiki.Class", 0, "property", "deleted
text",
+ new PositionImpl(2, 0));
+ root.appendChild(operation.toXml(doc));
+ root.appendChild(doc.createTextNode("\n"));
+
+ operation =
+
OperationFactoryImpl.getInstance().newOperation(RWOperation.TYPE_ATTACHMENT_ADD);
+ operation.addAttachment(new ByteArrayInputStream("hello".getBytes()),
"file", "XWiki.Me");
+ root.appendChild(operation.toXml(doc));
+ root.appendChild(doc.createTextNode("\n"));
+
DOMImplementationLS ls = (DOMImplementationLS) doc.getImplementation();
System.out.println(ls.createLSSerializer().writeToString(doc));
}
_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications