changeset 74:19e278488b42

Added NetworkPutAttributeOperation
author one
date Tue, 15 Oct 2013 14:38:46 +0900
parents 9ab7d515e076
children 87ec5dd0dc27
files src/alice/jungle/operations/NetworkPutAttributeOperation.java src/test/alice/jungle/core/operations/NetworkAppendChildOperationTest.java src/test/alice/jungle/core/operations/NetworkDeleteAttributeOprationTest.java src/test/alice/jungle/core/operations/NetworkPutAttributeOperationTest.java
diffstat 4 files changed, 94 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/jungle/operations/NetworkPutAttributeOperation.java	Tue Oct 15 14:38:46 2013 +0900
@@ -0,0 +1,65 @@
+package alice.jungle.operations;
+
+import java.nio.ByteBuffer;
+
+import org.msgpack.annotation.Message;
+
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.PutAttribute;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
+@Message
+public class NetworkPutAttributeOperation  implements NodeOperation
+{
+/*
+ *	private final String key;
+ *	private final ByteBuffer value;
+ */
+	private String key;
+	private ByteBuffer value;
+	
+	public NetworkPutAttributeOperation()
+	{
+		key = null;
+		value = null;
+	}
+	
+	public NetworkPutAttributeOperation(String _key,ByteBuffer _value)
+	{
+		key = _key;
+		value = _value;
+	}
+	
+	@Override
+	public Command getCommand()
+	{
+		return Command.PUT_ATTRIBUTE;
+	}
+	
+	@Override
+	public <T extends EditableNode<T>> Either<Error, T> invoke(T _target)
+	{
+		PutAttribute putAttribute = new PutAttribute(key,value);
+		return putAttribute.edit(_target);
+	}
+
+	@Override
+	public int getPosition()
+	{
+		return -1;
+	}
+
+	@Override
+	public String getKey()
+	{
+		return key;
+	}
+
+	@Override
+	public ByteBuffer getValue()
+	{
+		return value;
+	}
+}
--- a/src/test/alice/jungle/core/operations/NetworkAppendChildOperationTest.java	Tue Oct 15 14:26:25 2013 +0900
+++ b/src/test/alice/jungle/core/operations/NetworkAppendChildOperationTest.java	Tue Oct 15 14:38:46 2013 +0900
@@ -21,6 +21,4 @@
 		assertEquals(op.getPosition(), mOp.getPosition());
 
 	}
-	
-	
 }
--- a/src/test/alice/jungle/core/operations/NetworkDeleteAttributeOprationTest.java	Tue Oct 15 14:26:25 2013 +0900
+++ b/src/test/alice/jungle/core/operations/NetworkDeleteAttributeOprationTest.java	Tue Oct 15 14:38:46 2013 +0900
@@ -16,7 +16,7 @@
 		Value v = msgpack.unconvert(op);
 		NetworkDeleteAttributeOperation mOp = msgpack.convert(v, NetworkDeleteAttributeOperation.class);
 		assertEquals(op.getCommand(), mOp.getCommand());
-		assertEquals(mOp.getKey(), "hoge");
+		assert(mOp.getKey().equals("hoge"));
 
 	}
 	
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/alice/jungle/core/operations/NetworkPutAttributeOperationTest.java	Tue Oct 15 14:38:46 2013 +0900
@@ -0,0 +1,28 @@
+package test.alice.jungle.core.operations;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.msgpack.MessagePack;
+import org.msgpack.type.Value;
+
+import alice.jungle.operations.NetworkAppendChildAtOperation;
+import alice.jungle.operations.NetworkPutAttributeOperation;
+import junit.framework.TestCase;
+
+public class NetworkPutAttributeOperationTest extends TestCase {
+	
+	public void testMsgpackConvert() throws IOException {
+		ByteBuffer value = ByteBuffer.allocate(16);
+		value.put( "fuga".getBytes());
+		NetworkPutAttributeOperation op = new NetworkPutAttributeOperation("hoge", value);
+		MessagePack msgpack = new MessagePack();
+		Value v = msgpack.unconvert(op);
+		NetworkPutAttributeOperation mOp = msgpack.convert(v, NetworkPutAttributeOperation.class);
+//		NodeOperation mOp = msgpack.convert(v, NodeOperation.class);
+		assertEquals(op.getCommand(), mOp.getCommand());
+		System.out.println(new String(op.getValue().array()));
+		assert((new String(op.getValue().array())).equals(new String(mOp.getValue().array())));
+	}
+
+}