Updated reference and JSON support for GemfireTemplate queries
This commit is contained in:
@@ -52,7 +52,7 @@ public class GemfireTemplateTest {
|
||||
|
||||
private static final String SINGLE_QUERY = "(select * from /simple).size";
|
||||
|
||||
@Autowired GemfireTemplate template;
|
||||
@Autowired GemfireOperations template;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Before
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.data.gemfire.GemfireOperations;
|
||||
import org.springframework.data.gemfire.GemfireTemplate;
|
||||
|
||||
/**
|
||||
@@ -30,7 +31,7 @@ public class GemfireDaoSupportTests extends TestCase {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testGemfireDaoSupportWithTemplate() throws Exception {
|
||||
GemfireTemplate template = new GemfireTemplate();
|
||||
GemfireOperations template = new GemfireTemplate();
|
||||
final List test = new ArrayList();
|
||||
GemfireDaoSupport dao = new GemfireDaoSupport() {
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -24,14 +24,16 @@ import javax.annotation.Resource;
|
||||
|
||||
import org.codehaus.jackson.JsonGenerationException;
|
||||
import org.codehaus.jackson.map.JsonMappingException;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.gemfire.GemfireOperations;
|
||||
import org.springframework.data.gemfire.repository.sample.Person;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.query.SelectResults;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
@@ -40,17 +42,28 @@ import com.gemstone.gemfire.cache.Region;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class JSONRegionAdviceTest {
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Resource(name="someRegion")
|
||||
private Region region;
|
||||
|
||||
@Autowired
|
||||
GemfireOperations template;
|
||||
|
||||
@Test
|
||||
public void testPutString() {
|
||||
String json = "{\"hello\":\"world\"}";
|
||||
|
||||
region.put("key",json);
|
||||
Object result = region.put("key",json);
|
||||
assertEquals(json,result);
|
||||
|
||||
region.create("key2",json);
|
||||
|
||||
System.out.println(region.get("key"));
|
||||
assertEquals(json,region.get("key"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testPutAll() {
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
@@ -69,6 +82,32 @@ public class JSONRegionAdviceTest {
|
||||
region.put("dave",dave);
|
||||
String json = (String)region.get("dave");
|
||||
assertEquals(json,"{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}",json);
|
||||
Object result = region.put("dave",dave);
|
||||
assertEquals("{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}",result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemplateFindUnique() {
|
||||
Person dave = new Person(1L,"Dave","Turanski");
|
||||
region.put("dave",dave);
|
||||
String json = (String) template.findUnique("Select * from /someRegion where firstname=$1","Dave");
|
||||
assertEquals("{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}",json);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemplateFind() {
|
||||
Person dave = new Person(1L,"Dave","Turanski");
|
||||
region.put("dave",dave);
|
||||
SelectResults<String> results = template.find("Select * from /someRegion where firstname=$1","Dave");
|
||||
assertEquals("{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}",results.iterator().next());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemplateQuery() {
|
||||
Person dave = new Person(1L,"Dave","Turanski");
|
||||
region.put("dave",dave);
|
||||
SelectResults<String> results = template.query("firstname='Dave'");
|
||||
assertEquals("{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}",results.iterator().next());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user