package riakBinding.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.HashMap;

import org.junit.BeforeClass;
import org.junit.Test;

import riakBinding.java.RiakClient;

import com.basho.riak.client.IRiakClient;
import com.basho.riak.client.RiakException;
import com.basho.riak.client.RiakFactory;
import com.basho.riak.client.raw.http.HTTPClientConfig;
import com.basho.riak.client.raw.http.HTTPClusterConfig;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.StringByteIterator;

public class TestRiakClient {

	private static RiakClient client;
	
	@BeforeClass
	public static void initializerClient() throws RiakException {
		String[] hosts = {"127.0.0.1:2222,127.0.0.1:3333"};
		HTTPClusterConfig clusterConfig = new HTTPClusterConfig(50);
		HTTPClientConfig httpClientConfig = HTTPClientConfig.defaults();
		clusterConfig.addHosts(httpClientConfig, hosts);
		IRiakClient riakClient = RiakFactory.newClient(clusterConfig);
		client = new RiakClient(riakClient);
	}
	
	@Test
	public void test(){
		// Initialize parameters
		String bucketName = "abucket";
		String keyInBucket = "aKey";
		String mapKey = "mapkey";
		String mapValue = "mapValue";
		// Insert operation
		HashMap<String, ByteIterator> map = new HashMap<String, ByteIterator>();
		map.put(mapKey, new StringByteIterator(mapValue));
		client.insert(bucketName, keyInBucket, map);
		// Read operation
		HashMap<String, ByteIterator> readMap = new HashMap<String, ByteIterator>();
		int success = client.read(bucketName, keyInBucket, null, readMap);
		// Assert reads
		assertTrue(success == 0);
		assertTrue(readMap.size() == 1);
		ByteIterator byteIterator = readMap.get(mapKey);
		assertEquals(byteIterator.toString(), mapValue);
		// Delete operation
		success = client.delete(bucketName, keyInBucket);
		// Assert deletion
		assertTrue(success == 0);
		success = client.read(bucketName, keyInBucket, null, new HashMap<String, ByteIterator>());
		assertTrue(success == -1);
	}
	
}

@@ -1363,24 +1363,38 @@
 pValue));%0A%09%09
+int success = 
 client.inser
@@ -1435,22 +1435,48 @@
 %09// 
-Read operation
+Assert reads%0A%09%09assertTrue(success == 0);
 %0A%09%09H
@@ -1549,28 +1549,24 @@
 rator%3E();%0A%09%09
-int 
 success = cl
@@ -1616,34 +1616,16 @@
 adMap);%0A
-%09%09// Assert reads%0A
 %09%09assert
@@ -1781,16 +1781,586 @@
 Value);%0A
+%09%09// Update operation%0A%09%09String updatedValue = %22updatedValue%22;%0A%09%09HashMap%3CString, ByteIterator%3E valuesToUpdate = new HashMap%3CString, ByteIterator%3E();%0A%09%09valuesToUpdate.put(mapKey, new StringByteIterator(updatedValue));%0A%09%09success = client.update(bucketName, keyInBucket, valuesToUpdate);%0A%09%09// Assert update%0A%09%09assertTrue(success == 0);%0A%09%09readMap = new HashMap%3CString, ByteIterator%3E();%0A%09%09success = client.read(bucketName, keyInBucket, null, readMap);%0A%09%09assertTrue(success == 0);%0A%09%09assertTrue(readMap.size() == 1);%0A%09%09assertEquals(readMap.get(mapKey).toString(), updatedValue);%0A
 %09%09// Del

Test added for update method