package com.example.crystalgame.server.test.datawarehouse;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import com.example.crystalgame.library.data.HasID;
import com.example.crystalgame.library.util.RandomID;
import com.example.crystalgame.server.datawarehouse.ServerDataWarehouse;

public class ServerDataWarehouseTest {

	private class StringWithID implements HasID {
		
		private String id, value;
		
		public StringWithID(String value) {
			this.id = RandomID.getRandomId();
			this.value = value;
		}
		
		public String getValue() {
			return value;
		}

		@Override
		public String getID() {
			return id;
		}
		
	}
	
	private ServerDataWarehouse dw1;
	
	public ServerDataWarehouseTest() {
		
	}
	
	@Before
	public void setup() {
		String randomStamp = RandomID.getRandomId();
		dw1 = ServerDataWarehouse.getWarehouseForGroup("group1" + randomStamp);
	}
	
	@Test
	public void testPut() {
		StringWithID obj = new StringWithID("test test");
		assertNull("Data Warehouse 1 should be empty", dw1.get(StringWithID.class, obj.getID()));
		assertTrue("Put should be successful", dw1.put(StringWithID.class, obj));
	}

	@Test
	public void testGet() {
		StringWithID obj = new StringWithID("test test");
		dw1.put(StringWithID.class, obj);
		HasID _obj = dw1.get(StringWithID.class, obj.getID());
		assertNotNull("Data Warehouse 1 should not retur null", _obj);
		assertEquals("Returned object should have same ID", obj.getID(), _obj.getID());
		assertEquals("Returned object should have same value", obj.getValue(), ((StringWithID) _obj).getValue());
	}

	@Test
	public void testDelete() {
		StringWithID obj = new StringWithID("test test");
		dw1.put(StringWithID.class, obj);
		
		assertTrue("Data with key should not exist", dw1.delete(StringWithID.class, obj.getID()));
	}

	@Test
	public void testGetAll() {
		StringWithID obj = new StringWithID("test test");
		StringWithID obj2 = new StringWithID("test test");
		
		dw1.put(StringWithID.class, obj);
		dw1.put(StringWithID.class, obj2);
		
		assertEquals(2, dw1.getAll(StringWithID.class).size()); 
	}

}

@@ -184,24 +184,101 @@
 data.HasID;%0A
+import com.example.crystalgame.library.datawarehouse.DataWarehouseException;%0A
 import com.e
@@ -1056,16 +1056,25 @@
 test%22);%0A
+%09%09try %7B%0A%09
 %09%09assert
@@ -1155,24 +1155,25 @@
 etID()));%0A%09%09
+%09
 assertTrue(%22
@@ -1230,24 +1230,92 @@
 ass, obj));%0A
+%09%09%7D catch (DataWarehouseException e) %7B%0A%09%09%09fail(e.getMessage());%0A%09%09%7D%0A
 %09%7D%0A%0A%09@Test%0A%09
@@ -1382,32 +1382,41 @@
 D(%22test test%22);%0A
+%09%09try %7B%0A%09
 %09%09dw1.put(String
@@ -1435,16 +1435,17 @@
 , obj);%0A
+%09
 %09%09HasID 
@@ -1485,32 +1485,37 @@
 , obj.getID());%0A
+%09%09%09%0A%09
 %09%09assertNotNull(
@@ -1563,16 +1563,17 @@
  _obj);%0A
+%09
 %09%09assert
@@ -1646,16 +1646,17 @@
 tID());%0A
+%09
 %09%09assert
@@ -1751,24 +1751,92 @@
 etValue());%0A
+%09%09%7D catch (DataWarehouseException e) %7B%0A%09%09%09fail(e.getMessage());%0A%09%09%7D%0A
 %09%7D%0A%0A%09@Test%0A%09
@@ -1912,24 +1912,36 @@
 t test%22);%0A%09%09
+%0A%09%09try %7B%0A%09%09%09
 dw1.put(Stri
@@ -1960,26 +1960,24 @@
 ss, obj);%0A%09%09
-%0A%09
 %09assertTrue(
@@ -2056,16 +2056,84 @@
 ID()));%0A
+%09%09%7D catch (DataWarehouseException e) %7B%0A%09%09%09fail(e.getMessage());%0A%09%09%7D%0A
 %09%7D%0A%0A%09@Te
@@ -2271,16 +2271,25 @@
 t%22);%0A%09%09%0A
+%09%09try %7B%0A%09
 %09%09dw1.pu
@@ -2318,16 +2318,17 @@
 obj);%0A%09%09
+%09
 dw1.put(
@@ -2356,17 +2356,19 @@
 bj2);%0A%09%09
-%0A
+%09%0A%09
 %09%09assert
@@ -2416,16 +2416,83 @@
 size());
- 
+%0A%09%09%7D catch (DataWarehouseException e) %7B%0A%09%09%09fail(e.getMessage());%0A%09%09%7D
 %0A%09%7D%0A%0A%7D%0A

Update ServerDataWarehouseTest