Commit 67634536 authored by Alexander Basov's avatar Alexander Basov Committed by Matija Obreza
Browse files

CacheControllerTest completed

parent cd29dcf0
package org.genesys2.tests.resttests;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
public class CacheControllerTest extends AbstractRestTest{
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@EnableCaching
public class CacheControllerTest extends AbstractRestTest {
private static final Log LOG = LogFactory.getLog(CacheControllerTest.class);
......@@ -20,22 +31,56 @@ public class CacheControllerTest extends AbstractRestTest{
MockMvc mockMvc;
@Before
public void setUp(){
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@After
public void tearDown(){
@Test
public void cacheStatsTest() throws Exception {
LOG.info("Start test-method cacheStatsTest");
mockMvc.perform(get("/api/v0/cache")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.cacheMaps", hasSize(greaterThan(0))))
.andExpect(jsonPath("$.cacheOther", hasSize(0)));
LOG.info("Test cacheStatsTest passed.");
}
@Ignore
@Test
public void cacheStatsTest(){
LOG.info("Start test-method cacheStatsTest");
public void clearTilesCacheTest() throws Exception {
LOG.info("Start test-method clearTilesCacheTest");
String JSON_OK = "{\"result\":true}";
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(JSON_OK);
mockMvc.perform(post("/api/v0/cache/clearTilesCache")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(content().string(objectMapper.writeValueAsString(jsonNode)));
LOG.info("Test cacheStatsTest passed.");
LOG.info("Test clearTilesCacheTest passed.");
}
@Test
public void clearCachesTest() throws Exception {
LOG.info("Start test-method clearCachesTest");
String JSON_OK = "{\"result\":true}";
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(JSON_OK);
mockMvc.perform(post("/api/v0/cache/clearCaches")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().string(objectMapper.writeValueAsString(jsonNode)));
LOG.info("Test clearCachesTest passed.");
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment