use of org.springframework.test.web.servlet.MvcResult in project rdbcache by rdbcache.
the class RdbcacheApisTest method delkey_post1.
@Test
public void delkey_post1() {
try {
Map<String, Object> data1 = null, data2 = null;
{
RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/rdbcache/v1/select/user_table?limit=3").accept(MediaType.APPLICATION_JSON);
ResultActions actions = mockMvc.perform(requestBuilder);
MvcResult result = actions.andReturn();
MockHttpServletResponse response = result.getResponse();
assertEquals(200, response.getStatus());
String body = response.getContentAsString();
// System.out.println(body);
Map<String, Object> map = Utils.toMap(body);
data1 = (Map<String, Object>) map.get("data");
assertNotNull(data1);
assertEquals(3, data1.size());
}
Set<String> keys = data1.keySet();
{
RequestBuilder requestBuilder = MockMvcRequestBuilders.post("/rdbcache/v1/delkey/").contentType(MediaType.APPLICATION_JSON).content(Utils.toJsonMap(keys)).accept(MediaType.APPLICATION_JSON);
ResultActions actions = mockMvc.perform(requestBuilder);
MvcResult result = actions.andReturn();
MockHttpServletResponse response = result.getResponse();
assertEquals(200, response.getStatus());
String body = response.getContentAsString();
System.out.println(body);
Map<String, Object> map = Utils.toMap(body);
assertNotNull(map.get("data"));
}
// allow time to synchronize data
try {
Thread.sleep(500);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
Map<String, Object> redis = MockRedis.getData();
for (String key : keys) {
assertFalse(AppCtx.getLocalCache().containsKey(key));
assertFalse(redis.containsKey(PropCfg.getHdataPrefix() + "::" + key));
Map<String, Object> rdchkeys = (Map<String, Object>) redis.get("rdchkeys::keyinfo");
assertFalse(rdchkeys.containsKey(key));
Optional<KvPair> optional = AppCtx.getKvPairRepo().findById(new KvIdType(key, "info"));
assertFalse(optional.isPresent());
}
} catch (Exception e) {
e.printStackTrace();
fail("caught an exception");
}
}
use of org.springframework.test.web.servlet.MvcResult in project rdbcache by rdbcache.
the class RdbcacheApisTest method delall_post1.
@Test
public void delall_post1() {
try {
Map<String, Object> data1 = null, data2 = null;
{
RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/rdbcache/v1/select/user_table?limit=3").accept(MediaType.APPLICATION_JSON);
ResultActions actions = mockMvc.perform(requestBuilder);
MvcResult result = actions.andReturn();
MockHttpServletResponse response = result.getResponse();
assertEquals(200, response.getStatus());
String body = response.getContentAsString();
// System.out.println(body);
Map<String, Object> map = Utils.toMap(body);
data1 = (Map<String, Object>) map.get("data");
assertNotNull(data1);
assertEquals(3, data1.size());
}
Set<String> keys = data1.keySet();
{
RequestBuilder requestBuilder = MockMvcRequestBuilders.post("/rdbcache/v1/delall/").contentType(MediaType.APPLICATION_JSON).content(Utils.toJsonMap(keys)).accept(MediaType.APPLICATION_JSON);
ResultActions actions = mockMvc.perform(requestBuilder);
MvcResult result = actions.andReturn();
MockHttpServletResponse response = result.getResponse();
assertEquals(200, response.getStatus());
String body = response.getContentAsString();
// System.out.println(body);
Map<String, Object> map = Utils.toMap(body);
assertNotNull(map.get("data"));
}
// allow time to synchronize data
try {
Thread.sleep(250);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
Map<String, Object> redis = MockRedis.getData();
// System.out.println(Utils.toJsonMap(redis));
int i = 1;
for (String key : keys) {
assertFalse(AppCtx.getLocalCache().containsKey(key));
assertFalse(redis.containsKey(PropCfg.getHdataPrefix() + "::" + key));
Map<String, Object> rdchkeys = (Map<String, Object>) redis.get("rdchkeys::keyinfo");
// System.out.println(Utils.toJsonMap(rdchkeys));
assertFalse(rdchkeys.containsKey(key));
Optional<KvPair> optional = AppCtx.getKvPairRepo().findById(new KvIdType(key, "info"));
assertFalse(optional.isPresent());
{
RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/rdbcache/v1/get/*/user_table?id=" + i++).accept(MediaType.APPLICATION_JSON);
ResultActions actions = mockMvc.perform(requestBuilder);
MvcResult result = actions.andReturn();
MockHttpServletResponse response = result.getResponse();
assertEquals(404, response.getStatus());
}
}
} catch (Exception e) {
e.printStackTrace();
fail("caught an exception");
}
}
use of org.springframework.test.web.servlet.MvcResult in project rdbcache by rdbcache.
the class RdbcacheApisTest method get_get2.
@Test
public void get_get2() {
try {
RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/rdbcache/v1/get/my-test-hash-key/user_table?id=2").accept(MediaType.APPLICATION_JSON);
ResultActions actions = mockMvc.perform(requestBuilder);
MvcResult result = actions.andReturn();
MockHttpServletResponse response = result.getResponse();
assertEquals(200, response.getStatus());
String body = response.getContentAsString();
// System.out.println(body);
Map<String, Object> map = Utils.toMap(body);
assertTrue(map.containsKey("timestamp"));
assertTrue(map.containsKey("duration"));
assertTrue(map.containsKey("key"));
assertTrue(map.containsKey("data"));
assertTrue(map.containsKey("trace_id"));
Map<String, Object> data = (Map<String, Object>) map.get("data");
assertTrue(data.size() > 0);
assertEquals("2", data.get("id").toString());
assertEquals("kevin@example.com", data.get("email").toString());
} catch (Exception e) {
e.printStackTrace();
fail("caught an exception");
}
}
use of org.springframework.test.web.servlet.MvcResult in project uhgroupings by uhawaii-system-its-ti-iam.
the class GroupingsRestControllerTest method rootTest.
@Test
@WithMockUhUser
public void rootTest() throws Exception {
MvcResult result = mockMvc.perform(get("/api/groupings/")).andExpect(status().isOk()).andReturn();
assertEquals("University of Hawaii Groupings API", result.getResponse().getContentAsString());
}
use of org.springframework.test.web.servlet.MvcResult in project uhgroupings by uhawaii-system-its-ti-iam.
the class TestGroupingsRestController method mapGrouping.
// /////////////////////////////////////////////////////////////////////
// MVC mapping
// ////////////////////////////////////////////////////////////////////
private Grouping mapGrouping(String groupingPath) throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
MvcResult result = mockMvc.perform(get("/api/groupings/" + groupingPath + "/grouping")).andExpect(status().isOk()).andReturn();
return objectMapper.readValue(result.getResponse().getContentAsByteArray(), Grouping.class);
}
Aggregations